Simplify grizzly instrumentation, Part 2 (#618)
This commit is contained in:
parent
e2a0504bb2
commit
b3dd5a020b
|
@ -4,12 +4,10 @@ apply plugin: 'org.unbroken-dome.test-sets'
|
||||||
muzzle {
|
muzzle {
|
||||||
pass {
|
pass {
|
||||||
group = "org.glassfish.grizzly"
|
group = "org.glassfish.grizzly"
|
||||||
module = 'grizzly-http-server'
|
module = 'grizzly-http'
|
||||||
versions = "[2.0,)"
|
versions = "[2.0,)"
|
||||||
assertInverse = true
|
assertInverse = true
|
||||||
}
|
}
|
||||||
// Not bothering to test against 1.x since it has a different package name.
|
|
||||||
// https://mvnrepository.com/artifact/com.sun.grizzly/grizzly-http
|
|
||||||
}
|
}
|
||||||
|
|
||||||
testSets {
|
testSets {
|
||||||
|
@ -19,16 +17,13 @@ testSets {
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compileOnly group: 'org.glassfish.grizzly', name: 'grizzly-http-server', version: '2.0'
|
|
||||||
|
|
||||||
compile project(':instrumentation:grizzly-http-2.0')
|
compileOnly group: 'org.glassfish.grizzly', name: 'grizzly-http', version: '2.0'
|
||||||
|
|
||||||
testCompile group: 'javax.xml.bind', name: 'jaxb-api', version: '2.2.3'
|
testCompile group: 'javax.xml.bind', name: 'jaxb-api', version: '2.2.3'
|
||||||
testCompile group: 'javax.ws.rs', name: 'javax.ws.rs-api', version: '2.0'
|
testCompile group: 'javax.ws.rs', name: 'javax.ws.rs-api', version: '2.0'
|
||||||
testCompile group: 'org.glassfish.grizzly', name: 'grizzly-http-server', version: '2.0'
|
|
||||||
testCompile group: 'org.glassfish.jersey.containers', name: 'jersey-container-grizzly2-http', version: '2.0'
|
testCompile group: 'org.glassfish.jersey.containers', name: 'jersey-container-grizzly2-http', version: '2.0'
|
||||||
|
|
||||||
latestDepTestCompile group: 'org.glassfish.grizzly', name: 'grizzly-http-server', version: '+'
|
|
||||||
latestDepTestCompile group: 'org.glassfish.jersey.containers', name: 'jersey-container-grizzly2-http', version: '2.+'
|
latestDepTestCompile group: 'org.glassfish.jersey.containers', name: 'jersey-container-grizzly2-http', version: '2.+'
|
||||||
latestDepTestCompile group: 'org.glassfish.jersey.inject', name: 'jersey-hk2', version: '2.+'
|
latestDepTestCompile group: 'org.glassfish.jersey.inject', name: 'jersey-hk2', version: '2.+'
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,29 +0,0 @@
|
||||||
apply from: "$rootDir/gradle/instrumentation.gradle"
|
|
||||||
apply plugin: 'org.unbroken-dome.test-sets'
|
|
||||||
|
|
||||||
muzzle {
|
|
||||||
pass {
|
|
||||||
group = "org.glassfish.grizzly"
|
|
||||||
module = 'grizzly-http'
|
|
||||||
versions = "[2.0,)"
|
|
||||||
assertInverse = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
testSets {
|
|
||||||
latestDepTest {
|
|
||||||
dirName = 'test'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
|
|
||||||
compileOnly group: 'org.glassfish.grizzly', name: 'grizzly-http', version: '2.0'
|
|
||||||
|
|
||||||
testCompile group: 'javax.xml.bind', name: 'jaxb-api', version: '2.2.3'
|
|
||||||
testCompile group: 'javax.ws.rs', name: 'javax.ws.rs-api', version: '2.0'
|
|
||||||
testCompile group: 'org.glassfish.jersey.containers', name: 'jersey-container-grizzly2-http', version: '2.0'
|
|
||||||
|
|
||||||
latestDepTestCompile group: 'org.glassfish.jersey.containers', name: 'jersey-container-grizzly2-http', version: '2.+'
|
|
||||||
latestDepTestCompile group: 'org.glassfish.jersey.inject', name: 'jersey-hk2', version: '2.+'
|
|
||||||
}
|
|
|
@ -1,102 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright The OpenTelemetry Authors
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import org.glassfish.grizzly.http.server.HttpServer
|
|
||||||
import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory
|
|
||||||
import org.glassfish.jersey.server.ResourceConfig
|
|
||||||
|
|
||||||
import javax.ws.rs.GET
|
|
||||||
import javax.ws.rs.Path
|
|
||||||
import javax.ws.rs.QueryParam
|
|
||||||
import javax.ws.rs.container.AsyncResponse
|
|
||||||
import javax.ws.rs.container.Suspended
|
|
||||||
import javax.ws.rs.core.Response
|
|
||||||
import java.util.concurrent.ExecutorService
|
|
||||||
import java.util.concurrent.Executors
|
|
||||||
|
|
||||||
import static io.opentelemetry.auto.test.base.HttpServerTest.ServerEndpoint.ERROR
|
|
||||||
import static io.opentelemetry.auto.test.base.HttpServerTest.ServerEndpoint.EXCEPTION
|
|
||||||
import static io.opentelemetry.auto.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM
|
|
||||||
import static io.opentelemetry.auto.test.base.HttpServerTest.ServerEndpoint.REDIRECT
|
|
||||||
import static io.opentelemetry.auto.test.base.HttpServerTest.ServerEndpoint.SUCCESS
|
|
||||||
|
|
||||||
class GrizzlyAsyncTest extends GrizzlyTest {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
HttpServer startServer(int port) {
|
|
||||||
ResourceConfig rc = new ResourceConfig()
|
|
||||||
rc.register(SimpleExceptionMapper)
|
|
||||||
rc.register(AsyncServiceResource)
|
|
||||||
GrizzlyHttpServerFactory.createHttpServer(new URI("http://localhost:$port"), rc)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Path("/")
|
|
||||||
static class AsyncServiceResource {
|
|
||||||
private ExecutorService executor = Executors.newSingleThreadExecutor()
|
|
||||||
|
|
||||||
@GET
|
|
||||||
@Path("success")
|
|
||||||
void success(@Suspended AsyncResponse ar) {
|
|
||||||
executor.execute {
|
|
||||||
controller(SUCCESS) {
|
|
||||||
ar.resume(Response.status(SUCCESS.status).entity(SUCCESS.body).build())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@GET
|
|
||||||
@Path("query")
|
|
||||||
Response query_param(@QueryParam("some") String param, @Suspended AsyncResponse ar) {
|
|
||||||
controller(QUERY_PARAM) {
|
|
||||||
ar.resume(Response.status(QUERY_PARAM.status).entity("some=$param".toString()).build())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@GET
|
|
||||||
@Path("redirect")
|
|
||||||
void redirect(@Suspended AsyncResponse ar) {
|
|
||||||
executor.execute {
|
|
||||||
controller(REDIRECT) {
|
|
||||||
ar.resume(Response.status(REDIRECT.status).location(new URI(REDIRECT.body)).build())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@GET
|
|
||||||
@Path("error-status")
|
|
||||||
void error(@Suspended AsyncResponse ar) {
|
|
||||||
executor.execute {
|
|
||||||
controller(ERROR) {
|
|
||||||
ar.resume(Response.status(ERROR.status).entity(ERROR.body).build())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@GET
|
|
||||||
@Path("exception")
|
|
||||||
void exception(@Suspended AsyncResponse ar) {
|
|
||||||
executor.execute {
|
|
||||||
try {
|
|
||||||
controller(EXCEPTION) {
|
|
||||||
throw new Exception(EXCEPTION.body)
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
ar.resume(e)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,41 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright The OpenTelemetry Authors
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import static net.bytebuddy.matcher.ElementMatchers.named;
|
|
||||||
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
|
|
||||||
|
|
||||||
import com.google.auto.service.AutoService;
|
|
||||||
import io.opentelemetry.auto.test.base.HttpServerTestAdvice;
|
|
||||||
import io.opentelemetry.auto.tooling.Instrumenter;
|
|
||||||
import net.bytebuddy.agent.builder.AgentBuilder;
|
|
||||||
|
|
||||||
@AutoService(Instrumenter.class)
|
|
||||||
public class GrizzlyFilterchainServerTestInstrumentation implements Instrumenter {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public AgentBuilder instrument(final AgentBuilder agentBuilder) {
|
|
||||||
return agentBuilder
|
|
||||||
.type(named("org.glassfish.grizzly.http.HttpCodecFilter"))
|
|
||||||
.transform(
|
|
||||||
new AgentBuilder.Transformer.ForAdvice()
|
|
||||||
.advice(
|
|
||||||
named("handleRead")
|
|
||||||
.and(
|
|
||||||
takesArgument(
|
|
||||||
0, named("org.glassfish.grizzly.filterchain.FilterChainContext"))),
|
|
||||||
HttpServerTestAdvice.ServerEntryAdvice.class.getName()));
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,67 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright The OpenTelemetry Authors
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import org.glassfish.grizzly.IOStrategy
|
|
||||||
import org.glassfish.grizzly.http.server.HttpServer
|
|
||||||
import org.glassfish.grizzly.strategies.LeaderFollowerNIOStrategy
|
|
||||||
import org.glassfish.grizzly.strategies.SameThreadIOStrategy
|
|
||||||
import org.glassfish.grizzly.strategies.SimpleDynamicNIOStrategy
|
|
||||||
import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory
|
|
||||||
import org.glassfish.jersey.server.ResourceConfig
|
|
||||||
|
|
||||||
abstract class GrizzlyIOStrategyTest extends GrizzlyTest {
|
|
||||||
|
|
||||||
static {
|
|
||||||
System.setProperty("ota.integration.grizzly-http.enabled", "true")
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
HttpServer startServer(int port) {
|
|
||||||
ResourceConfig rc = new ResourceConfig()
|
|
||||||
rc.register(SimpleExceptionMapper)
|
|
||||||
rc.register(ServiceResource)
|
|
||||||
def server = GrizzlyHttpServerFactory.createHttpServer(new URI("http://localhost:$port"), rc)
|
|
||||||
server.getListener("grizzly").getTransport().setIOStrategy(strategy())
|
|
||||||
// Default in NIOTransportBuilder is WorkerThreadIOStrategy, so don't need to retest that.s
|
|
||||||
return server
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract IOStrategy strategy()
|
|
||||||
}
|
|
||||||
|
|
||||||
class LeaderFollowerTest extends GrizzlyIOStrategyTest {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
IOStrategy strategy() {
|
|
||||||
return LeaderFollowerNIOStrategy.instance
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class SameThreadTest extends GrizzlyIOStrategyTest {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
IOStrategy strategy() {
|
|
||||||
return SameThreadIOStrategy.instance
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class SimpleDynamicTest extends GrizzlyIOStrategyTest {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
IOStrategy strategy() {
|
|
||||||
return SimpleDynamicNIOStrategy.instance
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,109 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright The OpenTelemetry Authors
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import io.opentelemetry.auto.test.base.HttpServerTest
|
|
||||||
import org.glassfish.grizzly.http.server.HttpServer
|
|
||||||
import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory
|
|
||||||
import org.glassfish.jersey.server.ResourceConfig
|
|
||||||
|
|
||||||
import javax.ws.rs.GET
|
|
||||||
import javax.ws.rs.NotFoundException
|
|
||||||
import javax.ws.rs.Path
|
|
||||||
import javax.ws.rs.QueryParam
|
|
||||||
import javax.ws.rs.core.Response
|
|
||||||
import javax.ws.rs.ext.ExceptionMapper
|
|
||||||
|
|
||||||
import static io.opentelemetry.auto.test.base.HttpServerTest.ServerEndpoint.ERROR
|
|
||||||
import static io.opentelemetry.auto.test.base.HttpServerTest.ServerEndpoint.EXCEPTION
|
|
||||||
import static io.opentelemetry.auto.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM
|
|
||||||
import static io.opentelemetry.auto.test.base.HttpServerTest.ServerEndpoint.REDIRECT
|
|
||||||
import static io.opentelemetry.auto.test.base.HttpServerTest.ServerEndpoint.SUCCESS
|
|
||||||
|
|
||||||
class GrizzlyTest extends HttpServerTest<HttpServer> {
|
|
||||||
|
|
||||||
static {
|
|
||||||
System.setProperty("ota.integration.grizzly.enabled", "true")
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
HttpServer startServer(int port) {
|
|
||||||
ResourceConfig rc = new ResourceConfig()
|
|
||||||
rc.register(SimpleExceptionMapper)
|
|
||||||
rc.register(ServiceResource)
|
|
||||||
GrizzlyHttpServerFactory.createHttpServer(new URI("http://localhost:$port"), rc)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
void stopServer(HttpServer server) {
|
|
||||||
server.stop()
|
|
||||||
}
|
|
||||||
|
|
||||||
static class SimpleExceptionMapper implements ExceptionMapper<Throwable> {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
Response toResponse(Throwable exception) {
|
|
||||||
if (exception instanceof NotFoundException) {
|
|
||||||
return exception.getResponse()
|
|
||||||
}
|
|
||||||
Response.status(500).entity(exception.message).build()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Path("/")
|
|
||||||
static class ServiceResource {
|
|
||||||
|
|
||||||
@GET
|
|
||||||
@Path("success")
|
|
||||||
Response success() {
|
|
||||||
controller(SUCCESS) {
|
|
||||||
Response.status(SUCCESS.status).entity(SUCCESS.body).build()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@GET
|
|
||||||
@Path("query")
|
|
||||||
Response query_param(@QueryParam("some") String param) {
|
|
||||||
controller(QUERY_PARAM) {
|
|
||||||
Response.status(QUERY_PARAM.status).entity("some=$param".toString()).build()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@GET
|
|
||||||
@Path("redirect")
|
|
||||||
Response redirect() {
|
|
||||||
controller(REDIRECT) {
|
|
||||||
Response.status(REDIRECT.status).location(new URI(REDIRECT.body)).build()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@GET
|
|
||||||
@Path("error-status")
|
|
||||||
Response error() {
|
|
||||||
controller(ERROR) {
|
|
||||||
Response.status(ERROR.status).entity(ERROR.body).build()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@GET
|
|
||||||
@Path("exception")
|
|
||||||
Response exception() {
|
|
||||||
controller(EXCEPTION) {
|
|
||||||
throw new Exception(EXCEPTION.body)
|
|
||||||
}
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -68,7 +68,6 @@ include ':instrumentation:geode-1.4'
|
||||||
include ':instrumentation:google-http-client-1.19'
|
include ':instrumentation:google-http-client-1.19'
|
||||||
include ':instrumentation:grizzly-2.0'
|
include ':instrumentation:grizzly-2.0'
|
||||||
include ':instrumentation:grizzly-client-1.9'
|
include ':instrumentation:grizzly-client-1.9'
|
||||||
include ':instrumentation:grizzly-http-2.0'
|
|
||||||
include ':instrumentation:grpc-1.5'
|
include ':instrumentation:grpc-1.5'
|
||||||
include ':instrumentation:hibernate:hibernate-3.3'
|
include ':instrumentation:hibernate:hibernate-3.3'
|
||||||
include ':instrumentation:hibernate:hibernate-4.0'
|
include ':instrumentation:hibernate:hibernate-4.0'
|
||||||
|
|
Loading…
Reference in New Issue