Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add micrometer.prometheus-proxy.connected-metrics-metadata property #68

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ private Mono<RSocket> 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
Expand Down Expand Up @@ -186,12 +186,14 @@ public Mono<String> 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<String> getDyingPush() {
Expand All @@ -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) {
Expand Down Expand Up @@ -246,4 +251,4 @@ Payload createKeyPayload() {
return DefaultPayload.create(keyPair.getPublic().getEncoded());
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
}
}