Skip to content

Commit c761726

Browse files
author
Mateo00
committed
Add micrometer.prometheus-proxy.connected-metrics-metadata property
Signed-off-by: Mateo00 <[email protected]>
1 parent a726cde commit c761726

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

proxy-server/src/main/java/io/micrometer/prometheus/rsocket/PrometheusController.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ private Mono<RSocket> acceptRSocket(KeyPairGenerator generator, RSocket sendingS
121121
// respond with Mono.error(..) to
122122
RSocket metricsInterceptedSendingSocket = metricsInterceptor.apply(sendingSocket);
123123

124-
ConnectionState connectionState = new ConnectionState(generator.generateKeyPair());
124+
ConnectionState connectionState = new ConnectionState(generator.generateKeyPair(), this.properties);
125125
scrapableApps.put(metricsInterceptedSendingSocket, connectionState);
126126

127127
// a key to be used by the client to push metrics as it's dying if this happens before the first scrape
@@ -186,12 +186,14 @@ public Mono<String> prometheus() {
186186

187187
class ConnectionState {
188188
private final KeyPair keyPair;
189+
private final PrometheusControllerProperties properties;
189190

190191
// the last metrics of a dying application instance
191192
private String dyingPush;
192193

193-
ConnectionState(KeyPair keyPair) {
194+
ConnectionState(KeyPair keyPair, PrometheusControllerProperties properties) {
194195
this.keyPair = keyPair;
196+
this.properties = properties;
195197
}
196198

197199
Mono<String> getDyingPush() {
@@ -211,6 +213,9 @@ String receiveScrapePayload(Payload payload, Timer.Sample timing) {
211213
ByteBufUtil.getBytes(sliceData, sliceData.readerIndex(), sliceData.readableBytes(), false));
212214

213215
String uncompressed = Snappy.uncompressString(decrypted);
216+
if (!this.properties.getConnectedMetricsMetadata()) {
217+
uncompressed = uncompressed.replaceAll("(?m)^#.*\n", "");
218+
}
214219
scrapePayload.record(uncompressed.length());
215220
return uncompressed;
216221
} catch (IOException e) {
@@ -246,4 +251,4 @@ Payload createKeyPayload() {
246251
return DefaultPayload.create(keyPair.getPublic().getEncoded());
247252
}
248253
}
249-
}
254+
}

proxy-server/src/main/java/io/micrometer/prometheus/rsocket/PrometheusControllerProperties.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ public class PrometheusControllerProperties {
3333
*/
3434
private int websocketPort = 8081;
3535

36+
/**
37+
* Whether to enable publishing of Prometheus metadata (lines "# HELP ..." and lines "# TYPE ...") in the payload returned by the /metrics/connected endpoint.
38+
* Disabling metadata publishing reduces the amount of data sent sent on each scrape.
39+
*/
40+
private boolean connectedMetricsMetadata = true;
41+
3642
public int getTcpPort() {
3743
return tcpPort;
3844
}
@@ -48,4 +54,12 @@ public int getWebsocketPort() {
4854
public void setWebsocketPort(int websocketPort) {
4955
this.websocketPort = websocketPort;
5056
}
57+
58+
public boolean getConnectedMetricsMetadata() {
59+
return connectedMetricsMetadata;
60+
}
61+
62+
public void setConnectedMetricsMetadata(boolean connectedMetricsMetadata) {
63+
this.connectedMetricsMetadata = connectedMetricsMetadata;
64+
}
5165
}

0 commit comments

Comments
 (0)