diff --git a/src/main/java/io/jenkins/plugins/opentelemetry/job/MonitoringRunListener.java b/src/main/java/io/jenkins/plugins/opentelemetry/job/MonitoringRunListener.java index ace918de5..f57e960fe 100644 --- a/src/main/java/io/jenkins/plugins/opentelemetry/job/MonitoringRunListener.java +++ b/src/main/java/io/jenkins/plugins/opentelemetry/job/MonitoringRunListener.java @@ -74,7 +74,7 @@ public class MonitoringRunListener extends OtelContextAwareAbstractRunListener i protected static final Logger LOGGER = Logger.getLogger(MonitoringRunListener.class.getName()); - private AtomicInteger activeRun; + private AtomicInteger activeRunGauge; private List causeHandlers; private LongCounter runLaunchedCounter; private LongCounter runStartedCounter; @@ -103,12 +103,12 @@ public void postConstruct() { this.runHandlers = runHandlers; // METRICS - activeRun = new AtomicInteger(); - meter.gaugeBuilder(JenkinsSemanticMetrics.CI_PIPELINE_RUN_ACTIVE) - .ofLongs() - .setDescription("Gauge of active jobs") - .setUnit("1") - .buildWithCallback(valueObserver -> this.activeRun.get()); + activeRunGauge = new AtomicInteger(); + meter.gaugeBuilder(JenkinsSemanticMetrics.CI_PIPELINE_RUN_ACTIVE) + .ofLongs() + .setDescription("Gauge of active jobs") + .setUnit("{jobs}") + .buildWithCallback(valueObserver -> valueObserver.record(this.activeRunGauge.get())); runLaunchedCounter = meter.counterBuilder(JenkinsSemanticMetrics.CI_PIPELINE_RUN_LAUNCHED) .setDescription("Job launched") @@ -156,7 +156,7 @@ public CauseHandler getCauseHandler(@NonNull Cause cause) throws NoSuchElementEx public void _onInitialize(@NonNull Run run) { LOGGER.log(Level.FINE, () -> run.getFullDisplayName() + " - onInitialize"); - activeRun.incrementAndGet(); + activeRunGauge.incrementAndGet(); RunHandler runHandler = getRunHandlers().stream().filter(rh -> rh.canCreateSpanBuilder(run)).findFirst() .orElseThrow((Supplier) () -> new IllegalStateException("No RunHandler found for run " + run.getClass() + " - " + run)); @@ -396,7 +396,7 @@ public void _onFinalized(@NonNull Run run) { this.runAbortedCounter.add(1); } } finally { - activeRun.decrementAndGet(); + activeRunGauge.decrementAndGet(); } }