Skip to content

Commit

Permalink
Remove default value for OtlpMetricsProperties.url
Browse files Browse the repository at this point in the history
Signed-off-by: Johnny Lim <[email protected]>
  • Loading branch information
izeye committed Feb 28, 2025
1 parent e886785 commit 6ce057e
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ dependencies {
testImplementation("org.springframework.restdocs:spring-restdocs-webtestclient")
testImplementation("org.springframework.security:spring-security-test")
testImplementation("org.yaml:snakeyaml")
testImplementation("uk.org.webcompere:system-stubs-jupiter:2.1.7")

testRuntimeOnly("jakarta.management.j2ee:jakarta.management.j2ee-api")
testRuntimeOnly("jakarta.transaction:jakarta.transaction-api")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class OtlpMetricsProperties extends StepRegistryProperties {
/**
* URI of the OTLP server.
*/
private String url = "http://localhost:4318/v1/metrics";
private String url;

/**
* Aggregation temporality of sums. It defines the way additive values are expressed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import io.micrometer.registry.otlp.HistogramFlavor;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import uk.org.webcompere.systemstubs.SystemStubs;

import org.springframework.boot.actuate.autoconfigure.metrics.export.otlp.OtlpMetricsExportAutoConfiguration.PropertiesOtlpMetricsConnectionDetails;
import org.springframework.boot.actuate.autoconfigure.opentelemetry.OpenTelemetryProperties;
Expand Down Expand Up @@ -54,6 +55,23 @@ void setUp() {
this.connectionDetails = new PropertiesOtlpMetricsConnectionDetails(this.properties);
}

@Test
void whenPropertiesUrlIsNotSetAdapterUrlReturnsDefault() {
assertThat(createAdapter().url()).isEqualTo("http://localhost:4318/v1/metrics");
}

@Test
void whenPropertiesUrlIsNotSetAndOtelExporterOtlpEndpointIsSetAdapterUrlUsesIt() throws Exception {
SystemStubs.withEnvironmentVariable("OTEL_EXPORTER_OTLP_ENDPOINT", "https://my-endpoint")
.execute(() -> assertThat(createAdapter().url()).isEqualTo("https://my-endpoint/v1/metrics"));
}

@Test
void whenPropertiesUrlIsNotSetAndOtelExporterOtlpMetricsEndpointIsSetAdapterUrlUsesIt() throws Exception {
SystemStubs.withEnvironmentVariable("OTEL_EXPORTER_OTLP_METRICS_ENDPOINT", "https://my-endpoint")
.execute(() -> assertThat(createAdapter().url()).isEqualTo("https://my-endpoint/v1/metrics"));
}

@Test
void whenPropertiesUrlIsSetAdapterUrlReturnsIt() {
this.properties.setUrl("http://another-url:4318/v1/metrics");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ void defaultValuesAreConsistent() {
OtlpMetricsProperties properties = new OtlpMetricsProperties();
OtlpConfig config = OtlpConfig.DEFAULT;
assertStepRegistryDefaultValues(properties, config);
assertThat(properties.getUrl()).isEqualTo(config.url());
assertThat(properties.getAggregationTemporality()).isSameAs(config.aggregationTemporality());
assertThat(properties.getHistogramFlavor()).isSameAs(config.histogramFlavor());
assertThat(properties.getMaxScale()).isEqualTo(config.maxScale());
Expand Down

0 comments on commit 6ce057e

Please sign in to comment.