diff --git a/cmd/thanos/receive.go b/cmd/thanos/receive.go index bff82dd5a6..0460947724 100644 --- a/cmd/thanos/receive.go +++ b/cmd/thanos/receive.go @@ -7,8 +7,10 @@ import ( "context" "fmt" "net" + "net/http" "os" "path" + "strconv" "strings" "time" @@ -322,6 +324,19 @@ func runReceive( httpserver.WithGracePeriod(time.Duration(*conf.httpGracePeriod)), httpserver.WithTLSConfig(*conf.httpTLSConfig), ) + srv.Handle("/-/downscale", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + tenants := dbs.GetTenants() + n := len(tenants) + w.Header().Set("Tenant-Count", strconv.Itoa(n)) + for _, tname := range tenants { + w.Header().Add("Tenants", tname) + } + if n > 0 { + w.WriteHeader(http.StatusTooEarly) + } else { + w.WriteHeader(http.StatusOK) + } + })) g.Add(func() error { statusProber.Healthy() return srv.ListenAndServe() @@ -465,7 +480,7 @@ func runReceive( ctx, cancel := context.WithCancel(context.Background()) g.Add(func() error { return runutil.Repeat(conf.topMetricsUpdateInterval, ctx.Done(), func() error { - level.Info(logger).Log("msg", "getting top metrics") + level.Debug(logger).Log("msg", "getting top metrics") for _, ts := range dbs.TenantStats(conf.numTopMetricsPerTenant, labels.MetricName) { for _, ms := range ts.Stats.IndexPostingStats.CardinalityMetricsStats { if ms.Count >= conf.topMetricsMinimumCardinality { diff --git a/pkg/receive/multitsdb.go b/pkg/receive/multitsdb.go index 75d6f6a739..d40cf43c06 100644 --- a/pkg/receive/multitsdb.go +++ b/pkg/receive/multitsdb.go @@ -122,6 +122,16 @@ func NewMultiTSDB( return mt } +func (t *MultiTSDB) GetTenants() []string { + t.mtx.RLock() + tenants := make([]string, 0, len(t.tenants)) + for tname := range t.tenants { + tenants = append(tenants, tname) + } + defer t.mtx.RUnlock() + return tenants +} + type localClient struct { store *store.TSDBStore