-
Notifications
You must be signed in to change notification settings - Fork 378
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
improve performance of registry.metrics() #373
Conversation
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.
Thanks for rebasing and for your patience! Much easier to review now.
My two main concerns are ⭐'ed.
const name = metric.name; | ||
const help = escapeString(metric.help); | ||
const type = metric.type; | ||
const labelsCode = getLabelsCode(metric, defaultLabelNames, defaultLabels); |
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.
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.
Can you clarify what do you mean? Should I rewrite it or implement inside generated function?
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.
@zbjornson can you take a look on this?
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.
Thanks for the nudge, will review this PR this weekend.
On this particular comment: I'd (strongly) lean toward making the formatter work with dynamically declared labels. #298 has quite a bit of support so I suspect #368 will land. The main (probably minor) thing holding it up is #298 (comment).
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.
This eliminate the main idea of formatter
- build labels string once.
I need to think how to rewrite this.
function getLabelsCode(metric, defaultLabelNames, defaultLabels) { | ||
let labelString = ''; | ||
const labelNames = getLabelNames(metric, defaultLabelNames); | ||
for (let index = 0; index < labelNames.length; index++) { |
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.
⭐ It's valid to only set values for a subset of labels when a metric is updated. With this test:
it('should allow subsetse of labels', () => {
instance = new Gauge({
name: 'name_2',
help: 'help',
labelNames: ['code', 'success'],
});
instance.inc({ code: '200' }, 10);
const str = globalRegistry.getSingleMetricAsString('name_2');
console.log(str);
});
in this PR, you get
# HELP name_2 help
# TYPE name_2 gauge
name_2{code="200",success="undefined"} 10
whereas in master, you get
# HELP name_2 help
# TYPE name_2 gauge
name_2{code="200"} 10
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 add this as a test, no?
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.
Yes, of course. I’ll fix it
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.
The above test case passes, but now if the first label is undefined, there's a stray leading comma:
it.only('should allow combinations of labels', () => {
instance = new Gauge({
name: 'name_2',
help: 'help',
labelNames: ['code', 'success', 'ok'],
});
instance.inc({ code: '200' }, 10);
instance.inc({ code: '200', ok: 'yes' }, 10);
instance.inc({ ok: 'yes', success: 'false' }, 10);
instance.inc({ success: 'false', ok: 'no' }, 10);
const str = globalRegistry.getSingleMetricAsString('name_2');
console.log(str);
});
prints
# HELP name_2 help
# TYPE name_2 gauge
name_2{code="200"} 10
name_2{code="200",ok="yes"} 10
name_2{,success="false",ok="yes"} 10
name_2{,success="false",ok="no"} 10
(notice last two lines)
Something like these should both be committed as test cases. Do you feel like adding them please?
Just checked, benchmarks still look significantly faster despite the new branch added in the last commits. 👍
5bf5779
to
a1a3675
Compare
Any news here? 🙂 |
Does this still provide improvements after #594? |
I've rebased original PR #276 and achieve the same results