Closed skls1337 closed 3 months ago
I think you are clobbering the Pushgateway
registered by this module with your own:
import { Pushgateway } from 'prom-client';
providers: [PromService, Pushgateway],
Remove the unnecessary registration and see if it works.
I tried your suggestion and I have the same behaviour.
I found out that when you init the module the gatewayUrl
is undefined and forcing it to get a value fixes the connection to pushgateway. So maybe something is not going well here
onModuleInit() {
this.logger.log('Pushing to prometheus gateway');
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
this.pushgateway.gatewayUrl = 'http://pushgateway:9091';
this.pushgateway.push({
jobName: 'backforfront',
});
}
Yes, my env is defined,
can you hardcode it and see if you get the same result?
Can confirm with the env hardcoded that the gatewayUrl will come up as undefined
, and if I do the this.pushgateway.push()
I receive TypeError: The "url" argument must be of type string. Received undefined
Yeah not sure what to tell you, I have a test that proves it works. Maybe the reference is being lost in the way you are importing...I would definitely not have that additional Pushgateway
provider registered though as that isn't necessary.
Sure, I checked the tests and it proves it works. If I completely remove the onModuleInit
it goes fine, but for some reason, I can't query Prometheus with my metrics for my nestjs service
Hi, I found out I can fix my problem with registerAsync
PrometheusModule.registerAsync({
useFactory: () => {
return {
pushgateway: {
url: process.env.PUSHGATEWAY_URL,
},
};
},
}),
So this can conclude my fix to the issue I had. Thx for the support!
PromService .ts
PromModule.ts
Log from console on startup
Yes, my env is defined, there is already an issue closed on this topic, what am I doing wrong?