Merge pull request #16731 from overleaf/dp-ip-rate-metrics

Add tracking of rate limit method to metrics

GitOrigin-RevId: 3996c2a0ccb747018571ce402120be46fc52eace
This commit is contained in:
David
2024-02-13 09:04:09 +00:00
committed by Copybot
parent a669228aca
commit 32d2603adb
8 changed files with 22 additions and 16 deletions
@@ -34,7 +34,7 @@ class RateLimiter {
})
}
async consume(key, points = 1, options = {}) {
async consume(key, points = 1, options = { method: 'unknown' }) {
if (Settings.disableRateLimits) {
// Return a fake result in case it's used somewhere
return {
@@ -57,7 +57,10 @@ class RateLimiter {
if (err.consumedPoints - points <= this._rateLimiter.points) {
logger.warn({ path: this.name, key }, 'rate limit exceeded')
}
Metrics.inc('rate-limit-hit', 1, { path: this.name })
Metrics.inc('rate-limit-hit', 1, {
path: this.name,
method: options.method,
})
throw err
}
}