Skip to content

Commit

Permalink
simplify endpoint logic
Browse files Browse the repository at this point in the history
  • Loading branch information
yuchen-db committed Oct 22, 2024
1 parent 8da5b4a commit ea0d891
Showing 1 changed file with 4 additions and 17 deletions.
21 changes: 4 additions & 17 deletions cmd/thanos/receive.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package main

import (
"context"
"encoding/json"
"net/http"
"os"
"path"
Expand Down Expand Up @@ -322,25 +321,13 @@ func runReceive(
httpserver.WithGracePeriod(time.Duration(*conf.httpGracePeriod)),
httpserver.WithTLSConfig(*conf.httpTLSConfig),
)
var lastDownscalePrepareTimestamp int64 = 0
srv.Handle("/-/downscale", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
n := dbs.GetTenantsLen()
w.Header().Set("Tenant-Count", strconv.Itoa(n))
w.WriteHeader(http.StatusOK)
if r.Method == http.MethodDelete {
return
}
w.Header().Set("Content-Type", "application/json")
if lastDownscalePrepareTimestamp == 0 || n > 0 {
lastDownscalePrepareTimestamp = time.Now().Unix()
}
err := json.NewEncoder(w).Encode(struct {
Timestamp int64 `json:"timestamp"`
}{
Timestamp: lastDownscalePrepareTimestamp,
})
if err != nil {
level.Error(logger).Log("msg", "error writing downscale response", "err", err)
if n > 0 {
w.WriteHeader(http.StatusTooEarly)
} else {
w.WriteHeader(http.StatusOK)
}
}))
g.Add(func() error {
Expand Down

0 comments on commit ea0d891

Please sign in to comment.