diff --git a/proxy-server/src/main/java/io/micrometer/prometheus/rsocket/PrometheusController.java b/proxy-server/src/main/java/io/micrometer/prometheus/rsocket/PrometheusController.java index ff600f8..0b8af24 100644 --- a/proxy-server/src/main/java/io/micrometer/prometheus/rsocket/PrometheusController.java +++ b/proxy-server/src/main/java/io/micrometer/prometheus/rsocket/PrometheusController.java @@ -121,7 +121,7 @@ private Mono acceptRSocket(KeyPairGenerator generator, RSocket sendingS // respond with Mono.error(..) to RSocket metricsInterceptedSendingSocket = metricsInterceptor.apply(sendingSocket); - ConnectionState connectionState = new ConnectionState(generator.generateKeyPair()); + ConnectionState connectionState = new ConnectionState(generator.generateKeyPair(), this.properties); scrapableApps.put(metricsInterceptedSendingSocket, connectionState); // 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 prometheus() { class ConnectionState { private final KeyPair keyPair; + private final PrometheusControllerProperties properties; // the last metrics of a dying application instance private String dyingPush; - ConnectionState(KeyPair keyPair) { + ConnectionState(KeyPair keyPair, PrometheusControllerProperties properties) { this.keyPair = keyPair; + this.properties = properties; } Mono getDyingPush() { @@ -211,6 +213,9 @@ String receiveScrapePayload(Payload payload, Timer.Sample timing) { ByteBufUtil.getBytes(sliceData, sliceData.readerIndex(), sliceData.readableBytes(), false)); String uncompressed = Snappy.uncompressString(decrypted); + if (!this.properties.getConnectedMetricsMetadata()) { + uncompressed = uncompressed.replaceAll("(?m)^#.*\n", ""); + } scrapePayload.record(uncompressed.length()); return uncompressed; } catch (IOException e) { @@ -246,4 +251,4 @@ Payload createKeyPayload() { return DefaultPayload.create(keyPair.getPublic().getEncoded()); } } -} +} \ No newline at end of file diff --git a/proxy-server/src/main/java/io/micrometer/prometheus/rsocket/PrometheusControllerProperties.java b/proxy-server/src/main/java/io/micrometer/prometheus/rsocket/PrometheusControllerProperties.java index 936cc95..dca6a74 100644 --- a/proxy-server/src/main/java/io/micrometer/prometheus/rsocket/PrometheusControllerProperties.java +++ b/proxy-server/src/main/java/io/micrometer/prometheus/rsocket/PrometheusControllerProperties.java @@ -33,6 +33,12 @@ public class PrometheusControllerProperties { */ private int websocketPort = 8081; + /** + * Whether to enable publishing of Prometheus metadata (lines "# HELP ..." and lines "# TYPE ...") in the payload returned by the /metrics/connected endpoint. + * Disabling metadata publishing reduces the amount of data sent sent on each scrape. + */ + private boolean connectedMetricsMetadata = true; + public int getTcpPort() { return tcpPort; } @@ -48,4 +54,12 @@ public int getWebsocketPort() { public void setWebsocketPort(int websocketPort) { this.websocketPort = websocketPort; } + + public boolean getConnectedMetricsMetadata() { + return connectedMetricsMetadata; + } + + public void setConnectedMetricsMetadata(boolean connectedMetricsMetadata) { + this.connectedMetricsMetadata = connectedMetricsMetadata; + } }