@@ -19,11 +19,6 @@ type httpTenantLimitsResponse struct {
19
19
// ServeHTTP implements the http.Handler interface.
20
20
// It returns the current stream counts and status per tenant as a JSON response.
21
21
func (s * IngestLimits ) ServeHTTP (w http.ResponseWriter , r * http.Request ) {
22
- // TODO(grobinson): Avoid acquiring the mutex for the entire duration
23
- // of the request.
24
- s .mtx .RLock ()
25
- defer s .mtx .RUnlock ()
26
-
27
22
tenant := mux .Vars (r )["tenant" ]
28
23
if tenant == "" {
29
24
http .Error (w , "invalid tenant" , http .StatusBadRequest )
@@ -43,20 +38,22 @@ func (s *IngestLimits) ServeHTTP(w http.ResponseWriter, r *http.Request) {
43
38
response httpTenantLimitsResponse
44
39
)
45
40
46
- for _ , partitions := range s .metadata [tenant ] {
47
- for _ , stream := range partitions {
48
- if stream .lastSeenAt >= cutoff {
49
- activeStreams ++
41
+ s .metadata .All (func (tenantID string , _ int32 , stream Stream ) {
42
+ if tenantID != tenant {
43
+ return
44
+ }
45
+
46
+ if stream .LastSeenAt >= cutoff {
47
+ activeStreams ++
50
48
51
- // Calculate size only within the rate window
52
- for _ , bucket := range stream .rateBuckets {
53
- if bucket .timestamp >= rateWindowCutoff {
54
- totalSize += bucket .size
55
- }
49
+ // Calculate size only within the rate window
50
+ for _ , bucket := range stream .RateBuckets {
51
+ if bucket .Timestamp >= rateWindowCutoff {
52
+ totalSize += bucket .Size
56
53
}
57
54
}
58
55
}
59
- }
56
+ })
60
57
61
58
// Calculate rate using only data from within the rate window
62
59
calculatedRate := float64 (totalSize ) / s .cfg .WindowSize .Seconds ()
0 commit comments