Skip to content

Commit 4108ea5

Browse files
committed
spring-projectsGH-9260: Fix IntegrationManagementConfiguration.obtainObservationPatterns() logic
Fixes: spring-projects#9260 The current `IntegrationManagementConfiguration.obtainObservationPatterns()` is to always have an `*` as a first pattern in the final result. Because of `HashSet` natural order. This would lead to ignore all the patterns, especially those with negation * Fix `IntegrationManagementConfiguration.obtainObservationPatterns()` logic to ignore regular patterns if `*` is present. Optimization wise. * Always put `*` into the end of final array let negative patterns to do their job * Modify `IntegrationGraphServerTests` & `WebFluxObservationPropagationTests` test configurations to ensure that `*` pattern does not have a precedence over negative patterns. **Auto-cherry-pick to `6.3.x` & `6.2.x`**
1 parent bdcb856 commit 4108ea5

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed

spring-integration-core/src/main/java/org/springframework/integration/config/IntegrationManagementConfiguration.java

+15-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2015-2022 the original author or authors.
2+
* Copyright 2015-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,9 +16,10 @@
1616

1717
package org.springframework.integration.config;
1818

19+
import java.util.Collection;
1920
import java.util.HashSet;
2021
import java.util.Map;
21-
import java.util.Set;
22+
import java.util.stream.Collectors;
2223

2324
import io.micrometer.observation.ObservationRegistry;
2425

@@ -88,17 +89,27 @@ public IntegrationManagementConfigurer managementConfigurer(
8889
}
8990

9091
private String[] obtainObservationPatterns() {
91-
Set<String> observationPatterns = new HashSet<>();
92+
Collection<String> observationPatterns = new HashSet<>();
9293
String[] patternsProperties = (String[]) this.attributes.get("observationPatterns");
94+
boolean hasAsterisk = false;
9395
for (String patternProperty : patternsProperties) {
9496
String patternValue = this.environment.resolvePlaceholders(patternProperty);
9597
String[] patternsToProcess = StringUtils.commaDelimitedListToStringArray(patternValue);
9698
for (String pattern : patternsToProcess) {
97-
if (StringUtils.hasText(pattern)) {
99+
hasAsterisk |= "*".equals(pattern);
100+
if (StringUtils.hasText(pattern) && (pattern.startsWith("!") || !hasAsterisk)) {
98101
observationPatterns.add(pattern);
99102
}
100103
}
101104
}
105+
if (hasAsterisk) {
106+
observationPatterns =
107+
observationPatterns.stream()
108+
.filter((pattern) -> pattern.startsWith("!"))
109+
.collect(Collectors.toList());
110+
111+
observationPatterns.add("*");
112+
}
102113
return observationPatterns.toArray(new String[0]);
103114
}
104115

spring-integration-core/src/test/java/org/springframework/integration/graph/IntegrationGraphServerTests.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2023 the original author or authors.
2+
* Copyright 2016-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -290,7 +290,7 @@ void timersViaObservationArePopulated() {
290290

291291
@Configuration
292292
@EnableIntegration
293-
@EnableIntegrationManagement(observationPatterns = "myFilter")
293+
@EnableIntegrationManagement(observationPatterns = { "myFilter", "*" })
294294
@IntegrationComponentScan
295295
@ImportResource("org/springframework/integration/graph/integration-graph-context.xml")
296296
public static class Config {

spring-integration-webflux/src/test/java/org/springframework/integration/webflux/observation/WebFluxObservationPropagationTests.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ void observationIsPropagatedWebFluxRequestReply() {
125125
@Configuration
126126
@EnableWebFlux
127127
@EnableIntegration
128-
@EnableIntegrationManagement(observationPatterns = "*")
128+
@EnableIntegrationManagement(observationPatterns = "*,!notObserved*")
129129
public static class ContextConfiguration {
130130

131131
@Bean
@@ -200,6 +200,8 @@ IntegrationFlow webFluxRequestReplyFlow(
200200
.transformWith(t -> t
201201
.<String, String>transformer(String::toLowerCase)
202202
.id("testTransformer"))
203+
.channel("notObservedChannel")
204+
.bridge(e -> e.id("notObservedEndpoint"))
203205
.get();
204206
}
205207

0 commit comments

Comments
 (0)