Quality_gate_details metric missing conditions

Hi Team,

When a project measure is displayed as “–” in the SonarQube web interface, the /api/measures/component?component=xxx&metricKeys=quality_gate_details returned JSON won’t display the quality gate condition for that measure.

In the attached screenshots, the Coverage On New Code is less than 80.0% condition is not returned in the JSON text. It is a problem, because it seems that the condition is not included in the quality gate.

The JSON text should include all the quality gate conditions, even those which value is “–” (undefined or not computable).

Thanks in advance.

Best regards.

Hey,

In this situation, the condition on coverage is not returned because there are no coverage data available. In this case, the Quality Gate criteria on coverage is not taken into consideration to fail the quality gate, and that’s the reason why it’s not returned by the measure API. there is no coverage measure.

If you are trying to retrieve the quality gate criteria, you can use api/qualitygates/show, which returns the conditions on a specific quality gate:

{
  "id": 5,
  "name": "My Quality Gate",
  "conditions": [
    {
      "id": "AU-Tpxb--iU5OvuD2FLy",
      "metric": "blocker_violations",
      "op": "GT",
      "error": "0"
    },
    {
      "id": "AU-Tpxb--iU5OvuD2FLz",
      "metric": "tests",
      "op": "LT",
      "error": "10"
    }
  ],
  "isBuiltIn": false,
  "actions": {
    "rename": true,
    "setAsDefault": true,
    "copy": true,
    "associateProjects": true,
    "delete": true,
    "manageConditions": true,
    "delegate": true
  }
}

Hi @pierreguillot,

Thanks for your response.

In this situation, the condition on coverage is not returned because there are no coverage data available. In this case, the Quality Gate criteria on coverage is not taken into consideration to fail the quality gate, and that’s the reason why it’s not returned by the measure API. there is no coverage measure.

That’s exactly the new feature I am requesting: to see all the quality gate conditions, even those which are not computed.

Conditions with uncomputed values are still conditions of the quality gate. They could be returned in the JSON text with their corresponding empty value.

Thanks in advance

Any chances to have the don’t care quality gate conditions returned in the JSON response? It is quite confusing not seeing existing conditions of the quality gate, even if their measures are irrelevant to the quality gate status. It seems that such conditions are not included in the quality gate definition.

Thanks!

Hi,

What do you mean by “the don’t care quality gate conditions”? I’m looking at the QG status of SonarQube right now, and it looks like every condition in the QG is returned…

 
Ann

Hi Ann,

The problem was detected with the /api/measures/component endpoint:

I see that calling the endpoint you mentioned instead, /api/qualitygates/project_status, does return all conditions, even those whose measures are not relevant (don’t care) for the quality gate status computation. That’s good news :slight_smile:

Thank you!

1 Like

Hi @ganncamp,

In the link in your answer, all the conditions are returned because all the metrics are computed on master branch.

But in the same project if we query the “branch-8.9” branch, the coverage is not computed and so it is not returned in the response (Quality Gate status for branch “branch-8.9”)

Best regards.

2 Likes

Hi @ganncamp, @pierreguillot,

We’ve seen that neither the /api/measures/component?component=xxx&metricKeys=quality_gate_details or the /api/qualitygates/project_status endpoints will return the conditions which values have not been relevant for the quality gate status computation.

Is there any alternative? Calling /api/qualitygates/show returns the quality gate definition, including all its conditions, but not their values.

Thanks!

Hi,

Yup. In Quality Gate-related calls we only return data relevant to the Quality Gate.

Well, there’s the measures service. You can get all the measures from that…

 
Ann

Thanks for your quick reply, Ann.

I see that the /api/measures service will return the values grouped by periods:
https://my-sonar.com/api/measures/component?component=my-project&branch=main&metricKeys=new_security_rating

{"component":{"key":"my-project","name":"My Project","description":"My Project Description","qualifier":"TRK","measures":[{"metric":"new_security_rating","periods":[{"index":1,"value":"1.0","bestValue":true}],"period":{"index":1,"value":"1.0","bestValue":true}}]}}

We’d like to have a straightforward way to retrieve the current values. Is there any other service we could use instead? Otherwise, for future releases I kindly suggest making the /api/measures/component?component=xxx&metricKeys=quality_gate_details and the /api/qualitygates/project_status return all the quality conditions, even those which have not been relevant for the quality gate status computation. The measures for such conditions could be returned as empty strings, or “-”, for example.

We’d really appreciate having that data returned.

Best regards,
Barbara

Hi Barbara,

Have you tried isolating the data via the UI? If you can find all current values in the UI then there will be a web service that feeds the data. If not, then there’s not one.

 
Ann

Hi Ann,

I’m not sure what you mean by isolating the data via the UI :worried: Sorry for that…

We just want to retrieve a complete view of the quality gate details: all the conditions in the quality gate definition with its values, either or not relevant for the QG status.

Not returning some conditions is quite confusing: you can’t tell whether they are not in the quality gate definition, or they were just not relevant for the last quality gate status computation.

Regards,
Barbara

Hi,

Again, the Quality Gate-related web services give a “complete view of the quality gate details”. They provide the values of each metric tested in the Quality Gate. If you want other metrics, then you’ll need to look elsewhere.

You should be able to find current-state values of each metric on the Measures page. Your browser developer tools can help you understand which web services were used to get those values.

 
Ann