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
This commit is contained in:
Ethan 2020-01-30 12:43:37 -05:00 committed by Ethan Adams
parent ccd8b7f107
commit 208c05e3db
2 changed files with 9 additions and 1 deletions

View File

@ -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

View File

@ -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")
}