Skip to content

[FEATURE] Promltest: support to test expectation annotations#15995

Merged
beorn7 merged 15 commits intoprometheus:mainfrom
NeerajGartia21:promql/test
Apr 1, 2025
Merged

[FEATURE] Promltest: support to test expectation annotations#15995
beorn7 merged 15 commits intoprometheus:mainfrom
NeerajGartia21:promql/test

Conversation

@NeerajGartia21
Copy link
Contributor

Resolves #15794

This PR enhances the PromQL testing framework by allowing tests to check for expected annotations while keeping the existing syntax unchanged. Now, you can use expect lines to verify expected annotations. For example:

eval instant at 10m ()
expect warn msg: something went wrong

For more details see: #15794 (comment)

CC: @beorn7 @charleskorn

Signed-off-by: Neeraj Gartia <neerajgartia211002@gmail.com>
Signed-off-by: Neeraj Gartia <neerajgartia211002@gmail.com>
Signed-off-by: Neeraj Gartia <neerajgartia211002@gmail.com>
Signed-off-by: Neeraj Gartia <neerajgartia211002@gmail.com>
Signed-off-by: Neeraj Gartia <neerajgartia211002@gmail.com>
@beorn7 beorn7 self-requested a review February 7, 2025 21:41
Copy link
Contributor

@charleskorn charleskorn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can simplify this dramatically by dropping support for the old syntax and only supporting the new syntax: the number of consumers of this package are small, and converting from the old syntax to the new is straightforward to automate with something like sed.

What do you think @beorn7?

@beorn7
Copy link
Member

beorn7 commented Feb 11, 2025

I would like to believe that the number of consumers is indeed small, but experience tells that these assumptions are usually wrong when it comes to Prometheus.

If it's not an excessive amount of effort, I would like to have both ways in parallel for a while so that users can migrate gradually. Once the new way has proven itself, we can deprecate the old way and then drop the old way a minor release later or so (and then have the simplification we want after all).

@beorn7
Copy link
Member

beorn7 commented Feb 11, 2025

(Note: I still need to look at the code in detail, which might change my opinion above. ;)

@beorn7
Copy link
Member

beorn7 commented Feb 18, 2025

Sorry, this is still on my list. I'm just too busy with company-internal things at the moment. I hope I get to this before the week ends.

Copy link
Member

@beorn7 beorn7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much. Looks good so far, and I would say it seems manageable to support the "old way" for one or two more releases to allow a smooth migration.

One thing, though: I think we should (or need to) relax the requirement of "no annotations" for a simple eval command. That's a change of behavior, but it won't let any test fail that passes now (because it relaxes passing criteria). However, we clearly have to state that to keep the old strict behavior, you must add a expect no_warn and expect no_info now.

If we don't add this relaxation now, the no_info and no_warn expectations wouldn't do anything. But one of the requirements was to allow an eval that doesn't care about annotations (cf. #15713).

