Skip to content

Commit 7fb44a1

Browse files
Merge pull request #216 from m-lab/sandbox-roberto-metrics
Add metric to track rate-limited clients by client_name
2 parents 2e5c20c + 2f7a8c5 commit 7fb44a1

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

handler/handler.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,13 @@ func (c *Client) Nearest(rw http.ResponseWriter, req *http.Request) {
183183
result.Error = v2.NewError("client", tooManyRequests, http.StatusTooManyRequests)
184184
metrics.RequestsTotal.WithLabelValues("nearest", "rate limit",
185185
http.StatusText(result.Error.Status)).Inc()
186-
log.Printf("Rate limit exceeded for IP %s and UA %s", ip, ua)
186+
// If the client provided a client_name, we want to know how many times
187+
// that client_name was rate limited. This may be empty, which is fine.
188+
clientName := req.Form.Get("client_name")
189+
metrics.RateLimitedTotal.WithLabelValues(clientName).Inc()
190+
191+
log.Printf("Rate limit exceeded for IP: %s, client: %s, UA: %s", ip,
192+
clientName, ua)
187193
writeResult(rw, result.Error.Status, &result)
188194
return
189195
}

metrics/metrics.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,15 @@ var (
1919
[]string{"type", "condition", "status"},
2020
)
2121

22+
// RateLimitedTotal tracks the number of rate-limited requests by client name.
23+
RateLimitedTotal = promauto.NewCounterVec(
24+
prometheus.CounterOpts{
25+
Name: "locate_rate_limited_total",
26+
Help: "Total number of rate-limited requests by client name",
27+
},
28+
[]string{"clientname"},
29+
)
30+
2231
// AppEngineTotal counts the number of times App Engine headers are
2332
// used to try to find the client location.
2433
//

0 commit comments

Comments
 (0)