-
Notifications
You must be signed in to change notification settings - Fork 9.8k
[Test] Extract most PromQL test code into separate packages #13999
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
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.
Wow, epic work. And very nice. I think this makes a lot of sense.
I would assume this is uncontroversial, and I recommend to just merge. But I leave it to @bboreham to make a call if more feedback is required.
I think the main people impacted by this are people using PromQL as a library outside of Prometheus. Since I see I made a typo in one of the git commit headers, I will fix that and force-push. |
5287992
to
fc7fe82
Compare
We run those tests as a library, but moving them to a separate package sounds like a good idea. |
I don't understand why |
Without it we have a circular dependency between |
I see. I don't know. From a design perspective, I'm not sure this change is a net positive benefit. To make it happen, you had to introduce
To directly answer your question, looking at the changes I don't see any blocker for Mimir. |
Some people hold that this is actually a best practice. It is described at https://pkg.go.dev/testing:
More discussion: |
promql/engine.go
Outdated
@@ -584,6 +586,11 @@ func (ng *Engine) newTestQuery(f func(context.Context) error) Query { | |||
return qry | |||
} | |||
|
|||
func (ng *Engine) TestEnablePerStepStats() { ng.enablePerStepStats = true } |
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.
Is it not possible to set these via engine opts?
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.
Yes it is possible, but there wasn't a way to get those options in to NewTestEngine
.
I've pushed a commit which adds 20 false
parameters so we can do it that way.
The other way would be for this one test to not call NewTestEngine
.
Responding to Marco's point about exporting internals, I added parameters to Now the functions exported from
|
Also one more export: |
These changes look fine to me, I don't think they'll cause any issues for us. |
I have now removed all new exports from If no further comments I will clean up the commits a little and merge. |
To avoid a circular reference between promql and promqltest. Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
This saves having a function solely to call kahanSumInc. Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
So that promql package does not bring in test-only dependencies. Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
Lint started complaining after I moved the file. Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
So it nearly compiles. Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
And export `DefaultMaxSamplesPerQuery` so callers can replicate previous behaviour. Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
So that tests can call it from another package. Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
To packages outside of promql. Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
So that they can import promqltest which imports promql. Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
2ffdf2f
to
ec4a6f1
Compare
* set enablePerStepStats and lookback duration via `NewTestEngine` parameters. * check maxSamples by recreating query engine * check lookback without modifying internals Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
ec4a6f1
to
786e0e7
Compare
It is undesirable to have the
promql
package contain a lot of test-only code, which depends ontestify
and other utilities.I created three new packages:
promqltest
, the test utilities used by promql tests and by other packages such aspromtool
.promql_test
which is most of the tests forpromql
package itself, in the same directory.almost
, which extractsalmost.Equal
used by test and non-test code.I left some tests in the
promql
package, because they use a lot of unexported fields.Possibly these indicate that more new packages should be extracted.