Skip to content
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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

waitingsong
Copy link
Member

Checklist
  • npm test passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines
Affected core subsystem(s)
Description of change

@codecov-commenter
Copy link

codecov-commenter commented Apr 18, 2023

Codecov Report

Patch coverage: 100.00% and project coverage change: -0.16 ⚠️

Comparison is base (ef6e570) 81.67% compared to head (2fe7ee9) 81.52%.

📣 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     
Impacted Files Coverage Δ
packages/prometheus/src/service/dataService.ts 65.78% <100.00%> (+0.92%) ⬆️

... 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.
📢 Do you have feedback about the report comment? Let us know in this issue.

@@ -20,6 +20,7 @@ export class DataService {
bInit = false;

async init() {
Client.register.clear();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

调用这个的原因是?

Copy link
Member Author

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 重复注册导致的,解决办法是注册之前先清理一次。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants