2

My question is continuation of the question posted here on New code coverage metrics not returning values from SonarQube 5.3 API

We recently rolled out Sonar 5.3 to take advantage of new_coverage and other new metrics. However after some days worth of code analysis of several we are finding that Sonar is not correctly instrumenting new_coverage metric. It is however able to instrument new_violations, etc.

This situation is fairly regular and happening for several java based projects. After running the analysis, Sonar will report change in ncloc, new_violations, etc but will not report value for var2 and fvar2 for new_coverage. Here is a sample response for one application on url https://internal.sonar.server.com/api/resources?resource=prj_key&format=json&metrics=ncloc,new_coverage&includealerts=true&includetrends=true

[ { "creationDate": "2016-04-06T15:51:29-0400", "date": "2016-06-20T21:48:27-0400", "description": "", "id": 6610, "key": "<PRJ_KEY>", "lname": "<PRJ_LNAME>", "name": "<PRJ_LNAME>", "p1": "previous_version", "p1d": "2016-06-06T02:21:39-0400", "p1p": "16.06.00-SNAPSHOT", "p2": "previous_analysis", "p2d": "2016-06-20T16:42:38-0400", "p2p": "2016-06-20", "p3": "days", "p3d": "2016-05-22T02:22:57-0400", "p3p": "30", "qualifier": "TRK", "scope": "PRJ", "uuid": "AVPtITChBmbOnKmhsXJi", "version": "16.06.01-SNAPSHOT", "msr": [ { "alert": null, "alert_text": null, "frmt_val": "41,589", "fvar1": "483", "fvar2": "9", "fvar3": "743", "key": "ncloc", "val": 41589.0, "var1": 483.0, "var2": 9.0, "var3": 743.0 }, { "alert": null, "alert_text": null, "frmt_val": "47.9%", "fvar1": "-0.4%", "fvar2": "0.0%", "fvar3": "-0.3%", "key": "coverage", "val": 47.9, "var1": -0.399999999999999, "var2": 0.0, "var3": -0.300000000000004 }, { "alert": "OK", "alert_text": null, "fvar1": "15.2%", "fvar3": "28.1%", "key": "new_coverage", "var1": 15.2317880794702, "var3": 28.1407035175879 } ] } ]

As you see in the above response, we have lines of code changed since previous analysis (and all those lines are in the functional code not being ignored. However, there is no value for var2 for new_coverage field despite the fact there was an analysis just done yesterday. The issue is not just in API but even on the UI Side. We are not seeing "value since prev analysis" for new coverage metric for several metrics but other new code metrics and total coverage come just fine.

Community
  • 1
  • 1
Rohan
  • 665
  • 9
  • 17

1 Answers1

0

You can have new lines of code without new coverage, for example if the new lines of code are comments. You shouldn't have a value in this case because 0 means 0% of new code is covered.

Check metric new_lines_to_cover which returns the number of lines that needs to be covered on new code. Note there's a bug on this metric when there's no new lines to cover.

In the UI, a ticket has been created.

  • As i had mentioned at the end, the new lines were all functional code in .java class files and none of the files are being ignored. in fact, in a previous run, there were new_major_violations for var2 but no new_code_coverage for var2. That does seem ofd, righr? – Rohan Jun 23 '16 at 12:48
  • yes, it's odd. What does `new_lines_to_cover` return? – Teryk - SonarSource Jun 23 '16 at 13:17
  • so this issue did not come in the last analysis and since we were not taking note of this metric, we are not aware of value for that metric. However, we will now monitor this metric as well and will add my response in a day or two when we again observe this issue – Rohan Jun 23 '16 at 14:43