Просмотр исходного кода

Merge pull request #10740 from overleaf/jpa-auto-compile-rate-limit-two-buckets

[web] split rate-limit tracking for auto-compiles into two buckets

GitOrigin-RevId: dcc743343010afe7d877fe5d37f020f10a8fd412
Brian Gough 3 лет назад
Родитель
Сommit
5c06b29e77

+ 4 - 3
services/web/app/src/Features/Compile/CompileManager.js

@@ -228,12 +228,13 @@ module.exports = CompileManager = {
     if (!isAutoCompile) {
     if (!isAutoCompile) {
       return callback(null, true)
       return callback(null, true)
     }
     }
-    Metrics.inc(`auto-compile-${compileGroup}`)
+    const bucket = Math.random() > 0.5 ? 'b-one' : 'b-two'
+    Metrics.inc(`auto-compile-${compileGroup}`, 1, { method: bucket })
     const opts = {
     const opts = {
       endpointName: 'auto_compile',
       endpointName: 'auto_compile',
       timeInterval: 20,
       timeInterval: 20,
-      subjectName: compileGroup,
-      throttle: Settings.rateLimit.autoCompile[compileGroup] || 25,
+      subjectName: `${compileGroup}-${bucket}`,
+      throttle: (Settings.rateLimit.autoCompile[compileGroup] || 25) / 2,
     }
     }
     rateLimiter.addCount(opts, function (err, canCompile) {
     rateLimiter.addCount(opts, function (err, canCompile) {
       if (err) {
       if (err) {

+ 2 - 2
services/web/test/unit/src/Compile/CompileManagerTests.js

@@ -443,8 +443,8 @@ describe('CompileManager', function () {
             return done(err)
             return done(err)
           }
           }
           const args = this.ratelimiter.addCount.args[0][0]
           const args = this.ratelimiter.addCount.args[0][0]
-          args.throttle.should.equal(25)
-          args.subjectName.should.equal('everyone')
+          args.throttle.should.equal(12.5)
+          args.subjectName.should.be.oneOf(['everyone-b-one', 'everyone-b-two'])
           args.timeInterval.should.equal(20)
           args.timeInterval.should.equal(20)
           args.endpointName.should.equal('auto_compile')
           args.endpointName.should.equal('auto_compile')
           canCompile.should.equal(true)
           canCompile.should.equal(true)