-
Notifications
You must be signed in to change notification settings - Fork 543
runtimes/js: add support for custom metrics #2128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: fredr/ts-metrics
Are you sure you want to change the base?
Conversation
|
All committers have signed the CLA. |
f68e437 to
72f6462
Compare
72f6462 to
1efb0bd
Compare
| const metricsBuffer = __internalInitGlobalMetricsBuffer(); | ||
| const extraWorkers = runtime.RT.numWorkerThreads() - 1; | ||
| if (extraWorkers > 0) { | ||
| log.debug(`Starting ${extraWorkers} worker threads`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Intended? Remove?
| * export const OrdersProcessed = new CounterGroup<Labels>("orders_processed"); | ||
| * | ||
| * OrdersProcessed.with({ success: true }).increment(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| * export const OrdersProcessed = new CounterGroup<Labels>("orders_processed"); | |
| * | |
| * OrdersProcessed.with({ success: true }).increment(); | |
| * export const ordersProcessed = new CounterGroup<Labels>("orders_processed"); | |
| * | |
| * ordersProcessed.with({ success: true }).increment(); |
| * export const OrdersProcessed = new Counter("orders_processed"); | ||
| * | ||
| * OrdersProcessed.increment(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| * export const OrdersProcessed = new Counter("orders_processed"); | |
| * | |
| * OrdersProcessed.increment(); | |
| * export const ordersProcessed = new Counter("orders_processed"); | |
| * | |
| * ordersProcessed.increment(); |
| * Called during encores initialization | ||
| * @internal | ||
| */ | ||
| export function __internalSetGlobalMetricsBuffer( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to export this here? Could we put it in an internal/ folder?
| * | ||
| * Note: Number values in labels are converted to integers using Math.floor(). | ||
| */ | ||
| with(labels: L): AtomicCounter | NoOpCounter { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need this return type? Or could we always return a Counter so the user doesn't need to care about the difference? For other resources we've separated the underlying implementation into an impl field so we could do like:
const impl = new NoOpCounterImpl();
return new Counter(impl);or something like that. Maybe a bit tricky to do since it would require a private constructor?
Adds support for creating custom metrics in typescript apps. Depends on #2109
Inspired by the implementation in the go runtime.
Metrics needs to be defined within a service, and will automatically add the service label.
This implementation is backed by a SharedArrayBuffer, where each u64 slot is a metric value, created from js by the main thread. From js we do atomic operation to update values on this buffer, and from rust we do atomic load when collecting the metrics. The rust runtime is use to coordinate what slot should be used for a label set, so that we can support multiple workers updating the same metric.