mirror of
https://github.com/prometheus/prometheus.git
synced 2025-02-02 08:31:11 -08:00
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>
This commit is contained in:
parent
2737abf221
commit
3c400d443d
|
@ -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…
Reference in a new issue