Skip to content

Commit 60aa421

Browse files
authored
Enable http pipelining test on Grizzly (#8411)
1 parent 413890d commit 60aa421

File tree

5 files changed

+79
-16
lines changed

5 files changed

+79
-16
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package io.opentelemetry.javaagent.instrumentation.grizzly;
7+
8+
import static net.bytebuddy.matcher.ElementMatchers.named;
9+
import static net.bytebuddy.matcher.ElementMatchers.takesArguments;
10+
11+
import io.opentelemetry.context.Scope;
12+
import io.opentelemetry.javaagent.bootstrap.CallDepth;
13+
import io.opentelemetry.javaagent.bootstrap.Java8BytecodeBridge;
14+
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
15+
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
16+
import net.bytebuddy.asm.Advice;
17+
import net.bytebuddy.description.type.TypeDescription;
18+
import net.bytebuddy.matcher.ElementMatcher;
19+
import org.glassfish.grizzly.filterchain.FilterChainContext;
20+
21+
public class FilterChainContextInstrumentation implements TypeInstrumentation {
22+
@Override
23+
public ElementMatcher<TypeDescription> typeMatcher() {
24+
return named("org.glassfish.grizzly.filterchain.FilterChainContext");
25+
}
26+
27+
@Override
28+
public void transform(TypeTransformer transformer) {
29+
transformer.applyAdviceToMethod(
30+
named("resume").and(takesArguments(0)),
31+
FilterChainContextInstrumentation.class.getName() + "$ResumeAdvice");
32+
transformer.applyAdviceToMethod(
33+
named("write"), FilterChainContextInstrumentation.class.getName() + "$WriteAdvice");
34+
}
35+
36+
@SuppressWarnings("unused")
37+
public static class ResumeAdvice {
38+
39+
@Advice.OnMethodEnter(suppress = Throwable.class)
40+
public static Scope onEnter() {
41+
return Java8BytecodeBridge.rootContext().makeCurrent();
42+
}
43+
44+
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
45+
public static void onExit(@Advice.Enter Scope scope) {
46+
if (scope != null) {
47+
scope.close();
48+
}
49+
}
50+
}
51+
52+
@SuppressWarnings("unused")
53+
public static class WriteAdvice {
54+
55+
@Advice.OnMethodEnter(suppress = Throwable.class)
56+
public static void onEnter(@Advice.Local("otelCallDepth") CallDepth callDepth) {
57+
callDepth = CallDepth.forClass(FilterChainContext.class);
58+
callDepth.getAndIncrement();
59+
}
60+
61+
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
62+
public static void onExit(
63+
@Advice.This FilterChainContext filterChainContext,
64+
@Advice.Local("otelCallDepth") CallDepth callDepth) {
65+
// When exiting the outermost call to write clear context & request from filter chain context.
66+
// Write makes a copy of the current filter chain context and passes it on. In older versions
67+
// new and old filter chain context share the attributes, but in newer versions the attributes
68+
// are also copied. We need to remove the attributes here to ensure that the next request
69+
// starts with clean state, failing to do so causes http pipelining test to fail with the
70+
// latest deps.
71+
if (callDepth.decrementAndGet() == 0) {
72+
GrizzlyStateStorage.removeContext(filterChainContext);
73+
GrizzlyStateStorage.removeRequest(filterChainContext);
74+
}
75+
}
76+
}
77+
}

instrumentation/grizzly-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/grizzly/GrizzlyInstrumentationModule.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public List<TypeInstrumentation> typeInstrumentations() {
2525
new FilterInstrumentation(),
2626
new HttpCodecFilterInstrumentation(),
2727
new HttpServerFilterInstrumentation(),
28-
new HttpHandlerInstrumentation());
28+
new HttpHandlerInstrumentation(),
29+
new FilterChainContextInstrumentation());
2930
}
3031
}

instrumentation/grizzly-2.0/javaagent/src/test/groovy/GrizzlyAsyncTest.groovy

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,6 @@ class GrizzlyAsyncTest extends GrizzlyTest {
3939
false
4040
}
4141

42-
@Override
43-
boolean testHttpPipelining() {
44-
false
45-
}
46-
4742
@Override
4843
boolean verifyServerSpanEndTime() {
4944
// server spans are ended inside of the JAX-RS controller spans

instrumentation/grizzly-2.0/javaagent/src/test/groovy/GrizzlyFilterchainServerTest.groovy

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,6 @@ class GrizzlyFilterchainServerTest extends HttpServerTest<HttpServer> implements
8484
false
8585
}
8686

87-
@Override
88-
boolean testHttpPipelining() {
89-
false
90-
}
91-
9287
@Override
9388
boolean verifyServerSpanEndTime() {
9489
// server spans are ended inside of the controller spans

instrumentation/grizzly-2.0/javaagent/src/test/groovy/GrizzlyTest.groovy

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,6 @@ class GrizzlyTest extends HttpServerTest<HttpServer> implements AgentTestTrait {
6868
false
6969
}
7070

71-
@Override
72-
boolean testHttpPipelining() {
73-
false
74-
}
75-
7671
static class SimpleExceptionMapper implements ExceptionMapper<Throwable> {
7772

7873
@Override

0 commit comments

Comments
 (0)