Can't create maintainability rating condition through api.

280 views
Skip to first unread message

Kumar Gaurav

unread,
Apr 18, 2018, 10:03:54 AM4/18/18
to SonarQube

Dear All,

I am not able to create "Maintainability Rating" quality gate condition through API. I using endpoint "http://mysonar/api/qualitygates/create_condition and following are the output for different requests (have attached screenshot as well):

[{op=[GT], period=[1], metric=[sqale_rating], gateId=[6], warning=[], error=[1]}] : The metric 'Maintainability Rating' cannot be used on the leak period

[{op=[GT], period=[0], metric=[sqale_rating], gateId=[6], warning=[], error=[1]}] : Value of parameter 'period' (0) must be one of: [1]

The same error comes for Reliability Rating (didn't try other rating).

I remember it was working in 6.7.1. Is there something changed after that? Current version of my sonarqube is 7.1.

Please let me know if you need more information.

Thanks a lot
Kumar




G. Ann Campbell

unread,
Apr 18, 2018, 10:11:57 AM4/18/18
to SonarQube
Hi Kumar,

There's a separate, specific metric that should be used: new_maintainability_rating.


HTH,
Ann

Kumar Gaurav

unread,
Apr 18, 2018, 10:18:29 AM4/18/18
to SonarQube
Thanks Ann. Isn't new_maintainability_rating related to: Maintainability Rating on New Code?

To me it looks like:
sqale_rating => Maintainability Rating
new_maintainability_rating => Maintainability Rating on New Code

Please correct me if I am wrong?

Thanks again,
Kumar

G. Ann Campbell

unread,
Apr 18, 2018, 10:21:27 AM4/18/18
to SonarQube
Hi Kumar,

You've got the mapping right.


Ann

Kumar Gaurav

unread,
Apr 18, 2018, 10:28:58 AM4/18/18
to SonarQube
Thanks Ann. Does it mean it could be an issue that needs to be fixed? or is this a desired behaviour.. It was working on 6.7.1. I am basically trying to create "Maintainability Rating", not "Maintainability Rating on New Code". So I need to use sqale_rating.

Thanks & Regards,
Kumar

Kumar Gaurav

unread,
Apr 18, 2018, 11:09:29 AM4/18/18
to SonarQube
I just confirmed that it happens for security_rating and reliability_rating (not able to create condition). In case the information helps. :)

Thanks,
Kumar

G. Ann Campbell

unread,
Apr 18, 2018, 11:32:07 AM4/18/18
to Kumar Gaurav, SonarQube
Hi,

There's nothing here that needs to be fixed in terms of metrics, however we recognize that the interface for setting Quality Gates is a bit confusing. Here's the related initiative: MMF-473

Note that nothing is currently planned on this.


Ann



---
G. Ann Campbell | SonarSource
Product Manager
@GAnnCampbell

--
You received this message because you are subscribed to a topic in the Google Groups "SonarQube" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sonarqube/0Sj6xEoOlK8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sonarqube+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sonarqube/151902ba-4a36-4806-8b68-9348aef78a8f%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Kumar Gaurav

unread,
Apr 18, 2018, 7:52:02 PM4/18/18
to SonarQube
Thanks Ann for sharing details about metrics confusion. I completely agree with that however the original issue I am seeking help with is a different issue. Sorry if that was not clear.. Let me clarify the original issue:

Background:
Sonarqube has a web interface to create condition where we can create all kinds of metrics including maintainability/reliability/security rating for a quality gate.
Sonarqube also has an api to do the same (create quality gate condition) at endpoint: /api/qualitygates/create_condition. The documented description for which is:

{
"key": "create_condition",
"description": "Add a new condition to a quality gate.<br>Requires the 'Administer Quality Gates' permission.",
"since": "4.3",
"internal": false,
"post": true,
"hasResponseExample": true,
"changelog": [],
"params": [
{
"key": "error",
"description": "Condition error threshold",
"required": false,
"internal": false,
"exampleValue": "10",
"maximumLength": 64
},
{
"key": "gateId",
"description": "ID of the quality gate",
"required": true,
"internal": false,
"exampleValue": "1"
},
{
"key": "metric",
"description": "Condition metric",
"required": true,
"internal": false,
"exampleValue": "blocker_violations"
},
{
"key": "op",
"description": "Condition operator:<br/><ul><li>EQ = equals</li><li>NE = is not</li><li>LT = is lower than</li><li>GT = is greater than</li></ui>",
"required": false,
"internal": false,
"exampleValue": "EQ",
"possibleValues": [
"LT",
"GT",
"EQ",
"NE"
]
},
{
"key": "organization",
"description": "Organization key. If no organization is provided, the default organization is used.",
"since": "7.0",
"required": false,
"internal": false,
"exampleValue": "my-org"
},
{
"key": "period",
"description": "Condition period. If not set, the absolute value is considered.",
"required": false,
"internal": false,
"possibleValues": [
"1"
]
},
{
"key": "warning",
"description": "Condition warning threshold",
"required": false,
"internal": false,
"exampleValue": "5",
"maximumLength": 64
}
]
}


Issue
I can use web interface to create maintainability/reliability/security rating but I can't use api to do the same. I can use api to create other metrics e.g. maintainability on new code etc..but can 't create maintainability/reliability/security rating.

If I try to create api, I get 400 (bad request) with following messages, based on request data (you can also see in screenshots attached in first post):

request data: [{op=[GT], period=[1], metric=[sqale_rating], gateId=[6], warning=[], error=[1]}]
response code
: 400
response message
: The metric 'Maintainability Rating' cannot be used on the leak period


request data
: [{op=[GT], period=[0], metric=[sqale_rating], gateId=[6], warning=[], error=[1]}]
response code
: 400
response message
: Value of parameter 'period' (0) must be one of: [1]


Now I am not sure what data should I send to endpoint /api/qualitygates/create_condition in request to create Maintainability/Reliability/Security rating. Can you please help me with that.

Thanks a lot,
Kumar
To unsubscribe from this group and all its topics, send an email to sonarqube+...@googlegroups.com.

nicolas...@sonarsource.com

unread,
Apr 19, 2018, 4:59:26 AM4/19/18
to SonarQube
Hi Kumar,

Browser inspector is your friend in such case. When you define a condition on Maintainability Rating on New Code , it actually passes new_maintainability_rating to the WebAPI under the hood.


What Ann is essentially saying is that 'sqale_rating on new code' is what new_maintainability_rating actually is (and similar observation for other rating).

Makes sense ? I strongly recommend playing with browser inspector whenever you wonder about the WebAPI could actually be used (that's the beauty of it: the WebAPI you have access to is the actual one that is used by the UI).

Nicolas

Kumar Gaurav

unread,
Apr 19, 2018, 8:28:23 AM4/19/18
to SonarQube
Hi Nicolas, Thanks a lot for the awesome tip. I was actually trying to create Maintainability Rating (Not on new code). However using your tips, I could see what the problem was. In case of Maintainability Rating, I should not put "period" in request data. So request data should look like: 

[{op=[GT], metric=[sqale_rating], gateId=[6], warning=[], error=[1]}] 

Thanks again,
Kumar
Reply all
Reply to author
Forward
0 new messages