Add boot42-otel module: Spring Boot 4.2.0-RC1 OpenTelemetry conventions, shared OTLP settings and MDC keys vs 4.1.2
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
package com.ankurm.otel;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.web.client.RestClient;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* What a dashboard query sees. Scrapes /actuator/prometheus after one request and lists the
|
||||
* http_server* families and one labelled sample, for the default conventions and for the
|
||||
* open-telemetry conventions (spelled the way RC1 accepts it).
|
||||
*/
|
||||
class PrometheusNamesTest {
|
||||
|
||||
@Test
|
||||
void promNames() throws Exception {
|
||||
Transcript t = new Transcript("06-prometheus-names");
|
||||
List<String> modes = List.of("micrometer", "opentelemetry");
|
||||
java.util.Map<String, List<String>> families = new java.util.LinkedHashMap<>();
|
||||
for (String mode : modes) {
|
||||
ConfigurableApplicationContext ctx = Apps.start("management.observations.conventions=" + mode,
|
||||
"management.otlp.metrics.export.enabled=false");
|
||||
Apps.call(ctx, "/hello/ankur");
|
||||
io.micrometer.core.instrument.MeterRegistry registry = ctx.getBean(io.micrometer.core.instrument.MeterRegistry.class);
|
||||
Apps.awaitHttpMeter(registry);
|
||||
String port = ctx.getEnvironment().getProperty("local.server.port");
|
||||
String body = RestClient.create().get().uri("http://localhost:" + port + "/actuator/prometheus")
|
||||
.retrieve().body(String.class);
|
||||
TreeSet<String> names = new TreeSet<>();
|
||||
String sample = "";
|
||||
for (String line : body.split("\n")) {
|
||||
if (line.startsWith("http_server")) {
|
||||
names.add(line.substring(0, line.indexOf('{') > 0 ? line.indexOf('{') : line.indexOf(' ')));
|
||||
if (line.contains("_count{") && sample.isEmpty()) {
|
||||
sample = line.substring(0, line.lastIndexOf(' '));
|
||||
}
|
||||
}
|
||||
}
|
||||
t.line("");
|
||||
t.line("== management.observations.conventions=" + mode);
|
||||
names.forEach(n -> t.line(" " + n));
|
||||
t.line(" sample: " + sample);
|
||||
families.put(mode, new ArrayList<>(names));
|
||||
ctx.close();
|
||||
}
|
||||
t.write();
|
||||
if (Transcript.is42()) {
|
||||
assertThat(families.get("micrometer")).contains("http_server_requests_seconds_count");
|
||||
assertThat(families.get("opentelemetry")).contains("http_server_request_duration_seconds_count");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user