You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rocketmq.apache.org by "shendongsd (via GitHub)" <gi...@apache.org> on 2026/10/01 03:33:08 UTC

[I] [Bug] Prometheus exporter throws DuplicateLabelsException causing all Master broker metrics to be lost [rocketmq]

shendongsd opened a new issue, #11304:
URL: https://github.com/apache/rocketmq/issues/11304

   ### Before Creating the Bug Report
   
   - [x] I found a bug, not just asking a question, which should be created in [GitHub Discussions](https://github.com/apache/rocketmq/discussions).
   
   - [x] I have searched the [GitHub Issues](https://github.com/apache/rocketmq/issues) and [GitHub Discussions](https://github.com/apache/rocketmq/discussions)  of this repository and believe that this is not a duplicate.
   
   - [x] I have confirmed that this bug belongs to the current repository, not other repositories of RocketMQ.
   
   
   ### Runtime platform environment
   
   When using metricsExporterType=PROM (PrometheusHttpServer), if there are Pop consumers connected to the broker, the /metrics endpoint crashes with DuplicateLabelsException, causing all Master broker metrics to be lost. Slave brokers are not affected because Pop consumers only connect to Master.
   
   
   
   ### RocketMQ version
   
   Environment
   RocketMQ Version: V5_3_3 (issue also present in develop branch as of 2026-10-01)
   metricsExporterType: PROM
   Consume mode: Pop consumption
   
   ### JDK Version
   
   _No response_
   
   ### Describe the Bug
   
   Root Cause
   In BrokerMetricsManager.initLagAndDlqMetrics(), three gauges (rocketmq_consumer_lag_messages, rocketmq_consumer_lag_latency, rocketmq_consumer_ready_messages) use a single measurement object shared between two calculators:
   `consumerLagLatency = brokerMeter.gaugeBuilder(GAUGE_CONSUMER_LAG_LATENCY)
       .buildWithCallback(measurement -> {
           consumerLagCalculator.calculateLag(lagResult ->
               measurement.record(lagResult.getLagLatency(), buildLagAttributes(lagResult)));  // ①
   
           liteConsumerLagCalculator.calculateLiteLagLatency(lagResult ->
               measurement.record(lagResult.getLagLatency(), buildLagAttributes(lagResult)));  // ②
       });`
   For Pop consumers, ConsumerLagCalculator.calculate() records two entries per ProcessGroupInfo — one with isRetry=false and one with isRetry=true. When the same (consumer_group, topic, is_retry, is_system) label combination is produced across ① and ②, MetricSnapshot.validateLabels() throws DuplicateLabelsException.
   Once triggered, the entire /metrics scrape fails — all metrics from the Master broker disappear.
   
   
   ### Steps to Reproduce
   
   Environment
   RocketMQ Version: V5_3_3 (issue also present in develop branch as of 2026-10-01)
   metricsExporterType: PROM
   Consume mode: Pop consumption
   
   ### What Did You Expect to See?
   
   
   # HELP rocketmq_broker_permission default view for gauge.
   # TYPE rocketmq_broker_permission gauge
   rocketmq_broker_permission{cluster="...",node_id="...",node_type="broker",otel_scope_name="broker-meter"} 6.0
   # HELP rocketmq_consumer_connections default view for gauge.
   # TYPE rocketmq_consumer_connections gauge
   rocketmq_consumer_connections{cluster="...",consume_mode="push",consumer_group="...",is_system="false",language="java",node_id="...",node_type="broker",otel_scope_name="broker-meter",protocol_type="remoting",version="v5_3_3"} 2.0
   # HELP rocketmq_consumer_group_number default view for gauge.
   # TYPE rocketmq_consumer_group_number gauge
   rocketmq_consumer_group_number{cluster="...",node_id="...",node_type="broker",otel_scope_name="broker-meter"} 113.0
   # HELP rocketmq_consumer_inflight_messages default view for gauge.
   # TYPE rocketmq_consumer_inflight_messages gauge
   rocketmq_consumer_inflight_messages{cluster="...",consumer_group="...",is_retry="false",is_system="true",node_id="...",node_type="broker",otel_scope_name="broker-meter",topic="..."} 0.0
   # HELP rocketmq_consumer_lag_latency_milliseconds default view for gauge.
   # TYPE rocketmq_consumer_lag_latency_milliseconds gauge
   rocketmq_consumer_lag_latency_milliseconds{cluster="...",consumer_group="...",is_retry="false",is_system="true",node_id="...",node_type="broker",otel_scope_name="broker-meter",topic="..."} 0.0
   # HELP rocketmq_consumer_lag_messages default view for gauge.
   # TYPE rocketmq_consumer_lag_messages gauge
   rocketmq_consumer_lag_messages{cluster="...",consumer_group="...",is_retry="false",is_system="true",node_id="...",node_type="broker",otel_scope_name="broker-meter",topic="..."} 0.0
   # HELP rocketmq_consumer_queueing_latency_milliseconds default view for gauge.
   # TYPE rocketmq_consumer_queueing_latency_milliseconds gauge
   rocketmq_consumer_queueing_latency_milliseconds{cluster="...",consumer_group="...",is_retry="false",is_system="true",node_id="...",node_type="broker",otel_scope_name="broker-meter",topic="..."} 9.7563873E7
   # HELP rocketmq_consumer_ready_messages default view for gauge.
   # TYPE rocketmq_consumer_ready_messages gauge
   rocketmq_consumer_ready_messages{cluster="...",consumer_group="...",is_retry="false",is_system="true",node_id="...",node_type="broker",otel_scope_name="broker-meter",topic="..."} 7741731.0
   # HELP rocketmq_delay_message_latency_seconds Timer message set latency distribution
   # TYPE rocketmq_delay_message_latency_seconds histogram
   rocketmq_delay_message_latency_seconds_bucket{cluster="...",node_id="...",node_type="broker",otel_scope_name="broker-meter",storage_medium="disk
   
   ### What Did You See Instead?
   
   An Exception occurred while scraping metrics: 
   io.prometheus.metrics.model.snapshots.DuplicateLabelsException: Duplicate labels for metric 
   "rocketmq_consumer_lag_latency_milliseconds":
   {cluster="...",
    consumer_group="...",
    is_retry="true",
    is_system="false",
    node_id="...",
    node_type="broker",
    otel_scope_name="broker-meter",
    topic="..."}
       at io.prometheus.metrics.model.snapshots.MetricSnapshot.validateLabels(MetricSnapshot.java:42)
       at io.prometheus.metrics.model.snapshots.MetricSnapshot.<init>(MetricSnapshot.java:27)
       at io.prometheus.metrics.model.snapshots.GaugeSnapshot.<init>(GaugeSnapshot.java:18)
       at io.opentelemetry.exporter.prometheus.Otel2PrometheusConverter.convertLongGauge(...)
       at io.opentelemetry.exporter.prometheus.Otel2PrometheusConverter.convert(...)
       at io.opentelemetry.exporter.prometheus.PrometheusMetricReader.collect(...)
       at io.prometheus.metrics.model.registry.PrometheusRegistry.scrape(...)
   
   ### Additional Context
   
   _No response_


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@rocketmq.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [Bug] Prometheus exporter throws DuplicateLabelsException causing all Master broker metrics to be lost [rocketmq]

Posted by "Ayush0612005 (via GitHub)" <gi...@apache.org>.
Ayush0612005 commented on issue #11304:
URL: https://github.com/apache/rocketmq/issues/11304#issuecomment-5956180066

   Hi, I looked into this and I think the root cause may differ from the one described.
   
   LiteConsumerLagCalculator always emits isRetry=false, so it can't produce a duplicate is_retry="true" series. Also, 5.3.3 doesn't have the Lite calculator at all.
   
   In 5.3.3, when enableNotifyBeforePopCalculateLag is on and a pop request is pending, calculateLag passes lagRecorder into an async PopCommandCallback. That callback records into the OTel measurement later, from another thread, outside the collection callback. Those late writes can collide with the synchronous ones and produce duplicate label sets. [apache/rocketmq#9873](https://github.com/apache/rocketmq/pull/9873) (released in 5.4.0) changed this to a CompletableFuture-based approach, so could you check whether the exception still reproduces on 5.4.0+?
   
   While reading the current develop code, I also noticed a related issue. The async path calls calculate(info, future::complete), but for Pop groups calculate() invokes the recorder twice (normal lag, then retry lag). CompletableFuture.complete only keeps the first value, so the is_retry=true lag result is silently dropped whenever a pop request is pending.
   
   I'd like to work on a fix: collect all results from calculate() in the async path, not just the first, plus a unit test covering Pop groups. Could this be assigned to me?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@rocketmq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [Bug] Prometheus exporter throws DuplicateLabelsException causing all Master broker metrics to be lost [rocketmq]

Posted by "Yeti11H (via GitHub)" <gi...@apache.org>.
Yeti11H commented on issue #11304:
URL: https://github.com/apache/rocketmq/issues/11304#issuecomment-6209222463

   Hi maintainers,
   
   I investigated this issue on the current develop branch and found a related
   POP consumer lag problem in the asynchronous calculation path.
   
   When a pending POP request triggers `ConsumerLagCalculator.calculateLag()`,
   the calculation produces two results for a POP group: one for the normal topic
   and one for the retry topic. The current code passes
   `future::complete` as the recorder, so `CompletableFuture` keeps only the first
   result and silently drops the retry lag result.
   
   I prepared a focused fix that:
   
   - collects all results produced by the asynchronous calculation;
   - records both normal and retry lag after the future completes;
   - avoids recording metrics directly from the asynchronous callback thread;
   - keeps the existing public API and message semantics unchanged;
   - adds a regression test covering both result types and lag values.
   
   The related tests pass, including Checkstyle and SpotBugs validation.
   
   Would it be acceptable for me to open a pull request for this focused fix?
   If so, could you please assign the issue to me or confirm that I should proceed?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@rocketmq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org