-
Notifications
You must be signed in to change notification settings - Fork 1.2k
COUNTER-type metric names do not have the _total suffix #1154
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
Comments
The grouping logic in the convert method should not only consider the Current CodeThe current grouping logic is as follows: for (MatchedRule matchedRule : matchedRules) {
List<MatchedRule> matchedRulesWithSameName =
rulesByPrometheusMetricName.computeIfAbsent(
matchedRule.name, name -> new ArrayList<>());
matchedRulesWithSameName.add(matchedRule);
} Suggested ImprovementUpdate the grouping logic to include both for (MatchedRule matchedRule : matchedRules) {
String key = matchedRule.name + ":" + matchedRule.type; // Combine name and type as the key
List<MatchedRule> matchedRulesWithSameKey =
rulesByPrometheusMetricName.computeIfAbsent(
key, k -> new ArrayList<>());
matchedRulesWithSameKey.add(matchedRule);
} This change ensures that metrics with the same
Benefits
|
However, this will trigger a An Exception occurred while scraping metrics: java.lang.IllegalArgumentException: kafka_network_RequestMetrics_ErrorsPerSec: duplicate metric name
at io.prometheus.metrics.model.snapshots.MetricSnapshots.<init>(MetricSnapshots.java:45)
at io.prometheus.metrics.model.snapshots.MetricSnapshots$Builder.build(MetricSnapshots.java:99)
at io.prometheus.jmx.MatchedRuleToMetricSnapshotsConverter.convert(MatchedRuleToMetricSnapshotsConverter.java:82)
at io.prometheus.jmx.JmxCollector.collect(JmxCollector.java:909)
at io.prometheus.metrics.model.registry.MultiCollector.collect(MultiCollector.java:21)
at io.prometheus.metrics.model.registry.PrometheusRegistry.scrape(PrometheusRegistry.java:84)
at io.prometheus.metrics.exporter.common.PrometheusScrapeHandler.scrape(PrometheusScrapeHandler.java:135)
at io.prometheus.metrics.exporter.common.PrometheusScrapeHandler.handleRequest(PrometheusScrapeHandler.java:56)
at io.prometheus.metrics.exporter.httpserver.MetricsHandler.handle(MetricsHandler.java:33)
at jdk.httpserver/com.sun.net.httpserver.Filter$Chain.doFilter(Filter.java:95)
at jdk.httpserver/sun.net.httpserver.AuthFilter.doFilter(AuthFilter.java:82)
at jdk.httpserver/com.sun.net.httpserver.Filter$Chain.doFilter(Filter.java:98)
at jdk.httpserver/sun.net.httpserver.ServerImpl$Exchange$LinkHandler.handle(ServerImpl.java:852)
at jdk.httpserver/com.sun.net.httpserver.Filter$Chain.doFilter(Filter.java:95)
at jdk.httpserver/sun.net.httpserver.ServerImpl$Exchange.run(ServerImpl.java:819)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
at java.base/java.lang.Thread.run(Thread.java:842) |
So, in this situation, how should it be handled? |
Rules configuration:
Using the above configuration, metrics with the same name but different types are collected, as shown below:
Ideally, for metrics with a type of
COUNTER
, the metric name should include the_total
suffix, resulting inkafka_network_RequestMetrics_RequestsPerSec_total
. However, in practice, the suffix is missing.After debugging the code, I identified the issue in the following section:
Here, metrics with the same name are grouped together, and when the
getType
method is called, it returns"UNKNOWN"
. This causesCOUNTER
type metrics to be incorrectly processed and results in the_total
suffix not being added.The text was updated successfully, but these errors were encountered: