Skip to content

Commit d0fe9c1

Browse files
committed
Merge branch 'rate-limit-metrics' into stage
2 parents 3450b58 + 39a341b commit d0fe9c1

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
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
}

pkg/server/server.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,8 @@ func (s *Server) handler(ctx *fasthttp.RequestCtx) {
145145
s.ReleaseHandler.HandleHTTP(ctx)
146146
case "/api/0/envelope/":
147147
s.ErrorsHandler.HandleSentry(ctx)
148-
case "/test/generate-timeseries":
149-
s.HandleGenerateTestTimeSeries(ctx)
148+
// case "/test/generate-timeseries":
149+
// s.HandleGenerateTestTimeSeries(ctx)
150150
default:
151151
ctx.Error("Not found", fasthttp.StatusNotFound)
152152
}

0 commit comments

Comments
 (0)