Implement concurrent test for Netty http server
MODIFY
instrumentation/netty/netty-3.8/javaagent/src/latestDepTest/groovy/Netty38ServerTest.groovy
instrumentation/netty/netty-3.8/javaagent/src/latestDepTest/groovy/Netty38ServerTest.groovy
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION
+import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.INDEXED_CHILD
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.NOT_FOUND
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT
@@ -15,6 +16,7 @@ import static org.jboss.netty.handler.codec.http.HttpHeaders.Names.CONTENT_TYPE
import static org.jboss.netty.handler.codec.http.HttpHeaders.Names.LOCATION
import static org.jboss.netty.handler.codec.http.HttpVersion.HTTP_1_1
+import io.opentelemetry.api.trace.Span
import io.opentelemetry.instrumentation.test.AgentTestTrait
import io.opentelemetry.instrumentation.test.base.HttpServerTest
import org.jboss.netty.bootstrap.ServerBootstrap
@@ -36,6 +38,7 @@ import org.jboss.netty.handler.codec.http.HttpRequest
import org.jboss.netty.handler.codec.http.HttpResponse
import org.jboss.netty.handler.codec.http.HttpResponseStatus
import org.jboss.netty.handler.codec.http.HttpServerCodec
+import org.jboss.netty.handler.codec.http.QueryStringDecoder
import org.jboss.netty.handler.logging.LoggingHandler
import org.jboss.netty.logging.InternalLogLevel
import org.jboss.netty.logging.InternalLoggerFactory
@@ -71,6 +74,11 @@ class Netty38ServerTest extends HttpServerTest<ServerBootstrap> implements Agent
response = new DefaultHttpResponse(HTTP_1_1, HttpResponseStatus.valueOf(endpoint.status))
response.setContent(responseContent)
break
+ case INDEXED_CHILD:
+ QueryStringDecoder queryStringDecoder = new QueryStringDecoder(uri)
+ Span.current().setAttribute("test.request.id", queryStringDecoder.getParameters().get("id").find() as long)
+ response = new DefaultHttpResponse(HTTP_1_1, HttpResponseStatus.valueOf(endpoint.status))
+ break
case QUERY_PARAM:
responseContent = ChannelBuffers.copiedBuffer(uri.query, CharsetUtil.UTF_8)
response = new DefaultHttpResponse(HTTP_1_1, HttpResponseStatus.valueOf(endpoint.status))
@@ -145,4 +153,9 @@ class Netty38ServerTest extends HttpServerTest<ServerBootstrap> implements Agent
String expectedServerSpanName(ServerEndpoint endpoint) {
return "HTTP GET"
}
+
+ @Override
+ boolean testConcurrency() {
+ return true
+ }
}

MODIFY
instrumentation/netty/netty-3.8/javaagent/src/test/groovy/Netty38ServerTest.groovy
instrumentation/netty/netty-3.8/javaagent/src/test/groovy/Netty38ServerTest.groovy
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION
+import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.INDEXED_CHILD
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.NOT_FOUND
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT
@@ -15,6 +16,7 @@ import static org.jboss.netty.handler.codec.http.HttpHeaders.Names.CONTENT_TYPE
import static org.jboss.netty.handler.codec.http.HttpHeaders.Names.LOCATION
import static org.jboss.netty.handler.codec.http.HttpVersion.HTTP_1_1
+import io.opentelemetry.api.trace.Span
import io.opentelemetry.instrumentation.test.AgentTestTrait
import io.opentelemetry.instrumentation.test.base.HttpServerTest
import org.jboss.netty.bootstrap.ServerBootstrap
@@ -36,6 +38,7 @@ import org.jboss.netty.handler.codec.http.HttpRequest
import org.jboss.netty.handler.codec.http.HttpResponse
import org.jboss.netty.handler.codec.http.HttpResponseStatus
import org.jboss.netty.handler.codec.http.HttpServerCodec
+import org.jboss.netty.handler.codec.http.QueryStringDecoder
import org.jboss.netty.handler.logging.LoggingHandler
import org.jboss.netty.logging.InternalLogLevel
import org.jboss.netty.logging.InternalLoggerFactory
@@ -71,6 +74,11 @@ class Netty38ServerTest extends HttpServerTest<ServerBootstrap> implements Agent
response = new DefaultHttpResponse(HTTP_1_1, HttpResponseStatus.valueOf(endpoint.status))
response.setContent(responseContent)
break
+ case INDEXED_CHILD:
+ QueryStringDecoder queryStringDecoder = new QueryStringDecoder(uri)
+ Span.current().setAttribute("test.request.id", queryStringDecoder.getParameters().get("id").find() as long)
+ response = new DefaultHttpResponse(HTTP_1_1, HttpResponseStatus.valueOf(endpoint.status))
+ break
case QUERY_PARAM:
responseContent = ChannelBuffers.copiedBuffer(uri.query, CharsetUtil.UTF_8)
response = new DefaultHttpResponse(HTTP_1_1, HttpResponseStatus.valueOf(endpoint.status))
@@ -145,4 +153,9 @@ class Netty38ServerTest extends HttpServerTest<ServerBootstrap> implements Agent
String expectedServerSpanName(ServerEndpoint endpoint) {
return "HTTP GET"
}
+
+ @Override
+ boolean testConcurrency() {
+ return true
+ }
}

