forked from quarkusio/quarkus
-
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.
Continue PR quarkusio#40191 - Add docs - Add tests - Fix parent-child spans for reactive request
- Loading branch information
1 parent
b5140ea
commit 65271ec
Showing
25 changed files
with
681 additions
and
48 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
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
23 changes: 23 additions & 0 deletions
23
...ient/deployment/src/main/java/io/quarkus/mongodb/deployment/ContextProviderBuildItem.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,23 @@ | ||
package io.quarkus.mongodb.deployment; | ||
|
||
import java.util.List; | ||
|
||
import com.mongodb.reactivestreams.client.ReactiveContextProvider; | ||
|
||
import io.quarkus.builder.item.SimpleBuildItem; | ||
|
||
/** | ||
* Register additional {@link ReactiveContextProvider}s for the MongoDB clients. | ||
*/ | ||
public final class ContextProviderBuildItem extends SimpleBuildItem { | ||
|
||
private final List<String> classNames; | ||
|
||
public ContextProviderBuildItem(List<String> classNames) { | ||
this.classNames = classNames == null ? List.of() : classNames; | ||
} | ||
|
||
public List<String> getContextProviderClassNames() { | ||
return classNames; | ||
} | ||
} |
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
22 changes: 22 additions & 0 deletions
22
...ngodb-client/deployment/src/test/java/io/quarkus/mongodb/MockReactiveContextProvider.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,22 @@ | ||
package io.quarkus.mongodb; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.reactivestreams.Subscriber; | ||
|
||
import com.mongodb.RequestContext; | ||
import com.mongodb.reactivestreams.client.ReactiveContextProvider; | ||
|
||
import io.quarkus.mongodb.runtime.MongoRequestContext; | ||
|
||
public class MockReactiveContextProvider implements ReactiveContextProvider { | ||
|
||
public static final List<String> EVENTS = new ArrayList<>(); | ||
|
||
@Override | ||
public RequestContext getContext(Subscriber<?> subscriber) { | ||
EVENTS.add(MongoRequestContext.class.getName()); | ||
return new MongoRequestContext(null); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
...sions/mongodb-client/deployment/src/test/java/io/quarkus/mongodb/MongoTracingEnabled.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,49 @@ | ||
package io.quarkus.mongodb; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.awaitility.Awaitility.await; | ||
|
||
import java.time.Duration; | ||
|
||
import jakarta.inject.Inject; | ||
|
||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.mongodb.reactive.ReactiveMongoClient; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class MongoTracingEnabled extends MongoTestBase { | ||
|
||
@Inject | ||
ReactiveMongoClient reactiveClient; | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest().setArchiveProducer( | ||
() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClasses(MongoTestBase.class, MockReactiveContextProvider.class, MockCommandListener.class)) | ||
.withConfigurationResource("application-tracing-mongoclient.properties"); | ||
|
||
@AfterEach | ||
void cleanup() { | ||
if (reactiveClient != null) { | ||
reactiveClient.close(); | ||
} | ||
} | ||
|
||
@Test | ||
void invokeReactiveContextProvider() { | ||
String dbNames = reactiveClient.listDatabaseNames().toUni().await().atMost(Duration.ofSeconds(30L)); | ||
assertThat(dbNames).as("expect db names available").isNotBlank(); | ||
await().atMost(Duration.ofSeconds(30L)).untilAsserted( | ||
() -> assertThat(MockReactiveContextProvider.EVENTS) | ||
.as("reactive context provider must be called") | ||
.isNotEmpty()); | ||
assertThat(MockCommandListener.EVENTS).isNotEmpty(); | ||
|
||
} | ||
|
||
} |
42 changes: 42 additions & 0 deletions
42
...ongodb-client/deployment/src/test/java/io/quarkus/mongodb/MongoTracingNotEnabledTest.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,42 @@ | ||
package io.quarkus.mongodb; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import jakarta.inject.Inject; | ||
|
||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import com.mongodb.client.MongoClient; | ||
|
||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class MongoTracingNotEnabledTest extends MongoTestBase { | ||
|
||
@Inject | ||
MongoClient client; | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.setArchiveProducer( | ||
() -> ShrinkWrap.create(JavaArchive.class).addClasses(MongoTestBase.class, | ||
MockReactiveContextProvider.class)) | ||
.withConfigurationResource("default-mongoclient.properties"); | ||
|
||
@AfterEach | ||
void cleanup() { | ||
if (client != null) { | ||
client.close(); | ||
} | ||
} | ||
|
||
@Test | ||
void contextProviderMustNotBeCalledIfNoOpenTelemetryIsAvailable() { | ||
assertThat(client.listDatabaseNames().first()).isNotEmpty(); | ||
assertThat(MockReactiveContextProvider.EVENTS).isEmpty(); | ||
} | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
.../deployment/src/test/java/io/quarkus/mongodb/deployment/ContextProviderBuildItemTest.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,28 @@ | ||
package io.quarkus.mongodb.deployment; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.util.List; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
class ContextProviderBuildItemTest { | ||
|
||
@Test | ||
void getContextProviderClassNames() { | ||
ContextProviderBuildItem item = new ContextProviderBuildItem(List.of("foo.bar")); | ||
assertThat(item.getContextProviderClassNames()) | ||
.hasSize(1) | ||
.first() | ||
.isEqualTo("foo.bar"); | ||
} | ||
|
||
@Test | ||
void emptyOrNull() { | ||
ContextProviderBuildItem withNull = new ContextProviderBuildItem(null); | ||
assertThat(withNull.getContextProviderClassNames()).isEmpty(); | ||
|
||
ContextProviderBuildItem empty = new ContextProviderBuildItem(List.of()); | ||
assertThat(empty.getContextProviderClassNames()).isEmpty(); | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
...s/mongodb-client/deployment/src/test/resources/application-tracing-mongoclient.properties
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,3 @@ | ||
quarkus.mongodb.connection-string=mongodb://127.0.0.1:27018 | ||
quarkus.mongodb.tracing.enabled=true | ||
|
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
17 changes: 17 additions & 0 deletions
17
...client/runtime/src/main/java/io/quarkus/mongodb/runtime/MongoReactiveContextProvider.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,17 @@ | ||
package io.quarkus.mongodb.runtime; | ||
|
||
import org.reactivestreams.Subscriber; | ||
|
||
import com.mongodb.RequestContext; | ||
import com.mongodb.reactivestreams.client.ReactiveContextProvider; | ||
|
||
import io.opentelemetry.context.Context; | ||
|
||
public class MongoReactiveContextProvider implements ReactiveContextProvider { | ||
|
||
@Override | ||
public RequestContext getContext(Subscriber<?> subscriber) { | ||
return new MongoRequestContext(Context.current()); | ||
} | ||
|
||
} |
Oops, something went wrong.