Skip to content

Commit 5ca4a6a

Browse files
authored
Merge pull request prometheus#138 from mindprince/push-pushAdd-logic-reversed
push and pushAdd logic reversed. prometheus#137, prometheus#138.
2 parents f744e0c + 13ed0d8 commit 5ca4a6a

2 files changed

Lines changed: 37 additions & 41 deletions

File tree

simpleclient_pushgateway/src/main/java/io/prometheus/client/exporter/PushGateway.java

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -66,20 +66,20 @@ public PushGateway(String address) {
6666
}
6767

6868
/**
69-
* Pushes all metrics in a registry, replacing all those with the same job as the grouping key.
69+
* Pushes all metrics in a registry, replacing all those with the same job and no grouping key.
7070
* <p>
71-
* This uses the POST HTTP method.
71+
* This uses the PUT HTTP method.
7272
*/
7373
public void push(CollectorRegistry registry, String job) throws IOException {
74-
doRequest(registry, job, null, "POST");
74+
doRequest(registry, job, null, "PUT");
7575
}
7676

7777
/**
7878
* Pushes all metrics in a Collector, replacing all those with the same job and no grouping key.
7979
* <p>
8080
* This is useful for pushing a single Gauge.
8181
* <p>
82-
* This uses the POST HTTP method.
82+
* This uses the PUT HTTP method.
8383
*/
8484
public void push(Collector collector, String job) throws IOException {
8585
CollectorRegistry registry = new CollectorRegistry();
@@ -88,22 +88,20 @@ public void push(Collector collector, String job) throws IOException {
8888
}
8989

9090
/**
91-
* Pushes all metrics in a Collector, replacing all those with the same job and grouping key.
91+
* Pushes all metrics in a registry, replacing all those with the same job and grouping key.
9292
* <p>
93-
* This is useful for pushing a single Gauge.
94-
* <p>
95-
* This uses the POST HTTP method.
93+
* This uses the PUT HTTP method.
9694
*/
9795
public void push(CollectorRegistry registry, String job, Map<String, String> groupingKey) throws IOException {
98-
doRequest(registry, job, groupingKey, "POST");
96+
doRequest(registry, job, groupingKey, "PUT");
9997
}
10098

10199
/**
102100
* Pushes all metrics in a Collector, replacing all those with the same job and grouping key.
103101
* <p>
104102
* This is useful for pushing a single Gauge.
105103
* <p>
106-
* This uses the POST HTTP method.
104+
* This uses the PUT HTTP method.
107105
*/
108106
public void push(Collector collector, String job, Map<String, String> groupingKey) throws IOException {
109107
CollectorRegistry registry = new CollectorRegistry();
@@ -114,18 +112,18 @@ public void push(Collector collector, String job, Map<String, String> groupingKe
114112
/**
115113
* Pushes all metrics in a registry, replacing only previously pushed metrics of the same name and job and no grouping key.
116114
* <p>
117-
* This uses the PUT HTTP method.
115+
* This uses the POST HTTP method.
118116
*/
119117
public void pushAdd(CollectorRegistry registry, String job) throws IOException {
120-
doRequest(registry, job, null, "PUT");
118+
doRequest(registry, job, null, "POST");
121119
}
122120

123121
/**
124122
* Pushes all metrics in a Collector, replacing only previously pushed metrics of the same name and job and no grouping key.
125123
* <p>
126124
* This is useful for pushing a single Gauge.
127125
* <p>
128-
* This uses the PUT HTTP method.
126+
* This uses the POST HTTP method.
129127
*/
130128
public void pushAdd(Collector collector, String job) throws IOException {
131129
CollectorRegistry registry = new CollectorRegistry();
@@ -134,22 +132,20 @@ public void pushAdd(Collector collector, String job) throws IOException {
134132
}
135133

136134
/**
137-
* Pushes all metrics in a Collector, replacing only previously pushed metrics of the same name, job and grouping key.
138-
* <p>
139-
* This is useful for pushing a single Gauge.
135+
* Pushes all metrics in a registry, replacing only previously pushed metrics of the same name, job and grouping key.
140136
* <p>
141-
* This uses the PUT HTTP method.
137+
* This uses the POST HTTP method.
142138
*/
143139
public void pushAdd(CollectorRegistry registry, String job, Map<String, String> groupingKey) throws IOException {
144-
doRequest(registry, job, groupingKey, "PUT");
140+
doRequest(registry, job, groupingKey, "POST");
145141
}
146142

147143
/**
148144
* Pushes all metrics in a Collector, replacing only previously pushed metrics of the same name, job and grouping key.
149145
* <p>
150146
* This is useful for pushing a single Gauge.
151147
* <p>
152-
* This uses the PUT HTTP method.
148+
* This uses the POST HTTP method.
153149
*/
154150
public void pushAdd(Collector collector, String job, Map<String, String> groupingKey) throws IOException {
155151
CollectorRegistry registry = new CollectorRegistry();
@@ -182,7 +178,7 @@ public void delete(String job, Map<String, String> groupingKey) throws IOExcepti
182178
/**
183179
* Pushes all metrics in a registry, replacing all those with the same job and instance.
184180
* <p>
185-
* This uses the POST HTTP method.
181+
* This uses the PUT HTTP method.
186182
* @deprecated use {@link #push(CollectorRegistry, String, Map)}
187183
*/
188184
@Deprecated
@@ -195,7 +191,7 @@ public void push(CollectorRegistry registry, String job, String instance) throws
195191
* <p>
196192
* This is useful for pushing a single Gauge.
197193
* <p>
198-
* This uses the POST HTTP method.
194+
* This uses the PUT HTTP method.
199195
* @deprecated use {@link #push(Collector, String, Map)}
200196
*/
201197
@Deprecated
@@ -206,7 +202,7 @@ public void push(Collector collector, String job, String instance) throws IOExce
206202
/**
207203
* Pushes all metrics in a registry, replacing only previously pushed metrics of the same name.
208204
* <p>
209-
* This uses the PUT HTTP method.
205+
* This uses the POST HTTP method.
210206
* @deprecated use {@link #pushAdd(CollectorRegistry, String, Map)}
211207
*/
212208
@Deprecated
@@ -219,7 +215,7 @@ public void pushAdd(CollectorRegistry registry, String job, String instance) thr
219215
* <p>
220216
* This is useful for pushing a single Gauge.
221217
* <p>
222-
* This uses the PUT HTTP method.
218+
* This uses the POST HTTP method.
223219
* @deprecated use {@link #pushAdd(Collector, String, Map)}
224220
*/
225221
@Deprecated

simpleclient_pushgateway/src/test/java/io/prometheus/client/exporter/PushGatewayTest.java

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public void setUp() {
4040
public void testPush() throws IOException {
4141
mockServerClient.when(
4242
request()
43-
.withMethod("POST")
43+
.withMethod("PUT")
4444
.withPath("/metrics/job/j")
4545
).respond(response().withStatusCode(202));
4646
pg.push(registry, "j");
@@ -50,7 +50,7 @@ public void testPush() throws IOException {
5050
public void testNon202ResponseThrows() throws IOException {
5151
mockServerClient.when(
5252
request()
53-
.withMethod("POST")
53+
.withMethod("PUT")
5454
.withPath("/metrics/job/j")
5555
).respond(response().withStatusCode(500));
5656
pg.push(registry, "j");
@@ -60,7 +60,7 @@ public void testNon202ResponseThrows() throws IOException {
6060
public void testPushCollector() throws IOException {
6161
mockServerClient.when(
6262
request()
63-
.withMethod("POST")
63+
.withMethod("PUT")
6464
.withPath("/metrics/job/j")
6565
).respond(response().withStatusCode(202));
6666
pg.push(gauge, "j");
@@ -70,7 +70,7 @@ public void testPushCollector() throws IOException {
7070
public void testPushWithGroupingKey() throws IOException {
7171
mockServerClient.when(
7272
request()
73-
.withMethod("POST")
73+
.withMethod("PUT")
7474
.withPath("/metrics/job/j/l/v")
7575
).respond(response().withStatusCode(202));
7676
pg.push(registry, "j", groupingKey);
@@ -80,7 +80,7 @@ public void testPushWithGroupingKey() throws IOException {
8080
public void testPushWithMultiGroupingKey() throws IOException {
8181
mockServerClient.when(
8282
request()
83-
.withMethod("POST")
83+
.withMethod("PUT")
8484
.withPath("/metrics/job/j/l/v/l2/v2")
8585
).respond(response().withStatusCode(202));
8686
groupingKey.put("l2", "v2");
@@ -91,7 +91,7 @@ public void testPushWithMultiGroupingKey() throws IOException {
9191
public void testPushWithGroupingKeyWithSlashes() throws IOException {
9292
mockServerClient.when(
9393
request()
94-
.withMethod("POST")
94+
.withMethod("PUT")
9595
.withPath("/metrics/job/a%2Fb/l/v/l2/v%2F2")
9696
).respond(response().withStatusCode(202));
9797
groupingKey.put("l2", "v/2");
@@ -102,7 +102,7 @@ public void testPushWithGroupingKeyWithSlashes() throws IOException {
102102
public void testPushCollectorWithGroupingKey() throws IOException {
103103
mockServerClient.when(
104104
request()
105-
.withMethod("POST")
105+
.withMethod("PUT")
106106
.withPath("/metrics/job/j/l/v")
107107
).respond(response().withStatusCode(202));
108108
pg.push(gauge, "j", groupingKey);
@@ -112,7 +112,7 @@ public void testPushCollectorWithGroupingKey() throws IOException {
112112
public void testPushAdd() throws IOException {
113113
mockServerClient.when(
114114
request()
115-
.withMethod("PUT")
115+
.withMethod("POST")
116116
.withPath("/metrics/job/j")
117117
).respond(response().withStatusCode(202));
118118
pg.pushAdd(registry, "j");
@@ -122,7 +122,7 @@ public void testPushAdd() throws IOException {
122122
public void testPushAddCollector() throws IOException {
123123
mockServerClient.when(
124124
request()
125-
.withMethod("PUT")
125+
.withMethod("POST")
126126
.withPath("/metrics/job/j")
127127
).respond(response().withStatusCode(202));
128128
pg.pushAdd(gauge, "j");
@@ -132,7 +132,7 @@ public void testPushAddCollector() throws IOException {
132132
public void testPushAddWithGroupingKey() throws IOException {
133133
mockServerClient.when(
134134
request()
135-
.withMethod("PUT")
135+
.withMethod("POST")
136136
.withPath("/metrics/job/j/l/v")
137137
).respond(response().withStatusCode(202));
138138
pg.pushAdd(registry, "j", groupingKey);
@@ -142,7 +142,7 @@ public void testPushAddWithGroupingKey() throws IOException {
142142
public void testPushAddCollectorWithGroupingKey() throws IOException {
143143
mockServerClient.when(
144144
request()
145-
.withMethod("PUT")
145+
.withMethod("POST")
146146
.withPath("/metrics/job/j/l/v")
147147
).respond(response().withStatusCode(202));
148148
pg.pushAdd(gauge, "j", groupingKey);
@@ -174,7 +174,7 @@ public void testDeleteWithGroupingKey() throws IOException {
174174
public void testOldPushWithoutInstance() throws IOException {
175175
mockServerClient.when(
176176
request()
177-
.withMethod("POST")
177+
.withMethod("PUT")
178178
.withPath("/metrics/job/j/instance/")
179179
).respond(response().withStatusCode(202));
180180
pg.push(registry, "j", "");
@@ -184,7 +184,7 @@ public void testOldPushWithoutInstance() throws IOException {
184184
public void testOldPushWithInstance() throws IOException {
185185
mockServerClient.when(
186186
request()
187-
.withMethod("POST")
187+
.withMethod("PUT")
188188
.withPath("/metrics/job/j/instance/i")
189189
).respond(response().withStatusCode(202));
190190
pg.push(registry, "j", "i");
@@ -194,7 +194,7 @@ public void testOldPushWithInstance() throws IOException {
194194
public void testOldNon202ResponseThrows() throws IOException {
195195
mockServerClient.when(
196196
request()
197-
.withMethod("POST")
197+
.withMethod("PUT")
198198
.withPath("/metrics/job/j/instance/i")
199199
).respond(response().withStatusCode(500));
200200
pg.push(registry,"j", "i");
@@ -204,7 +204,7 @@ public void testOldNon202ResponseThrows() throws IOException {
204204
public void testOldPushWithSlashes() throws IOException {
205205
mockServerClient.when(
206206
request()
207-
.withMethod("POST")
207+
.withMethod("PUT")
208208
.withPath("/metrics/job/a%2Fb/instance/c%2Fd")
209209
).respond(response().withStatusCode(202));
210210
pg.push(registry, "a/b", "c/d");
@@ -214,7 +214,7 @@ public void testOldPushWithSlashes() throws IOException {
214214
public void testOldPushCollector() throws IOException {
215215
mockServerClient.when(
216216
request()
217-
.withMethod("POST")
217+
.withMethod("PUT")
218218
.withPath("/metrics/job/j/instance/i")
219219
).respond(response().withStatusCode(202));
220220
pg.push(gauge, "j", "i");
@@ -224,7 +224,7 @@ public void testOldPushCollector() throws IOException {
224224
public void testOldPushAdd() throws IOException {
225225
mockServerClient.when(
226226
request()
227-
.withMethod("PUT")
227+
.withMethod("POST")
228228
.withPath("/metrics/job/j/instance/i")
229229
).respond(response().withStatusCode(202));
230230
pg.pushAdd(registry, "j", "i");
@@ -234,7 +234,7 @@ public void testOldPushAdd() throws IOException {
234234
public void testOldPushAddCollector() throws IOException {
235235
mockServerClient.when(
236236
request()
237-
.withMethod("PUT")
237+
.withMethod("POST")
238238
.withPath("/metrics/job/j/instance/i")
239239
).respond(response().withStatusCode(202));
240240
pg.pushAdd(gauge, "j", "i");

0 commit comments

Comments
 (0)