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

Pushing to PushGateway is not pushing any metrics #659

Closed
ricardoatsouza opened this issue May 28, 2021 · 7 comments
Closed

Pushing to PushGateway is not pushing any metrics #659

ricardoatsouza opened this issue May 28, 2021 · 7 comments

Comments

@ricardoatsouza
Copy link

Hello,

I have a set of metrics in my batch job, all of them being created in the following way:

    r = CollectorRegistry()
    ...
    c = Counter(<name>, <description>, registry=r, labelnames=<global_label_names>, labelvalues=<global_label_values>)

In my use case, I have a small set of global labels that I define to every metric when they are created. Then, at the end of the batch job, the metrics are pushed to PushGateway through the push_to_gateway function. The command runs successfully. However, in PushGateway, none of the metrics is actually there.

    push_to_gateway(<url>, job=<job_name>, registry=r)

While trying to understand why, I crossed with this line in the code. Basically, the created metrics are only added to the given registry r when there are no labels given to it. Consequently, the registry r is empty when push_to_gateway runs.

I wonder if this is the intended behaviour. In case positive, is there a way to use the global prometheus registry in push_to_gateway (registry is a required parameter in the function call)?

@roidelapluie
Copy link
Member

labelvalues=<global_label_values> is an internal parameter (it is not mentioned in the documentation). Please look at the documentation for proper usage of counters. In particular, I think you need to call Counter.labels() to set the label values.

It makes more sense to ask questions like this on the prometheus-users mailing list or our forums rather than in a GitHub issue. In our community channels, more people are available to potentially respond to your question, and the whole community can benefit from the answers provided.

@roidelapluie
Copy link
Member

It also looks like grouping_key is not documented. Perhaps that is what you want?

@csmarchbanks
Copy link
Member

Hello, this is a duplicate of #398, I have also created #660 to close that issue and make it clear that labelvalues is for internal use only.

@ricardoatsouza
Copy link
Author

@roidelapluie Thanks for the quick answer. Sorry if I couldn't reply earlier. It would be indeed beneficial if the documentation explicitly say that this is intended for internal use.

What I would like to achieve is to define a set of fixed values for my counter (or histogram, etc). Those values do change on every execution of the batch process and are not dimensionally big. I saw in the documentation that I can create the labels using label_names, but then I would have to assign their values using labels every time I would call inc.

That's a small use case, and I am not sure whether it happens often enough to justify its implementation. 🤷‍♂️

@csmarchbanks
Copy link
Member

Hello, that is certainly a reasonable use case, and I wonder if this library covers it well enough as is. If not, we can create a new issue that is an enhancement request. Currently the way to create a metric with a fixed set of labels would be like this:

c = Counter(
    "my_requests_total",
    "HTTP Failures",
    ["method", "endpoint"],
).labels("get", "/")
c.inc()

Does a workflow like that enable what you require?

@ricardoatsouza
Copy link
Author

Hello @csmarchbanks. Naive if me not to think of your proposal. It seems to work just fine. If I encounter issues, I might come back, but for now the case is closed. Thanks!

@roidelapluie
Copy link
Member

Awesome 🥳

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

3 participants