From 3c400d443db42a2365884be1d09fa5cfd840cc46 Mon Sep 17 00:00:00 2001 From: Oleg Zaytsev Date: Tue, 21 Dec 2021 11:22:40 +0100 Subject: [PATCH] Accept promql.Engine interface in v1.NewAPI() (#10050) 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 --- web/api/v1/api.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/web/api/v1/api.go b/web/api/v1/api.go index a8888a17b1..e6a6daffca 100644 --- a/web/api/v1/api.go +++ b/web/api/v1/api.go @@ -155,11 +155,18 @@ type TSDBAdminStats interface { WALReplayStatus() (tsdb.WALReplayStatus, error) } +// QueryEngine defines the interface for the *promql.Engine, so it can be replaced, wrapped or mocked. +type QueryEngine interface { + SetQueryLogger(l promql.QueryLogger) + NewInstantQuery(q storage.Queryable, qs string, ts time.Time) (promql.Query, error) + NewRangeQuery(q storage.Queryable, qs string, start, end time.Time, interval time.Duration) (promql.Query, error) +} + // API can register a set of endpoints in a router and handle // them using the provided storage and query engine. type API struct { Queryable storage.SampleAndChunkQueryable - QueryEngine *promql.Engine + QueryEngine QueryEngine ExemplarQueryable storage.ExemplarQueryable targetRetriever func(context.Context) TargetRetriever @@ -192,7 +199,7 @@ func init() { // NewAPI returns an initialized API type. func NewAPI( - qe *promql.Engine, + qe QueryEngine, q storage.SampleAndChunkQueryable, ap storage.Appendable, eq storage.ExemplarQueryable,