Browse Source

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 <mail@olegzaytsev.com>
pull/10067/head
Oleg Zaytsev 3 years ago committed by GitHub
parent
commit
3c400d443d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 11
      web/api/v1/api.go

11
web/api/v1/api.go

@ -155,11 +155,18 @@ type TSDBAdminStats interface {
WALReplayStatus() (tsdb.WALReplayStatus, error) 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 // API can register a set of endpoints in a router and handle
// them using the provided storage and query engine. // them using the provided storage and query engine.
type API struct { type API struct {
Queryable storage.SampleAndChunkQueryable Queryable storage.SampleAndChunkQueryable
QueryEngine *promql.Engine QueryEngine QueryEngine
ExemplarQueryable storage.ExemplarQueryable ExemplarQueryable storage.ExemplarQueryable
targetRetriever func(context.Context) TargetRetriever targetRetriever func(context.Context) TargetRetriever
@ -192,7 +199,7 @@ func init() {
// NewAPI returns an initialized API type. // NewAPI returns an initialized API type.
func NewAPI( func NewAPI(
qe *promql.Engine, qe QueryEngine,
q storage.SampleAndChunkQueryable, q storage.SampleAndChunkQueryable,
ap storage.Appendable, ap storage.Appendable,
eq storage.ExemplarQueryable, eq storage.ExemplarQueryable,

Loading…
Cancel
Save