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

UnlabeledLoad.computeQueueLength() includes labeled jobs

    XMLWordPrintable

Details

    Description

      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.

      Attachments

        Issue Links

          Activity

            oleg_nenashev 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 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 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 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 Oleg Nenashev added a comment - https://github.com/jenkinsci/jenkins/pull/1709

            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_issue_link 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_issue_link 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

            Code changed in jenkins
            User: Oleg Nenashev
            Path:
            core/src/main/java/jenkins/model/UnlabeledLoadStatistics.java
            http://jenkins-ci.org/commit/jenkins/294ce778b3381d84fdb8969729b3628dd3197600
            Log:
            [FIXED JENKINS-28446] - Calculate only tasks without assigned labels

            This implementation does not create new methods in API, hence it can be backported.

            scm_issue_link SCM/JIRA link daemon added a comment - Code changed in jenkins User: Oleg Nenashev Path: core/src/main/java/jenkins/model/UnlabeledLoadStatistics.java http://jenkins-ci.org/commit/jenkins/294ce778b3381d84fdb8969729b3628dd3197600 Log: [FIXED JENKINS-28446] - Calculate only tasks without assigned labels This implementation does not create new methods in API, hence it can be backported.

            Code changed in jenkins
            User: Oleg Nenashev
            Path:
            core/src/main/java/hudson/model/Queue.java
            core/src/main/java/jenkins/model/UnlabeledLoadStatistics.java
            http://jenkins-ci.org/commit/jenkins/7697bdb4f57d974546ec4c7e95e87fc8f2ad7f1a
            Log:
            JENKINS-28446 - Introduce new API method in Queue to optimize the performance of UnlabeledLoadStatistics

            scm_issue_link 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/jenkins/model/UnlabeledLoadStatistics.java http://jenkins-ci.org/commit/jenkins/7697bdb4f57d974546ec4c7e95e87fc8f2ad7f1a Log: JENKINS-28446 - Introduce new API method in Queue to optimize the performance of UnlabeledLoadStatistics

            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
            core/src/main/java/jenkins/model/UnlabeledLoadStatistics.java
            test/src/test/java/jenkins/model/UnlabeledLoadStatisticsTest.java
            http://jenkins-ci.org/commit/jenkins/7205da0205a67324919cb9aae024cdd45a00792b
            Log:
            Merge pull request #1709 from oleg-nenashev/JENKINS-28446-fix

            [FIXED JENKINS-28446] - proper calculation of queue length in UnlabeledLoadStatistics

            Compare: https://github.com/jenkinsci/jenkins/compare/048ea9c754f9...7205da0205a6

            scm_issue_link 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 core/src/main/java/jenkins/model/UnlabeledLoadStatistics.java test/src/test/java/jenkins/model/UnlabeledLoadStatisticsTest.java http://jenkins-ci.org/commit/jenkins/7205da0205a67324919cb9aae024cdd45a00792b Log: Merge pull request #1709 from oleg-nenashev/ JENKINS-28446 -fix [FIXED JENKINS-28446] - proper calculation of queue length in UnlabeledLoadStatistics Compare: https://github.com/jenkinsci/jenkins/compare/048ea9c754f9...7205da0205a6

            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/de5d83de09d2f0ec47292691da063a8eb43846f0
            Log:
            Code documentation/annotation around JENKINS-28446.

            Just to prevent similar misuses in the future.

            (cherry picked from commit 298e371321b3fa3744d923554624fb94135d32ee)

            scm_issue_link 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/de5d83de09d2f0ec47292691da063a8eb43846f0 Log: Code documentation/annotation around JENKINS-28446 . Just to prevent similar misuses in the future. (cherry picked from commit 298e371321b3fa3744d923554624fb94135d32ee)

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

            (cherry picked from commit 43b06626414b192e695237dfbfe2b4d137cb1363)

            scm_issue_link 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/56fc3860954ea4e6d408dc617c1557f9cb9ec870 Log: JENKINS-28446 - Direct unit test for the issue (cherry picked from commit 43b06626414b192e695237dfbfe2b4d137cb1363)

            Code changed in jenkins
            User: Oleg Nenashev
            Path:
            core/src/main/java/jenkins/model/UnlabeledLoadStatistics.java
            http://jenkins-ci.org/commit/jenkins/ece651d4d0acc2a12bcc3c53780d67379a801e28
            Log:
            [FIXED JENKINS-28446] - Calculate only tasks without assigned labels

            This implementation does not create new methods in API, hence it can be backported.

            (cherry picked from commit 294ce778b3381d84fdb8969729b3628dd3197600)

            scm_issue_link SCM/JIRA link daemon added a comment - Code changed in jenkins User: Oleg Nenashev Path: core/src/main/java/jenkins/model/UnlabeledLoadStatistics.java http://jenkins-ci.org/commit/jenkins/ece651d4d0acc2a12bcc3c53780d67379a801e28 Log: [FIXED JENKINS-28446] - Calculate only tasks without assigned labels This implementation does not create new methods in API, hence it can be backported. (cherry picked from commit 294ce778b3381d84fdb8969729b3628dd3197600)

            Code changed in jenkins
            User: Oleg Nenashev
            Path:
            core/src/main/java/hudson/model/Queue.java
            core/src/main/java/jenkins/model/UnlabeledLoadStatistics.java
            http://jenkins-ci.org/commit/jenkins/84d80f57f2a31af44d733477efeb89db3f896021
            Log:
            JENKINS-28446 - Introduce new API method in Queue to optimize the performance of UnlabeledLoadStatistics

            (cherry picked from commit 7697bdb4f57d974546ec4c7e95e87fc8f2ad7f1a)

            scm_issue_link 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/jenkins/model/UnlabeledLoadStatistics.java http://jenkins-ci.org/commit/jenkins/84d80f57f2a31af44d733477efeb89db3f896021 Log: JENKINS-28446 - Introduce new API method in Queue to optimize the performance of UnlabeledLoadStatistics (cherry picked from commit 7697bdb4f57d974546ec4c7e95e87fc8f2ad7f1a)
            dogfood dogfood added a comment -

            Integrated in jenkins_main_trunk #4292
            Code documentation/annotation around JENKINS-28446. (Revision de5d83de09d2f0ec47292691da063a8eb43846f0)
            JENKINS-28446 - Direct unit test for the issue (Revision 56fc3860954ea4e6d408dc617c1557f9cb9ec870)
            [FIXED JENKINS-28446] - Calculate only tasks without assigned labels (Revision ece651d4d0acc2a12bcc3c53780d67379a801e28)
            JENKINS-28446 - Introduce new API method in Queue to optimize the performance of UnlabeledLoadStatistics (Revision 84d80f57f2a31af44d733477efeb89db3f896021)

            Result = UNSTABLE
            ogondza : de5d83de09d2f0ec47292691da063a8eb43846f0
            Files :

            • core/src/main/java/hudson/model/labels/LabelAssignmentAction.java
            • core/src/main/java/hudson/model/Queue.java

            ogondza : 56fc3860954ea4e6d408dc617c1557f9cb9ec870
            Files :

            • test/src/test/java/jenkins/model/UnlabeledLoadStatisticsTest.java

            ogondza : ece651d4d0acc2a12bcc3c53780d67379a801e28
            Files :

            • core/src/main/java/jenkins/model/UnlabeledLoadStatistics.java

            ogondza : 84d80f57f2a31af44d733477efeb89db3f896021
            Files :

            • core/src/main/java/jenkins/model/UnlabeledLoadStatistics.java
            • core/src/main/java/hudson/model/Queue.java
            dogfood dogfood added a comment - Integrated in jenkins_main_trunk #4292 Code documentation/annotation around JENKINS-28446 . (Revision de5d83de09d2f0ec47292691da063a8eb43846f0) JENKINS-28446 - Direct unit test for the issue (Revision 56fc3860954ea4e6d408dc617c1557f9cb9ec870) [FIXED JENKINS-28446] - Calculate only tasks without assigned labels (Revision ece651d4d0acc2a12bcc3c53780d67379a801e28) JENKINS-28446 - Introduce new API method in Queue to optimize the performance of UnlabeledLoadStatistics (Revision 84d80f57f2a31af44d733477efeb89db3f896021) Result = UNSTABLE ogondza : de5d83de09d2f0ec47292691da063a8eb43846f0 Files : core/src/main/java/hudson/model/labels/LabelAssignmentAction.java core/src/main/java/hudson/model/Queue.java ogondza : 56fc3860954ea4e6d408dc617c1557f9cb9ec870 Files : test/src/test/java/jenkins/model/UnlabeledLoadStatisticsTest.java ogondza : ece651d4d0acc2a12bcc3c53780d67379a801e28 Files : core/src/main/java/jenkins/model/UnlabeledLoadStatistics.java ogondza : 84d80f57f2a31af44d733477efeb89db3f896021 Files : core/src/main/java/jenkins/model/UnlabeledLoadStatistics.java core/src/main/java/hudson/model/Queue.java

            People

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

              Dates

                Created:
                Updated:
                Resolved: