Use only local tsdb for federation (#7096)

Signed-off-by: yeya24 <yb532204897@gmail.com>
This commit is contained in:
Ben Ye 2020-04-07 11:42:42 -04:00 committed by GitHub
parent 34c7f6e3c4
commit ecda6013ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 9 additions and 6 deletions

View File

@ -75,7 +75,7 @@ func (h *Handler) federation(w http.ResponseWriter, req *http.Request) {
) )
w.Header().Set("Content-Type", string(format)) w.Header().Set("Content-Type", string(format))
q, err := h.storage.Querier(req.Context(), mint, maxt) q, err := h.localStorage.Querier(req.Context(), mint, maxt)
if err != nil { if err != nil {
federationErrors.Inc() federationErrors.Inc()
http.Error(w, err.Error(), http.StatusInternalServerError) http.Error(w, err.Error(), http.StatusInternalServerError)
@ -209,10 +209,10 @@ func (h *Handler) federation(w http.ResponseWriter, req *http.Request) {
// Attach global labels if they do not exist yet. // Attach global labels if they do not exist yet.
for _, ln := range externalLabelNames { for _, ln := range externalLabelNames {
lv := externalLabels[ln] lv := externalLabels[ln]
if _, ok := globalUsed[string(ln)]; !ok { if _, ok := globalUsed[ln]; !ok {
protMetric.Label = append(protMetric.Label, &dto.LabelPair{ protMetric.Label = append(protMetric.Label, &dto.LabelPair{
Name: proto.String(string(ln)), Name: proto.String(ln),
Value: proto.String(string(lv)), Value: proto.String(lv),
}) })
} }
} }

View File

@ -199,8 +199,7 @@ func TestFederation(t *testing.T) {
} }
h := &Handler{ h := &Handler{
storage: suite.Storage(), localStorage: suite.Storage(),
queryEngine: suite.QueryEngine(),
lookbackDelta: 5 * time.Minute, lookbackDelta: 5 * time.Minute,
now: func() model.Time { return 101 * 60 * 1000 }, // 101min after epoch. now: func() model.Time { return 101 * 60 * 1000 }, // 101min after epoch.
config: &config.Config{ config: &config.Config{

View File

@ -180,6 +180,7 @@ type Handler struct {
context context.Context context context.Context
tsdb func() *tsdb.DB tsdb func() *tsdb.DB
storage storage.Storage storage storage.Storage
localStorage storage.Storage
notifier *notifier.Manager notifier *notifier.Manager
apiV1 *api_v1.API apiV1 *api_v1.API
@ -284,6 +285,7 @@ func New(logger log.Logger, o *Options) *Handler {
lookbackDelta: o.LookbackDelta, lookbackDelta: o.LookbackDelta,
tsdb: o.TSDB, tsdb: o.TSDB,
storage: o.Storage, storage: o.Storage,
localStorage: o.TSDB(),
notifier: o.Notifier, notifier: o.Notifier,
now: model.Now, now: model.Now,

View File

@ -399,6 +399,7 @@ func TestDebugHandler(t *testing.T) {
Host: "localhost.localdomain:9090", Host: "localhost.localdomain:9090",
Scheme: "http", Scheme: "http",
}, },
TSDB: func() *tsdb.DB { return nil },
} }
handler := New(nil, opts) handler := New(nil, opts)
handler.Ready() handler.Ready()
@ -425,6 +426,7 @@ func TestHTTPMetrics(t *testing.T) {
Host: "localhost.localdomain:9090", Host: "localhost.localdomain:9090",
Scheme: "http", Scheme: "http",
}, },
TSDB: func() *tsdb.DB { return nil },
}) })
getReady := func() int { getReady := func() int {
t.Helper() t.Helper()