-
Notifications
You must be signed in to change notification settings - Fork 9.8k
promql: extend test scripting language to support asserting on expected error message #14038
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
promql/test.go
Outdated
@@ -292,6 +292,12 @@ func (t *test) parseEval(lines []string, i int) (int, *evalCmd, error) { | |||
i-- | |||
break | |||
} | |||
|
|||
if cmd.fail && strings.HasPrefix(defLine, "expected_message") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about fail_message
or fail_msg
to be more explicit?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've changed it to expected_fail_message
, how's that?
Note for a future PR: It would be good to also be able to assert annotations. |
The nhcb branch lets us assert warning annotations, but not yet specific ones. After this is merged, when I fix the conflicts I can look into doing something similar to assert specific annotations. Might be slightly more complicated though because you can only have maximum 1 error but you may have multiple warning annotations. |
Why do we need both an explicit string and a regex, given the former is a subset of the latter? Incidentally "pattern" did not immediately suggest "regex" to me, maybe because I spent too much time using LogQL. |
Many error messages contain characters that are special in regexes (eg. However, an exact match isn't great for every case - sometimes a regex is more convenient or clearer (eg. if only parts of the error message are important).
Fair point, I'll change this. |
Signed-off-by: Charles Korn <charles.korn@grafana.com>
…age` Signed-off-by: Charles Korn <charles.korn@grafana.com>
Signed-off-by: Charles Korn <charles.korn@grafana.com>
Signed-off-by: Charles Korn <charles.korn@grafana.com>
Signed-off-by: Charles Korn <charles.korn@grafana.com>
199ff32
to
78861fe
Compare
I've rebased this to resolve the conflicts with #13999. |
Any chance I could get a review on this? Would be great to get this merged. |
The PR has diverged, with the introduction of regexes, since my initial review.
Could you provide examples? Moreover, we should clarify that we do not guarantee the stability of these messages, which might make these checks challenging to maintain. |
The use case for this is not for |
In that case, I think we can go with exact matching if we want to have such safeguards in our tests and let's see if they're easy to maintain. |
Unfortunately exact matching isn't always enough for my use case: I am testing Mimir's replacement PromQL engine, and it doesn't guarantee that error messages are identical to Prometheus' engine. For example, in some cases, Mimir's engine includes additional information in error messages, and in other cases, implementation differences mean we iterate through series in a different order and so different series are used for the error message. |
I'm currently reviewing #13662 (which @zenador mentioned above as another PR that needs assertions on returned errors (in this case annotations)). Since we use this for both the internal PromQL testing framework and the user-facing rule unit tests, I would tend towards making it flexible, even if the only use case right now is in Mimir. Every new feature in PromQL will ideally be testable in the framework and needs to extend it (as seen with native histograms), so erring on the side of making it more flexible is probably less hassle in the long run. |
Note that https://github.com/prometheus/prometheus/blob/main/docs/configuration/unit_testing_rules.md needs to be updated with the changes here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, thanks to you two for the details.
Let's give this a try ;)
@charleskorn could you update https://github.com/prometheus/prometheus/blob/main/docs/configuration/unit_testing_rules.md accordingly? Then we can merge this, and then #13662 can be adjusted on top of this. |
Sorry, I think I'm missing something - those docs don't talk about asserting that a query fails, so I'm not sure where I'd add documentation for asserting on the failure message. |
Maybe that was an omission even before. Or maybe you cannot use the query fail assertions with the Sorry for not being able to be more specific, I'm not a domain expert here. I would propose the following steps:
|
As far as I can see, I'll add a separate doc explaining the test scripting language and its features. |
Signed-off-by: Charles Korn <charles.korn@grafana.com>
Added: https://github.com/charleskorn/prometheus/blob/assert-on-query-error/promql/promqltest/README.md |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice. Thank you very much.
This PR extends the PromQL test scripting language to support asserting that a query fails with a particular error message or an error message matching a regexp (rather than just asserting that the query fails for any reason).