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

Custom counter sometimes not tracked #595

Open
kasszz opened this issue Oct 25, 2023 · 1 comment
Open

Custom counter sometimes not tracked #595

kasszz opened this issue Oct 25, 2023 · 1 comment

Comments

@kasszz
Copy link

kasszz commented Oct 25, 2023

Dear reader,

I have an issue that it seems random if the counter is actually counting every time the server re-deploys. Have you experienced something like this? For me this is a real head scratcher.

import { collectDefaultMetrics, Counter, register } from 'prom-client'

const PREFIX = 'test_'

// Need to clear the register for HMR
register.clear()
collectDefaultMetrics({ prefix: PREFIX })

const counter1 = new Counter({
  name: `${PREFIX}counter_1`,
  help: 'Counter 1',
})


export { counter1, register }

Context
We are running a NextJS server in Kubernetes with multiple pods. So every pod is running the exact same code.

The default collectDefaultMetrics metrics are working every time for every pod.

We use this counter to count the amount of SSR pages we have to render. So we counter1.inc() every time the getServersideProps() is invoked.

In Grafana you can see the problem happening, this is a graph where it's summed by pod, you can see every new deployment that we do, the amount of pods that are reporting is different:
image

I see this also happen when requesting the /metrics route from the website. Sometimes I only see the #HELP and #TYPE line of the custom counter, and sometimes the values are popping up. This is due to me hitting different pods every refresh, and some pods are not counting. So it's not a Grafana problem.

Hopefully I provided enough information and you see I do something stupid in this setup.
Thanks in advance, Casper

@zbjornson
Copy link
Collaborator

I don't have any advice, sorry. Probably need to add debugging code to see which pods/processes are reporting and if there's a pattern.

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

No branches or pull requests

2 participants