Hot Module Reload problem with prom-client
See original GitHub issueHi, I’am using your library and I love it, but I found this little problem (not really a big one, but …).
I’am using your library in a NestJS project. This framework proposes to use HMR with webpack. I have a provider class for prometheus-things which have this contructor :
constructor(){
this.counter = new Counter({
name: 'fred_total_method_calls',
help: 'Example of a counter',
labelNames: ['method','path']
});
this.gauge = new Gauge({
name: 'fred_method_response_time',
help: 'Example of a gauge',
labelNames: ['method','path']
});
}
When I’am running my project in my develop environment, and when I modify something somewhere in the project I have this error :
[HMR] Updated modules:
[HMR] - ./src/app.controller.ts
[HMR] - ./src/app.module.ts
[HMR] - ./src/main.hmr.ts
[HMR] - ./src/app.service.ts
[HMR] Update applied.
[Nest] 8624 - 2018-5-31 15:22:03 [ExceptionHandler] A metric with the name fred_total_method_calls has already been registered.
When the Hot Module Reload event is handled, webpack regenerate the changing code but existing metrics are still there.
I have found a workarround :
constructor(){
register.clear();
this.counter = new Counter({
name: 'fred_total_method_calls',
help: 'Example of a counter',
labelNames: ['method','path']
});
...
I call register.clear()
in my constructor and it works in HMR mode. But I don’t like this solution because this line is only here for my comfort allowing me to use HMR in my development phase. It has no direct buisness intrest.
So, do you have a better workarround for this problem?
Thank you
Issue Analytics
- State:
- Created 5 years ago
- Reactions:9
- Comments:9
I call
client.register.removeSingleMetric('<name>')
before I register metrics which seems to solve the issue.This works (you have to call clear on every HMR reload on SSR):
in express initialization: