Skip to content

Commit

Permalink
fix(metrics): fix potential NPE when exporting metrics
Browse files Browse the repository at this point in the history
Signed-off-by: Shichao Nie <niesc@automq.com>
  • Loading branch information
SCNieh committed Sep 19, 2024
1 parent ac9b075 commit 1773970
Showing 1 changed file with 3 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import io.opentelemetry.api.metrics.Meter;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicBoolean;
import kafka.autobalancer.metricsreporter.metric.MetricsUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -75,8 +76,9 @@ private void processDeltaHistogramMetric(MetricName name, DeltaHistogram deltaHi
metrics.compute(otelMetricName, (k, v) -> {
if (v == null) {
v = new ConcurrentHashMap<>();
final Map<MetricName, MetricWrapper> finalV = v;
OTelMetricUtils.toMeanGaugeBuilder(meter, name).buildWithCallback(measurement ->
metrics.get(otelMetricName).forEach((metricname, metricWrapper) ->
finalV.forEach((metricname, metricWrapper) ->
measurement.record(metricWrapper.mean(), metricWrapper.getAttr())));
LOGGER.info("Created delta gauge for metric: {}", otelMetricName);
}
Expand Down

0 comments on commit 1773970

Please sign in to comment.