Skip to content

Commit 0b11313

Browse files
authored
Merge pull request #144 from codex-team/rate-limit-metrics
Record rate-limited metrics
2 parents 23800ad + 39a341b commit 0b11313

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

pkg/server/errorshandler/handler.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ func (handler *Handler) process(body []byte) ResponseMessage {
7373

7474
if handler.RedisClient.IsBlocked(projectId) {
7575
handler.ErrorsBlockedByLimit.Inc()
76+
handler.recordProjectMetrics(projectId, "events-rate-limited")
7677
return ResponseMessage{402, true, "Project has exceeded the events limit"}
7778
}
7879

@@ -82,6 +83,7 @@ func (handler *Handler) process(body []byte) ResponseMessage {
8283
return ResponseMessage{402, true, "Failed to update rate limit"}
8384
}
8485
if !rateWithinLimit {
86+
handler.recordProjectMetrics(projectId, "events-rate-limited")
8587
return ResponseMessage{402, true, "Rate limit exceeded"}
8688
}
8789

pkg/server/errorshandler/handler_sentry.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ func (handler *Handler) HandleSentry(ctx *fasthttp.RequestCtx) {
102102

103103
if handler.RedisClient.IsBlocked(projectId) {
104104
handler.ErrorsBlockedByLimit.Inc()
105+
handler.recordProjectMetrics(projectId, "events-rate-limited")
105106
sendAnswerHTTP(ctx, ResponseMessage{402, true, "Project has exceeded the events limit"})
106107
return
107108
}
@@ -114,6 +115,7 @@ func (handler *Handler) HandleSentry(ctx *fasthttp.RequestCtx) {
114115
}
115116

116117
if !rateWithinLimit {
118+
handler.recordProjectMetrics(projectId, "events-rate-limited")
117119
sendAnswerHTTP(ctx, ResponseMessage{402, true, "Rate limit exceeded"})
118120
return
119121
}
@@ -141,5 +143,8 @@ func (handler *Handler) HandleSentry(ctx *fasthttp.RequestCtx) {
141143
// increment processed errors counter
142144
handler.ErrorsProcessed.Inc()
143145

146+
// record project metrics
147+
handler.recordProjectMetrics(projectId, "events-accepted")
148+
144149
sendAnswerHTTP(ctx, ResponseMessage{200, false, "OK"})
145150
}

0 commit comments

Comments
 (0)