소스 검색

Merge pull request #14501 from overleaf/jpa-streaming-log-noise

[web] CompileController: ignore noisy spurious error

GitOrigin-RevId: 8885286a5e06bfa38bc70d98b703f52a1269d899
Jakob Ackermann 3 년 전
부모
커밋
63bd1f6095
2개의 변경된 파일27개의 추가작업 그리고 10개의 파일을 삭제
  1. 23 10
      services/web/app/src/Features/Compile/CompileController.js
  2. 4 0
      services/web/test/unit/src/Compile/CompileControllerTests.js

+ 23 - 10
services/web/app/src/Features/Compile/CompileController.js

@@ -612,28 +612,41 @@ module.exports = CompileController = {
             return pipeline(stream, res)
           })
           .then(() => {
+            timer.labels.status = 'success'
             timer.done()
           })
           .catch(err => {
+            const reqAborted = Boolean(req.destroyed)
+            const status = reqAborted ? 'req-aborted-late' : 'error'
+            timer.labels.status = status
             const duration = timer.done()
-            if (!res.headersSent) {
+            Metrics.inc('proxy_to_clsi', 1, { path: action, status })
+            const streamingStarted = Boolean(res.headersSent)
+            if (!streamingStarted) {
               if (err instanceof RequestFailedError) {
                 res.sendStatus(err.response.status)
               } else {
                 res.sendStatus(500)
               }
             }
-            const reqAborted = Boolean(req.destroyed)
-            if (reqAborted) {
-              Metrics.inc('proxy_to_clsi', 1, {
-                path: action,
-                status: 'req-aborted-late',
-              })
-            } else {
-              Metrics.inc('proxy_to_clsi', 1, { path: action, status: 'error' })
+            if (
+              streamingStarted &&
+              reqAborted &&
+              err.code === 'ERR_STREAM_PREMATURE_CLOSE'
+            ) {
+              // Ignore noisy spurious error
+              return
             }
             logger.warn(
-              { err, projectId, url, action, reqAborted, duration },
+              {
+                err,
+                projectId,
+                url,
+                action,
+                reqAborted,
+                streamingStarted,
+                duration,
+              },
               'CLSI proxy error'
             )
           })

+ 4 - 0
services/web/test/unit/src/Compile/CompileControllerTests.js

@@ -81,6 +81,10 @@ describe('CompileController', function () {
         '@overleaf/metrics': (this.Metrics = {
           inc: sinon.stub(),
           Timer: class {
+            constructor() {
+              this.labels = {}
+            }
+
             done() {}
           },
         }),