-
Notifications
You must be signed in to change notification settings - Fork 637
GH-1444: Listener Observability Initial Commit #1500
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
6f35711
GH-1444: Listener Observability Initial Commit
garyrussell 3c767f1
Rename Sender/Receiver contexts and other PR review comments.
garyrussell 0886783
Rename contexts to Rabbit...; supply default KeyValues via the conven…
garyrussell 355f5db
Javadoc polishing.
garyrussell b39a5f9
Don't add default KV to high-card KVs.
garyrussell 393ed51
Fix previous commit.
garyrussell c282d46
Fix contextual name (receiver side).
garyrussell c5b2975
Fix checkstyle.
garyrussell 9de2da2
Polish previous commit.
garyrussell 55f0437
Fix contextual name (sender side)
garyrussell 3079268
Remove contextual names from observations.
garyrussell 0cf3e55
Fix checkstyle.
garyrussell d929b0f
Remove customization of KeyValues from conventions.
garyrussell b1bd023
Add `getDefaultConvention()` to observations.
garyrussell be4be28
Fix since 3.0.
garyrussell d422412
Support wider convention customization.
garyrussell d762752
Convention type safety.
garyrussell f1ac117
Fix Test - not sure why PR build succeeded.
garyrussell 03ccb33
Add Meters to ObservationTests.
garyrussell 2557794
Fix checkstyle.
garyrussell 970ba6c
Make INSTANCE final.
garyrussell a528d09
Add integration test.
garyrussell 1927f3b
Test all available integrations.
garyrussell cb6ba4c
Remove redundant test code.
garyrussell d0b758e
Move getContextualName to conventions.
garyrussell 0043280
Add docs.
garyrussell 599d5b7
Fix doc link.
garyrussell 38589a0
Remove unnecessary method overrides; make tag names more meaningful.
garyrussell d5464ab
Move getName() from contexts to conventions.
garyrussell 4ec81a1
Fix Race in Test
garyrussell 2651f1c
Fix Race in Test.
garyrussell File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
159 changes: 159 additions & 0 deletions
159
.../java/org/springframework/amqp/rabbit/support/micrometer/ObservationIntegrationTests.java
This file contains hidden or 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,159 @@ | ||
/* | ||
* Copyright 2022 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.amqp.rabbit.support.micrometer; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.util.List; | ||
import java.util.concurrent.CountDownLatch; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import org.springframework.amqp.rabbit.annotation.EnableRabbit; | ||
import org.springframework.amqp.rabbit.annotation.RabbitListener; | ||
import org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory; | ||
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory; | ||
import org.springframework.amqp.rabbit.core.RabbitTemplate; | ||
import org.springframework.amqp.rabbit.junit.RabbitAvailable; | ||
import org.springframework.amqp.rabbit.junit.RabbitAvailableCondition; | ||
import org.springframework.amqp.rabbit.listener.RabbitListenerEndpointRegistry; | ||
import org.springframework.context.annotation.AnnotationConfigApplicationContext; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.messaging.Message; | ||
|
||
import io.micrometer.common.KeyValues; | ||
import io.micrometer.core.tck.MeterRegistryAssert; | ||
import io.micrometer.observation.ObservationRegistry; | ||
import io.micrometer.tracing.Span.Kind; | ||
import io.micrometer.tracing.exporter.FinishedSpan; | ||
import io.micrometer.tracing.test.SampleTestRunner; | ||
import io.micrometer.tracing.test.simple.SpanAssert; | ||
import io.micrometer.tracing.test.simple.SpansAssert; | ||
|
||
/** | ||
* @author Artem Bilan | ||
* @author Gary Russell | ||
* | ||
* @since 3.0 | ||
*/ | ||
@RabbitAvailable(queues = { "int.observation.testQ1", "int.observation.testQ2" }) | ||
public class ObservationIntegrationTests extends SampleTestRunner { | ||
|
||
@Override | ||
public TracingSetup[] getTracingSetup() { | ||
return new TracingSetup[]{ TracingSetup.IN_MEMORY_BRAVE }; | ||
} | ||
|
||
@Override | ||
public SampleTestRunnerConsumer yourCode() { | ||
// template -> listener -> template -> listener | ||
return (bb, meterRegistry) -> { | ||
ObservationRegistry observationRegistry = getObservationRegistry(); | ||
try (AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext()) { | ||
applicationContext.registerBean(ObservationRegistry.class, () -> observationRegistry); | ||
applicationContext.register(Config.class); | ||
applicationContext.refresh(); | ||
RabbitListenerEndpointRegistry bean = applicationContext.getBean(RabbitListenerEndpointRegistry.class); | ||
applicationContext.getBean(RabbitTemplate.class).convertAndSend("int.observation.testQ1", "test"); | ||
assertThat(applicationContext.getBean(Listener.class).latch1.await(10, TimeUnit.SECONDS)).isTrue(); | ||
} | ||
|
||
List<FinishedSpan> finishedSpans = bb.getFinishedSpans(); | ||
SpansAssert.assertThat(finishedSpans) | ||
.haveSameTraceId() | ||
.hasSize(4); | ||
SpanAssert.assertThat(finishedSpans.get(0)) | ||
.hasKindEqualTo(Kind.PRODUCER) | ||
.hasTag("bean.name", "template"); | ||
SpanAssert.assertThat(finishedSpans.get(1)) | ||
.hasKindEqualTo(Kind.PRODUCER) | ||
.hasTag("bean.name", "template"); | ||
SpanAssert.assertThat(finishedSpans.get(2)) | ||
.hasKindEqualTo(Kind.CONSUMER) | ||
.hasTag("listener.id", "obs1"); | ||
SpanAssert.assertThat(finishedSpans.get(3)) | ||
.hasKindEqualTo(Kind.CONSUMER) | ||
.hasTag("listener.id", "obs2"); | ||
|
||
MeterRegistryAssert.assertThat(getMeterRegistry()) | ||
.hasTimerWithNameAndTags("spring.rabbit.template", KeyValues.of("bean.name", "template")) | ||
.hasTimerWithNameAndTags("spring.rabbit.template", KeyValues.of("bean.name", "template")) | ||
.hasTimerWithNameAndTags("spring.rabbit.listener", KeyValues.of("listener.id", "obs1")) | ||
.hasTimerWithNameAndTags("spring.rabbit.listener", KeyValues.of("listener.id", "obs1")) | ||
.hasTimerWithNameAndTags("spring.rabbit.listener", KeyValues.of("listener.id", "obs2")); | ||
}; | ||
} | ||
|
||
|
||
@Configuration | ||
@EnableRabbit | ||
public static class Config { | ||
|
||
@Bean | ||
CachingConnectionFactory ccf() { | ||
return new CachingConnectionFactory(RabbitAvailableCondition.getBrokerRunning().getConnectionFactory()); | ||
} | ||
|
||
@Bean | ||
RabbitTemplate template(CachingConnectionFactory ccf) { | ||
RabbitTemplate template = new RabbitTemplate(ccf); | ||
template.setObservationEnabled(true); | ||
return template; | ||
} | ||
|
||
@Bean | ||
SimpleRabbitListenerContainerFactory rabbitListenerContainerFactory(CachingConnectionFactory ccf) { | ||
SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory(); | ||
factory.setConnectionFactory(ccf); | ||
factory.setContainerCustomizer(container -> container.setObservationEnabled(true)); | ||
return factory; | ||
} | ||
|
||
@Bean | ||
Listener listener(RabbitTemplate template) { | ||
return new Listener(template); | ||
} | ||
|
||
} | ||
|
||
public static class Listener { | ||
|
||
private final RabbitTemplate template; | ||
|
||
final CountDownLatch latch1 = new CountDownLatch(1); | ||
|
||
volatile Message message; | ||
|
||
public Listener(RabbitTemplate template) { | ||
this.template = template; | ||
} | ||
|
||
@RabbitListener(id = "obs1", queues = "int.observation.testQ1") | ||
void listen1(Message in) { | ||
this.template.convertAndSend("int.observation.testQ2", in); | ||
} | ||
|
||
@RabbitListener(id = "obs2", queues = "int.observation.testQ2") | ||
void listen2(Message in) { | ||
this.message = in; | ||
this.latch1.countDown(); | ||
} | ||
|
||
} | ||
|
||
|
||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't have to explicitly set this - if you don't have Zipkin running or Wavefront configured they will be ignored. Why have you ignored the OTel tests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks; that wasn't obvious from the docs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://micrometer.io/docs/tracing#_running_integration_tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks correct to me:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So
testq2 send
is a child of atestq1 receive
? If that's the case then it looks good!In some cases the name has
/
at the beginning - should it look like this?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the test1 receiver forwards the message to test2 which is received by the second receiver.
Yes, with RabbitMQ, the sender doesn't know the destination queue; it sends to
exchange/routingKey
. In this case, I am sending to the default exchange""
with a routing key equal to the queue name (which is a default binding provided by rabbitmq).The
/
is not present in the Kafka PR because the sender knows the destination topic name.