Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ de.thetaphi:forbiddenapis:3.10=compileClasspath,latestDepForkedTestCompileClassp
io.leangen.geantyref:geantyref:1.3.16=latestDepForkedTestRuntimeClasspath,latestDepTestRuntimeClasspath,testRuntimeClasspath
io.sqreen:libsqreen:17.3.0=latestDepForkedTestRuntimeClasspath,latestDepTestRuntimeClasspath,testRuntimeClasspath
io.undertow:undertow-core:2.0.0.Final=compileClasspath,testCompileClasspath,testRuntimeClasspath
io.undertow:undertow-core:2.2.39.Final=latestDepForkedTestCompileClasspath,latestDepForkedTestRuntimeClasspath,latestDepTestCompileClasspath,latestDepTestRuntimeClasspath
io.undertow:undertow-core:2.2.40.Final=latestDepForkedTestCompileClasspath,latestDepForkedTestRuntimeClasspath,latestDepTestCompileClasspath,latestDepTestRuntimeClasspath
io.undertow:undertow-servlet:2.0.0.Final=compileClasspath,testCompileClasspath,testRuntimeClasspath
io.undertow:undertow-servlet:2.2.39.Final=latestDepForkedTestCompileClasspath,latestDepForkedTestRuntimeClasspath,latestDepTestCompileClasspath,latestDepTestRuntimeClasspath
io.undertow:undertow-servlet:2.2.40.Final=latestDepForkedTestCompileClasspath,latestDepForkedTestRuntimeClasspath,latestDepTestCompileClasspath,latestDepTestRuntimeClasspath
io.undertow:undertow-websockets-jsr:2.0.0.Final=testCompileClasspath,testRuntimeClasspath
io.undertow:undertow-websockets-jsr:2.2.39.Final=latestDepForkedTestCompileClasspath,latestDepForkedTestRuntimeClasspath,latestDepTestCompileClasspath,latestDepTestRuntimeClasspath
io.undertow:undertow-websockets-jsr:2.2.40.Final=latestDepForkedTestCompileClasspath,latestDepForkedTestRuntimeClasspath,latestDepTestCompileClasspath,latestDepTestRuntimeClasspath
javax.servlet:javax.servlet-api:3.1.0=latestDepForkedTestCompileClasspath,latestDepForkedTestRuntimeClasspath,latestDepTestCompileClasspath,latestDepTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
jaxen:jaxen:2.0.0=spotbugs
junit:junit:4.13.2=latestDepForkedTestRuntimeClasspath,latestDepTestRuntimeClasspath,testRuntimeClasspath
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public HttpRequestParserInstrumentation() {

@Override
public String hierarchyMarkerType() {
// removed in https://github.com/undertow-io/undertow/pull/1949/changes
// see RequestParserInstrumentation for the new type
return "io.undertow.server.protocol.http.HttpRequestParser";
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package datadog.trace.instrumentation.undertow;

import static datadog.trace.agent.tooling.bytebuddy.matcher.NameMatchers.named;
import static net.bytebuddy.matcher.ElementMatchers.isMethod;
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;

import com.google.auto.service.AutoService;
import datadog.trace.agent.tooling.Instrumenter;
import datadog.trace.agent.tooling.InstrumenterModule;

@AutoService(InstrumenterModule.class)
public class RequestParserInstrumentation extends InstrumenterModule.Tracing
implements Instrumenter.ForSingleType, Instrumenter.HasMethodAdvice {
public RequestParserInstrumentation() {
super("undertow", "undertow-2.2", "undertow-request-parse");
}

@Override
public String instrumentedType() {
// new class added in new minor versions in
// https://github.com/undertow-io/undertow/pull/1949/changes
// from 2.2.40, 2.3.25 and 2.4.0
// not instrumenting the hierarchy like in its predecessor HttpRequestParserInstrumentation
// because RequestParser is marked final.
return "io.undertow.server.protocol.http.RequestParser";
}

@Override
public void methodAdvice(MethodTransformer transformer) {
transformer.applyAdvice(
isMethod()
.and(named("handle"))
.and(takesArgument(2, named("io.undertow.server.HttpServerExchange"))),
HttpRequestParserInstrumentation.class.getName() + "$RequestParseFailureAdvice");
}

@Override
public String[] helperClassNames() {
return new String[] {
packageName + ".HttpServerExchangeURIDataAdapter",
packageName + ".UndertowDecorator",
packageName + ".UndertowBlockingHandler",
packageName + ".IgnoreSendAttribute",
packageName + ".UndertowBlockResponseFunction",
packageName + ".UndertowExtractAdapter",
packageName + ".UndertowExtractAdapter$Request",
packageName + ".UndertowExtractAdapter$Response"
};
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.BODY_MULTIPART
import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.BODY_URLENCODED
import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.CREATED
import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.CREATED_IS
import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.ERROR
import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.EXCEPTION
import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.FORWARDED
import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.LOGIN
import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.NOT_FOUND
import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.NOT_HERE
import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.PATH_PARAM
import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.QUERY_ENCODED_BOTH
import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.QUERY_ENCODED_QUERY
import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM
import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.REDIRECT
import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.SUCCESS
import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.TIMEOUT
import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.TIMEOUT_ERROR
import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.USER_BLOCK
import static datadog.trace.agent.test.base.HttpServerTest.controller

import datadog.trace.agent.test.asserts.TraceAssert
import datadog.trace.agent.test.base.HttpServer
import datadog.trace.agent.test.base.HttpServerTest
Expand All @@ -14,8 +35,8 @@ import io.undertow.servlet.api.InstanceHandle
import io.undertow.servlet.api.ServletContainer
import io.undertow.servlet.api.ServletInfo
import io.undertow.servlet.util.ImmediateInstanceHandle
import org.slf4j.LoggerFactory

import java.nio.charset.StandardCharsets
import java.util.concurrent.atomic.AtomicReference
import javax.servlet.AsyncContext
import javax.servlet.AsyncEvent
import javax.servlet.AsyncListener
Expand All @@ -26,29 +47,7 @@ import javax.servlet.WriteListener
import javax.servlet.http.HttpServlet
import javax.servlet.http.HttpServletRequest
import javax.servlet.http.HttpServletResponse
import java.nio.charset.StandardCharsets
import java.util.concurrent.atomic.AtomicReference

import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.BODY_MULTIPART
import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.BODY_URLENCODED
import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.CREATED
import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.CREATED_IS
import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.ERROR
import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.EXCEPTION
import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.FORWARDED
import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.LOGIN
import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.NOT_FOUND
import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.NOT_HERE
import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.PATH_PARAM
import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.QUERY_ENCODED_BOTH
import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.QUERY_ENCODED_QUERY
import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM
import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.REDIRECT
import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.SUCCESS
import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.TIMEOUT
import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.TIMEOUT_ERROR
import static datadog.trace.agent.test.base.HttpServerTest.ServerEndpoint.USER_BLOCK
import static datadog.trace.agent.test.base.HttpServerTest.controller
import org.slf4j.LoggerFactory

class UndertowServletAsyncTest extends HttpServerTest<Undertow> {
private static final CONTEXT = "ctx"
Expand Down Expand Up @@ -119,9 +118,10 @@ class UndertowServletAsyncTest extends HttpServerTest<Undertow> {
dispatch = false
req.setAttribute('ddog.dispatched', 1)
if (req.servletPath.contains(' ')) {
// bug in undertow when dispatching from /foo%20bar
// (matches mapping "/foo bar" 1st and "/foo%20bar" after dispatch)
asyncContext.dispatch(req.servletPath)
// Older versions match the decoded servlet path on redispatch,
// while the newer RequestParser expects the raw encoded path;
// using the other form either misses the servlet mapping or hangs.
asyncContext.dispatch(hasNewRequestParser() ? ep.rawPath : req.servletPath)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Migrate touched Groovy test to JUnit 5

This patch adds new behavior to an existing Groovy/Spock test, but the root AGENTS.md for this tree says to use JUnit 5 and to migrate an existing Groovy test when it is written in Groovy. Please move this updated coverage to a JUnit 5 test instead of extending UndertowServletAsyncTest.groovy.

Useful? React with 👍 / 👎.

} else {
asyncContext.dispatch()
}
Expand Down Expand Up @@ -260,6 +260,16 @@ class UndertowServletAsyncTest extends HttpServerTest<Undertow> {
operation()
}

private static boolean hasNewRequestParser() {
// returns true for versions that include the bugfix pushed in https://github.com/undertow-io/undertow/pull/1949
try {
Class.forName('io.undertow.server.protocol.http.RequestParser')
return true
} catch (ClassNotFoundException ignored) {
return false
}
}

@Override
boolean testTimeout() {
true
Expand Down Expand Up @@ -408,7 +418,8 @@ class UndertowServletAsyncTest extends HttpServerTest<Undertow> {
trace.span {
serviceName expectedServiceName()
operationName 'servlet.dispatch'
String resName = endpoint.path == endpoint.rawPath ? 'servlet.dispatch' : endpoint.path
String resName =
endpoint.path == endpoint.rawPath ? 'servlet.dispatch' : hasNewRequestParser() ? endpoint.rawPath : endpoint.path
resourceName resName
errored(endpoint.throwsException || endpoint == TIMEOUT_ERROR)
childOfPrevious()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@ io.smallrye.common:smallrye-common-ref:2.4.0=latestDepForkedTestRuntimeClasspath
io.sqreen:libsqreen:17.3.0=latest22ForkedTestRuntimeClasspath,latest22TestRuntimeClasspath,latestDepForkedTestRuntimeClasspath,latestDepTestRuntimeClasspath,testRuntimeClasspath
io.undertow:undertow-core:2.2.14.Final=compileClasspath,testCompileClasspath,testRuntimeClasspath
io.undertow:undertow-core:2.2.20.Final=latest22ForkedTestCompileClasspath,latest22ForkedTestRuntimeClasspath,latest22TestCompileClasspath,latest22TestRuntimeClasspath
io.undertow:undertow-core:2.3.24.Final=latestDepForkedTestCompileClasspath,latestDepForkedTestRuntimeClasspath,latestDepTestCompileClasspath,latestDepTestRuntimeClasspath
io.undertow:undertow-core:2.3.25.Final=latestDepForkedTestCompileClasspath,latestDepForkedTestRuntimeClasspath,latestDepTestCompileClasspath,latestDepTestRuntimeClasspath
io.undertow:undertow-servlet-jakarta:2.2.14.Final=compileClasspath,latestDepForkedTestCompileClasspath,latestDepForkedTestRuntimeClasspath,latestDepTestCompileClasspath,latestDepTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
io.undertow:undertow-servlet-jakarta:2.2.20.Final=latest22ForkedTestCompileClasspath,latest22ForkedTestRuntimeClasspath,latest22TestCompileClasspath,latest22TestRuntimeClasspath
io.undertow:undertow-servlet:2.3.24.Final=latestDepForkedTestCompileClasspath,latestDepForkedTestRuntimeClasspath,latestDepTestCompileClasspath,latestDepTestRuntimeClasspath
io.undertow:undertow-servlet:2.3.25.Final=latestDepForkedTestCompileClasspath,latestDepForkedTestRuntimeClasspath,latestDepTestCompileClasspath,latestDepTestRuntimeClasspath
io.undertow:undertow-websockets-jsr-jakarta:2.2.14.Final=latestDepForkedTestCompileClasspath,latestDepForkedTestRuntimeClasspath,latestDepTestCompileClasspath,latestDepTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
io.undertow:undertow-websockets-jsr-jakarta:2.2.20.Final=latest22ForkedTestCompileClasspath,latest22ForkedTestRuntimeClasspath,latest22TestCompileClasspath,latest22TestRuntimeClasspath
io.undertow:undertow-websockets-jsr:2.3.24.Final=latestDepForkedTestCompileClasspath,latestDepForkedTestRuntimeClasspath,latestDepTestCompileClasspath,latestDepTestRuntimeClasspath
io.undertow:undertow-websockets-jsr:2.3.25.Final=latestDepForkedTestCompileClasspath,latestDepForkedTestRuntimeClasspath,latestDepTestCompileClasspath,latestDepTestRuntimeClasspath
jakarta.annotation:jakarta.annotation-api:2.0.0=compileClasspath,latest22ForkedTestCompileClasspath,latest22ForkedTestRuntimeClasspath,latest22TestCompileClasspath,latest22TestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
jakarta.annotation:jakarta.annotation-api:2.1.1=latestDepForkedTestCompileClasspath,latestDepForkedTestRuntimeClasspath,latestDepTestCompileClasspath,latestDepTestRuntimeClasspath
jakarta.servlet:jakarta.servlet-api:5.0.0=compileClasspath,latest22ForkedTestCompileClasspath,latest22ForkedTestRuntimeClasspath,latest22TestCompileClasspath,latest22TestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
Expand Down