Skip to content

Commit e4cab67

Browse files
authored
Handle empty label values for the pushgateway. (#553)
Fixes #552 Signed-off-by: Brian Brazil <brian.brazil@robustperception.io>
1 parent 5554fc7 commit e4cab67

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,9 @@ void doRequest(CollectorRegistry registry, String job, Map<String, String> group
286286

287287
if (groupingKey != null) {
288288
for (Map.Entry<String, String> entry: groupingKey.entrySet()) {
289-
if (entry.getValue().contains("/")) {
289+
if (entry.getValue().isEmpty()) {
290+
url += "/" + entry.getKey() + "@base64/=";
291+
} else if (entry.getValue().contains("/")) {
290292
url += "/" + entry.getKey() + "@base64/" + base64url(entry.getValue());
291293
} else {
292294
url += "/" + entry.getKey() + "/" + URLEncoder.encode(entry.getValue(), "UTF-8");

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

+12-3
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,17 @@ public void testPushWithMultiGroupingKey() throws IOException {
111111
pg.push(registry, "j", groupingKey);
112112
}
113113

114+
@Test
115+
public void testPushWithEmptyLabelGroupingKey() throws IOException {
116+
mockServerClient.when(
117+
request()
118+
.withMethod("PUT")
119+
.withPath("/metrics/job/j/l/v/l2@base64/=")
120+
).respond(response().withStatusCode(202));
121+
groupingKey.put("l2", "");
122+
pg.push(registry, "j", groupingKey);
123+
}
124+
114125
@Test
115126
public void testPushWithGroupingKeyWithSlashes() throws IOException {
116127
mockServerClient.when(
@@ -192,14 +203,12 @@ public void testDeleteWithGroupingKey() throws IOException {
192203
pg.delete("j", groupingKey);
193204
}
194205

195-
196-
197206
@Test
198207
public void testOldPushWithoutInstance() throws IOException {
199208
mockServerClient.when(
200209
request()
201210
.withMethod("PUT")
202-
.withPath("/metrics/job/j/instance/")
211+
.withPath("/metrics/job/j/instance@base64/=")
203212
).respond(response().withStatusCode(202));
204213
pg.push(registry, "j", "");
205214
}

0 commit comments

Comments
 (0)