Skip to content

Commit ea0d891

Browse files
committed
simplify endpoint logic
1 parent 8da5b4a commit ea0d891

File tree

1 file changed

+4
-17
lines changed

1 file changed

+4
-17
lines changed

cmd/thanos/receive.go

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ package main
55

66
import (
77
"context"
8-
"encoding/json"
98
"net/http"
109
"os"
1110
"path"
@@ -322,25 +321,13 @@ func runReceive(
322321
httpserver.WithGracePeriod(time.Duration(*conf.httpGracePeriod)),
323322
httpserver.WithTLSConfig(*conf.httpTLSConfig),
324323
)
325-
var lastDownscalePrepareTimestamp int64 = 0
326324
srv.Handle("/-/downscale", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
327325
n := dbs.GetTenantsLen()
328326
w.Header().Set("Tenant-Count", strconv.Itoa(n))
329-
w.WriteHeader(http.StatusOK)
330-
if r.Method == http.MethodDelete {
331-
return
332-
}
333-
w.Header().Set("Content-Type", "application/json")
334-
if lastDownscalePrepareTimestamp == 0 || n > 0 {
335-
lastDownscalePrepareTimestamp = time.Now().Unix()
336-
}
337-
err := json.NewEncoder(w).Encode(struct {
338-
Timestamp int64 `json:"timestamp"`
339-
}{
340-
Timestamp: lastDownscalePrepareTimestamp,
341-
})
342-
if err != nil {
343-
level.Error(logger).Log("msg", "error writing downscale response", "err", err)
327+
if n > 0 {
328+
w.WriteHeader(http.StatusTooEarly)
329+
} else {
330+
w.WriteHeader(http.StatusOK)
344331
}
345332
}))
346333
g.Add(func() error {

0 commit comments

Comments
 (0)