Skip to content
13 changes: 12 additions & 1 deletion cmd/thanos/receive.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ package main

import (
"context"
"net/http"
"os"
"path"
"strconv"
"strings"
"time"

Expand Down Expand Up @@ -319,6 +321,15 @@ func runReceive(
httpserver.WithGracePeriod(time.Duration(*conf.httpGracePeriod)),
httpserver.WithTLSConfig(*conf.httpTLSConfig),
)
srv.Handle("/-/downscale", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
n := dbs.GetTenantsLen()
w.Header().Set("Tenant-Count", strconv.Itoa(n))
if n > 0 {
w.WriteHeader(http.StatusTooEarly)
} else {
w.WriteHeader(http.StatusOK)
}
}))
g.Add(func() error {
statusProber.Healthy()
return srv.ListenAndServe()
Expand Down Expand Up @@ -462,7 +473,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 {
Expand Down
6 changes: 6 additions & 0 deletions pkg/receive/multitsdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,12 @@ func NewMultiTSDB(
return mt
}

func (t *MultiTSDB) GetTenantsLen() int {
t.mtx.RLock()
defer t.mtx.RUnlock()
return len(t.tenants)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shall we log how many tenants left and what are they?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: add unit test?

}

type localClient struct {
store *store.TSDBStore

Expand Down
Loading