Skip to content

Build queue metrics not registered #1174

Description

@YanekC

Jenkins and plugins versions report

Environment
Jenkins: 2.504.3
OS: Linux - 5.14.0-570.21.1.el9_6.x86_64
Java: 21.0.7 - Red Hat, Inc. (OpenJDK 64-Bit Server VM)
---
analysis-model-api:13.7.0
ansicolor:1.0.6
ant:513.vde9e7b_a_0da_0f
antisamy-markup-formatter:173.v680e3a_b_69ff3
apache-httpcomponents-client-4-api:4.5.14-269.vfa_2321039a_83
apache-httpcomponents-client-5-api:5.5-150.veb_76e719855b_
artifactory:4.0.8
asm-api:9.8-163.vb_2a_96d3f9c3c
audit-trail:395.vce180b_359a_b_5
authentication-tokens:1.131.v7199556c3004
badge:2.9.1
basic-branch-build-strategies:228.v68c089762a_db_
blueocean:1.27.21
blueocean-autofavorite:1.2.5
blueocean-bitbucket-pipeline:1.27.21
blueocean-commons:1.27.21
blueocean-config:1.27.21
blueocean-core-js:1.27.21
blueocean-dashboard:1.27.21
blueocean-display-url:2.4.4
blueocean-events:1.27.21
blueocean-git-pipeline:1.27.21
blueocean-github-pipeline:1.27.21
blueocean-i18n:1.27.21
blueocean-jwt:1.27.21
blueocean-personalization:1.27.21
blueocean-pipeline-api-impl:1.27.21
blueocean-pipeline-editor:1.27.21
blueocean-pipeline-scm-api:1.27.21
blueocean-rest:1.27.21
blueocean-rest-impl:1.27.21
blueocean-web:1.27.21
bootstrap5-api:5.3.7-2
bouncycastle-api:2.30.1.80-261.v00c0e2618ec3
branch-api:2.1235.v04e86c7ce54c
buildtriggerbadge:307.v19decf05a_0df
caffeine-api:3.2.2-178.v353b_8428ed56
checks-api:373.vfe7645102093
cloud-stats:377.vd8a_6c953e98e
cloudbees-bitbucket-branch-source:936.4.4
cloudbees-folder:6.1037.v4cb_8573b_72a_a_
command-launcher:123.v37cfdc92ef67
commons-compress-api:1.27.1-3
commons-lang3-api:3.18.0-98.v3a_674c06072d
commons-text-api:1.14.0-194.v804a_dc3a_1b_d8
config-file-provider:988.v0461fcc2b_9d1
configuration-as-code:1985.vdda_32d0c4ea_b_
coverage:2.7.1
credentials:1419.v2337d1ceceef
credentials-binding:702.vfe613e537e88
dark-theme:524.vd675b_22b_30cb_
dashboard-view:2.537.v5132851f6ca_f
data-tables-api:2.3.2-3
dependency-track:6.0.1
display-url-api:2.209.v582ed814ff2f
docker-commons:457.v0f62a_94f11a_3
docker-workflow:621.va_73f881d9232
durable-task:595.ve87b_f1318d67
echarts-api:6.0.0-1
eddsa-api:0.3.0.1-19.vc432d923e5ee
email-ext:1922.v5c93c9e80a_f9
embeddable-build-status:548.v5653c6e28c41
emoji-symbols-api:16.0-26.v9818ff7423f0
factory-cicd-jenkins-metrics-log:1.0.1
favorite:2.237.v79163ca_8b_892
figlet-buildstep:0.2
flatpickr-api:4.6.13-18.vcf5f6a_5b_8468
font-awesome-api:7.0.0-1
forensics-api:3.1.0
git:5.7.0
git-client:6.3.0
git-server:137.ve0060b_432302
github:1.44.0
github-api:1.321-488.v9b_c0da_9533f8
github-branch-source:1834.v857721ea_74c6
github-scm-trait-notification-context:45.v8ef831829589
gradle:2.15
gson-api:2.13.1-153.vb_3d0c48a_a_b_4a_
h2-api:11.1.4.199-36.vb_ee07e965744
handy-uri-templates-2-api:2.1.8-36.v85e4cb_234a_13
hidden-parameter:468.va_f691d08ce6d
htmlpublisher:427
http_request:1.20
insightappsec:1.0.6
instance-identity:203.v15e81a_1b_7a_38
ionicons-api:94.vcc3065403257
ivy:582.v35fb_da_0312f7
jackson2-api:2.19.2-408.v18248a_324cfe
jakarta-activation-api:2.1.3-2
jakarta-mail-api:2.1.3-2
javadoc:354.vee1a_660b_4990
javax-activation-api:1.2.0-8
javax-mail-api:1.6.2-11
jaxb:2.3.9-133.vb_ec76a_73f706
jdk-tool:83.v417146707a_3d
jenkins-design-language:1.27.21
jersey2-api:2.47-165.ve7809a_3e87e0
jjwt-api:0.11.5-120.v0268cf544b_89
jms-messaging:1.1.28
joda-time-api:2.14.0-149.v1c3ce991d1b_9
jquery3-api:3.7.1-3
jsch:0.2.16-95.v3eecb_55fa_b_78
json-api:20250517-163.v1c5da_e99c775
json-path-api:2.9.0-178.vca_b_c71881321
jsoup:1.21.1-58.vfc578e6e2610
junit:1335.v6b_a_a_e18534e1
ldap:780.vcb_33c9a_e4332
lockable-resources:1408.vb_7d1f371781d
mailer:515.vd788654779b_1
mapdb-api:1.0.9-44.va_1e1310c9118
mask-passwords:199.va_0218b_a_59186
matrix-auth:3.2.6
matrix-project:849.v0cd64ed7e531
maven-plugin:3.26
mcp-server:0.999999-SNAPSHOT (private-4a0d810a-bmaire)
mercurial:1309.v6802b_f0efb_b_9
metrics:4.2.32-481.v75f035fdc894
mina-sshd-api-common:2.15.0-161.vb_200831a_c15b_
mina-sshd-api-core:2.15.0-161.vb_200831a_c15b_
multibranch-build-strategy-extension:64.v348e3c69f1f5
octoperf:4.7.0
oic-auth:4.524.v38858a_b_1c6a_4
oidc-provider:111.v29fd614b_3617
okhttp-api:4.11.0-189.v976fa_d3379d6
opentelemetry:3.1543.v8446b_92b_cd64
opentelemetry-api:1.49.0.77.va_c69ec2472c0
osf-builder-suite-for-sfcc-credentials:1.0.8
osf-builder-suite-for-sfcc-deploy:1.1.13
oss-symbols-api:392.v27a_482d90083
parameter-separator:296.v9b_a_90c81160d
pipeline-build-step:571.v08a_fffd4b_0ce
pipeline-github-lib:65.v203688e7727e
pipeline-graph-analysis:241.vc3d48fb_b_2582
pipeline-graph-view:619.v92f3fcdc39db_
pipeline-groovy-lib:752.vdddedf804e72
pipeline-input-step:532.v9e7466cb_4406
pipeline-maven:1556.vd9051b_d6ef5d
pipeline-maven-api:1556.vd9051b_d6ef5d
pipeline-milestone-step:138.v78ca_76831a_43
pipeline-model-api:2.2258.v4e96d2b_da_f9b_
pipeline-model-definition:2.2258.v4e96d2b_da_f9b_
pipeline-model-extensions:2.2258.v4e96d2b_da_f9b_
pipeline-npm:424.v57d3deb_ea_909
pipeline-rest-api:2.38
pipeline-stage-step:322.vecffa_99f371c
pipeline-stage-tags-metadata:2.2258.v4e96d2b_da_f9b_
pipeline-stage-view:2.38
pipeline-utility-steps:2.19.0
plain-credentials:199.v9f8e1f741799
plugin-util-api:6.1.0
popper2-api:2.11.6-5
port-allocator:351.v7a_94cf6e4677
prism-api:1.30.0-1
publish-over:0.22
pubsub-light:1.19
rebuild:338.va_0a_b_50e29397
resource-disposer:0.25
resources-ai-chatbot:1.0-rc236.5442b_6ea_e4c4
rich-text-publisher-plugin:1.5
run-condition:243.v3c3f94e46a_8b_
schedule-build:667.vda_a_fe31e1659
scm-api:707.v749f968369d4
script-security:1378.vf25626395f49
sectioned-view:1.30
slack:794.va_5081e5ea_423
snakeyaml-api:2.3-125.v4d77857a_b_402
sonar:2.18
sse-gateway:1.28
ssh:158.ve2a_e90fb_7319
ssh-agent:386.v36cc0c7582f0
ssh-credentials:359.v2191c4cf635f
ssh-slaves:3.1071.v0d059c7b_c555
sshd:3.372.v5d04a_e92d8cf
structs:350.v3b_30f09f2363
support-core:1744.vf4f8e8f2b_0b_5
swarm:3.50
tap:2.4.4
theme-manager:319.v9193461f9671
timestamper:1.30
token-macro:477.vd4f0dc3cb_cf1
trilead-api:2.209.v0e69b_c43c245
uno-choice:2.8.8
validating-string-parameter:255.v31e2e6d0d273
variant:70.va_d9f17f859e0
view-job-filters:401.va_809f6a_b_0c26
warnings-ng:12.9.0
windows-slaves:1.8.1
workflow-aggregator:608.v67378e9d3db_1
workflow-api:1382.veca_a_efe062fa_
workflow-basic-steps:1079.vce64b_a_929c5a_
workflow-cps:4175.ve65b_fa_663eed
workflow-durable-task-step:1446.v3efd13441220
workflow-job:1540.v295eccc9778f
workflow-multibranch:810.v6b_6e77da_7058
workflow-scm-step:437.v05a_f66b_e5ef8
workflow-step-api:706.v518c5dcb_24c0
workflow-support:976.vb_d9493c2eb_09

