Support OpenMetrics text format with Prometheus

Update `PrometheusScrapeEndpoint` so that it can produce both classic
Prometheus text output as well as Openmetrics output.

See gh-25564
This commit is contained in:
Andy Wilkinson
2021-03-18 19:11:02 -07:00
committed by Phillip Webb
parent c81a0223cc
commit 11b4a19dee
5 changed files with 101 additions and 8 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -40,13 +40,21 @@ import static org.assertj.core.api.Assertions.assertThat;
class PrometheusScrapeEndpointIntegrationTests {
@WebEndpointTest
void scrapeHasContentTypeText004(WebTestClient client) {
void scrapeHasContentTypeText004ByDefault(WebTestClient client) {
client.get().uri("/actuator/prometheus").exchange().expectStatus().isOk().expectHeader()
.contentType(MediaType.parseMediaType(TextFormat.CONTENT_TYPE_004)).expectBody(String.class)
.value((body) -> assertThat(body).contains("counter1_total").contains("counter2_total")
.contains("counter3_total"));
}
@WebEndpointTest
void scrapeCanProduceOpenMetrics100(WebTestClient client) {
MediaType openMetrics = MediaType.parseMediaType(TextFormat.CONTENT_TYPE_OPENMETRICS_100);
client.get().uri("/actuator/prometheus").accept(openMetrics).exchange().expectStatus().isOk().expectHeader()
.contentType(openMetrics).expectBody(String.class).value((body) -> assertThat(body)
.contains("counter1_total").contains("counter2_total").contains("counter3_total"));
}
@WebEndpointTest
void scrapeWithIncludedNames(WebTestClient client) {
client.get().uri("/actuator/prometheus?includedNames=counter1_total,counter2_total").exchange().expectStatus()