Skip to content
This repository has been archived by the owner on Apr 2, 2024. It is now read-only.

Update PromQL from upstream #1295

Merged

Conversation

Harkishen-Singh
Copy link
Member

@Harkishen-Singh Harkishen-Singh commented Apr 12, 2022

Fixes: #1296

This PR updates the PromQL module with the latest commits from upstream. It also contains the newly implemented feature for PromQL evaluation statistics.

@cevian
Copy link
Contributor

cevian commented Apr 28, 2022

Checks aren't passing so taking myself off the review. Please request re-review when this PR is ready and all checks pass

google.golang.org/grpc v1.46.0
google.golang.org/protobuf v1.28.0
gopkg.in/yaml.v2 v2.4.0
)

// Make sure Prometheus version is pinned as Prometheus semver does not include Go APIs.
replace github.com/prometheus/prometheus => github.com/prometheus/prometheus v1.8.2-0.20220117154355-4855a0c067e2
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you think we can update to latest prometheus and not use git hash anymore?

Copy link
Member Author

Choose a reason for hiding this comment

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

If you mean @latest, I think we should stick to git hash (monthly wise). Otherwise, I have seen incompatibility with @latest mod version, which is not good, as anyone who updates the mod next might have to fix the incompatibilities.

"strconv"
"strings"
"time"

"github.com/grafana/regexp"
Copy link
Contributor

Choose a reason for hiding this comment

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

Why using this package instead of default golang one? I mean what are the benefits?

Copy link
Member Author

Choose a reason for hiding this comment

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

Well, the point is to make outputs similar to what Prometheus does. Recently, Prometheus shifted from go regex to grafana regex. I don't know the reason, will try to see the godoc APIs. But, there might be an edge case in response comparison if we shifted back to the original.

Copy link
Member Author

Choose a reason for hiding this comment

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

This repo is a fork of the upstream Go regexp package, with some code optimisations to make it run faster.

Source

Copy link
Contributor

@antekresic antekresic left a comment

Choose a reason for hiding this comment

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

Looks good in general.

I'd like us to verify that these traces that are now being generated in the query engine are compatible with our setup and that we can actually use them ourselves.

@Harkishen-Singh
Copy link
Member Author

@antekresic yes, it does. We can apply jaeger traces endpoint and get the input. We can also provide otel-collector and direct the traces there and then back to promscale.

image

if warning != nil {
// An invalid content type is being passed, which should not happen
// in this context.
panic(warning)
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we really panic here because of invalid contentType? I am not sure where this is being used

Copy link
Member Author

Choose a reason for hiding this comment

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

This is a direct copy from Prometheus

https://github.com/prometheus/prometheus/blob/957092451175e9c4b37c52b6d3c8444c1d3eebc4/promql/fuzz.go#L64

But I agree, we can replace that with a warning log.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah I've noticed it's borrowed code. Just wanted to make sure we have full understanding and doing the right thing in our context.

@@ -89,6 +89,7 @@ func queryRange(promqlConf *query.Config, queryEngine *promql.Engine, queryable

qry, err := queryEngine.NewRangeQuery(
queryable,
&promql.QueryOpts{EnablePerStepStats: true},
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you explain why we want stats enabled? Do we use these stats?

Copy link
Member Author

Choose a reason for hiding this comment

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

This allows the stats feature to work.

sampleStats: stats.NewQuerySamples(ng.enablePerStepStats && opts.EnablePerStepStats),

If you see how the feature works, there is a logical AND condition between

  1. Input of -enable-feature=promql-per-step-stats that is supplied in the CLI (ng.enablePerStepStats part)
  2. Input from the caller creating query (range & instant) (opts.EnablePerStepStats part). This one is the line you commented on

So, the feature will work only when 1 && 2 == true. 1 is based on user, 2 is Promscale enabling the feature. Hence, we pass in &promql.QueryOpts{EnablePerStepStats: true} so that the stats feature is now enabled.

why we want stats enabled?

It's a PromQL feature that we were lacking. Prometheus provides it, but we don't, as it was recently merged into Prometheus master. With this PR, we are again up to date with the master.

Copy link
Member Author

@Harkishen-Singh Harkishen-Singh May 24, 2022

Choose a reason for hiding this comment

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

Note: We do not enable this, the enabling will happen only when the user passes in -enable-feature=promql-per-step-stats. We just do not want to block the feature from being enabled.

@niksajakovljevic
Copy link
Contributor

@Harkishen-Singh Btw since you do mention that this brings in new features. Do we miss some tests for new features? I've only seen fuzz_test as a new test file, but missed to find one on statistics?

@Harkishen-Singh
Copy link
Member Author

Test on this new feature is again borrowed from the Prometheus side in this case. That should be enough.

func TestQueryStatistics(t *testing.T) {

Signed-off-by: Harkishen-Singh <harkishensingh@hotmail.com>

This commit updates the PromQL code upto commit
3e4bd4d9135200f6e74a2ba3ef47dba1de8656d9

This commit also includes the changes for the new
PromQL stats support which is an optional feature.
Signed-off-by: Harkishen-Singh <harkishensingh@hotmail.com>
Signed-off-by: Harkishen-Singh <harkishensingh@hotmail.com>

This commit enables the `promql-per-step-stats` feature. This is done by
passing `&QueryOpts{EnablePerStepStats: true}` when creating a query.
This result goes with logical AND with
`-enable-feature=promql-per-step-stats` applied as Promscale starts.
@Harkishen-Singh Harkishen-Singh enabled auto-merge (rebase) May 25, 2022 08:59
@Harkishen-Singh Harkishen-Singh merged commit a5ffe9d into timescale:master May 25, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement PromQL stats as feature options
5 participants