From 208c05e3db7e0a9bdac4756901d09f066402e241 Mon Sep 17 00:00:00 2001 From: Ethan Date: Thu, 30 Jan 2020 12:43:37 -0500 Subject: [PATCH] Add metrics to track rate limit. Add monkit metric for the rate-limit when the rate limit is hit Logs warning with projectID https://storjlabs.atlassian.net/browse/SM-165 Change-Id: I352dc40006021990d1bc66a999f62bbf8deb54db --- monkit.lock | 1 + satellite/metainfo/validation.go | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/monkit.lock b/monkit.lock index 6dfcb47a9..23618ba86 100644 --- a/monkit.lock +++ b/monkit.lock @@ -50,6 +50,7 @@ storj.io/storj/satellite/gracefulexit."graceful_exit_success" Meter storj.io/storj/satellite/gracefulexit."graceful_exit_successful_pieces_transfer_ratio" IntVal storj.io/storj/satellite/gracefulexit."graceful_exit_transfer_piece_fail" Meter storj.io/storj/satellite/gracefulexit."graceful_exit_transfer_piece_success" Meter +storj.io/storj/satellite/metainfo."metainfo_rate_limit_exceeded" Event storj.io/storj/satellite/orders."download_failed_not_enough_pieces_uplink" Meter storj.io/storj/satellite/repair/checker."checker_segment_age" IntVal storj.io/storj/satellite/repair/checker."checker_segment_healthy_count" IntVal diff --git a/satellite/metainfo/validation.go b/satellite/metainfo/validation.go index 7e788731b..84df04f93 100644 --- a/satellite/metainfo/validation.go +++ b/satellite/metainfo/validation.go @@ -166,7 +166,8 @@ func (endpoint *Endpoint) validateAuth(ctx context.Context, header *pb.RequestHe return keyInfo, nil } -func (endpoint *Endpoint) checkRate(ctx context.Context, projectID uuid.UUID) error { +func (endpoint *Endpoint) checkRate(ctx context.Context, projectID uuid.UUID) (err error) { + defer mon.Task()(&ctx)(&err) if !endpoint.limiterConfig.Enabled { return nil } @@ -190,6 +191,12 @@ func (endpoint *Endpoint) checkRate(ctx context.Context, projectID uuid.UUID) er } if !limiter.(*rate.Limiter).Allow() { + endpoint.log.Warn("too many requests for project", + zap.Stringer("projectID", projectID), + zap.Float64("limit", float64(limiter.(*rate.Limiter).Limit()))) + + mon.Event("metainfo_rate_limit_exceeded") //locked + return rpcstatus.Error(rpcstatus.ResourceExhausted, "Too Many Requests") }