Skip to content

Commit

Permalink
fix: use existing prometheus content type constant
Browse files Browse the repository at this point in the history
  • Loading branch information
tomjo committed Feb 21, 2024
1 parent 72d000e commit c265c49
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
11 changes: 5 additions & 6 deletions bookkeeper-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@
<artifactId>circe-checksum</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.bookkeeper.stats</groupId>
<artifactId>prometheus-metrics-provider</artifactId>
<version>${project.parent.version}</version>
</dependency>
<dependency>
<groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId>
Expand Down Expand Up @@ -210,12 +215,6 @@
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.bookkeeper.stats</groupId>
<artifactId>prometheus-metrics-provider</artifactId>
<version>${project.parent.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.bookkeeper.stats</groupId>
<artifactId>otel-metrics-provider</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

package org.apache.bookkeeper.server.http.service;

import io.prometheus.client.exporter.common.TextFormat;
import java.io.IOException;
import java.io.StringWriter;
import org.apache.bookkeeper.conf.ServerConfiguration;
Expand All @@ -35,8 +36,6 @@
*/
public class MetricsService implements HttpEndpointService {

public static final String PROMETHEUS_CONTENT_TYPE_004 = "text/plain; version=0.0.4; charset=utf-8";

private final ServerConfiguration conf;
private final StatsProvider statsProvider;

Expand Down Expand Up @@ -67,7 +66,7 @@ public HttpServiceResponse handle(HttpServiceRequest request) throws Exception {
statsProvider.writeAllMetrics(writer);
writer.flush();
response.setCode(StatusCode.OK);
response.setContentType(PROMETHEUS_CONTENT_TYPE_004);
response.setContentType(TextFormat.CONTENT_TYPE_004);
response.setBody(writer.getBuffer().toString());
} catch (UnsupportedOperationException uoe) {
response.setCode(StatusCode.INTERNAL_ERROR);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;

import io.prometheus.client.exporter.common.TextFormat;
import java.io.IOException;
import java.io.Writer;
import org.apache.bookkeeper.conf.ServerConfiguration;
Expand Down Expand Up @@ -89,7 +90,7 @@ public void testWriteMetrics() throws Exception {
HttpServiceResponse response = service.handle(request);

assertEquals(StatusCode.OK.getValue(), response.getStatusCode());
assertEquals(MetricsService.PROMETHEUS_CONTENT_TYPE_004, response.getContentType());
assertEquals(TextFormat.CONTENT_TYPE_004, response.getContentType());
assertEquals(content, response.getBody());
}

Expand Down

0 comments on commit c265c49

Please sign in to comment.