Skip to content

Impove promtool test rules output diff on test failure#7549

Closed
topliceanu wants to merge 3 commits intoprometheus:masterfrom
smartcontractkit:promtool-test-output-diff
Closed

Impove promtool test rules output diff on test failure#7549
topliceanu wants to merge 3 commits intoprometheus:masterfrom
smartcontractkit:promtool-test-output-diff

Conversation

@topliceanu
Copy link
Copy Markdown

@topliceanu topliceanu commented Jul 10, 2020

Why?

The promtool test rules utility produces error outputs that are sometimes hard to parse. This is because the expected and actual data structures being compared are printed using a %#v dump. It is hard to read the difference between the two structures when they are large - eg. a lot of labels and/or a lot of annotations.

How?

I have imported github.com/google/go-cmp@v0.5.0/cmp and I'm using it to calculate and pretty-print a diff between the two structures under test on failure.

I don't feel strongly about using this library. Consider this as more of a PoC, I'm happy to proceed with this however the community feels its best: using a different library, adding a diff implementation to the source, etc.

An alternative is to defer the presentation to other tools by returning some kind of standardized output.

Thanks for your feedback!

Signed-off-by: alexandru topliceanu <alexandru.topliceanu@gmail.com>
Signed-off-by: alexandru topliceanu <alexandru.topliceanu@gmail.com>
@topliceanu topliceanu force-pushed the promtool-test-output-diff branch from 68f17de to 40ba0f3 Compare July 10, 2020 16:49
Signed-off-by: alexandru topliceanu <alexandru.topliceanu@gmail.com>
@topliceanu
Copy link
Copy Markdown
Author

CC @simonpasquier

@vanugrah
Copy link
Copy Markdown

+1. Could we also get rid of the / delimiter around quotations as well for improved readability.

@roidelapluie
Copy link
Copy Markdown
Member

Hello @simonpasquier, can you have a look at this? Thanks! Also, it appears that it is not our usual way to compare structs.

@dgl
Copy link
Copy Markdown
Member

dgl commented Oct 15, 2020

I looked at this a bit and one issue is using go-cmp prints out internal implementation details as it's really designed for unit tests, e.g.:

expr: "count(ALERTS) by (alertname, alertstate)", time: 4m,
        exp:"{alertname=\"InstanceDown\", alertstate=\"firing\"} 1E+00"
        got:"nil"
        diff (-exp, +got):
  []main.parsedSample(
-       {{Labels: s`{alertname="InstanceDown", alertstate="firing"}`, Value: 1}},
+       nil,

It's a bit confusing for the user to see the diff in the form of the internal structures that promtool uses, rather than PromQL syntax. I'm working on an alternative, first removing the use of %#v to make the output just clearer: #8064 and then I'm going to investigate some kind of diff.

@codesome
Copy link
Copy Markdown
Member

Closing in favor of #8064, thanks for the PR @topliceanu!

@codesome codesome closed this Oct 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants