|
1 | 1 | package io.prometheus.metrics.exporter.pushgateway; |
2 | 2 |
|
3 | | -import static io.prometheus.metrics.exporter.pushgateway.Scheme.HTTP; |
4 | | -import static io.prometheus.metrics.model.snapshots.PrometheusNaming.*; |
5 | | - |
6 | 3 | import io.prometheus.metrics.config.ExporterPushgatewayProperties; |
7 | 4 | import io.prometheus.metrics.config.PrometheusProperties; |
8 | 5 | import io.prometheus.metrics.config.PrometheusPropertiesException; |
|
13 | 10 | import io.prometheus.metrics.model.registry.MultiCollector; |
14 | 11 | import io.prometheus.metrics.model.registry.PrometheusRegistry; |
15 | 12 | import io.prometheus.metrics.model.snapshots.EscapingScheme; |
| 13 | + |
16 | 14 | import java.io.ByteArrayOutputStream; |
17 | 15 | import java.io.IOException; |
18 | 16 | import java.io.InputStream; |
|
32 | 30 | import java.util.Map; |
33 | 31 | import java.util.TreeMap; |
34 | 32 |
|
| 33 | +import static io.prometheus.metrics.exporter.pushgateway.Scheme.HTTP; |
| 34 | +import static io.prometheus.metrics.model.snapshots.PrometheusNaming.escapeName; |
| 35 | + |
35 | 36 | /** |
36 | 37 | * Export metrics via the <a href="https://github.com/prometheus/pushgateway">Prometheus |
37 | 38 | * Pushgateway</a> |
@@ -466,36 +467,34 @@ private Format getFormat() { |
466 | 467 |
|
467 | 468 | private URL makeUrl(ExporterPushgatewayProperties properties) |
468 | 469 | throws UnsupportedEncodingException, MalformedURLException { |
469 | | - String url = getScheme(properties) + "://" + getAddress(properties) + "/metrics/"; |
| 470 | + StringBuilder url = |
| 471 | + new StringBuilder(getScheme(properties) + "://" + getAddress(properties) + "/metrics/"); |
470 | 472 | String job = getJob(properties); |
471 | 473 | if (job.contains("/")) { |
472 | | - url += "job@base64/" + base64url(job); |
| 474 | + url.append("job@base64/").append(base64url(job)); |
473 | 475 | } else { |
474 | | - url += "job/" + URLEncoder.encode(job, "UTF-8"); |
| 476 | + url.append("job/").append(URLEncoder.encode(job, "UTF-8")); |
475 | 477 | } |
476 | 478 | if (groupingKey != null) { |
477 | 479 | for (Map.Entry<String, String> entry : groupingKey.entrySet()) { |
478 | 480 | if (entry.getValue().isEmpty()) { |
479 | | - url += |
480 | | - "/" |
481 | | - + escapeName(entry.getKey(), EscapingScheme.VALUE_ENCODING_ESCAPING) |
482 | | - + "@base64/="; |
| 481 | + url.append("/") |
| 482 | + .append(escapeName(entry.getKey(), EscapingScheme.VALUE_ENCODING_ESCAPING)) |
| 483 | + .append("@base64/="); |
483 | 484 | } else if (entry.getValue().contains("/")) { |
484 | | - url += |
485 | | - "/" |
486 | | - + escapeName(entry.getKey(), EscapingScheme.VALUE_ENCODING_ESCAPING) |
487 | | - + "@base64/" |
488 | | - + base64url(entry.getValue()); |
| 485 | + url.append("/") |
| 486 | + .append(escapeName(entry.getKey(), EscapingScheme.VALUE_ENCODING_ESCAPING)) |
| 487 | + .append("@base64/") |
| 488 | + .append(base64url(entry.getValue())); |
489 | 489 | } else { |
490 | | - url += |
491 | | - "/" |
492 | | - + escapeName(entry.getKey(), EscapingScheme.VALUE_ENCODING_ESCAPING) |
493 | | - + "/" |
494 | | - + URLEncoder.encode(entry.getValue(), "UTF-8"); |
| 490 | + url.append("/") |
| 491 | + .append(escapeName(entry.getKey(), EscapingScheme.VALUE_ENCODING_ESCAPING)) |
| 492 | + .append("/") |
| 493 | + .append(URLEncoder.encode(entry.getValue(), "UTF-8")); |
495 | 494 | } |
496 | 495 | } |
497 | 496 | } |
498 | | - return URI.create(url).normalize().toURL(); |
| 497 | + return URI.create(url.toString()).normalize().toURL(); |
499 | 498 | } |
500 | 499 |
|
501 | 500 | private String base64url(String v) { |
|
0 commit comments