MODIFY
instrumentation/netty/netty-4.0/javaagent/src/test/groovy/Netty40ServerTest.groovy
instrumentation/netty/netty-4.0/javaagent/src/test/groovy/Netty40ServerTest.groovy
@@ -9,6 +9,7 @@ import static io.netty.handler.codec.http.HttpResponseStatus.INTERNAL_SERVER_ERR
import static io.netty.handler.codec.http.HttpVersion.HTTP_1_1
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION
+import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.INDEXED_CHILD
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.NOT_FOUND
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT
@@ -31,9 +32,11 @@ import io.netty.handler.codec.http.HttpRequest
import io.netty.handler.codec.http.HttpRequestDecoder
import io.netty.handler.codec.http.HttpResponseEncoder
import io.netty.handler.codec.http.HttpResponseStatus
+import io.netty.handler.codec.http.QueryStringDecoder
import io.netty.handler.logging.LogLevel
import io.netty.handler.logging.LoggingHandler
import io.netty.util.CharsetUtil
+import io.opentelemetry.api.trace.Span
import io.opentelemetry.instrumentation.test.AgentTestTrait
import io.opentelemetry.instrumentation.test.base.HttpServerTest
@@ -62,13 +65,18 @@ class Netty40ServerTest extends HttpServerTest<EventLoopGroup> implements AgentT
ServerEndpoint endpoint = ServerEndpoint.forPath(uri.path)
ctx.write controller(endpoint) {
ByteBuf content = null
- FullHttpResponse response = null
+ FullHttpResponse response
switch (endpoint) {
case SUCCESS:
case ERROR:
content = Unpooled.copiedBuffer(endpoint.body, CharsetUtil.UTF_8)
response = new DefaultFullHttpResponse(HTTP_1_1, HttpResponseStatus.valueOf(endpoint.status), content)
break
+ case INDEXED_CHILD:
+ QueryStringDecoder queryStringDecoder = new QueryStringDecoder(uri)
+ Span.current().setAttribute("test.request.id", queryStringDecoder.parameters().get("id").find() as long)
+ response = new DefaultFullHttpResponse(HTTP_1_1, HttpResponseStatus.valueOf(endpoint.status))
+ break
case QUERY_PARAM:
content = Unpooled.copiedBuffer(uri.query, CharsetUtil.UTF_8)
response = new DefaultFullHttpResponse(HTTP_1_1, HttpResponseStatus.valueOf(endpoint.status), content)
@@ -117,4 +125,9 @@ class Netty40ServerTest extends HttpServerTest<EventLoopGroup> implements AgentT
String expectedServerSpanName(ServerEndpoint endpoint) {
return "HTTP GET"
}
+
+ @Override
+ boolean testConcurrency() {
+ return true
+ }
}

MODIFY
instrumentation/netty/netty-4.1/javaagent/src/test/groovy/Netty41ServerTest.groovy
instrumentation/netty/netty-4.1/javaagent/src/test/groovy/Netty41ServerTest.groovy
@@ -9,6 +9,7 @@ import static io.netty.handler.codec.http.HttpResponseStatus.INTERNAL_SERVER_ERR
import static io.netty.handler.codec.http.HttpVersion.HTTP_1_1
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION
+import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.INDEXED_CHILD
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.NOT_FOUND
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM
import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT
@@ -30,9 +31,11 @@ import io.netty.handler.codec.http.HttpHeaderNames
import io.netty.handler.codec.http.HttpRequest
import io.netty.handler.codec.http.HttpResponseStatus
import io.netty.handler.codec.http.HttpServerCodec
+import io.netty.handler.codec.http.QueryStringDecoder
import io.netty.handler.logging.LogLevel
import io.netty.handler.logging.LoggingHandler
import io.netty.util.CharsetUtil
+import io.opentelemetry.api.trace.Span
import io.opentelemetry.instrumentation.test.AgentTestTrait
import io.opentelemetry.instrumentation.test.base.HttpServerTest
@@ -57,17 +60,22 @@ class Netty41ServerTest extends HttpServerTest<EventLoopGroup> implements AgentT
pipeline.addLast([
channelRead0 : { ctx, msg ->
if (msg instanceof HttpRequest) {
- def uri = URI.create((msg as HttpRequest).uri)
+ def uri = URI.create((msg as HttpRequest).uri())
ServerEndpoint endpoint = ServerEndpoint.forPath(uri.path)
ctx.write controller(endpoint) {
ByteBuf content = null
- FullHttpResponse response = null
+ FullHttpResponse response
switch (endpoint) {
case SUCCESS:
case ERROR:
content = Unpooled.copiedBuffer(endpoint.body, CharsetUtil.UTF_8)
response = new DefaultFullHttpResponse(HTTP_1_1, HttpResponseStatus.valueOf(endpoint.status), content)
break
+ case INDEXED_CHILD:
+ QueryStringDecoder queryStringDecoder = new QueryStringDecoder(uri)
+ Span.current().setAttribute("test.request.id", queryStringDecoder.parameters().get("id").find() as long)
+ response = new DefaultFullHttpResponse(HTTP_1_1, HttpResponseStatus.valueOf(endpoint.status))
+ break
case QUERY_PARAM:
content = Unpooled.copiedBuffer(uri.query, CharsetUtil.UTF_8)
response = new DefaultFullHttpResponse(HTTP_1_1, HttpResponseStatus.valueOf(endpoint.status), content)
@@ -116,4 +124,9 @@ class Netty41ServerTest extends HttpServerTest<EventLoopGroup> implements AgentT
String expectedServerSpanName(ServerEndpoint endpoint) {
return "HTTP GET"
}
+
+ @Override
+ boolean testConcurrency() {
+ return true
+ }
}

Implement concurrent test for Netty http server (#2750)