Skip to content
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

Add engine param to thanos engine constructor #228

Merged
merged 1 commit into from
Apr 8, 2023

Conversation

PradyumnaKrishna
Copy link
Contributor

@PradyumnaKrishna PradyumnaKrishna commented Mar 28, 2023

Prometheus and Thanos engine both uses same registerer to register the metrics. A error raises when we try to register a metric multiple time in promql engine. To avoid them I seperated thanos promql engine metrics with prefix compatibility_engine_.

Edit: Added engine for fallback engine in EngineOpts. If engine is not provided then creates one otherwise uses the same.
Also, change prom type to v1.QueryEngine from *promql.Engine in thanos CompatibilityEngine.

Related: thanos-io/thanos#6234

Copy link
Member

@saswatamcode saswatamcode left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks!

engine/engine.go Outdated
@@ -175,6 +175,10 @@ func New(opts Opts) *compatibilityEngine {
),
}

if opts.Reg != nil {
opts.EngineOpts.Reg = prometheus.WrapRegistererWithPrefix("compatibility_engine_", opts.Reg)
Copy link
Collaborator

@fpetkovski fpetkovski Mar 28, 2023

Choose a reason for hiding this comment

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

I am not sure if compatibility_engine_ is the best name because this is an implementation detail of how we manage to support all promql functions. Can we use thanos_engine_ or whatever the prefix is for the main engine?

Copy link
Member

Choose a reason for hiding this comment

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

So while working with thanos-io/thanos#6234, we noticed that we would basically have 3 engines: the new engine, the new engine's compatibility prometheus engine, and the regular prometheus engine in Thanos. The metrics between the compatibility prometheus engine, and the prometheus engine run in Thanos clash when registering, so the compatibility_engine prefix is only added to the compatibility prometheus engine. And we reserve the thanos_engine prefix for metrics exported by new engine.

I wonder if there is some better way of handling this. Seems like we are running duplicative engines.

Copy link
Collaborator

@fpetkovski fpetkovski Mar 28, 2023

Choose a reason for hiding this comment

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

Right, but what does compatibility_engine mean to someone who is using the library? Should they even know that there is a fallback to the Prometheus engine?

What I am suggesting is we use thanos_engine_ as the prefix so we don't have to ask users to use two metric sets to monitor essentially a single component.

Copy link
Collaborator

@fpetkovski fpetkovski Mar 28, 2023

Choose a reason for hiding this comment

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

Alternatively, we can have a constructor where a user injects a QueryEngine so we don't need to instantiate one internally. This way we don't need to have a third prefix and we are transparent to the user that we use a Prometheus engine for the fallback.

Copy link
Member

Choose a reason for hiding this comment

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

Hmm. For users of this library, I think knowing which queries hit fallback engine, might be somewhat desirable, but we already have a metric for that.

I think the latter constructor approach might be preferable here.

Copy link
Collaborator

Choose a reason for hiding this comment

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

👍 let's try the new constructor then and see if it fixes the problem.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Does that mean adding this prefix at QueryEngineFactory in thanos, not here?

Copy link
Member

Choose a reason for hiding this comment

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

If I understood correctly, let's pass an instance of the original Prometheus PromQL engine to the Thanos PromQL engine via the constructor. We can re-use the same, old one, no need to create a new one with a prefix this way.

Copy link
Member

@GiedriusS GiedriusS left a comment

Choose a reason for hiding this comment

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

Since it's still early days for this project and we don't have any major versions, my suggestion would be to edit the original functions instead of creating new ones. Thoughts, @fpetkovski @saswatamcode?

engine/engine.go Outdated
return Create(opts, promql.NewEngine(opts.EngineOpts))
}

func Create(opts Opts, engine *promql.Engine) *compatibilityEngine {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Does the engine param need to be a promql.Engine type? I guess we can make prom in compatibilityEngine a v1.QueryEngine type. Because when thanos creates a prometheus engine it gets type casted into v1.QueryEngine.

@saswatamcode
Copy link
Member

Let's edit the original function 🙂

@PradyumnaKrishna PradyumnaKrishna changed the title Add registerer prefix to avoid conflict Add engine param to thanos engine constructor Apr 5, 2023
Copy link
Member

@saswatamcode saswatamcode left a comment

Choose a reason for hiding this comment

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

Thanks! This looks good to me!

Can you resolve the conflicts?

Updates the compatibility engine constructor to create an
engine, using the fallback engine provided in the options.

Since promql-engine is in early days and doesnt have any major
versions, it is finalized to use orignal function and add engine
to options.

Changes `prom` in `compatibilityEngine` to `v1.QueryEngine` type
from `promql.Engine`. Since, prom is an fallback engine and any
`QueryEngine` must work with in prom. Also, when thanos creates
a engine it get type casted into `v1.QueryEngine`, that can't
be passed to this constructor as an fallback engine option.

Signed-off-by: Pradyumna Krishna <[email protected]>
Copy link
Collaborator

@fpetkovski fpetkovski left a comment

Choose a reason for hiding this comment

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

Thanks, lgtm!

@GiedriusS GiedriusS merged commit 190e5c3 into thanos-io:main Apr 8, 2023
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.

4 participants