-
Notifications
You must be signed in to change notification settings - Fork 577
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(prometheus): call Client.register.clear() before init #2892
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportPatch coverage:
📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more Additional details and impacted files@@ Coverage Diff @@
## main #2892 +/- ##
==========================================
- Coverage 81.67% 81.52% -0.16%
==========================================
Files 437 437
Lines 15818 15827 +9
Branches 3731 3734 +3
==========================================
- Hits 12920 12903 -17
- Misses 2630 2651 +21
- Partials 268 273 +5
... and 8 files with indirect coverage changes Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report in Codecov by Sentry. |
@@ -20,6 +20,7 @@ export class DataService { | |||
bInit = false; | |||
|
|||
async init() { | |||
Client.register.clear(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
调用这个的原因是?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我单测里面会出现这种异常
2023-04-11 15:39:52,166 ERROR 3250 Error [unhandledRejectionError]: A metric with the name http_request_latency_milliseconds has already been registered.
at Registry.registerMetric (/__w/midway-components/midway-components/node_modules/prom-client/lib/registry.js:67:10)
at new Metric (/__w/midway-components/midway-components/node_modules/prom-client/lib/metric.js:48:13)
at new Summary (/__w/midway-components/midway-components/node_modules/prom-client/lib/summary.js:17:3)
at DataService.init (/__w/midway-components/midway-components/node_modules/@midwayjs/prometheus/dist/service/dataService.js:23:32)
at DataService.getUser (/__w/midway-components/midway-components/node_modules/@midwayjs/prometheus/dist/service/dataService.js:47:18)
at /__w/midway-components/midway-components/node_modules/@midwayjs/prometheus/dist/configuration.js:77:25
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async /__w/midway-components/midway-components/node_modules/@midwayjs/i18n/dist/middleware.js:150:17
at async handleAppExceptionAndNext (/__w/midway-components/midway-components/packages/otel/dist/middleware/helper.middleware.js:28:9)
at async bodyParser (/__w/midway-components/midway-components/node_modules/koa-bodyparser/index.js:91:5)
2023-04-11 15:39:52,169 ERROR 3250 TypeError: Cannot read properties of undefined (reading 'labels')
at DataService.getUser (/__w/midway-components/midway-components/node_modules/@midwayjs/prometheus/dist/service/dataService.js:51:14)
at /__w/midway-components/midway-components/node_modules/@midwayjs/prometheus/dist/configuration.js:77:25
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async /__w/midway-components/midway-components/node_modules/@midwayjs/i18n/dist/middleware.js:150:17
at async handleAppExceptionAndNext (/__w/midway-components/midway-components/packages/otel/dist/middleware/helper.middleware.js:28:9)
at async bodyParser (/__w/midway-components/midway-components/node_modules/koa-bodyparser/index.js:91:5)
at async session (/__w/midway-components/midway-components/node_modules/@midwayjs/session/dist/middleware/session.js:137:17)
at async middleware (/__w/midway-components/midway-components/packages/boot/dist/middleware/error-handler.middleware.js:30:9)
at async handleTopExceptionAndNext (/__w/midway-components/midway-components/packages/otel/dist/middleware/helper.middleware.js:12:9)
at async middleware (/__w/midway-components/midway-components/packages/otel/dist/middleware/trace-outer.middleware.js:58:5)
导致后续频繁出现 undefined 异常:
2023-04-11 15:39:52,177 ERROR 3250 TypeError: Cannot read properties of undefined (reading 'labels')
at DataService.getUser (/__w/midway-components/midway-components/node_modules/@midwayjs/prometheus/dist/service/dataService.js:51:14)
at /__w/midway-components/midway-components/node_modules/@midwayjs/prometheus/dist/configuration.js:77:25
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async /__w/midway-components/midway-components/node_modules/@midwayjs/i18n/dist/middleware.js:150:17
at async handleAppExceptionAndNext (/__w/midway-components/midway-components/packages/otel/dist/middleware/helper.middleware.js:28:9)
at async bodyParser (/__w/midway-components/midway-components/node_modules/koa-bodyparser/index.js:91:5)
at async session (/__w/midway-components/midway-components/node_modules/@midwayjs/session/dist/middleware/session.js:137:17)
at async middleware (/__w/midway-components/midway-components/packages/boot/dist/middleware/error-handler.middleware.js:30:9)
at async handleTopExceptionAndNext (/__w/midway-components/midway-components/packages/otel/dist/middleware/helper.middleware.js:12:9)
at async middleware (/__w/midway-components/midway-components/packages/otel/dist/middleware/trace-outer.middleware.js:58:5)
搜索了下,问题似乎应该是 prom 重复注册导致的,解决办法是注册之前先清理一次。
Checklist
npm test
passesAffected core subsystem(s)
Description of change