[Test] Extract most PromQL test code into separate packages#13999
[Test] Extract most PromQL test code into separate packages#13999bboreham merged 13 commits intoprometheus:mainfrom
Conversation
|
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
| return qry | ||
| } | ||
|
|
||
| func (ng *Engine) TestEnablePerStepStats() { ng.enablePerStepStats = true } |
There was a problem hiding this comment.
Is it not possible to set these via engine opts?
There was a problem hiding this comment.
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
promqlpackage contain a lot of test-only code, which depends ontestifyand other utilities.I created three new packages:
promqltest, the test utilities used by promql tests and by other packages such aspromtool.promql_testwhich is most of the tests forpromqlpackage itself, in the same directory.almost, which extractsalmost.Equalused by test and non-test code.I left some tests in the
promqlpackage, because they use a lot of unexported fields.Possibly these indicate that more new packages should be extracted.