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

Gauge without label should not have a default value of 0 (zero) #622

Open
thomaschaaf opened this issue Mar 27, 2024 · 0 comments
Open

Gauge without label should not have a default value of 0 (zero) #622

thomaschaaf opened this issue Mar 27, 2024 · 0 comments

Comments

@thomaschaaf
Copy link

A gauge that is registered but does not have a value set is currently set to 0 (zero). I believe this behavior to be incorrect because a gauge without a label does not work like it.

const client = require('prom-client');
const gauge = new client.Gauge({ name: 'metric_name', help: 'metric_help', labelNames: ['example'] });
const gauge2 = new client.Gauge({ name: 'metric_name2', help: 'metric_help2' });

console.log(await client.register.metrics())

gauge.set({ example: 'true' }, 1)

console.log(await client.register.metrics())

gauge.reset();

console.log(await client.register.metrics())

Output 1 after initialization:

# HELP metric_name metric_help
# TYPE metric_name gauge

# HELP metric_name2 metric_help2
# TYPE metric_name2 gauge
metric_name2 0

Output 2 after setting gauge:

# HELP metric_name metric_help
# TYPE metric_name gauge
metric_name{example="true"} 1

# HELP metric_name2 metric_help2
# TYPE metric_name2 gauge
metric_name2 0

Output 3 after reset:

# HELP metric_name metric_help
# TYPE metric_name gauge

# HELP metric_name2 metric_help2
# TYPE metric_name2 gauge
metric_name2 0

I would expect the output 1 of both gauges to be the same and instead of a default of 0 having a default of undefined.

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

No branches or pull requests

1 participant