More general TODOs:

  • Update documentation (in promql/promqltest/README.md) with the new stuff.
  • Mark the old stuff as deprecated in the documentation.
  • Ideally, provide conversion scripts (old → new) in the documentation (sed line or something) or as a file (if it's an actual program of some kind in a language of choice – back in my days, I used Perl for that, but I guess that would look weird today… ;).

Signed-off-by: Neeraj Gartia <neerajgartia211002@gmail.com>
Signed-off-by: Neeraj Gartia <neerajgartia211002@gmail.com>
@NeerajGartia21
Copy link
Contributor Author

Thanks @beorn7 for the review.

One thing, though: I think we should (or need to) relax the requirement of "no annotations" for a simple eval command. That's a change of behavior, but it won't let any test fail that passes now (because it relaxes passing criteria). However, we clearly have to state that to keep the old strict behavior, you must add a expect no_warn and expect no_info now.

Since this is requested, we can relax the "no annotations" for a simple eval cmd. So for this do we need to add both expect no_warn and expect no_info to each line that are simple eval statements?

More general TODOs:
Update documentation (in promql/promqltest/README.md) with the new stuff.
Mark the old stuff as deprecated in the documentation.
Ideally, provide conversion scripts (old → new) in the documentation (sed line or something) or as a file (if it's an actual program of some kind in a language of choice – back in my days, I used Perl for that, but I guess that would look weird today… ;).

Thanks. I will update the documentation for these TODOs.

@beorn7
Copy link
Member

beorn7 commented Feb 27, 2025

As discussed separately, we do not want to add expect no_warn and expect no_info to each and every test that formerly used a simple eval. Instead, we want to add those explicit expectation of no annotations only to those tests that have the intention of testing for the lack of annotations. A typical example would be if there is one test testing how an annotation triggers, and then there is another test just before or after testing something similar but with a change to prevent the annotation to show up.

Copy link
Member

@beorn7 beorn7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just two small things left in the code. (But we also need documentation, see separate command.)

@beorn7
Copy link
Member

beorn7 commented Feb 27, 2025

About the documentation update:

What we need in this PR is an update of the documentation (in promql/promqltest/README.md) with the new stuff, and a deprecation note for the old stuff. Also, very important, the note that a simple eval, while formerly asserting that there are no annotations, will now tolerate annotations. So in the (probably rare) case that the tester intends to assert that there are no annotations, they now have to add the no_warn/no_info lines.

We don't necessarily need the conversion scripts in this PR, but we should give written instructions how the old and the now way looks like. This could go along with the stuff above (like discussing when to add no_warn/no_info).

As discussed with @NeerajGartia21 separately, we'll have a separate PR to convert our own tests (those in the prometheus/prometheus repo). We can then also discuss where we want the explicit no_warn/no_info lines. And we might want to add tests for specific annotation content at the same time.

BTW, given that adding the no_warn/no_info lines and adding tests for specific annotation content needs additional information and also best judgement, maybe we should not strive for very sophisticated auto-conversion. Just do the minimal thing to convert old syntax into valid new syntax, but without no_warn/no_info lines. @NeerajGartia21 while working on the conversion, you could explore what's the best way to do so in a scripted fashion.

Signed-off-by: Neeraj Gartia <neerajgartia211002@gmail.com>
Signed-off-by: Neeraj Gartia <neerajgartia211002@gmail.com>
Signed-off-by: Neeraj Gartia <neerajgartia211002@gmail.com>
@NeerajGartia21
Copy link
Contributor Author

@beorn7 I have added the suggestions and updated the ReadMe with the new stuffs. Please have another look.

Copy link
Member

@beorn7 beorn7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tiny documentation improvements, but otherwise looks good.

@charleskorn do you have any comments or concerns left?

@charleskorn
Copy link
Contributor

@charleskorn do you have any comments or concerns left?

Sorry, I've had a couple of other things on my plate, I'll try to review this today or early next week if not.

Signed-off-by: Neeraj Gartia <neerajgartia211002@gmail.com>
@NeerajGartia21
Copy link
Contributor Author

Tiny documentation improvements, but otherwise looks good.

I have updated the documentation based on your suggestions.

@beorn7
Copy link
Member

beorn7 commented Mar 21, 2025

Thank you. Let's wait a bit for @charleskorn .

Copy link
Contributor

@charleskorn charleskorn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this!

Signed-off-by: Neeraj Gartia <neerajgartia211002@gmail.com>
@NeerajGartia21
Copy link
Contributor Author

I've updated the PR. Please have a look, @charleskorn, @beorn7.

Signed-off-by: Neeraj Gartia <neerajgartia211002@gmail.com>
Signed-off-by: Neeraj Gartia <neerajgartia211002@gmail.com>
@beorn7
Copy link
Member

beorn7 commented Mar 30, 2025

@NeerajGartia21 thank you very much for following up.

@charleskorn are all your concerns addressed?

KubeCon week is starting, so I'll have limited availability during the coming week, but it would be great if we could wrap this up soon.

@beorn7
Copy link
Member

beorn7 commented Mar 30, 2025

In fact, if we get this merged before Wednesday, we could give the test conversions (including maybe a script) to attendees of the Prometheus contrib fest as one of the possible tasks. See https://kccnceu2025.sched.com/event/1tcx4/contribfest-contribution-guide-and-workshop-help-us-improve-the-prometheus-ecosystem

Signed-off-by: Neeraj Gartia <neerajgartia211002@gmail.com>
Copy link
Contributor

@charleskorn charleskorn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this @NeerajGartia21!

@NeerajGartia21
Copy link
Contributor Author

Thanks @charleskorn @beorn7 for the reviews!

@beorn7
Copy link
Member

beorn7 commented Apr 1, 2025

Great. I'll give this a final look and then merge.
And we'll propose the test conversion as a ContribFest task tomorrow. (@NeerajGartia21 no need for you to work on it right now. Let's first see what kind of contribution we get from the ContribFest.)

@beorn7 beorn7 merged commit 6e51c2d into prometheus:main Apr 1, 2025
27 checks passed
@beorn7
Copy link
Member

beorn7 commented Apr 1, 2025

Created #16367 for the conversion.

@NeerajGartia21
Copy link
Contributor Author

And we'll propose the test conversion as a ContribFest task tomorrow. (@NeerajGartia21 no need for you to work on it right now. Let's first see what kind of contribution we get from the ContribFest.)

That's great! Meanwhile, I'll work on other issues.

@NeerajGartia21 NeerajGartia21 deleted the promql/test branch April 1, 2025 11:25
krajorama added a commit to prometheus/docs that referenced this pull request May 8, 2025
Follow up prometheus/prometheus#15995

Signed-off-by: György Krajcsovits <gyorgy.krajcsovits@grafana.com>
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.

promqltest: more detailed expectations for annotations

3 participants