Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ tomcat = "8.5.100"
wavefront = "3.4.3"
wiremock = "2.35.2"
wiremock-junit5 = "1.3.1"
# docker images for integration tests
docker-otel-collector = "otel/opentelemetry-collector-contrib:0.144.0"

[libraries]
activemqArtemisJakartaClient = { module = "org.apache.activemq:artemis-jakarta-client", version.ref = "activemq-artemis" }
Expand Down
2 changes: 1 addition & 1 deletion implementations/micrometer-registry-otlp/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ dependencies {
}

dockerTest {
systemProperty 'otel-collector-image.version', '0.144.0'
systemProperty 'otel-collector-image.name', libs.versions.docker.otel.collector.get()
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ class OTelCollectorIntegrationTest {

private static final String CONFIG_FILE_NAME = "collector-config.yml";

private static final DockerImageName COLLECTOR_IMAGE = DockerImageName
.parse("otel/opentelemetry-collector-contrib:" + getCollectorImageVersion());
private static final DockerImageName COLLECTOR_IMAGE = getOtelCollectorImage();

@Container
private final GenericContainer<?> container = new GenericContainer(COLLECTOR_IMAGE)
Expand All @@ -60,13 +59,13 @@ class OTelCollectorIntegrationTest {
.waitingFor(Wait.forLogMessage(".*Everything is ready.*", 1))
.waitingFor(Wait.forListeningPorts(4318));

private static String getCollectorImageVersion() {
String version = System.getProperty("otel-collector-image.version");
if (version == null) {
private static DockerImageName getOtelCollectorImage() {
String imageName = System.getProperty("otel-collector-image.name");
if (imageName == null) {
throw new IllegalStateException(
"System property 'otel-collector-image.version' is not set. This should be set in the build configuration for running from the command line. If you are running OTelCollectorIntegrationTest from an IDE, set the system property to the desired collector image version.");
"System property 'otel-collector-image.name' is not set. This should be set in the build configuration for running from the command line. If you are running OTelCollectorIntegrationTest from an IDE, set the system property to the desired collector image name.");
}
return version;
return DockerImageName.parse(imageName);
}

@Test
Expand All @@ -84,45 +83,44 @@ void collectorShouldExportMetrics() throws Exception {
.untilAsserted(() -> whenPrometheusScraped().then()
.statusCode(200)
.contentType(OPENMETRICS_TEXT)
.body(endsWith("# EOF\n"), not(startsWith("# EOF\n")))
);

// tags can vary depending on where you run your tests:
// - IDE: no telemetry_sdk_version tag
// - Gradle: telemetry_sdk_version has the version number
whenPrometheusScraped().then().body(
containsString("{job=\"test\",otel_scope_name=\"\",otel_scope_schema_url=\"\",otel_scope_version=\"\",service_name=\"test\",telemetry_sdk_language=\"java\",telemetry_sdk_name=\"io.micrometer\""),

containsString("# HELP test_counter \n"),
containsString("# TYPE test_counter counter\n"),
matchesPattern("(?s)^.*test_counter_total\\{.+} 42\\.0\\n.*$"),

containsString("# HELP test_gauge \n"),
containsString("# TYPE test_gauge gauge\n"),
matchesPattern("(?s)^.*test_gauge\\{.+} 12\\.0\\n.*$"),

containsString("# HELP test_timer_milliseconds \n"),
containsString("# TYPE test_timer_milliseconds histogram\n"),
matchesPattern("(?s)^.*test_timer_milliseconds_count\\{.+} 1\\n.*$"),
// Earlier this was 123s (123), should have been 123ms (0.123)
// see: https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/18903
// it seems units are still not converted but at least the unit is in the name now (breaking change)
// see: https://github.com/open-telemetry/opentelemetry-collector-contrib/pull/20519
matchesPattern("(?s)^.*test_timer_milliseconds_sum\\{.+} 123\\.0\\n.*$"),
matchesPattern("(?s)^.*test_timer_milliseconds_bucket\\{.+,le=\"\\+Inf\"} 1\\n.*$"),

containsString("# HELP test_timer_max_milliseconds \n"),
containsString("# TYPE test_timer_max_milliseconds gauge\n"),
matchesPattern("(?s)^.*test_timer_max_milliseconds\\{.+} 123\\.0\n.*$"),

containsString("# HELP test_ds \n"),
containsString("# TYPE test_ds histogram\n"),
matchesPattern("(?s)^.*test_ds_count\\{.+} 1\\n.*$"),
matchesPattern("(?s)^.*test_ds_sum\\{.+} 24\\.0\\n.*$"),
matchesPattern("(?s)^.*test_ds_max\\{.+} 24\\.0\\n.*$"),
matchesPattern("(?s)^.*test_ds_bucket\\{.+,le=\"\\+Inf\"} 1\\n.*$")
);
// @formatter:on
.body(
endsWith("# EOF\n"),
not(startsWith("# EOF\n")),
// tags can vary depending on where you run your tests:
// - IDE: no telemetry_sdk_version tag
// - Gradle: telemetry_sdk_version has the version number
containsString("{job=\"test\",otel_scope_name=\"\",otel_scope_schema_url=\"\",otel_scope_version=\"\",service_name=\"test\",telemetry_sdk_language=\"java\",telemetry_sdk_name=\"io.micrometer\""),

containsString("# HELP test_counter \n"),
containsString("# TYPE test_counter counter\n"),
matchesPattern("(?s)^.*test_counter_total\\{.+} 42\\.0\\n.*$"),

containsString("# HELP test_gauge \n"),
containsString("# TYPE test_gauge gauge\n"),
matchesPattern("(?s)^.*test_gauge\\{.+} 12\\.0\\n.*$"),

containsString("# HELP test_timer_milliseconds \n"),
containsString("# TYPE test_timer_milliseconds histogram\n"),
matchesPattern("(?s)^.*test_timer_milliseconds_count\\{.+} 1\\n.*$"),
// Earlier this was 123s (123), should have been 123ms (0.123)
// see: https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/18903
// it seems units are still not converted but at least the unit is in the name now (breaking change)
// see: https://github.com/open-telemetry/opentelemetry-collector-contrib/pull/20519
matchesPattern("(?s)^.*test_timer_milliseconds_sum\\{.+} 123\\.0\\n.*$"),
matchesPattern("(?s)^.*test_timer_milliseconds_bucket\\{.+,le=\"\\+Inf\"} 1\\n.*$"),

containsString("# HELP test_timer_max_milliseconds \n"),
containsString("# TYPE test_timer_max_milliseconds gauge\n"),
matchesPattern("(?s)^.*test_timer_max_milliseconds\\{.+} 123\\.0\n.*$"),

containsString("# HELP test_ds \n"),
containsString("# TYPE test_ds histogram\n"),
matchesPattern("(?s)^.*test_ds_count\\{.+} 1\\n.*$"),
matchesPattern("(?s)^.*test_ds_sum\\{.+} 24\\.0\\n.*$"),
matchesPattern("(?s)^.*test_ds_max\\{.+} 24\\.0\\n.*$"),
matchesPattern("(?s)^.*test_ds_bucket\\{.+,le=\"\\+Inf\"} 1\\n.*$")
));
// @formatter:on
}

@Test
Expand All @@ -140,36 +138,35 @@ void collectorShouldExportMetricsWithGzipCompression() throws Exception {
.untilAsserted(() -> whenPrometheusScraped().then()
.statusCode(200)
.contentType(OPENMETRICS_TEXT)
.body(endsWith("# EOF\n"), not(startsWith("# EOF\n")))
);

// tags can vary depending on where you run your tests:
// - IDE: no telemetry_sdk_version tag
// - Gradle: telemetry_sdk_version has the version number
whenPrometheusScraped().then().body(
containsString("{job=\"test\",otel_scope_name=\"\",otel_scope_schema_url=\"\",otel_scope_version=\"\",service_name=\"test\",telemetry_sdk_language=\"java\",telemetry_sdk_name=\"io.micrometer\""),

containsString("# HELP test_counter_gzip \n"),
containsString("# TYPE test_counter_gzip counter\n"),
matchesPattern("(?s)^.*test_counter_gzip_total\\{.+} 42\\.0\\n.*$"),

containsString("# HELP test_gauge_gzip \n"),
containsString("# TYPE test_gauge_gzip gauge\n"),
matchesPattern("(?s)^.*test_gauge_gzip\\{.+} 12\\.0\\n.*$"),

containsString("# HELP test_timer_gzip_milliseconds \n"),
containsString("# TYPE test_timer_gzip_milliseconds histogram\n"),
matchesPattern("(?s)^.*test_timer_gzip_milliseconds_count\\{.+} 1\\n.*$"),
matchesPattern("(?s)^.*test_timer_gzip_milliseconds_sum\\{.+} 123\\.0\\n.*$"),
matchesPattern("(?s)^.*test_timer_gzip_milliseconds_bucket\\{.+,le=\"\\+Inf\"} 1\\n.*$"),

containsString("# HELP test_ds_gzip \n"),
containsString("# TYPE test_ds_gzip histogram\n"),
matchesPattern("(?s)^.*test_ds_gzip_count\\{.+} 1\\n.*$"),
matchesPattern("(?s)^.*test_ds_gzip_sum\\{.+} 24\\.0\\n.*$"),
matchesPattern("(?s)^.*test_ds_gzip_bucket\\{.+,le=\"\\+Inf\"} 1\\n.*$")
);
// @formatter:on
.body(
endsWith("# EOF\n"),
not(startsWith("# EOF\n")),
// tags can vary depending on where you run your tests:
// - IDE: no telemetry_sdk_version tag
// - Gradle: telemetry_sdk_version has the version number
containsString("{job=\"test\",otel_scope_name=\"\",otel_scope_schema_url=\"\",otel_scope_version=\"\",service_name=\"test\",telemetry_sdk_language=\"java\",telemetry_sdk_name=\"io.micrometer\""),

containsString("# HELP test_counter_gzip \n"),
containsString("# TYPE test_counter_gzip counter\n"),
matchesPattern("(?s)^.*test_counter_gzip_total\\{.+} 42\\.0\\n.*$"),

containsString("# HELP test_gauge_gzip \n"),
containsString("# TYPE test_gauge_gzip gauge\n"),
matchesPattern("(?s)^.*test_gauge_gzip\\{.+} 12\\.0\\n.*$"),

containsString("# HELP test_timer_gzip_milliseconds \n"),
containsString("# TYPE test_timer_gzip_milliseconds histogram\n"),
matchesPattern("(?s)^.*test_timer_gzip_milliseconds_count\\{.+} 1\\n.*$"),
matchesPattern("(?s)^.*test_timer_gzip_milliseconds_sum\\{.+} 123\\.0\\n.*$"),
matchesPattern("(?s)^.*test_timer_gzip_milliseconds_bucket\\{.+,le=\"\\+Inf\"} 1\\n.*$"),

containsString("# HELP test_ds_gzip \n"),
containsString("# TYPE test_ds_gzip histogram\n"),
matchesPattern("(?s)^.*test_ds_gzip_count\\{.+} 1\\n.*$"),
matchesPattern("(?s)^.*test_ds_gzip_sum\\{.+} 24\\.0\\n.*$"),
matchesPattern("(?s)^.*test_ds_gzip_bucket\\{.+,le=\"\\+Inf\"} 1\\n.*$")
));
// @formatter:on
}

@Test
Expand All @@ -182,30 +179,30 @@ void collectorShouldNotExportMaxMetricsWhenPublishHistogramMaxIsFalse() throws E
await().atMost(Duration.ofSeconds(5))
.pollDelay(Duration.ofMillis(100))
.pollInterval(Duration.ofMillis(100))
.untilAsserted(() -> whenPrometheusScraped().then()
.untilAsserted(() -> whenPrometheusScraped()
.then()
.statusCode(200)
.contentType(OPENMETRICS_TEXT)
.body(endsWith("# EOF\n"), not(startsWith("# EOF\n")))
);

whenPrometheusScraped().then().body(
// Verify timer histogram is exported
containsString("# HELP test_timer_nomax_milliseconds \n"),
containsString("# TYPE test_timer_nomax_milliseconds histogram\n"),
matchesPattern("(?s)^.*test_timer_nomax_milliseconds_count\\{.+} 1\\n.*$"),
matchesPattern("(?s)^.*test_timer_nomax_milliseconds_sum\\{.+} 123\\.0\\n.*$"),
matchesPattern("(?s)^.*test_timer_nomax_milliseconds_bucket\\{.+,le=\"\\+Inf\"} 1\\n.*$"),
// Verify distribution summary histogram is exported
containsString("# HELP test_ds_nomax \n"),
containsString("# TYPE test_ds_nomax histogram\n"),
matchesPattern("(?s)^.*test_ds_nomax_count\\{.+} 1\\n.*$"),
matchesPattern("(?s)^.*test_ds_nomax_sum\\{.+} 24\\.0\\n.*$"),
matchesPattern("(?s)^.*test_ds_nomax_bucket\\{.+,le=\"\\+Inf\"} 1\\n.*$"),
// Verify .max gauges are NOT exported
not(containsString("# HELP test_timer_nomax_max_milliseconds \n")),
not(containsString("# TYPE test_timer_nomax_max_milliseconds gauge\n")),
not(matchesPattern("(?s)^.*test_timer_nomax_max_milliseconds\\{.+} 123\\.0\n.*$"))
);
.body(
endsWith("# EOF\n"),
not(startsWith("# EOF\n")),
// Verify timer histogram is exported
containsString("# HELP test_timer_nomax_milliseconds \n"),
containsString("# TYPE test_timer_nomax_milliseconds histogram\n"),
matchesPattern("(?s)^.*test_timer_nomax_milliseconds_count\\{.+} 1\\n.*$"),
matchesPattern("(?s)^.*test_timer_nomax_milliseconds_sum\\{.+} 123\\.0\\n.*$"),
matchesPattern("(?s)^.*test_timer_nomax_milliseconds_bucket\\{.+,le=\"\\+Inf\"} 1\\n.*$"),
// Verify distribution summary histogram is exported
containsString("# HELP test_ds_nomax \n"),
containsString("# TYPE test_ds_nomax histogram\n"),
matchesPattern("(?s)^.*test_ds_nomax_count\\{.+} 1\\n.*$"),
matchesPattern("(?s)^.*test_ds_nomax_sum\\{.+} 24\\.0\\n.*$"),
matchesPattern("(?s)^.*test_ds_nomax_bucket\\{.+,le=\"\\+Inf\"} 1\\n.*$"),
// Verify .max gauges are NOT exported
not(containsString("# HELP test_timer_nomax_max_milliseconds \n")),
not(containsString("# TYPE test_timer_nomax_max_milliseconds gauge\n")),
not(matchesPattern("(?s)^.*test_timer_nomax_max_milliseconds\\{.+} 123\\.0\n.*$"))
));
// @formatter:on
}

Expand Down
Loading