What Operating System are you using (both controller, and any agents involved in the problem)?

Linux 5.14.0-570.21.1.el9_6.x86_64

Reproduction steps

We had the build queue metric working, but since I don't really know when, the metric stopped working.

Now, the build queue Items count are always at 0.

Image

I've tried enabling logging to stdout, so I got this kind of logs which are similar to what I get in Elastic :

metric: ImmutableMetricData{
    resource=Resource{
        schemaUrl=null,
        attributes={
            host.arch="amd64",
            host.name="*****", 
            jenkins.opentelemetry.plugin.version="3.1543.v8446b_92b_cd64", 
            jenkins.url="https://jenkins*****/", 
            jenkins.version="2.504.3", 
            os.description="Linux 5.14.0-570.21.1.el9_6.x86_64", 
            os.type="linux", 
            process.command_args=[/usr/lib/jvm/java-21-openjdk-21.0.7.0.6-1.el9.x86_64/bin/java, -Djava.awt.headless=true, -XX:+AlwaysPreTouch, -XX:+HeapDumpOnOutOfMemoryError, -XX:HeapDumpPath=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin, -XX:+UseG1GC, -XX:+UseStringDeduplication, -XX:+ParallelRefProcEnabled, -XX:+DisableExplicitGC, -Dhudson.remoting.Launcher.pingTimeoutSec=600, -Dhudson.remoting.Launcher.pingIntervalSec=1200, -Dcom.sun.management.jmxremote, -Dcom.sun.management.jmxremote.port=9999, -Dcom.sun.management.jmxremote.authenticate=false, -Dcom.sun.management.jmxremote.ssl=false, -jar, /usr/share/java/jenkins.war, --webroot=/var/cache/jenkins/war, --logfile=/var/log/jenkins/jenkins.log, --httpPort=8080],
            process.executable.path="/usr/lib/jvm/java-21-openjdk-21.0.7.0.6-1.el9.x86_64/bin/java",
            process.pid=59772, 
            process.runtime.description="Red Hat, Inc. OpenJDK 64-Bit Server VM 21.0.7+6-LTS", 
            process.runtime.name="OpenJDK Runtime Environment", 
            process.runtime.version="21.0.7+6-LTS", 
            service.instance.id="*****", 
            service.name="jenkins", 
            service.namespace="jenkins", 
            service.version="2.504.3", 
            telemetry.sdk.language="java", 
            telemetry.sdk.name="opentelemetry", 
            telemetry.sdk.version="1.49.0"
            }
        }, 
        instrumentationScopeInfo=InstrumentationScopeInfo{
            name=io.jenkins.opentelemetry, 
            version=3.1543.v8446b_92b_cd64, 
            schemaUrl=null, 
            attributes={}
        },
        name=jenkins.queue.count, 
        description=Number of tasks in the queue, 
        unit=${tasks}, 
        type=LONG_GAUGE, 
        data=ImmutableGaugeData{
            points=[
                ImmutableLongPointData{startEpochNanos=1754305169294916254, epochNanos=1754305289295298843, attributes={status="buildable"}, value=0, exemplars=[]}, 
                ImmutableLongPointData{startEpochNanos=1754305169294916254, epochNanos=1754305289295298843, attributes={status="waiting"}, value=0, exemplars=[]}, 
                ImmutableLongPointData{startEpochNanos=1754305169294916254, epochNanos=1754305289295298843, attributes={status="blocked"}, value=0, exemplars=[]}, 
                ImmutableLongPointData{startEpochNanos=1754305169294916254, epochNanos=1754305289295298843, attributes={status="stuck"}, value=0, exemplars=[]}
            ]
        }
    }

