Push gateway PUT vs POST

549 views
Skip to first unread message

Markos Fragkakis

unread,
Jul 25, 2022, 3:50:39 AM7/25/22
to Prometheus Users
Hello,

I have a scheduled task that periodically pushes metrics to the prometheus gateway.

My desired behaviour would be for each "push" to overwrite previous pushes, even if the metrics and labels pushed are not one-for-one compared to previous push.

Reading the documentation on PUT vs POST I see this:

> PUT is used to push a group of metrics. All metrics with the grouping key specified in the URL are replaced by the metrics pushed with PUT.

My understanding of the above is that PUT will do exactly what I want. However, in the POST section I read:

> POST works exactly like the PUT method but only metrics with the same name as the newly pushed metrics are replaced (among those with the same grouping key).

What does "metrics with the same name" mean? Let's say I have 2 consecutive pushes with the payloads below. What using POST would do vs using PUT? Which are the "metrics with the same name" that would be replaced? Would it be `external_ats_metric1`, regardless the fact that there are different labels in the 2nd push?

Thank you,

Markos

PUSH #1

# TYPE external_ats_metric1 gauge
external_ats_metric1{app=\"foo\",component=\"component1\",priority=\"low\"} 1
external_ats_metric1{app=\"foo\",component=\"component2\",priority=\"low\"} 2
external_ats_metric1{app=\"foo\",component=\"component3\",priority=\"low\"} 3

# TYPE external_ats_metric2 gauge
external_ats_metric2{app=\"foo\",component=\"component1\",priority=\"low\"} 1
external_ats_metric2{app=\"foo\",component=\"component2\",priority=\"low\"} 2
external_ats_metric2{app=\"foo\",component=\"component3\",priority=\"low\"} 3

PUSH #2

# TYPE external_ats_metric1 gauge
external_ats_metric1{app=\"foo\",component=\"component4\",priority=\"low\"} 1
external_ats_metric1{app=\"foo\",component=\"component5\",priority=\"low\"} 2
external_ats_metric1{app=\"foo\",component=\"component6\",priority=\"low\"} 3

# TYPE external_ats_metric3 gauge
external_ats_metric3{app=\"foo\",component=\"component1\",priority=\"low\"} 1
external_ats_metric3{app=\"foo\",component=\"component2\",priority=\"low\"} 2
external_ats_metric3{app=\"foo\",component=\"component3\",priority=\"low\"} 3

Bjoern Rabenstein

unread,
Sep 29, 2022, 9:33:07 AM9/29/22
to Markos Fragkakis, Prometheus Users
Apologies for late reply. Just seeing this now...

On 25.07.22 00:47, Markos Fragkakis wrote:
>
> What does "metrics with the same name" mean? Let's say I have 2 consecutive
> pushes with the payloads below. What using POST would do vs using PUT?
> Which are the "metrics with the same name" that would be replaced? Would it
> be `external_ats_metric1`, regardless the fact that there are different
> labels in the 2nd push?

Yes, just the metric name matters, not its labels.

After POSTing the 2nd push, you would end up with all the
external_ats_metric1 lines from the 2nd push (but none from the 1st),
the external_ats_metric2 lines from the 1st push, and the
external_ats_metric3 lines from the 2nd push.

If you use PUT, you would end up with only the lines from the 2nd
push.

All of this assumes you are pushing using the same grouping labels.
> --
> You received this message because you are subscribed to the Google Groups "Prometheus Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to prometheus-use...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/prometheus-users/7d3796e9-6592-47af-8ed4-6c593ea67d36n%40googlegroups.com.


--
Björn Rabenstein
[PGP-ID] 0x851C3DA17D748D03
[email] bjo...@rabenste.in
Reply all
Reply to author
Forward
0 new messages