SonarCloud integration (Import API)

Unlock the potential of SonarCloud integration using the Import API functionality, empowering you to craft custom metrics tailored to your data source.

While SonarCloud was not officially supported by Perf in the past, it used to function within Perf under SonarQube integration versions prior to 8.6. However, this integration broke after subsequent updates on SonarQube side.

Let's walk through the process:

  1. Go to Data Source Configuration page

  2. Choose “SonarCloud” in Import API section

    image-20240213-192738.png
  3. Enter SonarCloud link and password

    image-20240213-192840.png
  4. Fill in your SonarCloud projects (this should be done manually)

  5. Save and run data load

Important: for each new environment it's required SonarCloud agent to be enabled

 

Now you are ready to explore the Custom Metrics feature to effortlessly generate your own metrics by associating them with the respective table names:

Metric

Table name

Metric

Table name

Technical Debt (in hours)

sc_tech_debt

Technical Debt for a New Code (in hours)

sc_new_tech_debt

Unit Test Coverage, %

sc_unit_tests_cov

Code Violations by Priorities

sc_viol_by_priority

Duplicated Lines (%)

sc_dup_lines_density

Code Maintainability Rating, grade

sc_maint_rating

Cyclomatic Complexity Per File, level

sc_file_complexity

OWASP Security Vulnerabilities (in items)

sc_owasp_vulns

Security Rating, grade

sc_sec_rating

Additionally, here are some examples with notes that can assist you in crafting PerQL.

Metric type

Chart Type

PerfQL

Notes

Applicable tables

Metric type

Chart Type

PerfQL

Notes

Applicable tables

Historical metric values per project

Line Chart

select to_char(calculated_on, 'YYYY-MM-DD') as calculated_on,      max(value) FILTER (WHERE project = 'prj1') AS prj1,      max(value) FILTER (WHERE project = 'prj2') AS prj2,      max(value) FILTER (WHERE project = 'prj3') AS prj3 from sc_tech_debt group by calculated_on order by calculated_on
  1. sc_tech_debt can be replaced with any table from Applicable tables

  1. prj1, prj2, prj3 must be replaced with projects configured in Sonar Agent data source.

sc_tech_debt
sc_unit_tests_cov
sc_dup_lines_density
sc_maint_rating
sc_file_complexity
sc_owasp_vulns
sc_sec_rating

Historical metric values as sum for all project

Line Chart

with days as(     select distinct calculated_on as start from sc_tech_debt                              ),     calculated_on_day as(     select project, max(sc.calculated_on) as calculated_on, days.start as day from sc_tech_debt sc, days     where sc.calculated_on <= days.start     group by sc.project, days.start )   select to_char(day, 'YYYY-MM-DD') as calculated_day, sum(value) as value from calculated_on_day c   inner join sc_tech_debt sc on sc.calculated_on = c.calculated_on     group by day order by day

sc_tech_debt can be replaced with any table from Applicable tables

sc_tech_debt
sc_unit_tests_cov
sc_dup_lines_density
sc_maint_rating
sc_file_complexity
sc_owasp_vulns
sc_sec_rating

Actual metric values

Vertical Bar Chart

select   distinct     project,     first_value(value) over(         partition by project         order by calculated_on desc     ) as actual_value from     sc_tech_debt     order by project

sc_tech_debt can be replaced with any table from Applicable tables

sc_tech_debt
sc_new_tech_debt
sc_unit_tests_cov
sc_dup_lines_density
sc_maint_rating
sc_file_complexity
sc_owasp_vulns
sc_sec_rating

Metric - Violations by priority - Actual values

Vertical Bar Chart

 

sc_viol_by_priority

Metric - Violations by priority - Historical values for project

 

prj1 must be replaced with one of projects configured in Sonar Agent data source.

sc_viol_by_priority

If you require assistance or have any questions, feel free to reach out to our support team for expert guidance and consultations.