-
Notifications
You must be signed in to change notification settings - Fork 335
fix(vertx-web): finish vertx.route-handler via RoutingContext.addEndHandler fallback #11312
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
Open
zarirhamza
wants to merge
6
commits into
master
Choose a base branch
from
zarir/sles-2837-vertx-web-finish-route-handler
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
97f9933
fix(vertx-web): finish vertx.route-handler via RoutingContext.addEndH…
zarirhamza 01aeb85
Apply changes to vertex-web 3.4
rithikanarayan b6dc5d1
Add unit test for 3.x
rithikanarayan 04e85b4
Merge branch 'master' into zarir/sles-2837-vertx-web-finish-route-han…
rithikanarayan 490cd63
Clean up unit test
rithikanarayan 07787a9
Add junit jupiter to gradle setup
rithikanarayan 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
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
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
109 changes: 109 additions & 0 deletions
109
...entation/vertx/vertx-web/vertx-web-3.4/src/test/java/server/RouteHandlerSendFileTest.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,109 @@ | ||
| package server; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
|
||
| import datadog.trace.agent.test.AbstractInstrumentationTest; | ||
| import io.vertx.core.Vertx; | ||
| import io.vertx.core.http.HttpServer; | ||
| import io.vertx.ext.web.Router; | ||
| import java.io.BufferedReader; | ||
| import java.io.InputStreamReader; | ||
| import java.net.HttpURLConnection; | ||
| import java.net.ServerSocket; | ||
| import java.net.URL; | ||
| import java.nio.charset.StandardCharsets; | ||
| import java.nio.file.Files; | ||
| import java.nio.file.Path; | ||
| import java.util.concurrent.CountDownLatch; | ||
| import java.util.concurrent.TimeUnit; | ||
| import org.junit.jupiter.api.AfterAll; | ||
| import org.junit.jupiter.api.BeforeAll; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| /** | ||
| * Regression test for the vertx-web 3.x route-handler span lifecycle on the {@code | ||
| * response.sendFile(...)} path. | ||
| * | ||
| * <p>{@code HttpServerResponseImpl.doSendFile} (vertx-core 3.x) only invokes {@code bodyEndHandler} | ||
| * after the file is written; it never invokes {@code endHandler}. With only the {@code endHandler} | ||
| * registration (pre-fix), the {@code vertx.route-handler} span never finishes on this path, the | ||
| * trace fails to flush, and {@code waitForTraces} times out. With the fallback {@code | ||
| * addBodyEndHandler} registration, the span finishes on every response-end path. | ||
| */ | ||
| class RouteHandlerSendFileTest extends AbstractInstrumentationTest { | ||
|
|
||
| private static Vertx vertx; | ||
| private static HttpServer server; | ||
| private static int port; | ||
| private static Path payload; | ||
|
|
||
| @BeforeAll | ||
| static void startServer() throws Exception { | ||
| payload = Files.createTempFile("vertx-sendfile-", ".txt"); | ||
| Files.write(payload, "vertx sendFile payload\n".getBytes(StandardCharsets.UTF_8)); | ||
| payload.toFile().deleteOnExit(); | ||
|
|
||
| try (ServerSocket socket = new ServerSocket(0)) { | ||
| port = socket.getLocalPort(); | ||
| } | ||
|
|
||
| vertx = Vertx.vertx(); | ||
| Router router = Router.router(vertx); | ||
| router | ||
| .route("/sendfile") | ||
| .handler(ctx -> ctx.response().sendFile(payload.toAbsolutePath().toString())); | ||
|
|
||
| CountDownLatch ready = new CountDownLatch(1); | ||
| server = | ||
| vertx | ||
| .createHttpServer() | ||
| .requestHandler(router::accept) | ||
| .listen( | ||
| port, | ||
| result -> { | ||
| if (result.failed()) { | ||
| throw new RuntimeException("Failed to start Vert.x server", result.cause()); | ||
| } | ||
| ready.countDown(); | ||
| }); | ||
| if (!ready.await(10, TimeUnit.SECONDS)) { | ||
| throw new IllegalStateException("Vert.x server did not start in time"); | ||
| } | ||
| } | ||
|
|
||
| @AfterAll | ||
| static void stopServer() throws Exception { | ||
| if (server != null) { | ||
| CountDownLatch closed = new CountDownLatch(1); | ||
| server.close(ar -> closed.countDown()); | ||
| closed.await(10, TimeUnit.SECONDS); | ||
| } | ||
| if (vertx != null) { | ||
| CountDownLatch closed = new CountDownLatch(1); | ||
| vertx.close(ar -> closed.countDown()); | ||
| closed.await(10, TimeUnit.SECONDS); | ||
| } | ||
| if (payload != null) { | ||
| Files.deleteIfExists(payload); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| void sendFileFinishesRouteHandlerSpan() throws Exception { | ||
| HttpURLConnection conn = | ||
| (HttpURLConnection) new URL("http://localhost:" + port + "/sendfile").openConnection(); | ||
| conn.setRequestMethod("GET"); | ||
| conn.setConnectTimeout(5000); | ||
| conn.setReadTimeout(5000); | ||
| assertEquals(200, conn.getResponseCode()); | ||
| try (BufferedReader reader = | ||
| new BufferedReader(new InputStreamReader(conn.getInputStream(), StandardCharsets.UTF_8))) { | ||
| assertEquals("vertx sendFile payload", reader.readLine()); | ||
| } | ||
|
|
||
| // Strict-mode trace writes only publish a trace when every span in it has finished. | ||
| // Pre-fix: the route-handler span never finishes on the sendFile path, so the trace | ||
| // is never published and this call throws TimeoutException. | ||
| writer.waitForTraces(1); | ||
| } | ||
| } | ||
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
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
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.
This module's shared Gradle setup only adds JUnit 5 as
testRuntimeOnly, whiletestImplementationis Spock/Groovy plus instrumentation-testing, so a Java test source that importsorg.junit.jupiter.apiis not on thecompileTestJavaclasspath. As a result:dd-java-agent:instrumentation:vertx:vertx-web:vertx-web-3.4:compileTestJavawill fail withpackage org.junit.jupiter.api does not existunless the module adds a Jupiter API/testImplementation dependency for this new JUnit test.Useful? React with 👍 / 👎.
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.
@DataDog fix 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.
I can only run on private repositories.