Skip to content
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

Merged
merged 7 commits into from
Apr 21, 2021
Merged

feat: add metrics to core-utils #503

merged 7 commits into from
Apr 21, 2021

Conversation

annieke
Copy link
Contributor

@annieke annieke commented Apr 20, 2021

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.

@changeset-bot
Copy link

changeset-bot bot commented Apr 20, 2021

🦋 Changeset detected

Latest commit: c15a77a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 7 packages
Name Type
@eth-optimism/core-utils Minor
@eth-optimism/data-transport-layer Minor
@eth-optimism/batch-submitter Patch
@eth-optimism/contracts Patch
@eth-optimism/message-relayer Patch
@eth-optimism/smock Patch

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

@annieke annieke requested a review from snario April 20, 2021 01:20
@annieke
Copy link
Contributor Author

annieke commented Apr 20, 2021

@gakonst i'll need to use the updated core-utils package in batch-submitter and data-transport-layer, do i need to do anything else besides add the changeset for a new version of core-utils to be published? or can i just use master when it's merged?

happy to open another PR on the README to document these necessary steps!

Comment on lines +7 to +10
export interface MetricsOptions {
prefix: string
labels?: Object
}
Copy link
Contributor Author

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
Copy link
Contributor

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?

Copy link
Contributor Author

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?

@gakonst
Copy link
Contributor

gakonst commented Apr 20, 2021

@gakonst i'll need to use the updated core-utils package in batch-submitter and data-transport-layer, do i need to do anything else besides add the changeset for a new version of core-utils to be published? or can i just use master when it's merged?

No need for you to do anything, once this PR is merged, you'll see that the Version Packages PR will be updated with the changes from this PR's changeset!

@gakonst
Copy link
Contributor

gakonst commented Apr 20, 2021

Running this locally, I get:

dtl_1              | Well, that's that. We ran into a fatal error. Here's the dump. Goodbye!
dtl_1              | (node:1) UnhandledPromiseRejectionWarning: Error: Invalid metric name
dtl_1              |     at new Metric (/opt/optimism/node_modules/prom-client/lib/metric.js:36:10)
dtl_1              |     at new Counter (/opt/optimism/node_modules/prom-client/lib/counter.js:12:1)
dtl_1              |     at module.exports (/opt/optimism/node_modules/prom-client/lib/metrics/processCpuTotal.js:16:30)
dtl_1              |     at Object.collectDefaultMetrics (/opt/optimism/node_modules/prom-client/lib/defaultMetrics.js:43:3)
dtl_1              |     at new Metrics (/opt/optimism/packages/core-utils/src/common/metrics.ts:29:5)
dtl_1              |     at new BaseService (/opt/optimism/packages/core-utils/src/base-service.ts:29:20)
dtl_1              |     at new L1DataTransportService (/opt/optimism/packages/data-transport-layer/src/services/main/service.ts:47:5)
dtl_1              |     at /opt/optimism/packages/data-transport-layer/src/services/run.ts:25:21
dtl_1              |     at Object.<anonymous> (/opt/optimism/packages/data-transport-layer/src/services/run.ts:63:3)
dtl_1              |     at Module._compile (internal/modules/cjs/loader.js:1063:30)
dtl_1              |     at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
dtl_1              |     at Module.load (internal/modules/cjs/loader.js:928:32)
dtl_1              |     at Function.Module._load (internal/modules/cjs/loader.js:769:14)
dtl_1              |     at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
dtl_1              |     at internal/main/run_main_module.js:17:47

@annieke
Copy link
Contributor Author

annieke commented Apr 20, 2021

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('_') })
Copy link
Contributor

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.

Copy link
Contributor Author

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?

Copy link
Contributor Author

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

@annieke annieke changed the title feat: add metrics to core-utils feat: add metrics to core-utils and use in services Apr 21, 2021
@annieke annieke changed the title feat: add metrics to core-utils and use in services feat: add metrics to core-utils Apr 21, 2021
@snario
Copy link
Contributor

snario commented Apr 21, 2021

Latest integration job is failing, seems to be the #430?

@annieke annieke requested a review from K-Ho as a code owner April 21, 2021 12:22
@gakonst
Copy link
Contributor

gakonst commented Apr 21, 2021

The failure was due to not renaming message relayer metric, which resulted in the message relayer not being brought up. Fixed in c15a77a

Copy link
Contributor

@gakonst gakonst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@maurelian maurelian removed their request for review April 21, 2021 15:11
@maurelian
Copy link
Contributor

I've removed myself as a core-utils CODEOWNER for the time being.

@snario snario merged commit f950b71 into master Apr 21, 2021
@snario snario deleted the feat/prom-client branch April 21, 2021 15:38
bap2pecs added a commit to babylonlabs-io/optimism that referenced this pull request Jul 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants