Skip to content

Improvements to defaultLabels in metrics, and matching benchmarks - #683

Closed
jdmarshall wants to merge 4 commits into
prometheus:masterfrom
jdmarshall:aggregation
Closed

jdmarshall wants to merge 4 commits into
prometheus:masterfrom
jdmarshall:aggregation

Conversation

@jdmarshall

@jdmarshall jdmarshall commented Jul 7, 2025 •

Copy link
Copy Markdown
Contributor

This is about a 20% improvement in the getMetricsAs{String,JSON} functions, when defaultLabels are set.

Note that this PR shares some benchmark-only commits in common with #680

Additional benchmark suites boost code coverage #676

File                             | % Stmts | % Branch | % Funcs | % Lines |
---------------------------------|---------|----------|---------|---------|
All files                        |   52.36 |    29.55 |   49.14 |   53.05 |

No breaking changes

Comment thread benchmarks/utils/labels.js Resolved
This should help with further optimizations, especially for cluster.js
I believe I see some perf issues with default labels and I'd like to
explore those.

Increases code coverage by .6%, but branch coverage by 1.2%

File                             | % Stmts | % Branch | % Funcs | % Lines |
---------------------------------|---------|----------|---------|---------|
All files                        |   51.78 |    28.35 |    48.8 |   52.45 |
All files                        |   52.36 |    29.55 |   49.14 |   53.05 |

Relates to prometheus#676
…rmats.

getMetricsAsJSON and getMetricsAsString use different mechanisms
to merge in default labels. It turns out that the getMetricsAsJSON
version is substantially faster.

... except in how it short circuits out of the inner loop.

✓ registry ➭ getMetricsAsJSON#2 x 4, 2 defaults is 21.55% faster.
✓ registry ➭ getMetricsAsJSON#2 x 2, 4 defaults is 22.69% faster.
✓ registry ➭ metrics#2 x 4, 2 defaults is 26.95% faster.
✓ registry ➭ metrics() 2 x 4, 2 defaults and openMetrics is 25.78% faster.
✓ registry ➭ metrics#2 x 2, 4 defaults is 25.53% faster.
✓ registry ➭ metrics() 2 x 2, 4 defaults and openMetrics is 26.98% faster.
Start all of the metrics but then only await them one at a time.

This should help with prometheus#543 by introducing some pauses for other work
to complete.
@jdmarshall

Copy link
Copy Markdown
Contributor Author

This contains the same code as in #687

@jdmarshall jdmarshall closed this Jul 12, 2025
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.

1 participant