Replies: 2 comments 2 replies
-
Hi there, The current implementation/SARIF-output always does provide both the The "message" is always attached to the rule-definition itself: ansible-lint/src/ansiblelint/formatters/__init__.py Lines 263 to 268 in 7849f27 The "details" are present in the result-item (which refers to the rule): ansible-lint/src/ansiblelint/formatters/__init__.py Lines 289 to 295 in 7849f27 e.g.
So... all the information is already available:
It's up to you/the consumer of the SARIF-output to parse/compile this information. I don't see the need or any value in further merging these texts (and produce redundant content). |
Beta Was this translation helpful? Give feedback.
-
It's not my call, since I'm not responsible or the owner of this project. |
Beta Was this translation helpful? Give feedback.
-
Background
I just added ansible-lint to our jenkins pipeline in our ansible project. There were multiple issues I encountered and I think most of them can be broken down to a very specific discussion.
Maybe as a context: this ansible project is a bit bigger (~6k files) and already established. Our team decided on a few categories we will not follow and ignore, some categories we want to adapt to over time, but categorize as warnings for now and the rest are pipeline-breaking issues.
First, I quickly found the AnsibleLint parser for the WarningsNG plugin, implemented mostly via Regex. I thought "Great, I just need to add the -p flag and pipe the output somewhere warnings-ng can pick it up".
Sadly, it did not determine the severity and put all issues into the "normal" category which would be crucial when figuring out which issue broke the build. Also, it only parses the first line of the issue message and some can be multi-line. I'm not sure if/how the pep8 format even handles multiline-output.
I then looked for alternative formats and intersections of the warnings-ng parser list and the formats of ansible-lint. I found sarif, which conveniently wraps all issues in json, so multiline shouldn't be an issue. Also, severities are handled properly. But it's not all sunshine and roses either, because the sarif formatter (in the issues I tested) outputs more generic warnings than the AnsibleLint plugin. But conveniently we can output both formats with a single ansible-lint invocation and just use both parsers so we get all information.
Obviously this is not convenient at all (and I pulled my hair out a few times while having all these issues). I think I Identified a few core problems, which could make at least sarif work properly (since the pep8 format seems broken anyways, since severities are only tacked on and multiline is also not working).
The problem with formatting (in sarif)
It basically comes down to this line:
ansible-lint/src/ansiblelint/formatters/__init__.py
Lines 292 to 296 in 7849f27
This was mostly the result of (and with reasonable explanation) #3163. The result of that MR still has a few problems:
match.details
now, even ifmatch.message
has far more interesting content. E.g.match.message
, for some rules, can be very specific for the one issue that was detected.e.g. lets take this issue (normal output from ansible-lint):
message is
Syntax error in jinja2 template: {{ inventory_dir + '/../../files/docker-nginx/hosts/group_a/extra/index.html') }}
and details isunexpected ')'
or e.g. from jinja[spacing] with multiline issues:
Here, the
details
basically repeat part of the message (and the message would be a very bad descriptor for the rule as a whole)Or another example where the details are not helping at all and the message is the interesting part:
If you keep in mind that jenkins' sarif visualization will only show the part with "Returned errors will not include..." it's not just unhelpful, it's infuriating, given the context that could be delivered in the message ("the issue is in a with_items block and looks like ")
Another example:
Here, the message is generic, but the details are not that helpful as well, since we already have the line in the file where the task is written.
Ways to a solution
Imho, the best way out of this would be the following, given we want to change existing rules and output as little as possible:
0. Keep the message and description fields
Of course there are also different options, like only having one message going forward, which includes the details. This would require bigger changes and would also affect the output of other formatters.
I'm also interested in pushing this myself, with implementations and tests. But I want to hear your opinion first, to see if this is reasonable and/or wanted or has some issues. I would imagine that this can also be achieved in small steps, like first doing 1., progressively doing 2 and 3 and see what 4 should contain. Imho 4. is the most difficult part to figure out and should be up to other people to decide.
Also tagging @4ch1m and @atiterlea since they were involved in the last bigger changes of the sarif output and "fixing jenkins" shouldn't break other peoples pipelines.
Beta Was this translation helpful? Give feedback.
All reactions