Skip to content

Commit 6cf9daa

Browse files
authored
Add receiver downscale endpoint (#88)
2 parents 17f9d7c + 662332a commit 6cf9daa

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

cmd/thanos/receive.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ import (
77
"context"
88
"fmt"
99
"net"
10+
"net/http"
1011
"os"
1112
"path"
13+
"strconv"
1214
"strings"
1315
"time"
1416

@@ -322,6 +324,19 @@ func runReceive(
322324
httpserver.WithGracePeriod(time.Duration(*conf.httpGracePeriod)),
323325
httpserver.WithTLSConfig(*conf.httpTLSConfig),
324326
)
327+
srv.Handle("/-/downscale", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
328+
tenants := dbs.GetTenants()
329+
n := len(tenants)
330+
w.Header().Set("Tenant-Count", strconv.Itoa(n))
331+
for _, tname := range tenants {
332+
w.Header().Add("Tenants", tname)
333+
}
334+
if n > 0 {
335+
w.WriteHeader(http.StatusTooEarly)
336+
} else {
337+
w.WriteHeader(http.StatusOK)
338+
}
339+
}))
325340
g.Add(func() error {
326341
statusProber.Healthy()
327342
return srv.ListenAndServe()
@@ -465,7 +480,7 @@ func runReceive(
465480
ctx, cancel := context.WithCancel(context.Background())
466481
g.Add(func() error {
467482
return runutil.Repeat(conf.topMetricsUpdateInterval, ctx.Done(), func() error {
468-
level.Info(logger).Log("msg", "getting top metrics")
483+
level.Debug(logger).Log("msg", "getting top metrics")
469484
for _, ts := range dbs.TenantStats(conf.numTopMetricsPerTenant, labels.MetricName) {
470485
for _, ms := range ts.Stats.IndexPostingStats.CardinalityMetricsStats {
471486
if ms.Count >= conf.topMetricsMinimumCardinality {

pkg/receive/multitsdb.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,16 @@ func NewMultiTSDB(
122122
return mt
123123
}
124124

125+
func (t *MultiTSDB) GetTenants() []string {
126+
t.mtx.RLock()
127+
tenants := make([]string, 0, len(t.tenants))
128+
for tname := range t.tenants {
129+
tenants = append(tenants, tname)
130+
}
131+
defer t.mtx.RUnlock()
132+
return tenants
133+
}
134+
125135
type localClient struct {
126136
store *store.TSDBStore
127137

0 commit comments

Comments
 (0)