chore: update the HTTP debug routes for ingest-limits (#16830)

pull/16829/merge
George Robinson 2 months ago committed by GitHub
parent a1fbd8b137
commit 7aa545485f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 13
      pkg/limits/http.go
  2. 4
      pkg/loki/modules.go

@ -5,6 +5,7 @@ import (
"time"
"github.com/go-kit/log/level"
"github.com/gorilla/mux"
"github.com/grafana/loki/v3/pkg/util"
)
@ -12,9 +13,17 @@ import (
// ServeHTTP implements the http.Handler interface.
// It returns the current stream counts and status per tenant as a JSON response.
func (s *IngestLimits) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// TODO(grobinson): Avoid acquiring the mutex for the entire duration
// of the request.
s.mtx.RLock()
defer s.mtx.RUnlock()
tenant := mux.Vars(r)["tenant"]
if tenant == "" {
http.Error(w, "invalid tenant", http.StatusBadRequest)
return
}
// Get the cutoff time for active streams
cutoff := time.Now().Add(-s.cfg.WindowSize).UnixNano()
@ -27,10 +36,6 @@ func (s *IngestLimits) ServeHTTP(w http.ResponseWriter, r *http.Request) {
ActiveStreams uint64 `json:"activeStreams"`
Rate float64 `json:"rate"`
}
// Get tenant and partitions from query parameters
params := r.URL.Query()
tenant := params.Get("tenant")
var (
activeStreams uint64
totalSize uint64

@ -456,7 +456,7 @@ func (t *Loki) initIngestLimits() (services.Service, error) {
logproto.RegisterIngestLimitsServer(t.Server.GRPC, ingestLimits)
// Register HTTP handler for metadata
t.Server.HTTP.Path("/ingest/limits").Methods("GET").Handler(ingestLimits)
t.Server.HTTP.Path("/ingest-limits/usage/{tenant}").Methods("GET").Handler(ingestLimits)
return ingestLimits, nil
}
@ -516,7 +516,7 @@ func (t *Loki) initIngestLimitsFrontend() (services.Service, error) {
// Register HTTP handler to check if a tenant exceeds limits
// Returns a JSON response for the frontend to display which
// streams are rejected.
t.Server.HTTP.Path("/ingest/exceeds-limits").Methods("POST").Handler(ingestLimitsFrontend)
t.Server.HTTP.Path("/ingest-limits/exceeds-limits").Methods("POST").Handler(ingestLimitsFrontend)
return ingestLimitsFrontend, nil
}

Loading…
Cancel
Save