web: clean up api/v2 (#4554)

Signed-off-by: Simon Pasquier <spasquie@redhat.com>
pull/4572/head
Simon Pasquier 6 years ago committed by Goutham Veeramachaneni
parent 63ed9d1b70
commit 75bd348135

@ -19,7 +19,6 @@ import (
"math" "math"
"math/rand" "math/rand"
"net/http" "net/http"
"net/url"
"os" "os"
"path/filepath" "path/filepath"
"time" "time"
@ -39,37 +38,21 @@ import (
"github.com/prometheus/prometheus/pkg/labels" "github.com/prometheus/prometheus/pkg/labels"
"github.com/prometheus/prometheus/pkg/timestamp" "github.com/prometheus/prometheus/pkg/timestamp"
pb "github.com/prometheus/prometheus/prompb" pb "github.com/prometheus/prometheus/prompb"
"github.com/prometheus/prometheus/promql"
"github.com/prometheus/prometheus/scrape"
"github.com/prometheus/prometheus/storage"
) )
// API encapsulates all API services. // API encapsulates all API services.
type API struct { type API struct {
enableAdmin bool enableAdmin bool
now func() time.Time
db func() *tsdb.DB db func() *tsdb.DB
q func(ctx context.Context, mint, maxt int64) (storage.Querier, error)
targets func() []*scrape.Target
alertmanagers func() []*url.URL
} }
// New returns a new API object. // New returns a new API object.
func New( func New(
now func() time.Time,
db func() *tsdb.DB, db func() *tsdb.DB,
qe *promql.Engine,
q func(ctx context.Context, mint, maxt int64) (storage.Querier, error),
targets func() []*scrape.Target,
alertmanagers func() []*url.URL,
enableAdmin bool, enableAdmin bool,
) *API { ) *API {
return &API{ return &API{
now: now,
db: db, db: db,
q: q,
targets: targets,
alertmanagers: alertmanagers,
enableAdmin: enableAdmin, enableAdmin: enableAdmin,
} }
} }

@ -412,16 +412,7 @@ func (h *Handler) Run(ctx context.Context) error {
grpcSrv = grpc.NewServer() grpcSrv = grpc.NewServer()
) )
av2 := api_v2.New( av2 := api_v2.New(
time.Now,
h.options.TSDB, h.options.TSDB,
h.options.QueryEngine,
h.options.Storage.Querier,
func() []*scrape.Target {
return h.options.ScrapeManager.TargetsActive()
},
func() []*url.URL {
return h.options.Notifier.Alertmanagers()
},
h.options.EnableAdminAPI, h.options.EnableAdminAPI,
) )
av2.RegisterGRPC(grpcSrv) av2.RegisterGRPC(grpcSrv)

Loading…
Cancel
Save