|
| 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