Skip to content

Accept promql.Engine interface in v1.NewAPI()#10050

Merged
roidelapluie merged 1 commit intoprometheus:mainfrom
colega:accept-promql-engine-interface-in-api
Dec 21, 2021
Merged

Accept promql.Engine interface in v1.NewAPI()#10050
roidelapluie merged 1 commit intoprometheus:mainfrom
colega:accept-promql-engine-interface-in-api

Conversation

@colega
Copy link
Contributor

@colega colega commented Dec 20, 2021

Instead of requesting a concrete type. This would allow other implementations that use the same API to replace or wrap the engine implementation while maintaining the same API.

Signed-off-by: Oleg Zaytsev mail@olegzaytsev.com

Instead of requesting a concrete type. This would allow other
implementations that use the same API to replace or wrap the engine
implementation while maintaining the same API.

Signed-off-by: Oleg Zaytsev <mail@olegzaytsev.com>
@roidelapluie
Copy link
Member

I am not sure we are doing ourserlves a favor by accepting this. This is the Prometheus API, meant to be used with PromQL only.

@codesome
Copy link
Member

meant to be used with PromQL only

Yes, PromQL, but not necessarily promql.Engine :). Maybe we can rename the interface to PromQLEngine and add comments about it executing PromQL.

@colega
Copy link
Contributor Author

colega commented Dec 21, 2021

I'm fine renaming the interface to any other name, PromlQLEngine was actually my first option but I didn't like the case and then I saw that API has the QueryEngine field so I named it after that.

My main reason to wrap this right now, @roidelapluie is to be able to return other errors here:

qry, err := api.QueryEngine.NewRangeQuery(api.Queryable, r.FormValue("query"), start, end, step)
if err == promql.ErrValidationAtModifierDisabled {
err = errors.New("@ modifier is disabled, use --enable-feature=promql-at-modifier to enable it")
} else if err == promql.ErrValidationNegativeOffsetDisabled {
err = errors.New("negative offset is disabled, use --enable-feature=promql-negative-offset to enable it")
}

In order to avoid referring to prometheus-specific fields when this API implementation is being used by Cortex/Thanos/etc.

I have considered a more complex approach by injecting an error mapper into the API, and even though it would be cleaner for the downstream implementations, it would be unnecessarily overengineered (IMO) for Prometheus itself. But we can still discuss that option too.

Copy link
Member

@roidelapluie roidelapluie 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 explaining your point. The code change is small, seems fine to me.

@roidelapluie roidelapluie merged commit 3c400d4 into prometheus:main Dec 21, 2021
@colega
Copy link
Contributor Author

colega commented Dec 21, 2021

Thank you!

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.

3 participants