|
|
|
@ -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 |
|
|
|
|