0

I need some help with Sonarqube Database.

Every month, I'm extracting some indicators from the Sonarqube database as RCI and Coverage. We use Sonar 7.1 and Branch Plugin Community Edition in version 2.0.0.0.

When we execute a select in a sonar database by Branch Master, we retrieve the exactly RCI number and Coverage number showed in Sonarqube Web Application. But, when we change the query to retrieve another branch, the number showed in Sonarqube Web Application is one, em the number retrieve in the query is another.

For example, I have a component called "contagarantida.garantias-temporarias". The result of RCI showed em Sonarqube Web Application in a branch master is 93,7. I use this query to get the number by Sonar Database, and everything works well:

https://cdn1.imggmi.com/uploads/2019/9/13/ef907e9f7290d61ebcf5313f5879ee05-full.jpg

But, when we change the name of the branch in a query to 1.0.0.21 for example, the number showed em Sonarqube Web Application is 92,6 and the number in Sonarqube Database is 93,70:

https://cdn1.imggmi.com/uploads/2019/9/13/4275372dfad4ec889867c158213a0d66-full.jpg

select    p.kee,
          p.name,
          m.value,
          b.kee,          
          (TO_DATE('19700101','yyyymmdd') + ((s.CREATED_AT/1000)/24/60/60)) CREATED_AT,
          (TO_DATE('19700101','yyyymmdd') + ((s.BUILD_DATE/1000)/24/60/60)) BUILD_DATE
 from sonar_owner_71.snapshots s  
 left join sonar_owner_71.project_measures m on s.uuid = m.analysis_uuid
 left join sonar_owner_71.projects p on m.component_uuid = p.root_uuid
 inner join sonar_owner_71.Project_Branches b on b.project_uuid = p.project_uuid
 where m.metric_id = 161
    and p.scope = 'PRJ'
    and s.islast = 1
    and (TO_DATE('20190101','yyyymmdd')) < (TO_DATE('19700101','yyyymmdd') + ((s.BUILD_DATE/1000)/24/60/60))
    and (p.kee='contagarantida.garantias-temporarias' and b.kee='master');

I can't find the reason for this difference. My query is wrong? Can you help me?

  • Query the database directly is not a supported feature. A better idea is to use the SonarQube API. If you still want to know the difference you could try to find the source code related to this page and scan for the differences. – Jeroen Heier Sep 15 '19 at 07:45
  • 1
    I solved this problem using the SonarQube API. Here some examples: To get the RCI: http://localhost:9000/api/measures/component?component=contagarantida.garantias-temporarias&metricKeys=rules_compliance_index&branch=1.0.0.21 To get the COVERAGE: http://localhost:9000/api/measures/component?component=contagarantida.garantias-temporarias&metricKeys=coverage&branch=1.0.0.21 Thank You! – Cristiano Schaarschmidt Oct 02 '19 at 18:53

0 Answers0