Repository navigation
Add support for default labels - #137
Conversation
There was a problem hiding this comment.
Oooh, I like this! I thought about tying them to the default metrics, but tying them to the register itself makes a lot more sense! I started on an implementation at work today, but I much prefer this version to what I had going on.
The only thing missing is also passing on default metrics when merging registries (the static merge function). And please update the changelog as well.
Other than that, this looks great!
| process_resident_memory_bytes{serviceName="api-v1"} 33853440 1498510040309 | ||
| ``` | ||
|
|
||
| Default metrics will be overridden if there is a name conflict. |
There was a problem hiding this comment.
"labels", not "metrics", right?
| key => `${key}="${escapeLabelValue(val.labels[key])}"` | ||
| ); | ||
|
|
||
| labels = Object.assign(this._defaultLabels, labels); |
There was a problem hiding this comment.
not sure Object.assign makes sense here, they are arrays not objects. should be this._defaultLables.concat(labels). Unsure how to handle dupes, though? I can see from the tests that it works, but it feels weird to me
There was a problem hiding this comment.
if you keep _defaultLabels as an object internally, then do Object.assign before the map?
|
Thanks for the feedback! Glad you like it. How should the Edit:
|
|
Not sure if I did the type def'n correctly. Let me know if there's anything else 😄 |
|
Looks good! If you rebase on master the build should be green again |
| Static labels may be applied to every metric emitted by a registry: | ||
| ```js | ||
| var client = require('prom-client'); | ||
| var defaultLabels = { serviceName: "api-v1"}; |
There was a problem hiding this comment.
this has inconsistent spacing
|
I'm still getting local npm test failures - |
|
Have you ran |
|
Oops! That did it. Thanks. |
|
I like the idea tying it together with the registry, that makes sense I think. One thought I had earlier was to instead of providing an object which is the default labels, you could instead provide a function that in turn returns an object which is the default labels. That would make it more flexible and more powerful, however the api might be a bit more complex. |
|
What's the use case for a function? When would you want to use it? |
|
Functional options are a great pattern to allow for expanding an API without breaking it. It would require some rework for sure. This is for golang, but I think the pattern still applies to js: |
|
I have no strong feeling either way. Doing While I get the general argument "it's more extensible", I don't get what it would give default metrics. Would it receive the metric as an argument? Still, I don't see what you could really do with it. |
|
I'll let you guys decide how you'd like to do this. |
|
Well, it's probably bait YAGNI, so lets keep it as it is and if we find another use case where a function is better we could probably live with both versions for awhile.. |
I believe this is a pretty good solution for #83
It's simple, doesn't break any APIs, allows you to configure static labels per registry, and defaulted values can be overridden.
Let me know if this wasn't what you were thinking about this, or if there are any styling considerations I should be changing.
Thanks!