-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
925a311
commit de6ce81
Showing
11 changed files
with
243 additions
and
102 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
jaxrs/deployment/src/main/java/org/jboss/shamrock/jaxrs/JaxrsProviderBuildItem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package org.jboss.shamrock.jaxrs; | ||
|
||
import org.jboss.builder.item.MultiBuildItem; | ||
|
||
/** | ||
* A build item that represents a JAX-RS provider class, these items will be merged | ||
* into the 'resteasy.providers' context param. | ||
*/ | ||
public final class JaxrsProviderBuildItem extends MultiBuildItem { | ||
|
||
private final String name; | ||
|
||
public JaxrsProviderBuildItem(String name) { | ||
this.name = name; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 47 additions & 29 deletions
76
...tracing/deployment/src/main/java/org/jboss/shamrock/opentracing/OpentracingProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,63 @@ | ||
package org.jboss.shamrock.opentracing; | ||
|
||
import java.lang.reflect.Method; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import javax.enterprise.inject.spi.ObserverMethod; | ||
import javax.inject.Inject; | ||
|
||
import io.opentracing.contrib.interceptors.OpenTracingInterceptor; | ||
import org.eclipse.microprofile.opentracing.Traced; | ||
import org.jboss.shamrock.deployment.ArchiveContext; | ||
import org.jboss.shamrock.deployment.BeanDeployment; | ||
import org.jboss.shamrock.deployment.ProcessorContext; | ||
import org.jboss.shamrock.deployment.ResourceProcessor; | ||
import org.jboss.shamrock.deployment.RuntimePriority; | ||
import org.jboss.shamrock.deployment.codegen.BytecodeRecorder; | ||
import javax.servlet.DispatcherType; | ||
|
||
import org.jboss.shamrock.annotations.BuildProducer; | ||
import org.jboss.shamrock.annotations.BuildStep; | ||
import org.jboss.shamrock.annotations.ExecutionTime; | ||
import org.jboss.shamrock.annotations.Record; | ||
import org.jboss.shamrock.deployment.builditem.AdditionalBeanBuildItem; | ||
import org.jboss.shamrock.deployment.builditem.ReflectiveMethodBuildItem; | ||
import org.jboss.shamrock.jaxrs.JaxrsProviderBuildItem; | ||
import org.jboss.shamrock.opentracing.runtime.ShamrockTracingDynamicFeature; | ||
import org.jboss.shamrock.opentracing.runtime.TracerProducer; | ||
import org.jboss.shamrock.opentracing.runtime.TracingDeploymentTemplate; | ||
import org.jboss.shamrock.undertow.DeploymentInfoBuildItem; | ||
import org.jboss.shamrock.undertow.FilterBuildItem; | ||
import org.jboss.shamrock.undertow.ServletContextParamBuildItem; | ||
|
||
public class OpentracingProcessor implements ResourceProcessor { | ||
import io.opentracing.contrib.interceptors.OpenTracingInterceptor; | ||
import io.opentracing.contrib.jaxrs2.server.SpanFinishingFilter; | ||
|
||
@Inject | ||
BeanDeployment beanDeployment; | ||
public class OpentracingProcessor { | ||
|
||
@Override | ||
public void process(ArchiveContext archiveContext, ProcessorContext processorContext) throws Exception { | ||
System.err.println( "PROCESS OPENTRACING"); | ||
this.beanDeployment.addAdditionalBean(OpenTracingInterceptor.class); | ||
this.beanDeployment.addAdditionalBean(TracerProducer.class); | ||
processorContext.addReflectiveClass(false, false, Traced.class.getName()); | ||
@BuildStep | ||
List<AdditionalBeanBuildItem> registerBeans() { | ||
return Arrays.asList(new AdditionalBeanBuildItem(OpenTracingInterceptor.class, TracerProducer.class)); | ||
} | ||
|
||
@BuildStep | ||
ReflectiveMethodBuildItem registerMethod() throws Exception { | ||
Method isAsync = ObserverMethod.class.getMethod("isAsync"); | ||
processorContext.addReflectiveMethod(isAsync); | ||
|
||
try (BytecodeRecorder recorder = processorContext.addStaticInitTask(RuntimePriority.JAXRS_DEPLOYMENT + 1)) { | ||
TracingDeploymentTemplate tracing = recorder.getRecordingProxy(TracingDeploymentTemplate.class); | ||
tracing.registerTracer(); | ||
tracing.integrateJaxrs(null); | ||
} | ||
return new ReflectiveMethodBuildItem(isAsync); | ||
} | ||
|
||
@Override | ||
public int getPriority() { | ||
return 0; | ||
@BuildStep | ||
@Record(ExecutionTime.STATIC_INIT) | ||
void setupFilter(BuildProducer<JaxrsProviderBuildItem> providers, | ||
BuildProducer<FilterBuildItem> filterProducer, | ||
TracingDeploymentTemplate tracing) { | ||
|
||
//TODO: this needs to be a BuildItem so that more than one can be registered | ||
providers.produce(new JaxrsProviderBuildItem(ShamrockTracingDynamicFeature.class.getName())); | ||
|
||
FilterBuildItem filterInfo = new FilterBuildItem("tracingFilter", SpanFinishingFilter.class.getName()); | ||
filterInfo.setAsyncSupported(true); | ||
filterInfo.addFilterUrlMapping("*", DispatcherType.FORWARD); | ||
filterInfo.addFilterUrlMapping("*", DispatcherType.INCLUDE); | ||
filterInfo.addFilterUrlMapping("*", DispatcherType.REQUEST); | ||
filterInfo.addFilterUrlMapping("*", DispatcherType.ASYNC); | ||
filterInfo.addFilterUrlMapping("*", DispatcherType.ERROR); | ||
filterProducer.produce(filterInfo); | ||
|
||
//note that we can't put this into its own method as we need this to be registered before Undertow is started | ||
tracing.registerTracer(); | ||
|
||
} | ||
|
||
} |
12 changes: 0 additions & 12 deletions
12
opentracing/deployment/src/main/java/org/jboss/shamrock/opentracing/OpentracingSetup.java
This file was deleted.
Oops, something went wrong.
1 change: 0 additions & 1 deletion
1
...ployment/src/main/resources/META-INF/services/org.jboss.shamrock.deployment.ShamrockSetup
This file was deleted.
Oops, something went wrong.
44 changes: 2 additions & 42 deletions
44
...ntime/src/main/java/org/jboss/shamrock/opentracing/runtime/TracingDeploymentTemplate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,19 @@ | ||
package org.jboss.shamrock.opentracing.runtime; | ||
|
||
import java.util.EnumSet; | ||
import org.jboss.shamrock.runtime.Template; | ||
|
||
import javax.servlet.DispatcherType; | ||
import javax.servlet.Filter; | ||
import javax.servlet.FilterRegistration; | ||
|
||
import io.opentracing.contrib.jaxrs2.server.SpanFinishingFilter; | ||
import io.opentracing.util.GlobalTracer; | ||
import io.smallrye.opentracing.SmallRyeTracingDynamicFeature; | ||
import io.undertow.servlet.api.DeploymentInfo; | ||
import io.undertow.servlet.api.FilterInfo; | ||
import io.undertow.servlet.api.InstanceHandle; | ||
import org.jboss.shamrock.runtime.ContextObject; | ||
|
||
/** | ||
* Created by bob on 8/6/18. | ||
*/ | ||
@Template | ||
public class TracingDeploymentTemplate { | ||
public void registerTracer() { | ||
System.err.println("REGISTER TRACER"); | ||
//this.tracer = new ShamrockTracer(); | ||
GlobalTracer.register(new ShamrockTracer()); | ||
} | ||
|
||
public void integrateJaxrs(@ContextObject("deploymentInfo") DeploymentInfo info) { | ||
System.err.println("adding integration " + info); | ||
info.addInitParameter("resteasy.providers", ShamrockTracingDynamicFeature.class.getName()); | ||
|
||
FilterInfo filterInfo = new FilterInfo("tracingFilter", SpanFinishingFilter.class, () -> { | ||
SpanFinishingFilter filter = new SpanFinishingFilter(GlobalTracer.get()); | ||
return new InstanceHandle<Filter>() { | ||
@Override | ||
public Filter getInstance() { | ||
System.err.println("get instance of filter"); | ||
return filter; | ||
} | ||
|
||
@Override | ||
public void release() { | ||
System.err.println("release instance of filter"); | ||
// no-op | ||
} | ||
}; | ||
}); | ||
filterInfo.setAsyncSupported(true); | ||
info.addFilter(filterInfo); | ||
EnumSet<DispatcherType> enums = EnumSet.allOf(DispatcherType.class); | ||
info.addFilterUrlMapping("tracingFilter", "*", DispatcherType.FORWARD); | ||
info.addFilterUrlMapping("tracingFilter", "*", DispatcherType.INCLUDE); | ||
info.addFilterUrlMapping("tracingFilter", "*", DispatcherType.REQUEST); | ||
info.addFilterUrlMapping("tracingFilter", "*", DispatcherType.ASYNC); | ||
info.addFilterUrlMapping("tracingFilter", "*", DispatcherType.ERROR); | ||
} | ||
|
||
private ShamrockTracer tracer; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
122 changes: 122 additions & 0 deletions
122
undertow/deployment/src/main/java/org/jboss/shamrock/undertow/FilterBuildItem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
package org.jboss.shamrock.undertow; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import javax.servlet.DispatcherType; | ||
|
||
import org.jboss.builder.item.MultiBuildItem; | ||
|
||
public final class FilterBuildItem extends MultiBuildItem { | ||
|
||
private final String name; | ||
private final String filterClass; | ||
private int loadOnStartup; | ||
private boolean asyncSupported; | ||
private final List<FilterMappingInfo> mappings = new ArrayList<>(); | ||
|
||
public FilterBuildItem(String name, String filterClass) { | ||
this.name = name; | ||
this.filterClass = filterClass; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public String getFilterClass() { | ||
return filterClass; | ||
} | ||
|
||
public List<FilterMappingInfo> getMappings() { | ||
return mappings; | ||
} | ||
|
||
public int getLoadOnStartup() { | ||
return loadOnStartup; | ||
} | ||
|
||
public FilterBuildItem setLoadOnStartup(int loadOnStartup) { | ||
this.loadOnStartup = loadOnStartup; | ||
return this; | ||
} | ||
|
||
public FilterBuildItem addMapping(FilterMappingInfo mappingPath) { | ||
mappings.add(mappingPath); | ||
return this; | ||
} | ||
|
||
public boolean isAsyncSupported() { | ||
return asyncSupported; | ||
} | ||
|
||
public FilterBuildItem setAsyncSupported(boolean asyncSupported) { | ||
this.asyncSupported = asyncSupported; | ||
return this; | ||
} | ||
|
||
public FilterBuildItem addFilterUrlMapping(final String mapping, DispatcherType dispatcher) { | ||
mappings.add(new FilterMappingInfo(FilterMappingInfo.MappingType.URL, mapping, dispatcher)); | ||
return this; | ||
} | ||
|
||
public FilterBuildItem addFilterServletNameMapping(final String mapping, DispatcherType dispatcher) { | ||
mappings.add(new FilterMappingInfo(FilterMappingInfo.MappingType.SERVLET, mapping, dispatcher)); | ||
return this; | ||
} | ||
|
||
public FilterBuildItem insertFilterUrlMapping(final int pos, final String mapping, DispatcherType dispatcher) { | ||
mappings.add(pos, new FilterMappingInfo(FilterMappingInfo.MappingType.URL, mapping, dispatcher)); | ||
return this; | ||
} | ||
|
||
public FilterBuildItem insertFilterServletNameMapping(final int pos, final String filterName, final String mapping, DispatcherType dispatcher) { | ||
mappings.add(pos, new FilterMappingInfo(FilterMappingInfo.MappingType.SERVLET, mapping, dispatcher)); | ||
return this; | ||
} | ||
|
||
|
||
public static class FilterMappingInfo { | ||
|
||
private MappingType mappingType; | ||
private String mapping; | ||
private DispatcherType dispatcher; | ||
|
||
public FilterMappingInfo(final MappingType mappingType, final String mapping, final DispatcherType dispatcher) { | ||
this.mappingType = mappingType; | ||
this.mapping = mapping; | ||
this.dispatcher = dispatcher; | ||
} | ||
|
||
public void setMappingType(MappingType mappingType) { | ||
this.mappingType = mappingType; | ||
} | ||
|
||
public void setMapping(String mapping) { | ||
this.mapping = mapping; | ||
} | ||
|
||
public void setDispatcher(DispatcherType dispatcher) { | ||
this.dispatcher = dispatcher; | ||
} | ||
|
||
public MappingType getMappingType() { | ||
return mappingType; | ||
} | ||
|
||
public String getMapping() { | ||
return mapping; | ||
} | ||
|
||
public DispatcherType getDispatcher() { | ||
return dispatcher; | ||
} | ||
|
||
public enum MappingType { | ||
URL, | ||
SERVLET; | ||
} | ||
|
||
} | ||
|
||
} |
Oops, something went wrong.