From 51885c9d38c8874ec8de0ec22c4b3ba5eb47a287 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Thu, 27 Feb 2025 19:01:10 +0000 Subject: [PATCH] Remove deprecated management.otlp.metrics.export.resource-attributes It was deprecated in 3.2 and should have been removed in 3.4 so its removal is overdue. Closes gh-44468 --- .../export/otlp/OtlpMetricsProperties.java | 17 -------- .../OtlpMetricsPropertiesConfigAdapter.java | 3 +- ...lpMetricsPropertiesConfigAdapterTests.java | 42 ++----------------- 3 files changed, 4 insertions(+), 58 deletions(-) diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/otlp/OtlpMetricsProperties.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/otlp/OtlpMetricsProperties.java index 04b68036ce..60021201c1 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/otlp/OtlpMetricsProperties.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/otlp/OtlpMetricsProperties.java @@ -24,7 +24,6 @@ import io.micrometer.registry.otlp.HistogramFlavor; import org.springframework.boot.actuate.autoconfigure.metrics.export.properties.StepRegistryProperties; import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.boot.context.properties.DeprecatedConfigurationProperty; /** * {@link ConfigurationProperties @ConfigurationProperties} for configuring OTLP metrics @@ -48,11 +47,6 @@ public class OtlpMetricsProperties extends StepRegistryProperties { */ private AggregationTemporality aggregationTemporality = AggregationTemporality.CUMULATIVE; - /** - * Monitored resource's attributes. - */ - private Map resourceAttributes; - /** * Headers for the exported metrics. */ @@ -95,17 +89,6 @@ public class OtlpMetricsProperties extends StepRegistryProperties { this.aggregationTemporality = aggregationTemporality; } - @Deprecated(since = "3.2.0", forRemoval = true) - @DeprecatedConfigurationProperty(replacement = "management.opentelemetry.resource-attributes", since = "3.2.0") - public Map getResourceAttributes() { - return this.resourceAttributes; - } - - @Deprecated(since = "3.2.0", forRemoval = true) - public void setResourceAttributes(Map resourceAttributes) { - this.resourceAttributes = resourceAttributes; - } - public Map getHeaders() { return this.headers; } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/otlp/OtlpMetricsPropertiesConfigAdapter.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/otlp/OtlpMetricsPropertiesConfigAdapter.java index b6268dee51..cd520db9e8 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/otlp/OtlpMetricsPropertiesConfigAdapter.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/otlp/OtlpMetricsPropertiesConfigAdapter.java @@ -77,11 +77,10 @@ class OtlpMetricsPropertiesConfigAdapter extends StepRegistryPropertiesConfigAda } @Override - @SuppressWarnings("removal") public Map resourceAttributes() { Map resourceAttributes = this.openTelemetryProperties.getResourceAttributes(); Map result = new HashMap<>((!CollectionUtils.isEmpty(resourceAttributes)) ? resourceAttributes - : get(OtlpMetricsProperties::getResourceAttributes, OtlpConfig.super::resourceAttributes)); + : OtlpConfig.super.resourceAttributes()); result.computeIfAbsent("service.name", (key) -> getApplicationName()); result.computeIfAbsent("service.group", (key) -> getApplicationGroup()); return Collections.unmodifiableMap(result); diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/otlp/OtlpMetricsPropertiesConfigAdapterTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/otlp/OtlpMetricsPropertiesConfigAdapterTests.java index ba3276ac92..bd2bba76f3 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/otlp/OtlpMetricsPropertiesConfigAdapterTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/otlp/OtlpMetricsPropertiesConfigAdapterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2024 the original author or authors. + * Copyright 2012-2025 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,7 +16,6 @@ package org.springframework.boot.actuate.autoconfigure.metrics.export.otlp; -import java.util.Collections; import java.util.Map; import java.util.concurrent.TimeUnit; @@ -30,7 +29,6 @@ import org.springframework.boot.actuate.autoconfigure.opentelemetry.OpenTelemetr import org.springframework.mock.env.MockEnvironment; import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.entry; /** * Tests for {@link OtlpMetricsPropertiesConfigAdapter}. @@ -74,9 +72,8 @@ class OtlpMetricsPropertiesConfigAdapterTests { } @Test - @SuppressWarnings("removal") - void whenPropertiesResourceAttributesIsSetAdapterResourceAttributesReturnsIt() { - this.properties.setResourceAttributes(Map.of("service.name", "boot-service")); + void whenOpenTelemetryPropertiesResourceAttributesIsSetAdapterResourceAttributesReturnsIt() { + this.openTelemetryProperties.setResourceAttributes(Map.of("service.name", "boot-service")); assertThat(createAdapter().resourceAttributes()).containsEntry("service.name", "boot-service"); } @@ -131,32 +128,7 @@ class OtlpMetricsPropertiesConfigAdapterTests { } @Test - @SuppressWarnings("removal") - void openTelemetryPropertiesShouldOverrideOtlpPropertiesIfNotEmpty() { - this.properties.setResourceAttributes(Map.of("a", "alpha")); - this.openTelemetryProperties.setResourceAttributes(Map.of("b", "beta")); - assertThat(createAdapter().resourceAttributes()).contains(entry("b", "beta")); - assertThat(createAdapter().resourceAttributes()).doesNotContain(entry("a", "alpha")); - } - - @Test - @SuppressWarnings("removal") - void openTelemetryPropertiesShouldNotOverrideOtlpPropertiesIfEmpty() { - this.properties.setResourceAttributes(Map.of("a", "alpha")); - this.openTelemetryProperties.setResourceAttributes(Collections.emptyMap()); - assertThat(createAdapter().resourceAttributes()).contains(entry("a", "alpha")); - } - - @Test - @SuppressWarnings("removal") void serviceNameOverridesApplicationName() { - this.environment.setProperty("spring.application.name", "alpha"); - this.properties.setResourceAttributes(Map.of("service.name", "beta")); - assertThat(createAdapter().resourceAttributes()).containsEntry("service.name", "beta"); - } - - @Test - void serviceNameOverridesApplicationNameWhenUsingOtelProperties() { this.environment.setProperty("spring.application.name", "alpha"); this.openTelemetryProperties.setResourceAttributes(Map.of("service.name", "beta")); assertThat(createAdapter().resourceAttributes()).containsEntry("service.name", "beta"); @@ -174,15 +146,7 @@ class OtlpMetricsPropertiesConfigAdapterTests { } @Test - @SuppressWarnings("removal") void serviceGroupOverridesApplicationGroup() { - this.environment.setProperty("spring.application.group", "alpha"); - this.properties.setResourceAttributes(Map.of("service.group", "beta")); - assertThat(createAdapter().resourceAttributes()).containsEntry("service.group", "beta"); - } - - @Test - void serviceGroupOverridesApplicationGroupWhenUsingOtelProperties() { this.environment.setProperty("spring.application.group", "alpha"); this.openTelemetryProperties.setResourceAttributes(Map.of("service.group", "beta")); assertThat(createAdapter().resourceAttributes()).containsEntry("service.group", "beta");