Skip to content

Fix queue metrics visibility under restricted ACL contexts#1240

Open
Flamki wants to merge 1 commit into
jenkinsci:mainfrom
Flamki:fix/queue-metrics-acl-1174
Open

Fix queue metrics visibility under restricted ACL contexts#1240
Flamki wants to merge 1 commit into
jenkinsci:mainfrom
Flamki:fix/queue-metrics-acl-1174

Conversation

@Flamki
Copy link
Copy Markdown

@Flamki Flamki commented Feb 23, 2026

What problem does this solve?

jenkins.queue.count can report 0 for all statuses when queue metrics are collected in a restricted security context (for example anonymous context in hardened Jenkins setups). This hides queued/stuck items even though they are present in Jenkins UI/API.

This change wraps queue item reads for metric collection in ACL.SYSTEM2 so queue gauges are based on full queue visibility.

Fixes #1174.

How to test the change

  1. Run ./mvnw spotless:check
  2. Run ./mvnw test -Dtest=MonitoringQueueListenerTest
  3. Run ./mvnw spotbugs:check

Breaking changes

None.

Additional notes

A regression test (MonitoringQueueListenerTest) verifies that:

  • anonymous context sees no queue items,
  • metrics collection path still sees queued items via SYSTEM ACL.

Wrap queue item collection in SYSTEM ACL for metrics callback so restricted anonymous contexts do not force jenkins.queue.count statuses to 0.

Add a regression test for issue jenkinsci#1174 that verifies anonymous queue visibility is empty while metrics collection sees queued items.
@Flamki Flamki requested a review from a team as a code owner February 23, 2026 05:20
@ArpanC6
Copy link
Copy Markdown

ArpanC6 commented Mar 19, 2026

Great fix @Flamki! Wrapping queue item reads in ACL.SYSTEM2 is exactly
the right approach for infrastructure-level metrics that must observe
the full queue regardless of the caller's security context.

A few observations:

  1. ACL.SYSTEM2 pattern — Using ACL.SYSTEM2 instead of the deprecated
    ACL.SYSTEM is consistent with the rest of the codebase. The
    try-with-resources pattern for ACLContext is also the correct Jenkins idiom.

  2. Test coverage — 100% line and branch coverage is excellent. The
    test elegantly proves the fix by verifying that anonymous context sees 0
    items while the metrics path sees the queued item via SYSTEM ACL.

  3. @VisibleForTesting — Extracting getQueueItemsForMetrics() as a
    package-private method with @VisibleForTesting is a clean design
    choice — it makes the fix testable without exposing unnecessary API surface.

All CI checks passing including 235 tests on Linux. This looks ready
for merge!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Build queue metrics not registered

2 participants