Skip to content

Commit

Permalink
#1937 fix content type of prometheus endpoint to text/plain
Browse files Browse the repository at this point in the history
  • Loading branch information
robfrank committed Jan 28, 2025
1 parent f1621b1 commit 5b60af0
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import com.arcadedb.server.security.ServerSecurityUser;
import io.micrometer.prometheusmetrics.PrometheusMeterRegistry;
import io.undertow.server.HttpServerExchange;
import io.undertow.util.Headers;
import io.undertow.util.MimeMappings;

public class GetPrometheusMetricsHandler extends AbstractServerHttpHandler {

Expand All @@ -20,7 +22,12 @@ public GetPrometheusMetricsHandler(HttpServer httpServer, PrometheusMeterRegistr

@Override
public ExecutionResponse execute(HttpServerExchange exchange, ServerSecurityUser user) throws Exception {

String response = registry.scrape();

exchange.getResponseHeaders()
.put(Headers.CONTENT_TYPE, MimeMappings.DEFAULT.getMimeType("txt"));

return new ExecutionResponse(200, response);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.net.PasswordAuthentication;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpHeaders;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

Expand Down Expand Up @@ -50,6 +51,7 @@ protected PasswordAuthentication getPasswordAuthentication() {

HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
assertThat(response.statusCode()).isEqualTo(200);
assertThat(response.headers().firstValue("Content-Type").get()).isEqualTo("text/plain");
assertThat(response.body()).contains("system_cpu_usage");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ void testPrometheusEndpointWithoutAuth() throws IOException, InterruptedExceptio

HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
assertThat(response.statusCode()).isEqualTo(200);
assertThat(response.headers().firstValue("Content-Type").get()).isEqualTo("text/plain");
assertThat(response.body()).contains("system_cpu_usage");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
import io.undertow.server.HttpServerExchange;
import io.undertow.util.Headers;

import java.nio.*;
import java.nio.ByteBuffer;

public class ExecutionResponse {
public final int code;
public final String response;
private final int code;
private final String response;
private final byte[] binary;

public ExecutionResponse(final int code, final String response) {
Expand Down

0 comments on commit 5b60af0

Please sign in to comment.