-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WebSockets Next integration wiht OTel and Micrometer
- Loading branch information
1 parent
2ca2703
commit 53805a4
Showing
106 changed files
with
4,018 additions
and
53 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
18 changes: 18 additions & 0 deletions
18
...ava/io/quarkus/websockets/next/deployment/TelemetrySupportBuilderCustomizerBuildItem.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,18 @@ | ||
package io.quarkus.websockets.next.deployment; | ||
|
||
import java.util.function.Consumer; | ||
|
||
import io.quarkus.builder.item.MultiBuildItem; | ||
import io.quarkus.websockets.next.runtime.telemetry.TelemetrySupportProviderBuilder; | ||
|
||
/** | ||
* Provides a way to set up metrics and/or traces support in the WebSockets extension. | ||
*/ | ||
final class TelemetrySupportBuilderCustomizerBuildItem extends MultiBuildItem { | ||
|
||
final Consumer<TelemetrySupportProviderBuilder> builderCustomizer; | ||
|
||
TelemetrySupportBuilderCustomizerBuildItem(Consumer<TelemetrySupportProviderBuilder> builderCustomizer) { | ||
this.builderCustomizer = builderCustomizer; | ||
} | ||
} |
119 changes: 93 additions & 26 deletions
119
...xt/deployment/src/main/java/io/quarkus/websockets/next/deployment/WebSocketProcessor.java
Large diffs are not rendered by default.
Oops, something went wrong.
384 changes: 384 additions & 0 deletions
384
.../test/java/io/quarkus/websockets/next/test/telemetry/AbstractWebSocketsOnMessageTest.java
Large diffs are not rendered by default.
Oops, something went wrong.
86 changes: 86 additions & 0 deletions
86
...s-next/deployment/src/test/java/io/quarkus/websockets/next/test/telemetry/Connection.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,86 @@ | ||
package io.quarkus.websockets.next.test.telemetry; | ||
|
||
import static io.quarkus.websockets.next.test.utils.WSClient.ReceiverMode.BINARY; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import java.net.URI; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
|
||
import io.quarkus.websockets.next.test.utils.WSClient; | ||
import io.vertx.core.Vertx; | ||
import io.vertx.core.buffer.Buffer; | ||
import io.vertx.core.http.WebSocketConnectOptions; | ||
|
||
record Connection(URI uri, String[] messagesToSend, WSClient client, boolean broadcast, boolean binaryMode, | ||
String[] expectedResponses) { | ||
|
||
static Connection of(URI uri, boolean broadcast, boolean binaryMode, String[] sentMessages, String[] expectedResponses) { | ||
return new Connection(uri, sentMessages, null, broadcast, binaryMode, expectedResponses); | ||
} | ||
|
||
static Connection of(URI uri, String expectedResponse, boolean binaryMode, String... messages) { | ||
return new Connection(uri, messages, null, false, binaryMode, new String[] { expectedResponse }); | ||
} | ||
|
||
private Connection with(WSClient client) { | ||
return new Connection(uri, messagesToSend, client, broadcast, binaryMode, expectedResponses); | ||
} | ||
|
||
private Set<String> getReceivedMessages() { | ||
return client.getMessages().stream().map(Buffer::toString).collect(Collectors.toSet()); | ||
} | ||
|
||
static void sendAndAssertResponses(Vertx vertx, Connection... connections) { | ||
openConnectionsThenSend(connections, vertx, 0); | ||
} | ||
|
||
private static void openConnectionsThenSend(Connection[] connections, Vertx vertx, int idx) { | ||
var connection = connections[idx]; | ||
final WSClient client = connection.binaryMode() ? new WSClient(vertx, BINARY) : new WSClient(vertx); | ||
try (client) { | ||
client.connect(new WebSocketConnectOptions(), connection.uri()); | ||
connections[idx] = connection.with(client); | ||
|
||
if (idx < connections.length - 1) { | ||
openConnectionsThenSend(connections, vertx, idx + 1); | ||
} else { | ||
sendMessages(connections, connection.binaryMode()); | ||
} | ||
} | ||
} | ||
|
||
private static void sendMessages(Connection[] connections, boolean binaryMode) { | ||
for (Connection connection : connections) { | ||
for (String message : connection.messagesToSend()) { | ||
if (binaryMode) { | ||
connection.client().sendAndAwait(Buffer.buffer(message)); | ||
} else { | ||
connection.client().sendAndAwait(message); | ||
} | ||
} | ||
var expectedResponses = connection.expectedResponses(); | ||
if (expectedResponses.length != 0) { | ||
if (connection.broadcast()) { | ||
for (Connection conn : connections) { | ||
assertResponses(conn, expectedResponses); | ||
} | ||
} else { | ||
assertResponses(connection, expectedResponses); | ||
} | ||
} | ||
} | ||
} | ||
|
||
private static void assertResponses(Connection connection, String[] expectedResponses) { | ||
connection.client.waitForMessages(expectedResponses.length); | ||
Set<String> actualResponses = connection.getReceivedMessages(); | ||
|
||
for (String expectedResponse : expectedResponses) { | ||
assertTrue(actualResponses.contains(expectedResponse), | ||
() -> "Expected response '%s' not found, was: %s".formatted(expectedResponse, actualResponses)); | ||
} | ||
|
||
connection.client().getMessages().clear(); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
...c/test/java/io/quarkus/websockets/next/test/telemetry/ExpectedServerEndpointResponse.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,48 @@ | ||
package io.quarkus.websockets.next.test.telemetry; | ||
|
||
import java.util.Arrays; | ||
|
||
public interface ExpectedServerEndpointResponse { | ||
|
||
String[] NO_RESPONSE = new String[] {}; | ||
EchoExpectedServerEndpointResponse ECHO_RESPONSE = new EchoExpectedServerEndpointResponse(); | ||
DoubleEchoExpectedServerEndpointResponse DOUBLE_ECHO_RESPONSE = new DoubleEchoExpectedServerEndpointResponse(); | ||
|
||
/** | ||
* Endpoint returns void, Uni<Void> or results in exception and theefore, there is no response. | ||
*/ | ||
final class NoExpectedServerEndpointResponse { | ||
|
||
public String[] getExpectedResponse() { | ||
return new String[0]; | ||
} | ||
} | ||
|
||
/** | ||
* Received message is prefixed with 'echo 0: ' and returned. | ||
*/ | ||
final class EchoExpectedServerEndpointResponse implements ExpectedServerEndpointResponse { | ||
|
||
public String[] getExpectedResponse(String[] sentMessages) { | ||
return Arrays.stream(sentMessages).map(msg -> "echo 0: " + msg).toArray(String[]::new); | ||
} | ||
|
||
} | ||
|
||
/** | ||
* For each received message 'msg' endpoint returns 'echo 0: msg' and 'echo 1: msg' | ||
*/ | ||
final class DoubleEchoExpectedServerEndpointResponse implements ExpectedServerEndpointResponse { | ||
|
||
public String[] getExpectedResponse(String[] sentMessages) { | ||
return Arrays.stream(sentMessages) | ||
.mapMulti((msg, consumer) -> { | ||
consumer.accept("echo 0: " + msg); | ||
consumer.accept("echo 1: " + msg); | ||
}) | ||
.toArray(String[]::new); | ||
} | ||
|
||
} | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
...src/test/java/io/quarkus/websockets/next/test/telemetry/InMemorySpanExporterProducer.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,18 @@ | ||
package io.quarkus.websockets.next.test.telemetry; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.enterprise.inject.Produces; | ||
import jakarta.inject.Singleton; | ||
|
||
import io.opentelemetry.sdk.testing.exporter.InMemorySpanExporter; | ||
|
||
@ApplicationScoped | ||
public class InMemorySpanExporterProducer { | ||
|
||
@Produces | ||
@Singleton | ||
InMemorySpanExporter inMemorySpanExporter() { | ||
return InMemorySpanExporter.create(); | ||
} | ||
|
||
} |
Oops, something went wrong.