Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-28446

UnlabeledLoad.computeQueueLength() includes labeled jobs

      The Jenkins#unlabeledLoad LoadStatistics incorrectly counts labeled jobs from computeQueueLength().

      Steps to reproduce:

      1. Create a job with a label 'foo'
      2. Run the job and ensure it is the only job in the queue
      3. Evaluating Jenkins.getInstance().unlabeledLoad.computeQueueLength() will return 1

      This causes the Jenkins.unlabeledLoadProvisioner to provision slaves with null labels even though they will not be able to run the labeled jobs.

          [JENKINS-28446] UnlabeledLoad.computeQueueLength() includes labeled jobs

          Ryan Campbell created issue -

          Oleg Nenashev added a comment -

          Seems the issue exists starting from the first version of UnlabeledLoad: https://github.com/jenkinsci/jenkins/commit/be1f8f91a3dcdcdfd2ed07198659e7eb68abf1f7

          Jenkins.getInstance().getQueue().countBuildableItemsFor(null) is misused in the call (BTW the behavior is not documented). This method returns all tasks count if you call it with a null param.

          We will need a new method to maintain the backward compatibility

          Oleg Nenashev added a comment - Seems the issue exists starting from the first version of UnlabeledLoad: https://github.com/jenkinsci/jenkins/commit/be1f8f91a3dcdcdfd2ed07198659e7eb68abf1f7 Jenkins.getInstance().getQueue().countBuildableItemsFor(null) is misused in the call (BTW the behavior is not documented). This method returns all tasks count if you call it with a null param. We will need a new method to maintain the backward compatibility
          Oleg Nenashev made changes -
          Assignee New: Oleg Nenashev [ oleg_nenashev ]

          Oleg Nenashev added a comment -

          recampbell
          FYI, if you use computeQueueLength() in your code, it's recommended to switch to computeSnapshot() for the sake of a better performance. BTW, this issue will also happen in this call, so it is not a workaround.

          Oleg Nenashev added a comment - recampbell FYI, if you use computeQueueLength() in your code, it's recommended to switch to computeSnapshot() for the sake of a better performance. BTW, this issue will also happen in this call, so it is not a workaround.
          Oleg Nenashev made changes -
          Status Original: Open [ 1 ] New: In Progress [ 3 ]

          Oleg Nenashev added a comment -

          Oleg Nenashev added a comment - https://github.com/jenkinsci/jenkins/pull/1709
          Oleg Nenashev made changes -
          Remote Link New: This issue links to "jenkins/pull/1709 (Web Link)" [ 12914 ]
          Ryan Campbell made changes -
          Description Original: The {{Jenkins#unlabeledLoad}} LoadStatistics incorrectly counts labeled jobs from computeQueueLength().

          Steps to reproduce:
          # Create a job with a label 'foo'
          # Evaluating {{Jenkins.getInstance().unlabeledLoad.computeQueueLength()}} will return 1

          This causes the {{Jenkins.unlabeledLoadProvisioner}} to provision slaves with null labels even though they will not be able to run the labeled jobs.
          New: The {{Jenkins#unlabeledLoad}} LoadStatistics incorrectly counts labeled jobs from computeQueueLength().

          Steps to reproduce:
          # Create a job with a label 'foo'
          # Run the job and ensure it is the only job in the queue
          # Evaluating {{Jenkins.getInstance().unlabeledLoad.computeQueueLength()}} will return 1

          This causes the {{Jenkins.unlabeledLoadProvisioner}} to provision slaves with null labels even though they will not be able to run the labeled jobs.

          Code changed in jenkins
          User: Oleg Nenashev
          Path:
          core/src/main/java/hudson/model/Queue.java
          core/src/main/java/hudson/model/labels/LabelAssignmentAction.java
          http://jenkins-ci.org/commit/jenkins/298e371321b3fa3744d923554624fb94135d32ee
          Log:
          Code documentation/annotation around JENKINS-28446.

          Just to prevent similar misuses in the future.

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: Oleg Nenashev Path: core/src/main/java/hudson/model/Queue.java core/src/main/java/hudson/model/labels/LabelAssignmentAction.java http://jenkins-ci.org/commit/jenkins/298e371321b3fa3744d923554624fb94135d32ee Log: Code documentation/annotation around JENKINS-28446 . Just to prevent similar misuses in the future.

          Code changed in jenkins
          User: Oleg Nenashev
          Path:
          test/src/test/java/jenkins/model/UnlabeledLoadStatisticsTest.java
          http://jenkins-ci.org/commit/jenkins/43b06626414b192e695237dfbfe2b4d137cb1363
          Log:
          JENKINS-28446 - Direct unit test for the issue

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: Oleg Nenashev Path: test/src/test/java/jenkins/model/UnlabeledLoadStatisticsTest.java http://jenkins-ci.org/commit/jenkins/43b06626414b192e695237dfbfe2b4d137cb1363 Log: JENKINS-28446 - Direct unit test for the issue

            oleg_nenashev Oleg Nenashev
            recampbell Ryan Campbell
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: