Conversation
…ache#6671) shenyu_request_type_total was labelled with the raw request path, so every distinct path (for example /api/user/123 and /api/order/456) created a new Counter.Child inside the Prometheus client's internal children map, which is never evicted. On a gateway serving parameterised routes that map grows with the number of distinct paths and eventually exhausts the heap. Drop the path label and keep only rpcType, which is a bounded dimension, and add a regression test asserting that the raw path is no longer forwarded as a label value.
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
One or more issues must be addressed before approval.
Get a fresh assessment by requesting another Copilot review.
Pull request overview
Removes the raw request path from shenyu_request_type_total to prevent unbounded Prometheus label cardinality.
Changes:
- Uses only
rpcTypeas the request-type metric label. - Updates Prometheus registration to match the new label vector.
- Adds a regression test for path-independent increments.
File summaries
| File | Description |
|---|---|
| shenyu-plugin/shenyu-plugin-metrics/src/test/java/org/apache/shenyu/plugin/metrics/MetricsPluginTest.java | Updated as part of this pull request. |
| shenyu-plugin/shenyu-plugin-metrics/src/main/java/org/apache/shenyu/plugin/metrics/reporter/MetricsReporter.java | Updated as part of this pull request. |
| shenyu-plugin/shenyu-plugin-metrics/src/main/java/org/apache/shenyu/plugin/metrics/MetricsPlugin.java | Updated as part of this pull request. |
Review details
Suppressed comments (1)
shenyu-plugin/shenyu-plugin-metrics/src/main/java/org/apache/shenyu/plugin/metrics/reporter/MetricsReporter.java:43
- The regression test only verifies that the plugin passes a one-element value vector to a mock; it never asserts the counter is registered with the matching one-label schema. If this registration accidentally remains
{path, type}, the test would still pass even though the Prometheus client rejects the one-valuelabels(...)call at runtime. Please add a registration assertion (or exercise an actual Prometheus register) thatshenyu_request_type_totalhas exactly thetypelabel.
MetricsReporter.registerCounter(LabelNames.REQUEST_TYPE_TOTAL, new String[]{"type"}, "shenyu http request type total count");
- Files reviewed: 3/3 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| @Test | ||
| public void testRequestTypeTotalIsNotLabelledByRawPath() { | ||
| MetricsRegister metricsRegister = Mockito.mock(MetricsRegister.class); | ||
| MetricsReporter.register(metricsRegister); |
Aias00
approved these changes
Sep 19, 2026
Aias00
left a comment
Contributor
There was a problem hiding this comment.
Approved as PMC (Aias00). Small, well-scoped fix with regression tests; green CI, mergeable. Reviewed the diff.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Make sure that:
./mvnw clean install -Dmaven.javadoc.skip=true.Summary
Fixes #6671.
shenyu_request_type_totalwas incremented with the raw request path as alabel value, so every distinct path (
/api/user/123,/api/order/456, ...) created a newCounter.Childinside the Prometheus client's internal children map, which is neverevicted. The outer counter/gauge/histogram maps are bounded by metric name, but that
per-series map is not: heap usage grows with the number of distinct request paths, which
is unbounded on a gateway serving parameterised routes, and it also inflates the
/metricspayload. The path label is now dropped, keeping only the boundedrpcTypedimension.
Changes
MetricsPlugin#execute(shenyu-plugin/shenyu-plugin-metrics/src/main/java/org/apache/shenyu/plugin/metrics/MetricsPlugin.java:49) —counterIncrement(LabelNames.REQUEST_TYPE_TOTAL, ...)now passesnew String[]{shenyuContext.getRpcType()}instead ofnew String[]{exchange.getRequest().getURI().getRawPath(), shenyuContext.getRpcType()}.MetricsReporter#register(shenyu-plugin/shenyu-plugin-metrics/src/main/java/org/apache/shenyu/plugin/metrics/reporter/MetricsReporter.java:43) — the counter is registered with label names{"type"}instead of{"path", "type"}, so the registration matches the values the plugin emits.Note for reviewers: this changes the exposed label set of
shenyu_request_type_totalfrom
{path,type}to{type}. It is an intentional breaking change to the metric shape,since per-path granularity cannot be kept without the unbounded cardinality. Dashboards
that break this metric down by path need to be adjusted.
Test Cases
MetricsPluginTest.testRequestTypeTotalIsNotLabelledByRawPath(shenyu-plugin/shenyu-plugin-metrics/src/test/java/org/apache/shenyu/plugin/metrics/MetricsPluginTest.java:93) — executes the plugin for/api/user/123and/api/order/456and verifies both increments carry the same label vector{rpcType}, i.e. the raw path is no longer forwarded as a label value.Verification
./mvnw -pl shenyu-plugin/shenyu-plugin-metrics clean install -Dmaven.javadoc.skip=true— BUILD SUCCESS; Tests run: 15, Failures: 0, Errors: 0, Skipped: 0../mvnw clean install -Dmaven.javadoc.skip=true— all modules build and install. The only failure is a pre-existing, order-dependent one inshenyu-kubernetes-controller:DubboReconcilerTest#testReconcilefails when that module's test suite runs as a whole and passes when the class is run in isolation; it is untouched by this PR. Excluding only that class, the remaining reactor finishes green.close #6671