improve performance of registry.metrics()#373
Conversation
zbjornson
left a comment
There was a problem hiding this comment.
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.
Can you clarify what do you mean? Should I rewrite it or implement inside generated function?
There was a problem hiding this comment.
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.
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.
⭐ 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.
should add this as a test, no?
There was a problem hiding this comment.
Yes, of course. I’ll fix it
There was a problem hiding this comment.
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