fix: record left status in jenkins.queue.count metric and add queue metrics test - #1271
fix: record left status in jenkins.queue.count metric and add queue metrics test#1271kanagaabishek wants to merge 4 commits into
Conversation
… metrics test Issue jenkinsci#1174: The 'left' queue item status was counted in the batchCallback but never recorded to the queueItems ObservableLongMeasurement, making the 'left' status invisible in the jenkins.queue.count metric. This commit: - Records left items with STATUS='left' in the queueItems gauge - Adds MonitoringQueueListenerTest verifying all queue metrics are registered and exported after a job completes Fixes: jenkinsci#1174
|
I noticed PR #1240 also addresses #1174 by fixing ACL-restricted queue visibility. My PR addresses a separate gap: the left status is counted via AtomicInteger left but the corresponding queueItems.record(left.get(), ...) call was never written, so jenkins.queue.count{status="left"} is always absent regardless of ACL context. These two fixes address different failure modes of the same issue — #1240 fixes visibility under restricted auth, this PR fixes completeness of the left dimension. Happy to rebase on top of #1240 if the maintainers prefer a combined fix. |
| @Test | ||
| public void testQueueMetricsAreRegisteredAndExported() throws Exception { | ||
| // Schedule and complete a job so the queue is exercised | ||
| FreeStyleProject project = jenkinsRule.createFreeStyleProject("queue-metrics-test"); |
There was a problem hiding this comment.
Why a FreeStyle job? FreeStyle job is supported (mostly) but it is not the main focus of the plugin, we support Pipelines, if something does not work with FreeStyle jobs is not a priority, and we can remove support any time if we want.
There was a problem hiding this comment.
@kuisathaverat Thank you for the review. Updated the test to use WorkflowJob (Pipeline) instead of FreeStyleProject — Pipeline is the primary supported job type for this plugin. The queue mechanics exercised by the test are identical; only the job type changed.
Please let me know if any further changes required
Use WorkflowJob (Pipeline) instead of FreeStyleProject as suggested in review — Pipeline is the primary supported job type for this plugin.
… metrics test
Issue #1174: The 'left' queue item status was counted in the batchCallback but never recorded to the queueItems ObservableLongMeasurement, making the 'left' status invisible in the jenkins.queue.count metric.
This commit:
Fixes: #1174
Fixes #1174
The
leftqueue item status was counted inside thebatchCallbackinMonitoringQueueListenerbut was never recorded to thequeueItemsObservableLongMeasurement. This meant theleftstatus was silentlydropped from the
jenkins.queue.countmetric while all other statuses(blocked, buildable, stuck, waiting) were correctly recorded.
Root cause
In
MonitoringQueueListener.postConstruct(), the batch callback tracksleftitems viaAtomicInteger leftand increments it correctly, butthe corresponding
queueItems.record(left.get(), Attributes.of(STATUS, "left"))call was missing. Every other status had its recording call —
leftdid not.Changes
MonitoringQueueListener.java: addedqueueItems.record(left.get(), Attributes.of(STATUS, "left"))alongside the existing status recordingsMonitoringQueueListenerTest.java: first dedicated test for queue metrics — verifies all six queue metrics (jenkins.queue.count,jenkins.queue.waiting,jenkins.queue.blocked,jenkins.queue.buildable,jenkins.queue.left,jenkins.queue.time_spent_millis) are registered and exported after a job completesTesting done
Added
MonitoringQueueListenerTest— the first automated test for queue metrics.The test:
forceFlush().join(10, TimeUnit.SECONDS)jenkins.queue.leftcounter value is >= 1 after the job completesTo run:
./mvnw test -Dtest="MonitoringQueueListenerTest"
Test passes locally on Java 21 / Maven 3.9.9.
Submitter checklist