From a2e5ad61746ec143c8385a5536c542be060b78c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20S=CC=8Ctibrany=CC=81?= Date: Mon, 15 Feb 2021 12:30:00 +0100 Subject: [PATCH] Split queryable and appendable arguments in api_v1.NewAPI. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Peter Štibraný --- web/api/v1/api.go | 10 +++++----- web/web.go | 8 ++++++-- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/web/api/v1/api.go b/web/api/v1/api.go index 3210feb04..81980ae47 100644 --- a/web/api/v1/api.go +++ b/web/api/v1/api.go @@ -205,7 +205,8 @@ func init() { // NewAPI returns an initialized API type. func NewAPI( qe *promql.Engine, - s storage.Storage, + q storage.SampleAndChunkQueryable, + ap storage.Appendable, tr func(context.Context) TargetRetriever, ar func(context.Context) AlertmanagerRetriever, configFunc func() config.Config, @@ -224,11 +225,10 @@ func NewAPI( runtimeInfo func() (RuntimeInfo, error), buildInfo *PrometheusVersion, gatherer prometheus.Gatherer, - remoteWriteReceiver bool, ) *API { a := &API{ QueryEngine: qe, - Queryable: s, + Queryable: q, targetRetriever: tr, alertmanagerRetriever: ar, @@ -252,8 +252,8 @@ func NewAPI( gatherer: gatherer, } - if remoteWriteReceiver { - a.remoteWriteHandler = remote.NewWriteHandler(logger, s) + if ap != nil { + a.remoteWriteHandler = remote.NewWriteHandler(logger, ap) } return a diff --git a/web/web.go b/web/web.go index 3be9df83e..3c86a47d7 100644 --- a/web/web.go +++ b/web/web.go @@ -298,7 +298,12 @@ func New(logger log.Logger, o *Options) *Handler { factoryAr := func(_ context.Context) api_v1.AlertmanagerRetriever { return h.notifier } FactoryRr := func(_ context.Context) api_v1.RulesRetriever { return h.ruleManager } - h.apiV1 = api_v1.NewAPI(h.queryEngine, h.storage, factoryTr, factoryAr, + var app storage.Appendable + if o.RemoteWriteReceiver { + app = h.storage + } + + h.apiV1 = api_v1.NewAPI(h.queryEngine, h.storage, app, factoryTr, factoryAr, func() config.Config { h.mtx.RLock() defer h.mtx.RUnlock() @@ -323,7 +328,6 @@ func New(logger log.Logger, o *Options) *Handler { h.runtimeInfo, h.versionInfo, o.Gatherer, - o.RemoteWriteReceiver, ) if o.RoutePrefix != "/" {