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

UnlabeledLoad.computeQueueLength() includes labeled jobs

    XMLWordPrintable

    Details

    • Similar Issues:

      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

            recampbell Ryan Campbell created issue -
            Hide
            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

            Show
            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 made changes -
            Field Original Value New Value
            Assignee Oleg Nenashev [ oleg_nenashev ]
            Hide
            oleg_nenashev Oleg Nenashev added a comment -

            Ryan Campbell
            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.

            Show
            oleg_nenashev Oleg Nenashev added a comment - Ryan Campbell 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 made changes -
            Status Open [ 1 ] In Progress [ 3 ]
            Show
            oleg_nenashev Oleg Nenashev added a comment - https://github.com/jenkinsci/jenkins/pull/1709
            oleg_nenashev Oleg Nenashev made changes -
            Remote Link This issue links to "jenkins/pull/1709 (Web Link)" [ 12914 ]
            recampbell Ryan Campbell made changes -
            Description 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.
            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.
            Hide
            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.

            Show
            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.
            Hide
            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

            Show
            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
            Hide
            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.

            Show
            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.
            scm_issue_link SCM/JIRA link daemon made changes -
            Status In Progress [ 3 ] Resolved [ 5 ]
            Resolution Fixed [ 1 ]
            Hide
            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

            Show
            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
            Hide
            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

            Show
            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
            oleg_nenashev Oleg Nenashev made changes -
            Labels cloud loadstatistics cloud loadstatistics lts-candidate
            olivergondza Oliver Gondža made changes -
            Labels cloud loadstatistics lts-candidate 1.609 cloud loadstatistics
            olivergondza Oliver Gondža made changes -
            Labels 1.609 cloud loadstatistics 1.609.2-fixed cloud loadstatistics
            Hide
            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)

            Show
            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)
            Hide
            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)

            Show
            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)
            Hide
            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)

            Show
            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)
            Hide
            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)

            Show
            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)
            Hide
            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
            Show
            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
            rtyler R. Tyler Croy made changes -
            Workflow JNJira [ 163286 ] JNJira + In-Review [ 197161 ]

              People

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

                Dates

                • Created:
                  Updated:
                  Resolved: