Skip to content

Commit c5de174

Browse files
committed
fix merge
Signed-off-by: Gregor Zeitlinger <[email protected]>
1 parent 16a8fd8 commit c5de174

File tree

3 files changed

+24
-13
lines changed

3 files changed

+24
-13
lines changed

prometheus-metrics-config/src/main/java/io/prometheus/metrics/config/PrometheusProperties.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ public static class Builder {
116116
private ExporterHttpServerProperties exporterHttpServerProperties;
117117
private ExporterPushgatewayProperties pushgatewayProperties;
118118
private ExporterOpenTelemetryProperties otelConfig;
119+
private NamingProperties namingProperties;
119120

120121
private Builder() {}
121122

@@ -167,6 +168,11 @@ public Builder exporterOpenTelemetryProperties(
167168
return this;
168169
}
169170

171+
public Builder namingProperties(NamingProperties namingProperties) {
172+
this.namingProperties = namingProperties;
173+
return this;
174+
}
175+
170176
public PrometheusProperties build() {
171177
return new PrometheusProperties(
172178
defaultMetricsProperties,
@@ -176,7 +182,8 @@ public PrometheusProperties build() {
176182
exporterFilterProperties,
177183
exporterHttpServerProperties,
178184
pushgatewayProperties,
179-
otelConfig);
185+
otelConfig,
186+
namingProperties);
180187
}
181188
}
182189
}

prometheus-metrics-exporter-common/src/main/java/io/prometheus/metrics/exporter/common/PrometheusScrapeHandler.java

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import io.prometheus.metrics.expositionformats.ExpositionFormats;
77
import io.prometheus.metrics.model.registry.MetricNameFilter;
88
import io.prometheus.metrics.model.registry.PrometheusRegistry;
9+
import io.prometheus.metrics.model.snapshots.EscapingScheme;
910
import io.prometheus.metrics.model.snapshots.MetricSnapshots;
1011
import java.io.ByteArrayOutputStream;
1112
import java.io.IOException;
@@ -54,10 +55,11 @@ public void handleRequest(PrometheusHttpExchange exchange) throws IOException {
5455
try {
5556
PrometheusHttpRequest request = exchange.getRequest();
5657
MetricSnapshots snapshots = scrape(request);
57-
if (writeDebugResponse(snapshots, exchange)) {
58+
String acceptHeader = request.getHeader("Accept");
59+
EscapingScheme escapingScheme = EscapingScheme.fromAcceptHeader(acceptHeader);
60+
if (writeDebugResponse(snapshots, escapingScheme, exchange)) {
5861
return;
5962
}
60-
String acceptHeader = request.getHeader("Accept");
6163
ExpositionFormatWriter writer = expositionFormats.findWriter(acceptHeader);
6264
PrometheusHttpResponse response = exchange.getResponse();
6365
response.setHeader("Content-Type", writer.getContentType());
@@ -66,12 +68,12 @@ public void handleRequest(PrometheusHttpExchange exchange) throws IOException {
6668
response.setHeader("Content-Encoding", "gzip");
6769
try (GZIPOutputStream gzipOutputStream =
6870
new GZIPOutputStream(response.sendHeadersAndGetBody(200, 0))) {
69-
writer.write(gzipOutputStream, snapshots);
71+
writer.write(gzipOutputStream, snapshots, escapingScheme);
7072
}
7173
} else {
7274
ByteArrayOutputStream responseBuffer =
7375
new ByteArrayOutputStream(lastResponseSize.get() + 1024);
74-
writer.write(responseBuffer, snapshots);
76+
writer.write(responseBuffer, snapshots, escapingScheme);
7577
lastResponseSize.set(responseBuffer.size());
7678
int contentLength = responseBuffer.size();
7779
if (contentLength > 0) {
@@ -136,7 +138,8 @@ private MetricSnapshots scrape(PrometheusHttpRequest request) {
136138
}
137139
}
138140

139-
private boolean writeDebugResponse(MetricSnapshots snapshots, PrometheusHttpExchange exchange)
141+
private boolean writeDebugResponse(
142+
MetricSnapshots snapshots, EscapingScheme escapingScheme, PrometheusHttpExchange exchange)
140143
throws IOException {
141144
String debugParam = exchange.getRequest().getParameter("debug");
142145
PrometheusHttpResponse response = exchange.getResponse();
@@ -148,14 +151,16 @@ private boolean writeDebugResponse(MetricSnapshots snapshots, PrometheusHttpExch
148151
OutputStream body = response.sendHeadersAndGetBody(responseStatus, 0);
149152
switch (debugParam) {
150153
case "openmetrics":
151-
expositionFormats.getOpenMetricsTextFormatWriter().write(body, snapshots);
154+
expositionFormats.getOpenMetricsTextFormatWriter().write(body, snapshots, escapingScheme);
152155
break;
153156
case "text":
154-
expositionFormats.getPrometheusTextFormatWriter().write(body, snapshots);
157+
expositionFormats.getPrometheusTextFormatWriter().write(body, snapshots, escapingScheme);
155158
break;
156159
case "prometheus-protobuf":
157160
String debugString =
158-
expositionFormats.getPrometheusProtobufWriter().toDebugString(snapshots);
161+
expositionFormats
162+
.getPrometheusProtobufWriter()
163+
.toDebugString(snapshots, escapingScheme);
159164
body.write(debugString.getBytes(StandardCharsets.UTF_8));
160165
break;
161166
default:

prometheus-metrics-exporter-pushgateway/src/main/java/io/prometheus/metrics/exporter/pushgateway/PushGateway.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package io.prometheus.metrics.exporter.pushgateway;
22

3+
import static io.prometheus.metrics.exporter.pushgateway.Scheme.HTTP;
4+
import static io.prometheus.metrics.model.snapshots.PrometheusNaming.escapeName;
5+
36
import io.prometheus.metrics.config.ExporterPushgatewayProperties;
47
import io.prometheus.metrics.config.PrometheusProperties;
58
import io.prometheus.metrics.config.PrometheusPropertiesException;
@@ -10,7 +13,6 @@
1013
import io.prometheus.metrics.model.registry.MultiCollector;
1114
import io.prometheus.metrics.model.registry.PrometheusRegistry;
1215
import io.prometheus.metrics.model.snapshots.EscapingScheme;
13-
1416
import java.io.ByteArrayOutputStream;
1517
import java.io.IOException;
1618
import java.io.InputStream;
@@ -30,9 +32,6 @@
3032
import java.util.Map;
3133
import java.util.TreeMap;
3234

33-
import static io.prometheus.metrics.exporter.pushgateway.Scheme.HTTP;
34-
import static io.prometheus.metrics.model.snapshots.PrometheusNaming.escapeName;
35-
3635
/**
3736
* Export metrics via the <a href="https://github.com/prometheus/pushgateway">Prometheus
3837
* Pushgateway</a>

0 commit comments

Comments
 (0)