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

Metrics not being computed when the application is forked into a child process #1889

Closed
quixote15 opened this issue Sep 8, 2023 · 5 comments
Labels
question Further information is requested

Comments

@quixote15
Copy link

I created a new Nestjs project, Installed the lib and then copy pasted the example in the README of a counter. That worked fine.

However, forking the nestjs application into a sub-process and trying to increment the counter does not updates the metric value.

Even tough I increment the metric inside an infinite loop

let = 0; 
while (true) {
    console.log('incrementing prometheus counter in background... ' + i++);
    service.increment();
    await setTimeout(500);
  }

The metric endpoint returns zero

image

I've created repo which replicates this issue:

https://github.com/quixote15/nestjs-prometheus-fork-issue

Can anybody help me with this?

@willsoto
Copy link
Owner

Is this something that works using prom-client directly?

@willsoto willsoto added the question Further information is requested label Sep 10, 2023
@quixote15
Copy link
Author

quixote15 commented Sep 11, 2023

@willsoto

It could be something related to prom-client since it is a dependency of this lib but I'm just using the methods exported by nestjs-prometheus directly as you can see here

Maybe prom-client does not support child process ?

@willsoto
Copy link
Owner

Before I look into anything here, you will need to confirm the behavior of both prom-client and NestJS when it comes to child processes.

Given this library is a simple thin wrapper around prom-client, it's unlikely the issue would be here. But before I do any work to figure it out, you will need to confirm that the underlying libraries support child processes as you'd expect and then we could say with certainty that something in this library was preventing that from working.

@quixote15
Copy link
Author

Looking into prom-client repo I found that they are trying to add support to this

siimon/prom-client#403
siimon/prom-client#401 (comment)

So yeah, definetly not something in this library

@willsoto
Copy link
Owner

Great! Thanks for looking into it. If they ever get support added and it still doesn't work, please feel free to re-open this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants