-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
feat: add metrics to core-utils #503
Conversation
🦋 Changeset detectedLatest commit: c15a77a The changes in this PR will be included in the next version bump. This PR includes changesets to release 7 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
@gakonst i'll need to use the updated happy to open another PR on the README to document these necessary steps! |
export interface MetricsOptions { | ||
prefix: string | ||
labels?: Object | ||
} |
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.
@snario i based metrics.ts
off of logger.ts
and The Graph's Metrics. decided to keep it simple and not include passing in another registry as an option; lmk if you think that might be necessary for us though!
|
||
export interface MetricsOptions { | ||
prefix: string | ||
labels?: Object |
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.
Should this have a more specific type?
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.
prom-client makes it so that it's generic: https://github.com/siimon/prom-client/blame/master/README.md#L83-L91
i'm imagining adding environment as a label but not sure yet, can make an issue to make this type specific as we finalize labels, or remove until we start using labels - what do you think?
No need for you to do anything, once this PR is merged, you'll see that the |
Running this locally, I get:
|
last commit fixed the dtl build error cc @snario |
@@ -24,6 +26,7 @@ export class BaseService<T> { | |||
this.name = name | |||
this.options = mergeDefaultOptions(options, optionSettings) | |||
this.logger = new Logger({ name }) | |||
this.metrics = new Metrics({ prefix: name.split(' ').join('_') }) |
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.
Hm, this may be a bit annoying. Does the metrics client dislike spaces in service names? Perhaps we should refactor the BaseService
such that names cannot have spaces in them so that the logs and metrics use identical names.
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.
https://prometheus.io/docs/concepts/data_model/#metric-names-and-labels only underscores and colons 😬 honestly might be the move for cleanliness sake - thoughts on importing this validation and enforcing it? https://github.com/siimon/prom-client/blob/96f7495d66b1a21755f745b1367d3e530668a957/lib/validation.js#L5-L11 or should our validation be looser?
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.
just renamed everything without adding the validation since we will get the error on metrics initialization
The failure was due to not renaming message relayer metric, which resulted in the message relayer not being brought up. Fixed in c15a77a |
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.
LGTM
I've removed myself as a core-utils CODEOWNER for the time being. |
Description
We want to be collecting metrics in our TypeScript services. This PR adds a Metrics class to core-utils and uses it in base-service.
Additional context
The metrics class will be used to collect metrics in batch-submitter and data-transport-layer.