But when I run this script (inspired by this) in Jenkins script console, I get different results, which are the right results I think
Groovy Script :

import java.util.concurrent.atomic.AtomicInteger
def queue = Optional.ofNullable(Jenkins.getInstanceOrNull()).map({it -> it.getQueue() })
queue.map {it.getItems()}.ifPresent {items ->
    AtomicInteger blocked = new AtomicInteger();
    AtomicInteger buildable = new AtomicInteger();
    AtomicInteger left = new AtomicInteger();
    AtomicInteger stuck = new AtomicInteger();
    AtomicInteger unknown = new AtomicInteger();
    AtomicInteger waiting = new AtomicInteger();
    Arrays.stream(items).forEach({item -> 
        if (item instanceof Queue.BlockedItem) {
            blocked.incrementAndGet();
        } else if (item instanceof Queue.BuildableItem) {
            if (item.isStuck()) {
                // buildable but here for too long
                stuck.incrementAndGet();
            } else {
                buildable.incrementAndGet();
            }
        } else if (item instanceof Queue.WaitingItem) {
            waiting.incrementAndGet();
        } else if (item instanceof Queue.LeftItem) {
            left.incrementAndGet();
        } else {
            unknown.incrementAndGet();
        }
    });
    println("Queue items: " +
            "Blocked: ${blocked.get()}, " +
            "Buildable: ${buildable.get()}, " +
            "Left: ${left.get()}, " +
            "Stuck: ${stuck.get()}, " +
            "Unknown: ${unknown.get()}, " +
            "Waiting: ${waiting.get()}")
}

Result :

Queue items: Blocked: 0, Buildable: 0, Left: 0, Stuck: 8, Unknown: 0, Waiting: 0

Expected Results

The stuck metric should be 8 in Elastic, as it is in the groovy script result.

Actual Results

The stuck metric is zero in the debug logs, and in Kibana

Anything else?

I run out of debugging ideas, so I turn to the community to know if you have any idea how to find more informations about this bug.

Are you interested in contributing a fix?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions