ObservationPatterns as property placeholder

Make an `@EnableIntegrationManagement.observationPatterns`
as property placeholder aware and also support comma-separated values
This commit is contained in:
artembilan
2022-11-10 09:26:44 -05:00
parent 7bb330aaa9
commit 75b198d0c1
3 changed files with 18 additions and 2 deletions

View File

@@ -68,6 +68,7 @@ public @interface EnableIntegrationManagement {
* None by default - no unconditional observation instrumentation.
* Can be set to {@code *} to instrumentation all the integration components.
* The pattern can start with {@code !} to negate the matching.
* The value can be a property placeholder and/or comma-separated.
* @since 6.0
* @see org.springframework.integration.support.utils.PatternMatchUtils#smartMatch(String, String...)
*/

View File

@@ -16,7 +16,9 @@
package org.springframework.integration.config;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.beans.factory.config.BeanDefinition;
@@ -32,6 +34,7 @@ import org.springframework.integration.support.management.metrics.MetricsCaptor;
import org.springframework.util.Assert;
import io.micrometer.observation.ObservationRegistry;
import org.springframework.util.StringUtils;
/**
* {@code @Configuration} class that registers a {@link IntegrationManagementConfigurer} bean.
@@ -75,7 +78,7 @@ public class IntegrationManagementConfiguration implements ImportAware, Environm
Boolean.parseBoolean(this.environment.resolvePlaceholders(
(String) this.attributes.get("defaultLoggingEnabled"))));
configurer.setMetricsCaptorProvider(metricsCaptorProvider);
String[] observationPatterns = (String[]) this.attributes.get("observationPatterns");
String[] observationPatterns = obtainObservationPatterns();
if (observationPatterns.length > 0) {
configurer.setObservationPatterns(observationPatterns);
configurer.setObservationRegistry(observationRegistryProvider);
@@ -83,4 +86,14 @@ public class IntegrationManagementConfiguration implements ImportAware, Environm
return configurer;
}
private String[] obtainObservationPatterns() {
Set<String> patterns = new HashSet<>();
String[] observationPatterns = (String[]) this.attributes.get("observationPatterns");
for (String observationPattern : observationPatterns) {
String pattern = this.environment.resolvePlaceholders(observationPattern);
patterns.addAll(StringUtils.commaDelimitedListToSet(pattern));
}
return patterns.toArray(new String[0]);
}
}

View File

@@ -106,7 +106,9 @@ public class IntegrationObservabilityZipkinTests extends SampleTestRunner {
@Configuration
@EnableIntegration
@EnableIntegrationManagement(observationPatterns = { "observedEndpoint", "testInboundGateway" })
@EnableIntegrationManagement(
observationPatterns =
"${spring.integration.management.observation-patterns:observedEndpoint,testInboundGateway}")
public static class ObservationIntegrationTestConfiguration {
CountDownLatch observedHandlerLatch = new CountDownLatch(1);