forked from spring-cloud/spring-cloud-stream
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rework an observation for Rabbit Binder
The observation propagation doesn't work in multi-binder configuration * Remove `ObservationAutoConfiguration` since it is not visible in case of multi-binder configuration * Instead move `setObservationEnabled` flag setting to the `RabbitMessageChannelBinder` * Add `io.micrometer.observation.ObservationRegistry` into `shared.beans` to make it visible for binder-specific application context * Add `RabbitMultiBinderObservationTests` integration test where Rabbit Binder is in multi-binder environment As a side effect this fixes an observation propagation for Kafka binder as well in the multi-binder environment. Its configuration is OK, but an `ObservationRegistry` must make it visible for the binder-specific application context. See the mentioned `shared.beans` Related to spring-cloud#2901 Also see spring-cloud#2902 for possible evolution
- Loading branch information
1 parent
7fa7228
commit f48e4a1
Showing
8 changed files
with
196 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 0 additions & 63 deletions
63
...a/org/springframework/cloud/stream/binder/rabbit/config/ObservationAutoConfiguration.java
This file was deleted.
Oops, something went wrong.
1 change: 0 additions & 1 deletion
1
...esources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
org.springframework.cloud.stream.binder.rabbit.config.ExtendedBindingHandlerMappingsProviderConfiguration | ||
org.springframework.cloud.stream.binder.rabbit.config.ObservationAutoConfiguration |
110 changes: 110 additions & 0 deletions
110
...ngframework/cloud/stream/binder/rabbit/integration/RabbitMultiBinderObservationTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
/* | ||
* Copyright 2015-2024 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. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.springframework.cloud.stream.binder.rabbit.integration; | ||
|
||
import java.util.concurrent.CountDownLatch; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.function.Consumer; | ||
import java.util.stream.Collectors; | ||
|
||
import brave.handler.SpanHandler; | ||
import brave.test.TestSpanHandler; | ||
import io.micrometer.observation.Observation; | ||
import io.micrometer.observation.ObservationRegistry; | ||
import io.micrometer.tracing.brave.bridge.BraveFinishedSpan; | ||
import io.micrometer.tracing.test.simple.SpansAssert; | ||
import org.junit.jupiter.api.Test; | ||
import org.testcontainers.containers.RabbitMQContainer; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.SpringBootConfiguration; | ||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; | ||
import org.springframework.boot.test.autoconfigure.actuate.observability.AutoConfigureObservability; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.cloud.stream.binder.rabbit.RabbitTestContainer; | ||
import org.springframework.cloud.stream.function.StreamBridge; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.messaging.Message; | ||
import org.springframework.test.annotation.DirtiesContext; | ||
import org.springframework.test.context.DynamicPropertyRegistry; | ||
import org.springframework.test.context.DynamicPropertySource; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.awaitility.Awaitility.await; | ||
|
||
/** | ||
* @author Artem Bilan | ||
* @since 4.1.1 | ||
*/ | ||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE, | ||
args = "--spring.config.location=classpath:/rabbit-multi-binder-observation.yml") | ||
@DirtiesContext | ||
@AutoConfigureObservability | ||
public class RabbitMultiBinderObservationTests { | ||
|
||
private static final TestSpanHandler SPANS = new TestSpanHandler(); | ||
|
||
private static final RabbitMQContainer RABBITMQ = RabbitTestContainer.sharedInstance(); | ||
|
||
@Autowired | ||
StreamBridge streamBridge; | ||
|
||
@Autowired | ||
ObservationRegistry observationRegistry; | ||
|
||
@Autowired | ||
TestConfiguration testConfiguration; | ||
|
||
@DynamicPropertySource | ||
static void rabbitProperties(DynamicPropertyRegistry registry) { | ||
registry.add("spring.rabbitmq.port", RABBITMQ::getAmqpPort); | ||
} | ||
|
||
@Test | ||
void observationIsPropagatedInMultiBinderConfiguration() throws InterruptedException { | ||
Observation.createNotStarted("test parent observation", this.observationRegistry) | ||
.observe(() -> this.streamBridge.send("test-out-0", "test data")); | ||
|
||
assertThat(this.testConfiguration.messageReceived.await(10, TimeUnit.SECONDS)).isTrue(); | ||
|
||
// There is a race condition when we already have a reply, but the span in the | ||
// Rabbit listener is not closed yet. | ||
// parent -> StreamBridge -> RabbitTemplate -> Rabbit Listener -> Consumer | ||
await().untilAsserted(() -> assertThat(SPANS.spans()).hasSize(5)); | ||
SpansAssert.assertThat(SPANS.spans().stream().map(BraveFinishedSpan::fromBrave).collect(Collectors.toList())) | ||
.haveSameTraceId(); | ||
} | ||
|
||
@SpringBootConfiguration | ||
@EnableAutoConfiguration | ||
public static class TestConfiguration { | ||
|
||
final CountDownLatch messageReceived = new CountDownLatch(1); | ||
|
||
@Bean | ||
SpanHandler testSpanHandler() { | ||
return SPANS; | ||
} | ||
|
||
@Bean | ||
public Consumer<Message<?>> testListener() { | ||
return message -> this.messageReceived.countDown(); | ||
} | ||
|
||
} | ||
|
||
} |
34 changes: 34 additions & 0 deletions
34
.../spring-cloud-stream-binder-rabbit/src/test/resources/rabbit-multi-binder-observation.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
spring: | ||
cloud: | ||
function: | ||
definition: testListener | ||
stream: | ||
output-bindings: test | ||
bindings: | ||
test-out-0: | ||
binder: rabbit | ||
destination: test | ||
group: test | ||
testListener-in-0: | ||
binder: rabbit | ||
destination: test | ||
group: test | ||
binders: | ||
rabbit: | ||
type: rabbit | ||
environment: | ||
spring: | ||
cloud: | ||
stream: | ||
rabbit: | ||
binder: | ||
enableObservation: true | ||
logging: | ||
pattern: | ||
level: "%5p [${spring.application.name:},%X{traceId:-},%X{spanId:-}]" | ||
|
||
management: | ||
tracing: | ||
sampling: | ||
probability: 1 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters