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

URL Used to Retrieve Issues Metrics may not be correct

    • 3.0.2

      private static final String SONAR_ISSUES_BASE_URL = "/api/issues/search?ps=1&projectKeys=";

      I don't believe this URL is getting what you expect.  It returns the total number of issues in the entire sonarqube system whether you have the projectKeys request parameter or not.

      I believe to get the issues by project you need the following:
      $sonarurl="${SonarHostUrl}api/measures/component?metricKeys=code_smells,ncloc,duplicated_lines_density,open_issues,sqale_rating,critical_violations,blocker_violations,major_violations,vulnerabilities,complexity,sqale_index,sqale_debt_ratio,violations&component=$SonarProjectKey"
       
      You have to specify the metrics you want returned
       
      Then on the returned JSON, you need to get:

      $sonmeasures=$sonresult.component.measures
      This object will contain the metrics only for the project you are looking for.
       
      I'd be happy to talk further if anything isn't clear.  I love this plugin, btw.  Makes our grafana dashboards very helpful.
       

          [JENKINS-65692] URL Used to Retrieve Issues Metrics may not be correct

          Christian added a comment -

          Yes, i'm talking about when you get the total amounts of the different issue severities.  If you have multiple/many projects in sonarqube, that will return the total across all projects, as in

          Project_1:  2 INFO issues

          Project_2:  5 INFO issues

          Project_3:  10 INFO issues

          This call:  /api/issues/search?ps=1&projectKeys=Project_1 will return 17 INFO issues total in sonarqube version: 

          • Version 8.4.1 (build 35646)

          This could be because of the version of Sonarqube I'm using.  I haven't tried upgrading to see if it's fixed.  But I did confirm if you use the /api/measures/component, and ask for the Issues with metric keys:  "info_violations, major_violoations, critical_violations" the data does come up per project as expected.

           

           

          Christian added a comment - Yes, i'm talking about when you get the total amounts of the different issue severities.  If you have multiple/many projects in sonarqube, that will return the total across all projects, as in Project_1:  2 INFO issues Project_2:  5 INFO issues Project_3:  10 INFO issues This call:  /api/issues/search?ps=1&projectKeys=Project_1 will return 17 INFO issues total in sonarqube version:  Version 8.4.1 (build 35646) This could be because of the version of Sonarqube I'm using.  I haven't tried upgrading to see if it's fixed.  But I did confirm if you use the /api/measures/component, and ask for the Issues with metric keys:  "info_violations, major_violoations, critical_violations" the data does come up per project as expected.    

          Christian added a comment -

          I just looked at the API specs and it looks like it works when you change the parameter to "projects" instead of "projectKeys".  The web_api description on sonarqube states this as well:

          https://SONARHOST/web_api/api/projects/search

           

          Christian added a comment - I just looked at the API specs and it looks like it works when you change the parameter to "projects" instead of "projectKeys".  The web_api description on sonarqube states this as well: https://SONARHOST/web_api/api/projects/search  

          Christian added a comment -

          Hi Aleksi

           

          Did you get a chance to verify this issue?  With the parameter as "projectKeys" (instead of "projects") it returns the data for all projects in sonarqube.

           

          I wish I could change this myself and send your a PR because it is so simple, but I have no way to compile and verify easily as I'm a .Net developer and don't have the java tools setup.

          Christian added a comment - Hi Aleksi   Did you get a chance to verify this issue?  With the parameter as "projectKeys" (instead of "projects") it returns the data for all projects in sonarqube.   I wish I could change this myself and send your a PR because it is so simple, but I have no way to compile and verify easily as I'm a .Net developer and don't have the java tools setup.

          Aleksi Simell added a comment -

          Hi,

          Not yet, my email didn't notify about your responses (or I just missed them), so I didn't realize you had already answered my question earlier. I'll try to have a look at this ASAP.

          Aleksi Simell added a comment - Hi, Not yet, my email didn't notify about your responses (or I just missed them), so I didn't realize you had already answered my question earlier. I'll try to have a look at this ASAP.

          Christian added a comment -

          No problem.  Thank you for your assistance and contribution to this module.  It is working great for us otherwise.  We pull out lots of useful data from our builds using this plugin.

          Christian added a comment - No problem.  Thank you for your assistance and contribution to this module.  It is working great for us otherwise.  We pull out lots of useful data from our builds using this plugin.

          Christian added a comment -

          Hi Aleksi;

          Just wanted to follow up on this issue.  Sorry to bother you.  I tried to make the change myself and create a PR to development but I don't have permission.  The change is to change line 57 of jenkinsci.plugins.influxdb.generators.SonarQubePointGenerator

          from:  
              private static final String SONAR_ISSUES_BASE_URL = "/api/issues/search?ps=1&projectKeys=";
          to:
              private static final String SONAR_ISSUES_BASE_URL = "/api/issues/search?ps=1&projects=";

          You can see this is the right parameter in the Sonarqube api documentation: https://ANYSONARHOST/web_api/api/projects/search

          If you want to give me permission, I can do a PR.  My Github user cburne-oshyn.
           
          Thanks

          Christian added a comment - Hi Aleksi; Just wanted to follow up on this issue.  Sorry to bother you.  I tried to make the change myself and create a PR to development but I don't have permission.  The change is to change line 57 of jenkinsci.plugins.influxdb.generators.SonarQubePointGenerator from:       private static final String SONAR_ISSUES_BASE_URL = "/api/issues/search?ps=1&projectKeys="; to:     private static final String SONAR_ISSUES_BASE_URL = "/api/issues/search?ps=1&projects="; You can see this is the right parameter in the Sonarqube api documentation:  https://ANYSONARHOST/web_api/api/projects/search If you want to give me permission, I can do a PR.  My Github user cburne-oshyn.   Thanks

          Aleksi Simell added a comment -

          Hi cburne,

          The standard protocol for PRs is that

          1. You fork the repository to your account
          2. Implement the changes in your forked repository
          3. Make a PR from the forked repository to the base repository

          This way there's no need to touch repository access rights. Everyone has access to repositories in their own GitHub account.

          Aleksi Simell added a comment - Hi cburne , The standard protocol for PRs is that 1. You fork the repository to your account 2. Implement the changes in your forked repository 3. Make a PR from the forked repository to the base repository This way there's no need to touch repository access rights. Everyone has access to repositories in their own GitHub account.

          Christian added a comment -

          Great, thanks Aleksi.  Finally had some time to do the PR.  You should have it now:  https://github.com/jenkinsci/influxdb-plugin/pull/122

          Thanks again for the awesome plugin!

          Christian added a comment - Great, thanks Aleksi.  Finally had some time to do the PR.  You should have it now:  https://github.com/jenkinsci/influxdb-plugin/pull/122 Thanks again for the awesome plugin!

          Aleksi Simell added a comment - - edited

          Fixed with PR 122.

          Aleksi Simell added a comment - - edited Fixed with PR 122 .

          Christian added a comment -

          works as expected!

          Christian added a comment - works as expected!

            aleksisimell Aleksi Simell
            cburne Christian
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: