Skip to content

Commit

Permalink
Merge pull request #936 from jenkinsci/fix-missing-metric-ci_pipeline…
Browse files Browse the repository at this point in the history
…_run_active

Fix missing metric `ci.pipeline.run.active`
  • Loading branch information
cyrille-leclerc authored Sep 5, 2024
2 parents 77b35ef + 5bceda6 commit 32c9f94
Showing 1 changed file with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<CauseHandler> causeHandlers;
private LongCounter runLaunchedCounter;
private LongCounter runStartedCounter;
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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<RuntimeException>) () -> new IllegalStateException("No RunHandler found for run " + run.getClass() + " - " + run));
Expand Down Expand Up @@ -396,7 +396,7 @@ public void _onFinalized(@NonNull Run run) {
this.runAbortedCounter.add(1);
}
} finally {
activeRun.decrementAndGet();
activeRunGauge.decrementAndGet();
}
}

Expand Down

0 comments on commit 32c9f94

Please sign in to comment.