Skip to content

Commit b09f28d

Browse files
committed
Add smoke test for Prometheus
See gh-40904
1 parent 3c37e45 commit b09f28d

File tree

4 files changed

+106
-0
lines changed

4 files changed

+106
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
plugins {
2+
id "java"
3+
id "org.springframework.boot.conventions"
4+
}
5+
6+
description = "Spring Boot Prometheus smoke test"
7+
8+
dependencies {
9+
implementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-web"))
10+
implementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-actuator"))
11+
implementation('io.micrometer:micrometer-tracing-bridge-brave')
12+
runtimeOnly('io.micrometer:micrometer-registry-prometheus')
13+
14+
testImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test"))
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright 2012-2024 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package smoketest.prometheus;
18+
19+
import org.springframework.boot.SpringApplication;
20+
import org.springframework.boot.autoconfigure.SpringBootApplication;
21+
22+
@SpringBootApplication
23+
public class SamplePrometheusApplication {
24+
25+
public static void main(String[] args) {
26+
SpringApplication.run(SamplePrometheusApplication.class, args);
27+
}
28+
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
management.endpoints.web.exposure.include=*
2+
management.tracing.sampling.probability=1.0
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* Copyright 2012-2024 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package smoketest.prometheus;
18+
19+
import org.junit.jupiter.api.Test;
20+
21+
import org.springframework.beans.factory.annotation.Autowired;
22+
import org.springframework.boot.test.autoconfigure.actuate.observability.AutoConfigureObservability;
23+
import org.springframework.boot.test.context.SpringBootTest;
24+
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
25+
import org.springframework.boot.test.web.client.TestRestTemplate;
26+
import org.springframework.http.HttpEntity;
27+
import org.springframework.http.HttpHeaders;
28+
import org.springframework.http.HttpMethod;
29+
import org.springframework.http.HttpStatus;
30+
import org.springframework.http.ResponseEntity;
31+
32+
import static org.assertj.core.api.Assertions.assertThat;
33+
34+
/**
35+
* Integration tests for {@link SamplePrometheusApplication}.
36+
*
37+
* @author Moritz Halbritter
38+
*/
39+
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
40+
@AutoConfigureObservability
41+
class SamplePrometheusApplicationTests {
42+
43+
@Autowired
44+
private TestRestTemplate restTemplate;
45+
46+
@Test
47+
void shouldExportExemplars() {
48+
for (int i = 0; i < 10; i++) {
49+
ResponseEntity<String> response = this.restTemplate.getForEntity("/actuator", String.class);
50+
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
51+
}
52+
HttpHeaders headers = new HttpHeaders();
53+
headers.add(HttpHeaders.ACCEPT, "application/openmetrics-text; version=1.0.0; charset=utf-8");
54+
ResponseEntity<String> metrics = this.restTemplate.exchange("/actuator/prometheus", HttpMethod.GET,
55+
new HttpEntity<>(headers), String.class);
56+
assertThat(metrics.getStatusCode()).isEqualTo(HttpStatus.OK);
57+
assertThat(metrics.getBody()).containsSubsequence("http_client_requests_seconds_count", "span_id", "trace_id");
58+
}
59+
60+
}

0 commit comments

Comments
 (0)