diff --git a/opentracing-specialagent/pom.xml b/opentracing-specialagent/pom.xml index b06113544..52c24bdc5 100644 --- a/opentracing-specialagent/pom.xml +++ b/opentracing-specialagent/pom.xml @@ -470,13 +470,6 @@ true provided - - io.opentracing.contrib.specialagent.rule - mule-4-http-service - ${project.version} - true - provided - io.opentracing.contrib.specialagent.rule mule-4-module-artifact diff --git a/rule/grizzly-http-server/pom.xml b/rule/grizzly-http-server/pom.xml index 0dc98daf8..cd2c1b4b4 100644 --- a/rule/grizzly-http-server/pom.xml +++ b/rule/grizzly-http-server/pom.xml @@ -28,7 +28,7 @@ grizzly:http-server 2.3.35 - 0.1.3 + 0.2.0 @@ -42,15 +42,10 @@ - - org.glassfish.grizzly - grizzly-framework - org.glassfish.grizzly:grizzly-framework:[${min.version},] - org.glassfish.grizzly grizzly-http - org.glassfish.grizzly:grizzly-framework:[${min.version},] + org.glassfish.grizzly:grizzly-http:[${min.version},] @@ -76,13 +71,6 @@ test-jar test - - org.glassfish.grizzly - grizzly-framework - ${min.version} - true - provided - org.glassfish.grizzly grizzly-http diff --git a/rule/grizzly-http-server/src/main/java/io/opentracing/contrib/specialagent/rule/grizzly/http/server/FilterChainAgentIntercept.java b/rule/grizzly-http-server/src/main/java/io/opentracing/contrib/specialagent/rule/grizzly/http/server/FilterChainAgentIntercept.java deleted file mode 100644 index 627813d77..000000000 --- a/rule/grizzly-http-server/src/main/java/io/opentracing/contrib/specialagent/rule/grizzly/http/server/FilterChainAgentIntercept.java +++ /dev/null @@ -1,32 +0,0 @@ -/* Copyright 2019 The OpenTracing 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. - */ - -package io.opentracing.contrib.specialagent.rule.grizzly.http.server; - -import org.glassfish.grizzly.filterchain.FilterChainBuilder; - -import io.opentracing.contrib.grizzly.http.server.TracedFilterChainBuilder; -import io.opentracing.contrib.specialagent.AgentRuleUtil; -import io.opentracing.util.GlobalTracer; -import net.bytebuddy.asm.Advice; - -public class FilterChainAgentIntercept { - public static Object enter(final @Advice.This Object thiz) { - if (AgentRuleUtil.callerEquals(1, 3, "io.opentracing.contrib.grizzly.http.server.TracedFilterChainBuilder.build")) - return null; - - return new TracedFilterChainBuilder((FilterChainBuilder)thiz, GlobalTracer.get()).build(); - } -} \ No newline at end of file diff --git a/rule/grizzly-http-server/src/main/java/io/opentracing/contrib/specialagent/rule/grizzly/http/server/FilterChainAgentRule.java b/rule/grizzly-http-server/src/main/java/io/opentracing/contrib/specialagent/rule/grizzly/http/server/FilterChainAgentRule.java deleted file mode 100644 index d7964c0a3..000000000 --- a/rule/grizzly-http-server/src/main/java/io/opentracing/contrib/specialagent/rule/grizzly/http/server/FilterChainAgentRule.java +++ /dev/null @@ -1,72 +0,0 @@ -/* Copyright 2019 The OpenTracing 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. - */ - -package io.opentracing.contrib.specialagent.rule.grizzly.http.server; - -import static net.bytebuddy.matcher.ElementMatchers.*; - -import io.opentracing.contrib.specialagent.AgentRule; -import io.opentracing.contrib.specialagent.EarlyReturnException; -import net.bytebuddy.agent.builder.AgentBuilder; -import net.bytebuddy.agent.builder.AgentBuilder.Identified.Narrowable; -import net.bytebuddy.agent.builder.AgentBuilder.Transformer; -import net.bytebuddy.asm.Advice; -import net.bytebuddy.description.type.TypeDescription; -import net.bytebuddy.dynamic.DynamicType.Builder; -import net.bytebuddy.implementation.bytecode.assign.Assigner.Typing; -import net.bytebuddy.utility.JavaModule; - -public class FilterChainAgentRule extends AgentRule { - @Override - public AgentBuilder[] buildAgentUnchained(final AgentBuilder builder) { - final Narrowable narrowable = builder.type(hasSuperType(named("org.glassfish.grizzly.filterchain.FilterChainBuilder$StatelessFilterChainBuilder"))); - return new AgentBuilder[] { - narrowable - .transform(new Transformer() { - @Override - public Builder transform(final Builder builder, final TypeDescription typeDescription, final ClassLoader classLoader, final JavaModule module) { - return builder.visit(advice(typeDescription).to(OnEnter.class).on(named("build"))); - }}), - narrowable - .transform(new Transformer() { - @Override - public Builder transform(final Builder builder, final TypeDescription typeDescription, final ClassLoader classLoader, final JavaModule module) { - return builder.visit(advice(typeDescription).to(OnExit.class).on(named("build"))); - }})}; - } - - public static class OnEnter { - @Advice.OnMethodEnter - public static void enter(final @ClassName String className, final @Advice.Origin String origin, final @Advice.This Object thiz) throws EarlyReturnException { - if (!isAllowed(className, origin)) - return; - - final Object filterChain = FilterChainAgentIntercept.enter(thiz); - if (filterChain != null) - throw new EarlyReturnException(filterChain); - } - } - - public static class OnExit { - @SuppressWarnings("unused") - @Advice.OnMethodExit(onThrowable = Throwable.class) - public static void exit(@Advice.Return(readOnly = false, typing = Typing.DYNAMIC) Object returned, @Advice.Thrown(readOnly = false, typing = Typing.DYNAMIC) Throwable thrown) { - if (thrown instanceof EarlyReturnException) { - returned = ((EarlyReturnException)thrown).getReturnValue(); - thrown = null; - } - } - } -} \ No newline at end of file diff --git a/rule/grizzly-http-server/src/main/java/io/opentracing/contrib/specialagent/rule/grizzly/http/server/HttpServerFilterIntercept.java b/rule/grizzly-http-server/src/main/java/io/opentracing/contrib/specialagent/rule/grizzly/http/server/HttpServerFilterIntercept.java new file mode 100644 index 000000000..794a62658 --- /dev/null +++ b/rule/grizzly-http-server/src/main/java/io/opentracing/contrib/specialagent/rule/grizzly/http/server/HttpServerFilterIntercept.java @@ -0,0 +1,70 @@ +package io.opentracing.contrib.specialagent.rule.grizzly.http.server; + +import io.opentracing.Span; +import io.opentracing.SpanContext; +import io.opentracing.Tracer; +import io.opentracing.contrib.grizzly.http.server.GizzlyHttpRequestPacketAdapter; +import io.opentracing.contrib.grizzly.http.server.GrizzlyServerSpanDecorator; +import io.opentracing.propagation.Format; +import io.opentracing.propagation.TextMap; +import io.opentracing.util.GlobalTracer; +import org.glassfish.grizzly.filterchain.FilterChainContext; +import org.glassfish.grizzly.filterchain.NextAction; +import org.glassfish.grizzly.http.HttpContent; +import org.glassfish.grizzly.http.HttpRequestPacket; +import org.glassfish.grizzly.http.HttpResponsePacket; + +public class HttpServerFilterIntercept { + public static void onHandleReadExit( + final Object ctxObj, + Object toReturn) { + + FilterChainContext ctx = (FilterChainContext) ctxObj; + + // If not continuing to process + // See: org.glassfish.grizzly.filterchain.InvokeAction.TYPE + // If we have have already started a span for this request + if (!(ctx.getMessage() instanceof HttpContent) || ((NextAction) toReturn).type() != 0 || SpanAssociations.get().hasSpanFor(ctx)) { + return; + } + + Tracer tracer = GlobalTracer.get(); + final HttpRequestPacket request = (HttpRequestPacket) ((HttpContent) ctx.getMessage()).getHttpHeader(); + + TextMap adapter = new GizzlyHttpRequestPacketAdapter(request); + SpanContext extractedContext = tracer.extract(Format.Builtin.HTTP_HEADERS, + adapter); + + final Span span = tracer.buildSpan("HTTP::" + request.getMethod().getMethodString()) + .ignoreActiveSpan() + .asChildOf(extractedContext) + .start(); + + GrizzlyServerSpanDecorator.STANDARD_TAGS.onRequest(request, span); + ctx.addCompletionListener(new SpanCompletionListener(span)); + SpanAssociations.get().associateSpan(ctx, span); + } + + public static void onPrepareResponse( + final Object ctx, + final Object response) { + Span toTag = SpanAssociations.get().retrieveSpan(ctx); + if (toTag != null) { + GrizzlyServerSpanDecorator.STANDARD_TAGS.onResponse((HttpResponsePacket) response, toTag); + } + } + + public static class SpanCompletionListener implements FilterChainContext.CompletionListener { + private final Span span; + + public SpanCompletionListener(Span span) { + this.span = span; + } + + @Override + public void onComplete(FilterChainContext context) { + span.finish(); + SpanAssociations.get().dispose(context); + } + } +} diff --git a/rule/grizzly-http-server/src/main/java/io/opentracing/contrib/specialagent/rule/grizzly/http/server/HttpServerFilterRule.java b/rule/grizzly-http-server/src/main/java/io/opentracing/contrib/specialagent/rule/grizzly/http/server/HttpServerFilterRule.java new file mode 100644 index 000000000..22d4993a9 --- /dev/null +++ b/rule/grizzly-http-server/src/main/java/io/opentracing/contrib/specialagent/rule/grizzly/http/server/HttpServerFilterRule.java @@ -0,0 +1,124 @@ +package io.opentracing.contrib.specialagent.rule.grizzly.http.server; + +import io.opentracing.contrib.specialagent.Level; +import io.opentracing.contrib.specialagent.Logger; +import io.opentracing.Scope; +import io.opentracing.contrib.specialagent.AgentRule; +import net.bytebuddy.agent.builder.AgentBuilder; +import net.bytebuddy.asm.Advice; +import net.bytebuddy.description.type.TypeDescription; +import net.bytebuddy.dynamic.DynamicType; +import net.bytebuddy.implementation.bytecode.assign.Assigner; +import net.bytebuddy.utility.JavaModule; + +import static net.bytebuddy.matcher.ElementMatchers.*; + +public class HttpServerFilterRule extends AgentRule { + public static final Logger logger = Logger.getLogger(HttpServerFilterRule.class); + private static final String FILTER_CHAIN_CONTEXT = "org.glassfish.grizzly.filterchain.FilterChainContext"; + private static final String HANDLE_READ = "handleRead"; + + @Override + public AgentBuilder buildAgentChainedGlobal1(final AgentBuilder builder) { + return builder + .type(named("org.glassfish.grizzly.http.HttpServerFilter")) + .transform(new AgentBuilder.Transformer() { + @Override + public DynamicType.Builder transform(final DynamicType.Builder builder, final TypeDescription typeDescription, final ClassLoader classLoader, final JavaModule module) { + return builder.visit(advice(typeDescription).to(HandleReadAdvice.class).on(named(HANDLE_READ) + .and(takesArgument(0, named(FILTER_CHAIN_CONTEXT))))); + } + }) + .transform(new AgentBuilder.Transformer() { + @Override + public DynamicType.Builder transform(final DynamicType.Builder builder, final TypeDescription typeDescription, final ClassLoader classLoader, final JavaModule module) { + return builder.visit(advice(typeDescription).to(PrepareResponseAdvice.class).on(named("prepareResponse") + .and(takesArgument(0, named(FILTER_CHAIN_CONTEXT))) + .and(takesArgument(2, named("org.glassfish.grizzly.http.HttpResponsePacket"))))); + } + }) + + .type(hasSuperClass(named("org.glassfish.grizzly.filterchain.BaseFilter")) + // common http server filters + .and(not(named("org.glassfish.grizzly.filterchain.TransportFilter") + .or(named("org.glassfish.grizzly.nio.transport.TCPNIOTransportFilter")) + .or(named("org.glassfish.grizzly.http.HttpServerFilter")) + .or(named("org.glassfish.grizzly.http.HttpCodecFilter")) + .or(named("org.glassfish.grizzly.utils.IdleTimeoutFilter")) + // common http client filters + .or(named("com.ning.http.client.providers.grizzly.AsyncHttpClientFilter")) + .or(named("org.glassfish.grizzly.websockets.WebSocketClientFilter")) + .or(hasSuperClass(named("org.glassfish.grizzly.http.HttpClientFilter")))))) + .transform(new AgentBuilder.Transformer() { + @Override + public DynamicType.Builder transform(final DynamicType.Builder builder, final TypeDescription typeDescription, final ClassLoader classLoader, final JavaModule module) { + return builder.visit(advice(typeDescription).to(WorkerHandleReadAdvice.class).on(named(HANDLE_READ) + .and(takesArgument(0, named(FILTER_CHAIN_CONTEXT))))); + } + }); + } + + public static class HandleReadAdvice { + @Advice.OnMethodExit + public static void onExit( + final @ClassName String className, + final @Advice.Origin String origin, + @Advice.Argument(0) final Object ctx, + @Advice.Return Object toReturn) { + if (isAllowed(className, origin)) + HttpServerFilterIntercept.onHandleReadExit(ctx, toReturn); + } + } + + public static class WorkerHandleReadAdvice { + @Advice.OnMethodEnter + public static void onEnter( + final @ClassName String className, + final @Advice.Origin String origin, + final @Advice.This Object thiz, + @Advice.Argument(value = 0, typing = Assigner.Typing.DYNAMIC) final Object ctx, + @Advice.Local("scope") Scope scope) { + + if (hackShouldFilter(thiz)) + return; + + if (isAllowed(className, origin)) + scope = WorkerFilterIntercept.onHandleReadEnter(ctx); + } + + @Advice.OnMethodExit + public static void onExit( + final @ClassName String className, + final @Advice.Origin String origin, + final @Advice.This Object thiz, + @Advice.Local("scope") Scope scope) { + + if (hackShouldFilter(thiz)) + return; + + if (isAllowed(className, origin)) + WorkerFilterIntercept.onHandleReadExit(scope); + } + } + + public static class PrepareResponseAdvice { + @Advice.OnMethodExit + public static void onExit( + final @ClassName String className, + final @Advice.Origin String origin, + @Advice.Argument(value = 0, typing = Assigner.Typing.DYNAMIC) final Object ctx, + @Advice.Argument(value = 2, typing = Assigner.Typing.DYNAMIC) final Object response) { + + if (isAllowed(className, origin)) + HttpServerFilterIntercept.onPrepareResponse(ctx, response); + } + + } + + public static boolean hackShouldFilter(Object thiz) { + // TODO: 7/11/20 figure out why these are not filtered at TypeDescription + logger.log(Level.FINER, "Checking predicate for potential worker filter " + thiz.getClass().getName()); + return "com.ning.http.client.providers.grizzly.AsyncHttpClientFilter".equals(thiz.getClass().getName()) || + "org.glassfish.grizzly.websockets.WebSocketClientFilter".equals(thiz.getClass().getName()); + } +} diff --git a/rule/grizzly-http-server/src/main/java/io/opentracing/contrib/specialagent/rule/grizzly/http/server/SpanAssociations.java b/rule/grizzly-http-server/src/main/java/io/opentracing/contrib/specialagent/rule/grizzly/http/server/SpanAssociations.java new file mode 100644 index 000000000..fe90f66ef --- /dev/null +++ b/rule/grizzly-http-server/src/main/java/io/opentracing/contrib/specialagent/rule/grizzly/http/server/SpanAssociations.java @@ -0,0 +1,71 @@ +/* Copyright 2020 The OpenTracing 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. + */ + +package io.opentracing.contrib.specialagent.rule.grizzly.http.server; + +import io.opentracing.Span; + +import java.util.Collections; +import java.util.Map; +import java.util.WeakHashMap; + +/** + * This class provides span context capabilities. Based on + * https://github.com/opentracing-contrib/java-agent/blob/release-0.5.0/opentracing-agent/src/main/java/io/opentracing/contrib/agent/OpenTracingHelper.java + */ +public class SpanAssociations { + + private static final SpanAssociations INSTANCE = new SpanAssociations(); + private static final Map spanAssociations = Collections.synchronizedMap(new WeakHashMap()); + + private SpanAssociations() { + } + + public static SpanAssociations get() { + return INSTANCE; + } + + /** + * This method establishes an association between an application object + * (i.e. the subject of the instrumentation) and a span. Once the + * application object is no longer being used, the association with the + * span will automatically be discarded. + * + * @param obj The application object to be associated with the span + * @param span The span + */ + public void associateSpan(Object obj, Span span) { + spanAssociations.put(obj, span); + } + + /** + * This method retrieves the span associated with the supplied application + * object. + * + * @param obj The application object + * @return The span, or null if no associated span exists + */ + public Span retrieveSpan(Object obj) { + return spanAssociations.get(obj); + } + + public boolean hasSpanFor(Object obj) { + return spanAssociations.containsKey(obj); + } + + public void dispose(Object obj) { + spanAssociations.remove(obj); + } +} diff --git a/rule/grizzly-http-server/src/main/java/io/opentracing/contrib/specialagent/rule/grizzly/http/server/WorkerFilterIntercept.java b/rule/grizzly-http-server/src/main/java/io/opentracing/contrib/specialagent/rule/grizzly/http/server/WorkerFilterIntercept.java new file mode 100644 index 000000000..618caa43a --- /dev/null +++ b/rule/grizzly-http-server/src/main/java/io/opentracing/contrib/specialagent/rule/grizzly/http/server/WorkerFilterIntercept.java @@ -0,0 +1,23 @@ +package io.opentracing.contrib.specialagent.rule.grizzly.http.server; + +import io.opentracing.Scope; +import io.opentracing.Span; +import io.opentracing.util.GlobalTracer; + +public class WorkerFilterIntercept { + public static Scope onHandleReadEnter( + final Object ctx) { + Span span = SpanAssociations.get().retrieveSpan(ctx); + if (span != null) { + return GlobalTracer.get().scopeManager().activate(span); + } + + return null; + } + + public static void onHandleReadExit(Scope scope) { + if (scope != null) { + scope.close(); + } + } +} diff --git a/rule/grizzly-http-server/src/main/resources/otarules.mf b/rule/grizzly-http-server/src/main/resources/otarules.mf index 86ae0031b..57b1b041a 100644 --- a/rule/grizzly-http-server/src/main/resources/otarules.mf +++ b/rule/grizzly-http-server/src/main/resources/otarules.mf @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -io.opentracing.contrib.specialagent.rule.grizzly.http.server.FilterChainAgentRule \ No newline at end of file +io.opentracing.contrib.specialagent.rule.grizzly.http.server.HttpServerFilterRule diff --git a/rule/grizzly-http-server/src/test/java/io/opentracing/contrib/specialagent/rule/grizzly/http/server/HttpServerTest.java b/rule/grizzly-http-server/src/test/java/io/opentracing/contrib/specialagent/rule/grizzly/http/server/HttpServerTest.java index a105334df..b8e1ac64a 100644 --- a/rule/grizzly-http-server/src/test/java/io/opentracing/contrib/specialagent/rule/grizzly/http/server/HttpServerTest.java +++ b/rule/grizzly-http-server/src/test/java/io/opentracing/contrib/specialagent/rule/grizzly/http/server/HttpServerTest.java @@ -15,13 +15,15 @@ package io.opentracing.contrib.specialagent.rule.grizzly.http.server; -import static org.glassfish.grizzly.http.server.NetworkListener.*; +import static org.glassfish.grizzly.http.server.NetworkListener.DEFAULT_NETWORK_HOST; import static org.junit.Assert.*; import java.io.IOException; import java.net.URL; import java.util.List; +import com.ning.http.client.AsyncHttpClient; +import io.opentracing.contrib.grizzly.http.server.AbstractHttpTest; import org.glassfish.grizzly.http.server.HttpHandler; import org.glassfish.grizzly.http.server.HttpServer; import org.glassfish.grizzly.http.server.NetworkListener; @@ -32,9 +34,6 @@ import org.junit.Test; import org.junit.runner.RunWith; -import com.ning.http.client.AsyncHttpClient; - -import io.opentracing.contrib.grizzly.http.server.AbstractHttpTest; import io.opentracing.contrib.specialagent.AgentRunner; import io.opentracing.mock.MockSpan; import io.opentracing.mock.MockTracer; @@ -72,7 +71,7 @@ public void service(final Request request, final Response response) throws Excep response.setStatus(201); } }); - + try (final AsyncHttpClient client = new AsyncHttpClient()) { final com.ning.http.client.Response response = client.prepareGet(new URL("http", LOCALHOST, PORT, "/").toString()).execute().get(); assertEquals(201, response.getStatusCode()); diff --git a/rule/mule-4-http-service/README.md b/rule/mule-4-http-service/README.md deleted file mode 100644 index 88980a107..000000000 --- a/rule/mule-4-http-service/README.md +++ /dev/null @@ -1,11 +0,0 @@ -# SpecialAgent Rule for Mule 4 HTTP Service - -**Rule Name:** `mule:http-service:4` - -## Compatibility - -```xml -org.mule.runtime -mule-module-artifact -[4.2.2,4.0.0-M5),(4.0.0-M5.2,LATEST] -``` \ No newline at end of file diff --git a/rule/mule-4-http-service/pom.xml b/rule/mule-4-http-service/pom.xml deleted file mode 100644 index c997eade0..000000000 --- a/rule/mule-4-http-service/pom.xml +++ /dev/null @@ -1,135 +0,0 @@ - - - 4.0.0 - - io.opentracing.contrib.specialagent.rule - rule - 1.7.4-SNAPSHOT - - mule-4-http-service - SpecialAgent Rule for Mule 4 HTTP Service - - 1.8 - 1.8 - mule:http-service:4 - 1.4.7 - org.mule.services:mule-service-http:[${min.version},4.0.0-M5),(4.0.0-M5.2,] - 0.1.3 - 4.2.2 - 2.11.2 - - - - org.mule.services - mule-service-http - ${min.version} - true - provided - - - - io.opentracing.contrib - opentracing-grizzly-http-server - ${version.opentracing.grizzly.http.server} - true - - - io.opentracing.contrib - opentracing-grizzly-http-server - ${version.opentracing.grizzly.http.server} - test-jar - test - - - org.mule.runtime - mule-core - ${version.mule} - true - test - - - org.mule.runtime - mule-extensions-api - 1.2.2 - true - test - - - org.mule.runtime - mule-service-http-api - ${version.mule} - true - test - - - org.mule.tests - mule-tests-unit - ${version.mule} - true - test - - - org.apache.logging.log4j - log4j-api - ${version.apache-logging} - true - test - - - org.apache.logging.log4j - log4j-core - ${version.apache-logging} - true - test - - - org.apache.httpcomponents - fluent-hc - 4.5.2 - true - test - - - - - anypoint-exchange-v2 - Anypoint Exchange - https://maven.anypoint.mulesoft.com/api/v2/maven - default - - - mulesoft-releases - MuleSoft Releases Repository - https://repository.mulesoft.org/releases/ - default - - - - - mulesoft-releases - mulesoft release repository - default - https://repository.mulesoft.org/releases/ - - false - - - - \ No newline at end of file diff --git a/rule/mule-4-http-service/src/main/java/io/opentracing/contrib/specialagent/rule/mule4/service/http/MuleFilterChainAgentIntercept.java b/rule/mule-4-http-service/src/main/java/io/opentracing/contrib/specialagent/rule/mule4/service/http/MuleFilterChainAgentIntercept.java deleted file mode 100644 index 5a1f90cef..000000000 --- a/rule/mule-4-http-service/src/main/java/io/opentracing/contrib/specialagent/rule/mule4/service/http/MuleFilterChainAgentIntercept.java +++ /dev/null @@ -1,31 +0,0 @@ -/* Copyright 2019 The OpenTracing 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. - */ - -package io.opentracing.contrib.specialagent.rule.mule4.service.http; - -import org.glassfish.grizzly.filterchain.FilterChainBuilder; - -import io.opentracing.contrib.specialagent.AgentRuleUtil; -import io.opentracing.util.GlobalTracer; -import net.bytebuddy.asm.Advice; - -public class MuleFilterChainAgentIntercept { - public static Object enter(final @Advice.This Object thiz) { - if (AgentRuleUtil.callerEquals(1, 3, "io.opentracing.contrib.grizzly.http.server.TracedFilterChainBuilder.build")) - return null; - - return new TracedMuleFilterChainBuilder((FilterChainBuilder)thiz, GlobalTracer.get()).build(); - } -} \ No newline at end of file diff --git a/rule/mule-4-http-service/src/main/java/io/opentracing/contrib/specialagent/rule/mule4/service/http/MuleFilterChainAgentRule.java b/rule/mule-4-http-service/src/main/java/io/opentracing/contrib/specialagent/rule/mule4/service/http/MuleFilterChainAgentRule.java deleted file mode 100644 index 84642797a..000000000 --- a/rule/mule-4-http-service/src/main/java/io/opentracing/contrib/specialagent/rule/mule4/service/http/MuleFilterChainAgentRule.java +++ /dev/null @@ -1,72 +0,0 @@ -/* Copyright 2019 The OpenTracing 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. - */ - -package io.opentracing.contrib.specialagent.rule.mule4.service.http; - -import static net.bytebuddy.matcher.ElementMatchers.*; - -import io.opentracing.contrib.specialagent.AgentRule; -import io.opentracing.contrib.specialagent.EarlyReturnException; -import net.bytebuddy.agent.builder.AgentBuilder; -import net.bytebuddy.agent.builder.AgentBuilder.Identified.Narrowable; -import net.bytebuddy.agent.builder.AgentBuilder.Transformer; -import net.bytebuddy.asm.Advice; -import net.bytebuddy.description.type.TypeDescription; -import net.bytebuddy.dynamic.DynamicType.Builder; -import net.bytebuddy.implementation.bytecode.assign.Assigner.Typing; -import net.bytebuddy.utility.JavaModule; - -public class MuleFilterChainAgentRule extends AgentRule { - @Override - public AgentBuilder[] buildAgentUnchained(final AgentBuilder builder) { - final Narrowable narrowable = builder.type(named("org.glassfish.grizzly.filterchain.FilterChainBuilder$StatelessFilterChainBuilder")); - return new AgentBuilder[] { - narrowable - .transform(new Transformer() { - @Override - public Builder transform(final Builder builder, final TypeDescription typeDescription, final ClassLoader classLoader, final JavaModule module) { - return builder.visit(advice(typeDescription).to(OnEnter.class).on(named("build"))); - }}), - narrowable - .transform(new Transformer() { - @Override - public Builder transform(final Builder builder, final TypeDescription typeDescription, final ClassLoader classLoader, final JavaModule module) { - return builder.visit(advice(typeDescription).to(OnExit.class).on(named("build"))); - }})}; - } - - public static class OnEnter { - @Advice.OnMethodEnter - public static void enter(final @ClassName String className, final @Advice.Origin String origin, final @Advice.This Object thiz) throws EarlyReturnException { - if (!isAllowed(className, origin)) - return; - - final Object filterChain = MuleFilterChainAgentIntercept.enter(thiz); - if (filterChain != null) - throw new EarlyReturnException(filterChain); - } - } - - public static class OnExit { - @SuppressWarnings("unused") - @Advice.OnMethodExit(onThrowable = Throwable.class) - public static void exit(@Advice.Return(readOnly = false, typing = Typing.DYNAMIC) Object returned, @Advice.Thrown(readOnly = false, typing = Typing.DYNAMIC) Throwable thrown) { - if (thrown instanceof EarlyReturnException) { - returned = ((EarlyReturnException)thrown).getReturnValue(); - thrown = null; - } - } - } -} \ No newline at end of file diff --git a/rule/mule-4-http-service/src/main/java/io/opentracing/contrib/specialagent/rule/mule4/service/http/TracedMuleFilterChainBuilder.java b/rule/mule-4-http-service/src/main/java/io/opentracing/contrib/specialagent/rule/mule4/service/http/TracedMuleFilterChainBuilder.java deleted file mode 100644 index c9b178009..000000000 --- a/rule/mule-4-http-service/src/main/java/io/opentracing/contrib/specialagent/rule/mule4/service/http/TracedMuleFilterChainBuilder.java +++ /dev/null @@ -1,41 +0,0 @@ -/* Copyright 2019 The OpenTracing 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. - */ - -package io.opentracing.contrib.specialagent.rule.mule4.service.http; - -import org.glassfish.grizzly.filterchain.FilterChain; -import org.glassfish.grizzly.filterchain.FilterChainBuilder; -import org.mule.service.http.impl.service.server.grizzly.GrizzlyRequestDispatcherFilter; - -import io.opentracing.Tracer; -import io.opentracing.contrib.grizzly.http.server.TracedFilterChainBuilder; - -public class TracedMuleFilterChainBuilder extends TracedFilterChainBuilder { - public TracedMuleFilterChainBuilder(final FilterChainBuilder builder, final Tracer tracer) { - super(builder, tracer); - } - - @Override - public FilterChain build() { - final int dispatcherFilter = this.indexOfType(GrizzlyRequestDispatcherFilter.class); - if (dispatcherFilter != -1) { - // If contains an GrizzlyRequestDispatcherFilter - // @see https://github.com/mulesoft/mule-http-service/blob/1.4.7/src/main/java/org/mule/service/http/impl/service/server/grizzly/GrizzlyServerManager.java#L111 - addTracingFiltersAt(4); - } - - return super.build(); - } -} \ No newline at end of file diff --git a/rule/mule-4-http-service/src/main/resources/otarules.mf b/rule/mule-4-http-service/src/main/resources/otarules.mf deleted file mode 100644 index 0ea05b137..000000000 --- a/rule/mule-4-http-service/src/main/resources/otarules.mf +++ /dev/null @@ -1,15 +0,0 @@ -# Copyright 2019 The OpenTracing 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. - -io.opentracing.contrib.specialagent.rule.mule4.service.http.MuleFilterChainAgentRule diff --git a/rule/mule-4-http-service/src/test/java/io/opentracing/contrib/specialagent/rule/mule4/service/http/HttpServiceTest.java b/rule/mule-4-http-service/src/test/java/io/opentracing/contrib/specialagent/rule/mule4/service/http/HttpServiceTest.java deleted file mode 100644 index 4eeec67c0..000000000 --- a/rule/mule-4-http-service/src/test/java/io/opentracing/contrib/specialagent/rule/mule4/service/http/HttpServiceTest.java +++ /dev/null @@ -1,75 +0,0 @@ -/* Copyright 2020 The OpenTracing 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. - */ - -package io.opentracing.contrib.specialagent.rule.mule4.service.http; - -import static org.junit.Assert.*; - -import org.apache.http.client.fluent.Request; -import org.apache.http.client.fluent.Response; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mule.runtime.core.api.util.ClassUtils; -import org.mule.runtime.http.api.server.HttpServer; -import org.mule.runtime.http.api.server.HttpServerConfiguration; -import org.mule.service.http.impl.service.HttpServiceImplementation; -import org.mule.tck.SimpleUnitTestSupportSchedulerService; -import org.mule.tck.junit4.AbstractMuleTestCase; - -import io.opentracing.contrib.specialagent.AgentRunner; -import io.opentracing.mock.MockTracer; - -@RunWith(AgentRunner.class) -public class HttpServiceTest extends AbstractMuleTestCase { - private static final String HOST = "localhost"; - private static final int PORT = 9875; - private HttpServiceImplementation service; - private SimpleUnitTestSupportSchedulerService schedulerService; - private HttpServer server; - - @Before - public void before(final MockTracer tracer) throws Exception { - tracer.reset(); - - schedulerService = new SimpleUnitTestSupportSchedulerService(); - service = (HttpServiceImplementation)ClassUtils.instantiateClass(HttpServiceImplementation.class.getName(), new Object[] {schedulerService}, this.getClass().getClassLoader()); - service.start(); - - server = service.getServerFactory().create(new HttpServerConfiguration.Builder().setHost(HOST).setPort(PORT).setName("test-server").build()); - server.start(); - } - - @After - public void after() throws Exception { - if (server != null) - server.stop(); - - if (service != null) - service.stop(); - - if (schedulerService != null) - schedulerService.stop(); - } - - @Test - // @AgentRunner.TestConfig(verbose = true) - public void httpServiceTest(final MockTracer tracer) throws Exception { - final Response response = Request.Get("http://" + HOST + ":" + PORT + "/").execute(); - assertEquals(response.returnResponse().getStatusLine().getStatusCode(), 503); - assertEquals(1, tracer.finishedSpans().size()); - } -} \ No newline at end of file diff --git a/rule/pom.xml b/rule/pom.xml index 6a2ee32a6..278411863 100644 --- a/rule/pom.xml +++ b/rule/pom.xml @@ -69,7 +69,6 @@ apache-httpclient lettuce mule-4-core - mule-4-http-service mule-4-module-artifact spring-webflux redisson diff --git a/test/mule/mule-4.2.2/pom.xml b/test/mule/mule-4.2.2/pom.xml index b52ec5a87..d6b7a1696 100644 --- a/test/mule/mule-4.2.2/pom.xml +++ b/test/mule/mule-4.2.2/pom.xml @@ -31,7 +31,7 @@ 4.2.2 ${project.basedir}/src/test/mule-home FINE - -Dsa.integration.*.disable -Dsa.integration.mule*.enable -Dsa.integration.grizzly:http-client.enable -Dsa.integration.jdbc.enable + -Dsa.integration.*.disable -Dsa.integration.mule*.enable -Dsa.integration.grizzly:http-server.enable -Dsa.integration.grizzly:http-client.enable -Dsa.integration.jdbc.enable