diff --git a/Jenkinsfile b/Jenkinsfile index 621ddbe..f5ac4f2 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -36,7 +36,7 @@ podRetention: never()) { container('maven') { sh """ cd sematext-agent-java - mvn --batch-mode clean install -DskipTests + mvn --batch-mode clean install -DskipTests -e """ } } diff --git a/pom.xml b/pom.xml index 808be3a..99ddca9 100644 --- a/pom.xml +++ b/pom.xml @@ -10,13 +10,13 @@ UTF-8 - 1.6 - 1.6 - 1.6 - 1.6 + 1.8 + 1.8 + 1.8 + 1.8 1.1.1 4.13.1 - 2.17.1 + 2.17.2 1.4.7 checkstyle.xml @@ -118,9 +118,6 @@ spm-transfer spm-monitor-redis spm-monitor-storm - spm-tracing-agent - spm-tracing-testing - spm-tracing-agent-impl spm-monitor-haproxy @@ -135,7 +132,7 @@ org.apache.logging.log4j log4j-core - 2.17.1 + 2.17.2 compile diff --git a/spm-client-common-libs-parent/pom.xml b/spm-client-common-libs-parent/pom.xml index 3ccaa12..237de5d 100644 --- a/spm-client-common-libs-parent/pom.xml +++ b/spm-client-common-libs-parent/pom.xml @@ -10,8 +10,6 @@ provided - compile - compile compile @@ -35,26 +33,6 @@ - - com.sematext.spm - spm-tracing-agent - ${project.version} - ${tracing.agent.lib.scope} - - - - com.sematext.spm - spm-tracing-agent-impl - ${project.version} - ${tracing.agent.impl.lib.scope} - - - com.sematext.spm - spm-thrift-data - - - - com.sematext.spm spm-monitor-utils @@ -314,7 +292,7 @@ org.apache.logging.log4j log4j-core - 2.17.0 + 2.17.2 compile diff --git a/spm-client-common-libs/pom.xml b/spm-client-common-libs/pom.xml index ce451a6..6f3449b 100644 --- a/spm-client-common-libs/pom.xml +++ b/spm-client-common-libs/pom.xml @@ -11,8 +11,6 @@ compile - provided - provided provided @@ -25,7 +23,7 @@ org.apache.logging.log4j log4j-core - 2.17.0 + 2.17.2 compile diff --git a/spm-monitor-generic/pom.xml b/spm-monitor-generic/pom.xml index 8918483..c28b375 100644 --- a/spm-monitor-generic/pom.xml +++ b/spm-monitor-generic/pom.xml @@ -63,7 +63,7 @@ org.apache.logging.log4j log4j-core - 2.17.0 + 2.17.2 compile diff --git a/spm-monitor-generic/src/main/java/com/sematext/spm/client/GenericStatsCollectorsFactory.java b/spm-monitor-generic/src/main/java/com/sematext/spm/client/GenericStatsCollectorsFactory.java index 0647edd..c685331 100644 --- a/spm-monitor-generic/src/main/java/com/sematext/spm/client/GenericStatsCollectorsFactory.java +++ b/spm-monitor-generic/src/main/java/com/sematext/spm/client/GenericStatsCollectorsFactory.java @@ -74,19 +74,17 @@ import com.sematext.spm.client.jvm.JvmNotifBasedGcStatsCollector; import com.sematext.spm.client.observation.AttributeObservation; import com.sematext.spm.client.observation.ObservationBean; -import com.sematext.spm.client.tracing.TracingMonitorConfigurator; import com.sematext.spm.client.util.CollectionUtils.FunctionT; import com.sematext.spm.client.yaml.YamlConfigLoader; public class GenericStatsCollectorsFactory extends StatsCollectorsFactory> { private static final Log LOG = LogFactory.getLog(GenericStatsCollectorsFactory.class); - private final TracingMonitorConfigurator tracingConf = new TracingMonitorConfigurator(); public static final Cache> EXISTING_COLLECTORS_MAP = CacheBuilder.newBuilder() .maximumSize(300000) .expireAfterAccess(30, TimeUnit.MINUTES) .build(); - + private static final int MAX_PCTLS_DEFINITIONS = 10; private static int CURRENT_COUNT_PCTLS_DEFINITIONS = 0; @@ -126,23 +124,6 @@ public Collection> create(Properties monitorProperti .getProperty("SPM_MONITOR_SEND_JVM_NAME", "false") .trim()).trim())); - if (MonitorUtil.MONITOR_RUNTIME_SETUP_JAVAAGENT.get()) { - boolean tracingEnabled = "true".equalsIgnoreCase(MonitorUtil.stripQuotes(monitorProperties - .getProperty("SPM_MONITOR_TRACING_ENABLED", "false") - .trim()).trim()); - - if (tracingEnabled) { - try { - // always configure, it collects only if right settings are present though (handles it internally) - tracingConf - .configure(monitorConfig, currentCollectors, collectors, Serializer.INFLUX, appToken, subType, jvmName); - } catch (Throwable thr) { - // don't propagate, just continue - LOG.error("Error while configuring tracing conf", thr); - } - } - } - CURRENT_COUNT_PCTLS_DEFINITIONS = 0; LOG.info("Loading configs for collectors: " + types); @@ -167,7 +148,7 @@ public JvmNotifBasedGcStatsCollector apply(String id) { } collectors = groupCollectorsByTags(collectors, monitorConfig); - + // as last collector add HeartbeatCollector updateCollector(currentCollectors, collectors, HeartbeatStatsCollector.class, jvmName, new FunctionT() { @@ -176,7 +157,7 @@ public HeartbeatStatsCollector apply(String id) { return new HeartbeatStatsCollector(Serializer.INFLUX, appToken, jvmName, subType); } }); - + int collectorsCount = StatsCollector.getCollectorsCount(collectors); if (collectorsCount < 50) { LOG.info("Created " + collectors.size() + " collectors : " + collectors); @@ -657,7 +638,7 @@ private StatsExtractorConfig getStatsExtractorConfig(File configFile, String // replace all monitor properties placeholders with real values from properties file // NOTE: assumption is that it is ok if behavior will be undefined when two props have the same variants (ST_PROP - // and SPM_PROP) because order of execution would affect the end result + // and SPM_PROP) because order of execution would affect the end result for (Object property : monitorProperties.keySet()) { String propertyValue = MonitorUtil.stripQuotes(monitorProperties.getProperty(String.valueOf(property), "").trim()) .trim(); @@ -791,7 +772,7 @@ private List> groupCollectorsByTags(List> co } } - // check if everything resolved too + // check if everything resolved too if (!col.getGenericExtractor().isAllConfigTagsResolved()) { nonGroupableCollectors.add(sc); } else { diff --git a/spm-monitor-haproxy/pom.xml b/spm-monitor-haproxy/pom.xml index bd49f84..278de72 100644 --- a/spm-monitor-haproxy/pom.xml +++ b/spm-monitor-haproxy/pom.xml @@ -43,7 +43,7 @@ org.apache.logging.log4j log4j-core - 2.17.0 + 2.17.2 compile diff --git a/spm-monitor-parent/pom.xml b/spm-monitor-parent/pom.xml index d7867ae..d911cdc 100644 --- a/spm-monitor-parent/pom.xml +++ b/spm-monitor-parent/pom.xml @@ -29,7 +29,7 @@ org.apache.logging.log4j log4j-core - 2.17.0 + 2.17.2 compile @@ -59,7 +59,6 @@ com.sematext.spm:spm-monitor-utils - com.sematext.spm:spm-tracing-agent com.sematext.spm:spm-monitor-starter org.javassist:javassist org.eclipse.collections:eclipse-collections-api @@ -86,14 +85,13 @@ com.sematext.spm:spm-monitor-utils - com.sematext.spm:spm-tracing-agent com.sematext.spm:spm-monitor-starter org.javassist:javassist org.eclipse.collections:eclipse-collections-api org.eclipse.collections:eclipse-collections - com.sematext.spm:${artifactId} + com.sematext.spm:${project.artifactId} org.apache.thrift:libthrift org.slf4j:slf4j-api org.slf4j:slf4j-log4j12 @@ -102,15 +100,6 @@ - - com.sematext.spm:spm-tracing-agent - - org/** - com/sematext/spm/client/tracing/thrift/** - com/sematext/spm/client/monitor/thrift/** - com/sematext/spm/client/snap/** - - com.sematext.spm:spm-monitor-utils @@ -134,6 +123,21 @@ org.apache.maven.plugins maven-assembly-plugin 2.4 + + + /../spm-monitor-parent/src/main/assembly/dist.xml + + + + com.sematext.spm.client.MonitorAgentWrapper + true + + ${project.version} + development + ${project.url} + + + create-distro @@ -141,22 +145,6 @@ single - - - /../spm-monitor-parent/src/main/assembly/monitor-with-tracing-agent-dist.xml - - - - com.sematext.spm.client.MonitorAgentWrapper - true - - - ${project.version} - development - ${project.url} - - - diff --git a/spm-monitor-parent/src/main/assembly/dist.xml b/spm-monitor-parent/src/main/assembly/dist.xml index 8c292e1..08aaaf4 100644 --- a/spm-monitor-parent/src/main/assembly/dist.xml +++ b/spm-monitor-parent/src/main/assembly/dist.xml @@ -30,7 +30,7 @@ monitor-libs - com.sematext.spm:${artifactId} + com.sematext.spm:${project.artifactId} diff --git a/spm-monitor-parent/src/main/assembly/monitor-with-tracing-agent-dist.xml b/spm-monitor-parent/src/main/assembly/monitor-with-tracing-agent-dist.xml deleted file mode 100644 index 29fd5ee..0000000 --- a/spm-monitor-parent/src/main/assembly/monitor-with-tracing-agent-dist.xml +++ /dev/null @@ -1,42 +0,0 @@ - - withdeps - - jar - - - - - true - true - true - true - runtime - 0755 - 0755 - / - - - com.sematext.spm:${artifactId}:jar:shaded-bootstrap:* - - - - - true - true - false - true - - false - runtime - 0644 - 0755 - monitor-libs - - - com.sematext.spm:${artifactId}:jar:shaded-impl:* - - - - - / - \ No newline at end of file diff --git a/spm-monitor-redis/pom.xml b/spm-monitor-redis/pom.xml index 34c69da..1100598 100644 --- a/spm-monitor-redis/pom.xml +++ b/spm-monitor-redis/pom.xml @@ -58,7 +58,7 @@ org.apache.logging.log4j log4j-core - 2.17.0 + 2.17.2 compile diff --git a/spm-monitor-starter/pom.xml b/spm-monitor-starter/pom.xml index 771bdff..3592fcc 100644 --- a/spm-monitor-starter/pom.xml +++ b/spm-monitor-starter/pom.xml @@ -23,7 +23,7 @@ org.apache.logging.log4j log4j-core - 2.17.0 + 2.17.2 compile diff --git a/spm-monitor-storm/pom.xml b/spm-monitor-storm/pom.xml index e02c511..d59848b 100644 --- a/spm-monitor-storm/pom.xml +++ b/spm-monitor-storm/pom.xml @@ -86,7 +86,7 @@ org.apache.logging.log4j log4j-core - 2.17.0 + 2.17.2 compile @@ -116,8 +116,6 @@ com.sematext.spm:spm-monitor-utils - com.sematext.spm:spm-tracing-agent - com.sematext.spm:spm-tracing-agent-impl com.sematext.spm:spm-monitor-starter org.javassist:javassist org.eclipse.collections:eclipse-collections-api diff --git a/spm-monitor-storm/src/main/java/com/sematext/spm/client/storm/StormNimbusStatsCollectorsFactory.java b/spm-monitor-storm/src/main/java/com/sematext/spm/client/storm/StormNimbusStatsCollectorsFactory.java index cc315d2..e44bb09 100644 --- a/spm-monitor-storm/src/main/java/com/sematext/spm/client/storm/StormNimbusStatsCollectorsFactory.java +++ b/spm-monitor-storm/src/main/java/com/sematext/spm/client/storm/StormNimbusStatsCollectorsFactory.java @@ -36,14 +36,12 @@ import com.sematext.spm.client.StatsCollectorBadConfigurationException; import com.sematext.spm.client.StatsCollectorsFactory; import com.sematext.spm.client.jmx.configurator.JvmJmxBasedMonitorConfigurator; -import com.sematext.spm.client.tracing.TracingMonitorConfigurator; import com.sematext.spm.client.util.CollectionUtils.FunctionT; public class StormNimbusStatsCollectorsFactory extends StatsCollectorsFactory> { private static final Log LOG = LogFactory.getLog(StormNimbusStatsCollectorsFactory.class); private final JvmJmxBasedMonitorConfigurator jvmJmxConf = new JvmJmxBasedMonitorConfigurator(); - private final TracingMonitorConfigurator tracingConf = new TracingMonitorConfigurator(); @Override public Collection> create(Properties monitorProperties, @@ -60,23 +58,6 @@ public Collection> create(Properties monitorProperti try { jvmJmxConf.configure(Collections.EMPTY_MAP, monitorConfig, currentCollectors, collectors); - if (MonitorUtil.MONITOR_RUNTIME_SETUP_JAVAAGENT.get()) { - boolean tracingEnabled = "true".equalsIgnoreCase(MonitorUtil.stripQuotes(monitorProperties - .getProperty("SPM_MONITOR_TRACING_ENABLED", "false") - .trim()).trim()); - - if (tracingEnabled) { - try { - // always configure, it collects only if right settings are present though (handles it internally) - tracingConf - .configure(monitorConfig, currentCollectors, collectors, Serializer.INFLUX, appToken, subType, jvmName); - } catch (Throwable thr) { - // don't propagate, just continue - LOG.error("Error while configuring tracing conf", thr); - } - } - } - // as last collector add HeartbeatCollector updateCollector(currentCollectors, collectors, HeartbeatStatsCollector.class, jvmName, new FunctionT() { diff --git a/spm-monitor-storm/src/main/java/com/sematext/spm/client/storm/StormSupervisorStatsCollectorsFactory.java b/spm-monitor-storm/src/main/java/com/sematext/spm/client/storm/StormSupervisorStatsCollectorsFactory.java index 2eeb772..2a08bc2 100644 --- a/spm-monitor-storm/src/main/java/com/sematext/spm/client/storm/StormSupervisorStatsCollectorsFactory.java +++ b/spm-monitor-storm/src/main/java/com/sematext/spm/client/storm/StormSupervisorStatsCollectorsFactory.java @@ -36,13 +36,11 @@ import com.sematext.spm.client.StatsCollectorBadConfigurationException; import com.sematext.spm.client.StatsCollectorsFactory; import com.sematext.spm.client.jmx.configurator.JvmJmxBasedMonitorConfigurator; -import com.sematext.spm.client.tracing.TracingMonitorConfigurator; import com.sematext.spm.client.util.CollectionUtils.FunctionT; public class StormSupervisorStatsCollectorsFactory extends StatsCollectorsFactory> { private static final Log LOG = LogFactory.getLog(StormSupervisorStatsCollectorsFactory.class); private final JvmJmxBasedMonitorConfigurator jvmJmxConf = new JvmJmxBasedMonitorConfigurator(); - private final TracingMonitorConfigurator tracingConf = new TracingMonitorConfigurator(); public Collection> create(Properties monitorProperties, List> currentCollectors, @@ -58,23 +56,6 @@ public Collection> create(Properties monitorProperti // first read available JVM data from Jmx jvmJmxConf.configure(Collections.EMPTY_MAP, monitorConfig, currentCollectors, collectors); - if (MonitorUtil.MONITOR_RUNTIME_SETUP_JAVAAGENT.get()) { - boolean tracingEnabled = "true".equalsIgnoreCase(MonitorUtil.stripQuotes(monitorProperties - .getProperty("SPM_MONITOR_TRACING_ENABLED", "false") - .trim()).trim()); - - if (tracingEnabled) { - try { - // always configure, it collects only if right settings are present though (handles it internally) - tracingConf - .configure(monitorConfig, currentCollectors, collectors, Serializer.INFLUX, appToken, subType, jvmName); - } catch (Throwable thr) { - // don't propagate, just continue - LOG.error("Error while configuring tracing conf", thr); - } - } - } - // as last collector add HeartbeatCollector updateCollector(currentCollectors, collectors, HeartbeatStatsCollector.class, jvmName, new FunctionT() { diff --git a/spm-monitor-storm/src/main/java/com/sematext/spm/client/storm/StormWorkerStatsCollectorsFactory.java b/spm-monitor-storm/src/main/java/com/sematext/spm/client/storm/StormWorkerStatsCollectorsFactory.java index 7a227c7..b62ac1d 100644 --- a/spm-monitor-storm/src/main/java/com/sematext/spm/client/storm/StormWorkerStatsCollectorsFactory.java +++ b/spm-monitor-storm/src/main/java/com/sematext/spm/client/storm/StormWorkerStatsCollectorsFactory.java @@ -36,13 +36,11 @@ import com.sematext.spm.client.StatsCollectorBadConfigurationException; import com.sematext.spm.client.StatsCollectorsFactory; import com.sematext.spm.client.jmx.configurator.JvmJmxBasedMonitorConfigurator; -import com.sematext.spm.client.tracing.TracingMonitorConfigurator; import com.sematext.spm.client.util.CollectionUtils.FunctionT; public class StormWorkerStatsCollectorsFactory extends StatsCollectorsFactory> { private static final Log LOG = LogFactory.getLog(StormWorkerStatsCollectorsFactory.class); private final JvmJmxBasedMonitorConfigurator jvmJmxConf = new JvmJmxBasedMonitorConfigurator(); - private final TracingMonitorConfigurator tracingConf = new TracingMonitorConfigurator(); public Collection> create(Properties monitorProperties, List> currentCollectors, @@ -58,23 +56,6 @@ public Collection> create(Properties monitorProperti // first read available JVM data from Jmx jvmJmxConf.configure(Collections.EMPTY_MAP, monitorConfig, currentCollectors, collectors); - if (MonitorUtil.MONITOR_RUNTIME_SETUP_JAVAAGENT.get()) { - boolean tracingEnabled = "true".equalsIgnoreCase(MonitorUtil.stripQuotes(monitorProperties - .getProperty("SPM_MONITOR_TRACING_ENABLED", "false") - .trim()).trim()); - - if (tracingEnabled) { - try { - // always configure, it collects only if right settings are present though (handles it internally) - tracingConf - .configure(monitorConfig, currentCollectors, collectors, Serializer.INFLUX, appToken, subType, jvmName); - } catch (Throwable thr) { - // don't propagate, just continue - LOG.error("Error while configuring tracing conf", thr); - } - } - } - // as last collector add HeartbeatCollector updateCollector(currentCollectors, collectors, HeartbeatStatsCollector.class, jvmName, new FunctionT() { diff --git a/spm-monitor-utils/pom.xml b/spm-monitor-utils/pom.xml index 9fbc491..645d494 100644 --- a/spm-monitor-utils/pom.xml +++ b/spm-monitor-utils/pom.xml @@ -225,7 +225,7 @@ org.apache.logging.log4j log4j-core - 2.17.0 + 2.17.2 compile diff --git a/spm-monitor-utils/src/main/java/com/sematext/spm/client/monitor/SourceConfigProperties.java b/spm-monitor-utils/src/main/java/com/sematext/spm/client/monitor/SourceConfigProperties.java index c69f833..32e7867 100644 --- a/spm-monitor-utils/src/main/java/com/sematext/spm/client/monitor/SourceConfigProperties.java +++ b/spm-monitor-utils/src/main/java/com/sematext/spm/client/monitor/SourceConfigProperties.java @@ -23,6 +23,5 @@ public final class SourceConfigProperties { private SourceConfigProperties() { } - public static final String SPM_MONITOR_TRACING_ENABLED = "SPM_MONITOR_TRACING_ENABLED"; public static final String SPM_MONITOR_PROFILER_DISABLED = "SPM_MONITOR_PROFILER_DISABLED"; } diff --git a/spm-monitor-utils/src/main/java/com/sematext/spm/client/util/ThriftUtils.java b/spm-monitor-utils/src/main/java/com/sematext/spm/client/util/ThriftUtils.java new file mode 100644 index 0000000..35cd727 --- /dev/null +++ b/spm-monitor-utils/src/main/java/com/sematext/spm/client/util/ThriftUtils.java @@ -0,0 +1,62 @@ +/* + * Licensed to Sematext Group, Inc + * + * See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.util; + +import org.apache.thrift.TDeserializer; +import org.apache.thrift.TSerializer; +import org.apache.thrift.protocol.TBinaryProtocol; +import org.apache.thrift.transport.TTransportException; + +public final class ThriftUtils { + private ThriftUtils() { + } + + private static final ThreadLocal BINARY_PROTOCOL_SERIALIZER = new ThreadLocal() { + @Override + protected TSerializer initialValue() { + try { + return new TSerializer(new TBinaryProtocol.Factory()); + } catch (Exception tte) { + throw new RuntimeException(tte); + } + } + }; + + public static TSerializer binaryProtocolSerializer() { + return BINARY_PROTOCOL_SERIALIZER.get(); + } + + private static final ThreadLocal THRIFT_DESERIALIZER = new ThreadLocal() { + @Override + protected TDeserializer initialValue() { + try { + return new TDeserializer(new TBinaryProtocol.Factory()); + } catch (Exception tte) { + throw new RuntimeException(tte); + } + } + }; + + public static TDeserializer binaryProtocolDeserializer() { + return THRIFT_DESERIALIZER.get(); + } + +} diff --git a/spm-monitor/pom.xml b/spm-monitor/pom.xml index 93f0a2f..0584687 100644 --- a/spm-monitor/pom.xml +++ b/spm-monitor/pom.xml @@ -55,7 +55,7 @@ org.apache.logging.log4j log4j-core - 2.17.0 + 2.17.2 compile diff --git a/spm-monitor/src/main/java/com/sematext/spm/client/MonitorAgent.java b/spm-monitor/src/main/java/com/sematext/spm/client/MonitorAgent.java index 29ed873..1ae4690 100644 --- a/spm-monitor/src/main/java/com/sematext/spm/client/MonitorAgent.java +++ b/spm-monitor/src/main/java/com/sematext/spm/client/MonitorAgent.java @@ -32,7 +32,6 @@ import com.sematext.spm.client.jmx.JmxServiceContext; import com.sematext.spm.client.monitor.SourceConfigProperties; import com.sematext.spm.client.sender.SenderUtil; -import com.sematext.spm.client.tracing.agent.impl.AgentInitializer; import com.sematext.spm.client.util.PropertiesReader; /** @@ -208,24 +207,6 @@ public static void startMonitoring(String agentArgs, Instrumentation inst) throw Sender.initialize(monitorArgs.getToken(), monitorArgs.getJvmName(), monitorArgs .getSubType(), MonitorType.APPLICATION); - try { - boolean tracingEnabled = "true".equalsIgnoreCase(props.get(SourceConfigProperties.SPM_MONITOR_TRACING_ENABLED)); - if (tracingEnabled) { - log.info("Tracing enabled for " + propsFile.getName()); - } else { - log.info("Tracing disabled for " + propsFile.getName()); - } - - // can't initialize tracing for any kind of standalone monitor - if (inst == null) { - log.info("Tracing permanently disabled for standalone monitor for " + propsFile.getName()); - } else { - AgentInitializer.init(agentArgs, inst, tracingEnabled, false); - } - } catch (Exception e) { - throw new ConfigurationFailedException("Can't initialize tracing agent for " + propsFile.getName(), e); - } - final MonitorConfig metricsConfig = getMonitorConfig(null, monitorArgs, inst, DataFormat.PLAIN_TEXT, processOrdinal); if (metricsConfig == null) { return; diff --git a/spm-monitor/src/main/java/com/sematext/spm/client/command/BasicCommandPollingSetup.java b/spm-monitor/src/main/java/com/sematext/spm/client/command/BasicCommandPollingSetup.java index ee8485d..455ecb9 100644 --- a/spm-monitor/src/main/java/com/sematext/spm/client/command/BasicCommandPollingSetup.java +++ b/spm-monitor/src/main/java/com/sematext/spm/client/command/BasicCommandPollingSetup.java @@ -188,9 +188,6 @@ private void setupInternal(String agentArgs, MonitorConfig monitorConfig) { .addHandler(TCommandType.PING, new PingCommandHandler()) .addHandler(TCommandType.PROFILE, new ProfileCommandHandler(ctx)) .addHandler(TCommandType.GET_INSTRUMENTED_METHODS, new GetInstrumentedMethodsHandler()) - .addHandler(TCommandType.ENABLE_TRACING, new EnableTracingHandler()) - .addHandler(TCommandType.DISABLE_TRACING, new DisableTracingHandler()) - .addHandler(TCommandType.IS_TRACING_ENABLED, new IsTracingEnabledHandler()) .addHandler(TCommandType.UPDATE_INSTRUMENTATION_SETTINGS, new UpdateInstrumentationSettingsHandler()) .proxy(senderConfig.proxyHost, senderConfig.proxyPort, senderConfig.proxyUsername, senderConfig.proxyPassword) .build(); diff --git a/spm-monitor/src/main/java/com/sematext/spm/client/command/CancellableCommandHandler.java b/spm-monitor/src/main/java/com/sematext/spm/client/command/CancellableCommandHandler.java index bb0b7ed..cc558b6 100644 --- a/spm-monitor/src/main/java/com/sematext/spm/client/command/CancellableCommandHandler.java +++ b/spm-monitor/src/main/java/com/sematext/spm/client/command/CancellableCommandHandler.java @@ -19,6 +19,7 @@ */ package com.sematext.spm.client.command; +import com.sematext.spm.client.util.ThriftUtils; import org.apache.thrift.TException; import java.util.Map; @@ -31,7 +32,6 @@ import com.sematext.spm.client.monitor.thrift.TCommandResponse; import com.sematext.spm.client.monitor.thrift.TCommandResponseStatus; import com.sematext.spm.client.monitor.thrift.TCommandType; -import com.sematext.spm.client.tracing.agent.impl.ThriftUtils; import com.sematext.spm.client.util.Preconditions; public final class CancellableCommandHandler { @@ -69,12 +69,12 @@ public void handle(final TCommand command) { if (command.getType() == TCommandType.CANCEL) { final TCancelRequest request = new TCancelRequest(); + try { ThriftUtils.binaryProtocolDeserializer().deserialize(request, command.getRequest()); } catch (TException e) { throw new IllegalStateException("Can't deserialize cancel command.", e); } - LOG.info("Got cancel request for command " + request.getId() + "."); final Cancellable cancellable = cancellableHandlers.get(request.getId()); diff --git a/spm-monitor/src/main/java/com/sematext/spm/client/command/DisableTracingHandler.java b/spm-monitor/src/main/java/com/sematext/spm/client/command/DisableTracingHandler.java deleted file mode 100644 index 73e9b41..0000000 --- a/spm-monitor/src/main/java/com/sematext/spm/client/command/DisableTracingHandler.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.command; - -import com.sematext.spm.client.monitor.thrift.TCommand; -import com.sematext.spm.client.monitor.thrift.TCommandResponse; -import com.sematext.spm.client.monitor.thrift.TCommandResponseStatus; -import com.sematext.spm.client.tracing.agent.config.ServiceLocator; - -public class DisableTracingHandler implements CommandHandler { - @Override - public Cancellable handle(TCommand command, ResponseCallback callback) { - final TCommandResponseStatus status = ServiceLocator.getTracingAgentControl().disable() ? - TCommandResponseStatus.SUCCESS - : - TCommandResponseStatus.FAILURE; - - callback.respond(new TCommandResponse(status, command.getId())); - - return null; - } -} diff --git a/spm-monitor/src/main/java/com/sematext/spm/client/command/EnableTracingHandler.java b/spm-monitor/src/main/java/com/sematext/spm/client/command/EnableTracingHandler.java deleted file mode 100644 index f3aa664..0000000 --- a/spm-monitor/src/main/java/com/sematext/spm/client/command/EnableTracingHandler.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.command; - -import com.sematext.spm.client.monitor.thrift.TCommand; -import com.sematext.spm.client.monitor.thrift.TCommandResponse; -import com.sematext.spm.client.monitor.thrift.TCommandResponseStatus; -import com.sematext.spm.client.tracing.agent.config.ServiceLocator; - -public class EnableTracingHandler implements CommandHandler { - @Override - public Cancellable handle(TCommand command, ResponseCallback callback) { - final TCommandResponseStatus status = ServiceLocator.getTracingAgentControl().enable() ? - TCommandResponseStatus.SUCCESS - : - TCommandResponseStatus.FAILURE; - - callback.respond(new TCommandResponse(status, command.getId())); - return null; - } -} diff --git a/spm-monitor/src/main/java/com/sematext/spm/client/command/IsTracingEnabledHandler.java b/spm-monitor/src/main/java/com/sematext/spm/client/command/IsTracingEnabledHandler.java deleted file mode 100644 index 35bab35..0000000 --- a/spm-monitor/src/main/java/com/sematext/spm/client/command/IsTracingEnabledHandler.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.command; - -import org.apache.thrift.TException; - -import com.sematext.spm.client.Log; -import com.sematext.spm.client.LogFactory; -import com.sematext.spm.client.monitor.thrift.TCommand; -import com.sematext.spm.client.monitor.thrift.TCommandResponse; -import com.sematext.spm.client.monitor.thrift.TCommandResponseStatus; -import com.sematext.spm.client.monitor.thrift.TIsTracingEnabledResponse; -import com.sematext.spm.client.tracing.agent.config.ServiceLocator; -import com.sematext.spm.client.tracing.agent.impl.ThriftUtils; - -public final class IsTracingEnabledHandler implements CommandHandler { - - private final Log log = LogFactory.getLog(IsTracingEnabledHandler.class); - - @Override - public Cancellable handle(TCommand command, ResponseCallback callback) { - try { - final TIsTracingEnabledResponse isEnabledResp = new TIsTracingEnabledResponse(ServiceLocator - .getTracingAgentControl() - .isEnabled()); - byte[] serializedIsEnabledResp = ThriftUtils.binaryProtocolSerializer().serialize(isEnabledResp); - final TCommandResponse resp = new TCommandResponse(TCommandResponseStatus.SUCCESS, command.getId()); - resp.setResponse(serializedIsEnabledResp); - callback.respond(resp); - } catch (TException e) { - log.error("Can't serialize response.", e); - final TCommandResponse resp = new TCommandResponse(TCommandResponseStatus.SUCCESS, command.getId()); - resp.setFailureReason("Can't serialize response"); - callback.respond(resp); - } - return null; - } -} diff --git a/spm-monitor/src/main/java/com/sematext/spm/client/command/UpdateInstrumentationSettingsHandler.java b/spm-monitor/src/main/java/com/sematext/spm/client/command/UpdateInstrumentationSettingsHandler.java index 72028fc..0cf985e 100644 --- a/spm-monitor/src/main/java/com/sematext/spm/client/command/UpdateInstrumentationSettingsHandler.java +++ b/spm-monitor/src/main/java/com/sematext/spm/client/command/UpdateInstrumentationSettingsHandler.java @@ -19,6 +19,7 @@ */ package com.sematext.spm.client.command; +import com.sematext.spm.client.util.ThriftUtils; import org.apache.thrift.TException; import java.util.HashMap; @@ -31,9 +32,6 @@ import com.sematext.spm.client.monitor.thrift.TCommandResponseStatus; import com.sematext.spm.client.monitor.thrift.TInstrumentedMethodState; import com.sematext.spm.client.monitor.thrift.TUpdateInstrumentationSettings; -import com.sematext.spm.client.tracing.agent.TracingAgentControl; -import com.sematext.spm.client.tracing.agent.config.ServiceLocator; -import com.sematext.spm.client.tracing.agent.impl.ThriftUtils; import com.sematext.spm.client.unlogger.dynamic.BehaviorDescription; import com.sematext.spm.client.unlogger.dynamic.BehaviorState; @@ -53,7 +51,6 @@ public Cancellable handle(TCommand command, ResponseCallback callback) { callback.respond(response); return null; } - final Map state = new HashMap(); try { @@ -64,24 +61,13 @@ public Cancellable handle(TCommand command, ResponseCallback callback) { state.put(behDescription, behState); } - final TracingAgentControl agentControl = ServiceLocator.getTracingAgentControl(); - - agentControl.getInstrumentationSettings().update(state); - final boolean isStateApplied = agentControl.applyInstrumentationSettings(); - - log.info( - "Instrumentation settings " + (isStateApplied ? "Successfully applied" : "Not applied - tracing disabled")); + log.info("Instrumentation settings Not applied - tracing disabled"); final TCommandResponse response = new TCommandResponse(); - if (isStateApplied) { - response.setStatus(TCommandResponseStatus.SUCCESS); - response.setId(command.getId()); - } else { - response.setStatus(TCommandResponseStatus.FAILURE); - response.setId(command.getId()); - response.setFailureReason("Tracing is disabled"); - } + response.setStatus(TCommandResponseStatus.FAILURE); + response.setId(command.getId()); + response.setFailureReason("Tracing is disabled"); callback.respond(response); return null; diff --git a/spm-monitor/src/main/java/com/sematext/spm/client/tracing/TracingCrossAppCallStatsCollector.java b/spm-monitor/src/main/java/com/sematext/spm/client/tracing/TracingCrossAppCallStatsCollector.java deleted file mode 100644 index 2d60c07..0000000 --- a/spm-monitor/src/main/java/com/sematext/spm/client/tracing/TracingCrossAppCallStatsCollector.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing; - -import org.eclipse.collections.impl.map.mutable.UnifiedMap; - -import java.io.File; -import java.util.Collection; -import java.util.Map; - -import com.sematext.spm.client.GenericExtractor; -import com.sematext.spm.client.MonitorUtil; -import com.sematext.spm.client.MultipleStatsCollector; -import com.sematext.spm.client.Serializer; -import com.sematext.spm.client.StatValues; -import com.sematext.spm.client.StatValuesHelper; -import com.sematext.spm.client.tracing.agent.stats.CrossAppCall; - -public class TracingCrossAppCallStatsCollector extends MultipleStatsCollector { - private final String appToken; - private final String jvmName; - private final String subType; - private final File propsFile; - private final String finalJvmName; - - public TracingCrossAppCallStatsCollector(Serializer serializer, String appToken, String jvmName, String subType) { - super(serializer); - this.appToken = appToken; - this.jvmName = jvmName; - this.subType = subType; - if (subType == null || subType.trim().equals("")) { - this.finalJvmName = jvmName; - } else { - this.finalJvmName = jvmName + "-" + subType; - } - - this.propsFile = MonitorUtil.fetchSpmMonitorPropertiesFileObject(appToken, jvmName, subType); - } - - @Override - protected Collection getSlice(Map outerMetrics) { - return TracingStatsExtractors.callStatisticsView().crossAppCalls(); - } - - @Override - protected void appendStats(CrossAppCall call, StatValues statValues) { - statValues.setMetrics(new UnifiedMap()); - statValues.getMetrics().put("cross.app.call.src.duration", call.srcDuration()); - statValues.getMetrics().put("cross.app.call.dst.duration", call.dstDuration()); - statValues.getMetrics().put("cross.app.calls.count", call.callsCount()); - statValues.setTags(new UnifiedMap()); - statValues.getTags().put(GenericExtractor.JVM_NAME_TAG, finalJvmName); - statValues.getTags().put("tracing.cross.app.call.dst.token", call.dstToken()); - statValues.getTags().put("tracing.cross.app.call.dst.host", call.dstHostname()); - statValues.getTags().put("tracing.cross.app.call.tag", call.tag()); - statValues.getTags().put("tracing.cross.app.call.request", call.request()); - - StatValuesHelper.fillEnvTags(statValues, propsFile); - StatValuesHelper.fillConfigTags(statValues, MonitorUtil.loadMonitorProperties(propsFile)); - statValues.setTimestamp(System.currentTimeMillis()); - statValues.setAppToken(appToken); - statValues.setMetricNamespace("tracing"); - } - - @Override - public String getName() { - return "tracing-cross-app-call"; - } - - @Override - public String getCollectorIdentifier() { - return TracingCrossAppCallStatsCollector.class.getName(); - } -} diff --git a/spm-monitor/src/main/java/com/sematext/spm/client/tracing/TracingDatabaseOperationStatsCollector.java b/spm-monitor/src/main/java/com/sematext/spm/client/tracing/TracingDatabaseOperationStatsCollector.java deleted file mode 100644 index 8884fd6..0000000 --- a/spm-monitor/src/main/java/com/sematext/spm/client/tracing/TracingDatabaseOperationStatsCollector.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing; - -import org.eclipse.collections.impl.map.mutable.UnifiedMap; - -import java.io.File; -import java.util.Collection; -import java.util.Map; - -import com.sematext.spm.client.GenericExtractor; -import com.sematext.spm.client.MonitorUtil; -import com.sematext.spm.client.MultipleStatsCollector; -import com.sematext.spm.client.Serializer; -import com.sematext.spm.client.StatValues; -import com.sematext.spm.client.StatValuesHelper; -import com.sematext.spm.client.tracing.agent.stats.DatabaseOperationMetric; - -public class TracingDatabaseOperationStatsCollector extends MultipleStatsCollector { - private final String appToken; - private final String jvmName; - private final String subType; - private final File propsFile; - private final String finalJvmName; - - public TracingDatabaseOperationStatsCollector(Serializer serializer, String appToken, String jvmName, - String subType) { - super(serializer); - this.appToken = appToken; - this.jvmName = jvmName; - this.subType = subType; - if (subType == null || subType.trim().equals("")) { - this.finalJvmName = jvmName; - } else { - this.finalJvmName = jvmName + "-" + subType; - } - - this.propsFile = MonitorUtil.fetchSpmMonitorPropertiesFileObject(appToken, jvmName, subType); - } - - @Override - protected Collection getSlice(Map outerMetrics) { - return TracingStatsExtractors.callStatisticsView().databaseOperationMetrics(); - } - - @Override - protected void appendStats(DatabaseOperationMetric s, StatValues statValues) { - statValues.setMetrics(new UnifiedMap()); - statValues.getMetrics().put("database.ops", s.count()); - statValues.getMetrics().put("database.ops.time", s.duration()); - statValues.setTags(new UnifiedMap()); - statValues.getTags().put(GenericExtractor.JVM_NAME_TAG, finalJvmName); - statValues.getTags().put("tracing.db.operation.db", s.getId().getDatabase()); - statValues.getTags().put("tracing.db.operation.operation", s.getId().getOperation()); - - StatValuesHelper.fillEnvTags(statValues, propsFile); - StatValuesHelper.fillConfigTags(statValues, MonitorUtil.loadMonitorProperties(propsFile)); - statValues.setTimestamp(System.currentTimeMillis()); - statValues.setAppToken(appToken); - statValues.setMetricNamespace("tracing"); - } - - @Override - public String getName() { - return "tracing-database-operation"; - } - - @Override - public String getCollectorIdentifier() { - return TracingDatabaseOperationStatsCollector.class.getName(); - } -} diff --git a/spm-monitor/src/main/java/com/sematext/spm/client/tracing/TracingExternalCallStatsCollector.java b/spm-monitor/src/main/java/com/sematext/spm/client/tracing/TracingExternalCallStatsCollector.java deleted file mode 100644 index fef9642..0000000 --- a/spm-monitor/src/main/java/com/sematext/spm/client/tracing/TracingExternalCallStatsCollector.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing; - -import org.eclipse.collections.impl.map.mutable.UnifiedMap; - -import java.io.File; -import java.util.Collection; -import java.util.Map; - -import com.sematext.spm.client.GenericExtractor; -import com.sematext.spm.client.MonitorUtil; -import com.sematext.spm.client.MultipleStatsCollector; -import com.sematext.spm.client.Serializer; -import com.sematext.spm.client.StatValues; -import com.sematext.spm.client.StatValuesHelper; -import com.sematext.spm.client.tracing.agent.stats.ExternalCall; - -public class TracingExternalCallStatsCollector extends MultipleStatsCollector { - private final String appToken; - private final String jvmName; - private final String subType; - private final File propsFile; - private final String finalJvmName; - - public TracingExternalCallStatsCollector(Serializer serializer, String appToken, String jvmName, String subType) { - super(serializer); - this.appToken = appToken; - this.jvmName = jvmName; - this.subType = subType; - if (subType == null || subType.trim().equals("")) { - this.finalJvmName = jvmName; - } else { - this.finalJvmName = jvmName + "-" + subType; - } - - this.propsFile = MonitorUtil.fetchSpmMonitorPropertiesFileObject(appToken, jvmName, subType); - } - - @Override - protected Collection getSlice(Map outerMetrics) { - return TracingStatsExtractors.callStatisticsView().externalCalls(); - } - - @Override - protected void appendStats(ExternalCall call, StatValues statValues) { - statValues.setMetrics(new UnifiedMap()); - statValues.getMetrics().put("external.call.duration", call.duration()); - statValues.getMetrics().put("external.calls.count", call.callsCount()); - statValues.setTags(new UnifiedMap()); - statValues.getTags().put(GenericExtractor.JVM_NAME_TAG, finalJvmName); - statValues.getTags().put("tracing.external.call.destination", call.dstHostname()); - statValues.getTags().put("tracing.external.call.tag", call.tag()); - - StatValuesHelper.fillEnvTags(statValues, propsFile); - StatValuesHelper.fillConfigTags(statValues, MonitorUtil.loadMonitorProperties(propsFile)); - statValues.setTimestamp(System.currentTimeMillis()); - statValues.setAppToken(appToken); - statValues.setMetricNamespace("tracing"); - } - - @Override - public String getName() { - return "tracing-external-call"; - } - - @Override - public String getCollectorIdentifier() { - return TracingExternalCallStatsCollector.class.getName(); - } -} diff --git a/spm-monitor/src/main/java/com/sematext/spm/client/tracing/TracingMonitorConfigurator.java b/spm-monitor/src/main/java/com/sematext/spm/client/tracing/TracingMonitorConfigurator.java deleted file mode 100644 index 823bfa2..0000000 --- a/spm-monitor/src/main/java/com/sematext/spm/client/tracing/TracingMonitorConfigurator.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing; - -import java.util.List; - -import com.sematext.spm.client.MonitorConfig; -import com.sematext.spm.client.Serializer; -import com.sematext.spm.client.StatsCollector; -import com.sematext.spm.client.StatsCollectorBadConfigurationException; -import com.sematext.spm.client.StatsCollectorsFactory; -import com.sematext.spm.client.util.CollectionUtils.FunctionT; - -public final class TracingMonitorConfigurator { - public void configure(final MonitorConfig monitorConfig, final List> currentCollectors, - final List> collectors, - final Serializer serializer, final String appToken, final String subType, final String jvmName) - throws StatsCollectorBadConfigurationException { - StatsCollectorsFactory.updateCollector(currentCollectors, collectors, TracingReqCompStatsCollector.class, - TracingReqCompStatsCollector.class.getName(), - new FunctionT() { - @Override - public TracingReqCompStatsCollector apply(String id) { - return new TracingReqCompStatsCollector(serializer, appToken, jvmName, subType); - } - }); - - StatsCollectorsFactory.updateCollector(currentCollectors, collectors, TracingReqStatsCollector.class, - TracingReqStatsCollector.class.getName(), - new FunctionT() { - @Override - public TracingReqStatsCollector apply(String id) { - return new TracingReqStatsCollector(serializer, appToken, jvmName, subType, monitorConfig); - } - }); - - StatsCollectorsFactory.updateCollector(currentCollectors, collectors, TracingCrossAppCallStatsCollector.class, - TracingCrossAppCallStatsCollector.class.getName(), - new FunctionT() { - @Override - public TracingCrossAppCallStatsCollector apply(String id) { - return new TracingCrossAppCallStatsCollector(serializer, appToken, jvmName, subType); - } - }); - - StatsCollectorsFactory.updateCollector(currentCollectors, collectors, TracingExternalCallStatsCollector.class, - TracingExternalCallStatsCollector.class.getName(), - new FunctionT() { - @Override - public TracingExternalCallStatsCollector apply(String id) { - return new TracingExternalCallStatsCollector(serializer, appToken, jvmName, subType); - } - }); - - StatsCollectorsFactory.updateCollector(currentCollectors, collectors, TracingReqErrorsStatsCollector.class, - TracingReqErrorsStatsCollector.class.getName(), - new FunctionT() { - @Override - public TracingReqErrorsStatsCollector apply(String id) { - return new TracingReqErrorsStatsCollector(serializer, appToken, jvmName, subType); - } - }); - - StatsCollectorsFactory.updateCollector(currentCollectors, collectors, TracingDatabaseOperationStatsCollector.class, - TracingDatabaseOperationStatsCollector.class.getName(), - new FunctionT() { - @Override - public TracingDatabaseOperationStatsCollector apply(String id) { - return new TracingDatabaseOperationStatsCollector(serializer, appToken, jvmName, subType); - } - }); - } -} diff --git a/spm-monitor/src/main/java/com/sematext/spm/client/tracing/TracingReqCompStatsCollector.java b/spm-monitor/src/main/java/com/sematext/spm/client/tracing/TracingReqCompStatsCollector.java deleted file mode 100644 index f658792..0000000 --- a/spm-monitor/src/main/java/com/sematext/spm/client/tracing/TracingReqCompStatsCollector.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing; - -import org.eclipse.collections.impl.map.mutable.UnifiedMap; - -import java.io.File; -import java.util.Collection; -import java.util.Map; - -import com.sematext.spm.client.GenericExtractor; -import com.sematext.spm.client.MonitorUtil; -import com.sematext.spm.client.MultipleStatsCollector; -import com.sematext.spm.client.Serializer; -import com.sematext.spm.client.StatValues; -import com.sematext.spm.client.StatValuesHelper; -import com.sematext.spm.client.tracing.agent.stats.RequestComponentMetric; - -public class TracingReqCompStatsCollector extends MultipleStatsCollector { - private final String appToken; - private final String jvmName; - private final String subType; - private final File propsFile; - private final String finalJvmName; - - public TracingReqCompStatsCollector(Serializer serializer, String appToken, String jvmName, String subType) { - super(serializer); - this.appToken = appToken; - this.jvmName = jvmName; - this.subType = subType; - if (subType == null || subType.trim().equals("")) { - this.finalJvmName = jvmName; - } else { - this.finalJvmName = jvmName + "-" + subType; - } - - this.propsFile = MonitorUtil.fetchSpmMonitorPropertiesFileObject(appToken, jvmName, subType); - } - - @Override - protected Collection getSlice(Map outerMetrics) { - return TracingStatsExtractors.callStatisticsView().requestComponentMetrics(); - } - - @Override - protected void appendStats(RequestComponentMetric s, StatValues statValues) { - statValues.setMetrics(new UnifiedMap()); - statValues.getMetrics().put("component.requests", s.getCount()); - statValues.getMetrics().put("component.requests.time", s.getDuration()); - statValues.setTags(new UnifiedMap()); - statValues.getTags().put(GenericExtractor.JVM_NAME_TAG, finalJvmName); - statValues.getTags().put("tracing.request", s.getId().getRequest()); - statValues.getTags().put("tracing.component", s.getId().getComponent()); - - StatValuesHelper.fillEnvTags(statValues, propsFile); - StatValuesHelper.fillConfigTags(statValues, MonitorUtil.loadMonitorProperties(propsFile)); - statValues.setTimestamp(System.currentTimeMillis()); - statValues.setAppToken(appToken); - statValues.setMetricNamespace("tracing"); - } - - @Override - public String getName() { - return "tracing-req-comp"; - } - - @Override - public String getCollectorIdentifier() { - return getClass().getName(); - } -} diff --git a/spm-monitor/src/main/java/com/sematext/spm/client/tracing/TracingReqErrorsStatsCollector.java b/spm-monitor/src/main/java/com/sematext/spm/client/tracing/TracingReqErrorsStatsCollector.java deleted file mode 100644 index 5b99436..0000000 --- a/spm-monitor/src/main/java/com/sematext/spm/client/tracing/TracingReqErrorsStatsCollector.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing; - -import org.eclipse.collections.impl.map.mutable.UnifiedMap; - -import java.io.File; -import java.util.Collection; -import java.util.Map; - -import com.sematext.spm.client.GenericExtractor; -import com.sematext.spm.client.MonitorUtil; -import com.sematext.spm.client.MultipleStatsCollector; -import com.sematext.spm.client.Serializer; -import com.sematext.spm.client.StatValues; -import com.sematext.spm.client.StatValuesHelper; -import com.sematext.spm.client.tracing.agent.stats.RequestErrorsMetric; - -public class TracingReqErrorsStatsCollector extends MultipleStatsCollector { - private final String appToken; - private final String jvmName; - private final String subType; - private final File propsFile; - private final String finalJvmName; - - public TracingReqErrorsStatsCollector(Serializer serializer, String appToken, String jvmName, String subType) { - super(serializer); - this.appToken = appToken; - this.jvmName = jvmName; - this.subType = subType; - if (subType == null || subType.trim().equals("")) { - this.finalJvmName = jvmName; - } else { - this.finalJvmName = jvmName + "-" + subType; - } - - this.propsFile = MonitorUtil.fetchSpmMonitorPropertiesFileObject(appToken, jvmName, subType); - } - - @Override - protected Collection getSlice(Map outerMetrics) { - return TracingStatsExtractors.callStatisticsView().requestErrorMetrics(); - } - - @Override - protected void appendStats(RequestErrorsMetric metric, StatValues statValues) { - statValues.setMetrics(new UnifiedMap()); - statValues.getMetrics().put("requests.troubles", metric.getErrorsCount()); - statValues.getMetrics().put("requests.exceptions", metric.getExceptionsCount()); - statValues.getMetrics().put("requests.errors.4xx", metric.getResponseCode4xxCount()); - statValues.getMetrics().put("requests.errors.5xx", metric.getResponseCode5xxCount()); - statValues.setTags(new UnifiedMap()); - statValues.getTags().put(GenericExtractor.JVM_NAME_TAG, finalJvmName); - statValues.getTags().put("tracing.request", metric.getId()); - - StatValuesHelper.fillEnvTags(statValues, propsFile); - StatValuesHelper.fillConfigTags(statValues, MonitorUtil.loadMonitorProperties(propsFile)); - statValues.setTimestamp(System.currentTimeMillis()); - statValues.setAppToken(appToken); - statValues.setMetricNamespace("tracing"); - } - - @Override - public String getName() { - return "tracing-req-errors"; - } - - @Override - public String getCollectorIdentifier() { - return getClass().getName(); - } -} diff --git a/spm-monitor/src/main/java/com/sematext/spm/client/tracing/TracingReqStatsCollector.java b/spm-monitor/src/main/java/com/sematext/spm/client/tracing/TracingReqStatsCollector.java deleted file mode 100644 index 1dda113..0000000 --- a/spm-monitor/src/main/java/com/sematext/spm/client/tracing/TracingReqStatsCollector.java +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing; - -import org.eclipse.collections.impl.map.mutable.UnifiedMap; - -import java.io.File; -import java.util.Collection; -import java.util.Map; - -import com.sematext.spm.client.GenericExtractor; -import com.sematext.spm.client.Log; -import com.sematext.spm.client.LogFactory; -import com.sematext.spm.client.MonitorConfig; -import com.sematext.spm.client.MonitorUtil; -import com.sematext.spm.client.MultipleStatsCollector; -import com.sematext.spm.client.Serializer; -import com.sematext.spm.client.StatValues; -import com.sematext.spm.client.StatValuesHelper; -import com.sematext.spm.client.attributes.MetricType; -import com.sematext.spm.client.metrics.DecideFlushMetricsProcessor; -import com.sematext.spm.client.metrics.MetricsProcessorContext; -import com.sematext.spm.client.metrics.PercentilesMetricsProcessor; -import com.sematext.spm.client.observation.PercentilesDefinition; -import com.sematext.spm.client.tracing.agent.stats.RequestMetric; - -public class TracingReqStatsCollector extends MultipleStatsCollector { - private static final Log LOG = LogFactory.getLog(TracingReqStatsCollector.class); - - private final String appToken; - private final String jvmName; - private final String subType; - private final File propsFile; - private final String finalJvmName; - - private final MetricsProcessorContext context; - private final DecideFlushMetricsProcessor decideFlushProcessor; - private final PercentilesMetricsProcessor pctlsProcessor; - - public TracingReqStatsCollector(Serializer serializer, String appToken, String jvmName, String subType, - MonitorConfig monitorConfig) { - super(serializer); - this.appToken = appToken; - this.jvmName = jvmName; - this.subType = subType; - if (subType == null || subType.trim().equals("")) { - this.finalJvmName = jvmName; - } else { - this.finalJvmName = jvmName + "-" + subType; - } - - this.propsFile = MonitorUtil.fetchSpmMonitorPropertiesFileObject(appToken, jvmName, subType); - - this.decideFlushProcessor = new DecideFlushMetricsProcessor(monitorConfig.getMonitorCollectInterval()); - this.pctlsProcessor = new PercentilesMetricsProcessor(); - - context = new MetricsProcessorContext(); - context.collectorName = getCollectorIdentifier(); - context.knownMetricTypes = new UnifiedMap(2); - context.knownMetricTypes.put("requests.count", MetricType.COUNTER); - context.knownMetricTypes.put("requests.time", MetricType.COUNTER); - context.percentilesDefinitions = new UnifiedMap(); - PercentilesDefinition latencyPctl = new PercentilesDefinition("99, 95, 50", "requests.latency.avg"); - context.percentilesDefinitions.put("requests.latency.avg", latencyPctl); - } - - @Override - protected Collection getSlice(Map outerMetrics) { - return TracingStatsExtractors.callStatisticsView().requestMetrics(); - } - - @Override - protected void appendStats(RequestMetric s, StatValues statValues) { - Long count = s.getCount(); - Long duration = s.getDuration(); - - statValues.setMetrics(new UnifiedMap()); - statValues.getMetrics().put("requests.count", count); - statValues.getMetrics().put("requests.time", duration); - statValues.setTags(new UnifiedMap()); - statValues.getTags().put(GenericExtractor.JVM_NAME_TAG, finalJvmName); - statValues.getTags().put("tracing.request", s.getId()); - - StatValuesHelper.fillEnvTags(statValues, propsFile); - StatValuesHelper.fillConfigTags(statValues, MonitorUtil.loadMonitorProperties(propsFile)); - statValues.setTimestamp(System.currentTimeMillis()); - statValues.setAppToken(appToken); - statValues.setMetricNamespace("tracing"); - - context.reset(); - context.statValues = statValues; - if (count != null && duration != null) { - if (count > 0) { - statValues.getMetrics().put("requests.latency.avg", (duration.doubleValue()) / count); - } - } - decideFlushProcessor.process(context); - pctlsProcessor.process(context); - } - - @Override - public String getName() { - return "tracing-req"; - } - - @Override - public String getCollectorIdentifier() { - return getClass().getName(); - } -} diff --git a/spm-monitor/src/main/java/com/sematext/spm/client/tracing/TracingStatsExtractors.java b/spm-monitor/src/main/java/com/sematext/spm/client/tracing/TracingStatsExtractors.java deleted file mode 100644 index e9acb1d..0000000 --- a/spm-monitor/src/main/java/com/sematext/spm/client/tracing/TracingStatsExtractors.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing; - -import java.util.concurrent.atomic.AtomicLong; - -import com.sematext.spm.client.attributes.RealCounterValueHolder; -import com.sematext.spm.client.tracing.agent.config.ServiceLocator; -import com.sematext.spm.client.tracing.agent.stats.DiffCounterVar; -import com.sematext.spm.client.tracing.agent.stats.MutableVarProvider; -import com.sematext.spm.client.tracing.agent.stats.StatisticsView; -import com.sematext.spm.client.tracing.agent.stats.TracingStatistics; - -public final class TracingStatsExtractors { - - private static TracingStatistics getTracingStatistics() { - return ServiceLocator.getTracingStatistics(); - } - - private static volatile TracingStatistics TRACING_STATISTICS = null; - private static volatile StatisticsView CALL_STATISTICS_VIEW = null; - - private static class CounterValueHolderVar implements DiffCounterVar { - private final RealCounterValueHolder holder = new RealCounterValueHolder(); - private final AtomicLong accumulated = new AtomicLong(0L); - - public CounterValueHolderVar() { - holder.getValue(0L); - } - - @Override - public Long increment(Long diff) { - return accumulated.addAndGet(diff); - } - - @Override - public Long get() { - return holder.getValue(accumulated.get()); - } - } - - private static MutableVarProvider MUTABLE_VAR_PROVIDER = new MutableVarProvider() { - @Override - @SuppressWarnings("unchecked") - public > DiffCounterVar newCounter(C klass) { - if (Long.class.equals(klass)) { - return (DiffCounterVar) new CounterValueHolderVar(); - } - throw new IllegalArgumentException("Counter of type '" + klass + "' is not implemented."); - } - }; - - public static StatisticsView callStatisticsView() { - if (getTracingStatistics() != TRACING_STATISTICS) { - synchronized (TracingStatsExtractors.class) { - TracingStatistics current = getTracingStatistics(); - if (current != TRACING_STATISTICS) { - CALL_STATISTICS_VIEW = current.newCallStatisticsView(MUTABLE_VAR_PROVIDER); - TRACING_STATISTICS = current; - } - } - } - return CALL_STATISTICS_VIEW; - } -} diff --git a/spm-monitor/src/test/java/com/sematext/spm/client/command/CommandPollingTest.java b/spm-monitor/src/test/java/com/sematext/spm/client/command/CommandPollingTest.java index 869dc35..438d1e2 100644 --- a/spm-monitor/src/test/java/com/sematext/spm/client/command/CommandPollingTest.java +++ b/spm-monitor/src/test/java/com/sematext/spm/client/command/CommandPollingTest.java @@ -24,6 +24,7 @@ import static junit.framework.Assert.assertNull; import static junit.framework.TestCase.assertNotNull; +import com.sematext.spm.client.util.ThriftUtils; import com.sun.net.httpserver.HttpExchange; import com.sun.net.httpserver.HttpHandler; import com.sun.net.httpserver.HttpServer; @@ -54,7 +55,6 @@ import com.sematext.spm.client.monitor.thrift.TCommandResponseStatus; import com.sematext.spm.client.monitor.thrift.TCommandType; import com.sematext.spm.client.snap.serializer.TBinaryProto; -import com.sematext.spm.client.tracing.agent.impl.ThriftUtils; @RunWith(DataProviderRunner.class) public class CommandPollingTest { diff --git a/spm-sender/pom.xml b/spm-sender/pom.xml index cc93e78..d72d9f1 100644 --- a/spm-sender/pom.xml +++ b/spm-sender/pom.xml @@ -299,7 +299,7 @@ org.apache.logging.log4j log4j-core - 2.17.0 + 2.17.2 compile diff --git a/spm-thrift-data/pom.xml b/spm-thrift-data/pom.xml index 328dd42..7ffcdc3 100644 --- a/spm-thrift-data/pom.xml +++ b/spm-thrift-data/pom.xml @@ -44,6 +44,7 @@ org.codehaus.mojo build-helper-maven-plugin + 3.3.0 generate-sources @@ -66,7 +67,7 @@ org.apache.thrift libthrift - 0.14.0 + 0.16.0 org.apache.httpcomponents @@ -114,7 +115,7 @@ org.apache.logging.log4j log4j-core - 2.17.0 + 2.17.2 compile diff --git a/spm-tracing-agent-impl/pom.xml b/spm-tracing-agent-impl/pom.xml deleted file mode 100644 index d77537d..0000000 --- a/spm-tracing-agent-impl/pom.xml +++ /dev/null @@ -1,91 +0,0 @@ - - 4.0.0 - - - com.sematext.spm - spm-client-parent - 3.0.0 - - - spm-tracing-agent-impl - jar - SPM Tracing Agent Implementation - SPM system monitoring tool - http://maven.apache.org - - - - com.sematext.spm - spm-tracing-agent - ${project.version} - provided - - - com.sematext.spm - spm-sender - ${project.version} - provided - - - com.sematext.spm - spm-thrift-data - ${project.version} - - - - - - - - com.lmax - disruptor - 3.3.0 - - - junit - junit - ${junit.version} - test - - - org.apache.logging.log4j - log4j-core - 2.17.0 - compile - - - - - - - org.apache.maven.plugins - maven-assembly-plugin - 2.4 - - - dist-classic - package - - single - - - ${project.artifactId}-${project.version}-withdeps - false - - jar-with-dependencies - - - - com.sematext.spm.tracing.agent.impl.AgentInitializer - true - - - - - - - - - - diff --git a/spm-tracing-agent-impl/src/main/java/com/sematext/spm/client/tracing/agent/config/DefaultServiceConfigurer.java b/spm-tracing-agent-impl/src/main/java/com/sematext/spm/client/tracing/agent/config/DefaultServiceConfigurer.java deleted file mode 100644 index f948da2..0000000 --- a/spm-tracing-agent-impl/src/main/java/com/sematext/spm/client/tracing/agent/config/DefaultServiceConfigurer.java +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.config; - -import java.lang.instrument.Instrumentation; -import java.util.Arrays; -import java.util.List; -import java.util.concurrent.TimeUnit; - -import com.sematext.spm.client.tracing.agent.MuxSink; -import com.sematext.spm.client.tracing.agent.Sink; -import com.sematext.spm.client.tracing.agent.TracingAgentControl; -import com.sematext.spm.client.tracing.agent.errors.TracingError; -import com.sematext.spm.client.tracing.agent.impl.DisruptorThriftEventSink; -import com.sematext.spm.client.tracing.agent.impl.TracingAgentControlImpl; -import com.sematext.spm.client.tracing.agent.impl.TracingStatisticsImpl; -import com.sematext.spm.client.tracing.agent.model.PartialTransaction; -import com.sematext.spm.client.tracing.agent.sampling.FixedRateSampler; -import com.sematext.spm.client.tracing.agent.sampling.Sampler; -import com.sematext.spm.client.tracing.agent.sampling.TracingErrorFixedRateSampler; -import com.sematext.spm.client.tracing.agent.sampling.WeightedFixedRateSampler; -import com.sematext.spm.client.tracing.agent.stats.TracingStatistics; -import com.sematext.spm.client.util.StorageUnit; - -public class DefaultServiceConfigurer implements ServiceConfigurer { - private Config config; - private Sampler transactionSampler; - private Sampler tracingErrorSampler; - private List> transactionSinks; - private List> errorSinks; - private TracingStatistics tracingStatistics; - private TracingAgentControl tracingAgentControl; - - private DefaultServiceConfigurer() { - } - - @Override - public Config getConfig() { - return config; - } - - @Override - public Sampler getTransactionSampler() { - return transactionSampler; - } - - @Override - public Sampler getTracingErrorSampler() { - return tracingErrorSampler; - } - - @Override - public List> getTransactionSinks() { - return transactionSinks; - } - - @Override - public List> getErrorSinks() { - return errorSinks; - } - - @Override - public TracingStatistics getTracingStatistics() { - return tracingStatistics; - } - - @Override - public TracingAgentControl getTracingAgentControl() { - return tracingAgentControl; - } - - @SuppressWarnings("unchecked") - public static DefaultServiceConfigurer embeddedAgentConfigurer(final String args, Instrumentation instrumentation, - boolean tracingEnabled, ClassLoader loader) { - final DefaultServiceConfigurer configurer = new DefaultServiceConfigurer(); - - configurer.config = Config.embeddedAgentConfig(args); - configurer.transactionSampler = new FixedRateSampler(1, TimeUnit.MINUTES, 10000); - - final DisruptorThriftEventSink eventSink = DisruptorThriftEventSink - .create(configurer.config.getLogPath(), (int) StorageUnit.MEGABYTES.toBytes(100), 3); - configurer.transactionSinks = Arrays.>asList(new MuxSink(eventSink)); - configurer.errorSinks = Arrays.>asList(new MuxSink(eventSink)); - - configurer.transactionSampler = new WeightedFixedRateSampler(1, 1, 1, TimeUnit.SECONDS); - configurer.tracingErrorSampler = new TracingErrorFixedRateSampler(100, 1, TimeUnit.MINUTES); - configurer.tracingStatistics = new TracingStatisticsImpl(); - configurer.tracingAgentControl = TracingAgentControlImpl - .create(tracingEnabled, instrumentation, loader, configurer.config); - return configurer; - } -} diff --git a/spm-tracing-agent-impl/src/main/java/com/sematext/spm/client/tracing/agent/impl/AgentInitializer.java b/spm-tracing-agent-impl/src/main/java/com/sematext/spm/client/tracing/agent/impl/AgentInitializer.java deleted file mode 100644 index 5141e88..0000000 --- a/spm-tracing-agent-impl/src/main/java/com/sematext/spm/client/tracing/agent/impl/AgentInitializer.java +++ /dev/null @@ -1,135 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.impl; - -import java.io.File; -import java.lang.instrument.Instrumentation; -import java.util.concurrent.TimeUnit; - -import com.sematext.spm.client.DataFormat; -import com.sematext.spm.client.Log; -import com.sematext.spm.client.LogFactory; -import com.sematext.spm.client.MonitorUtil; -import com.sematext.spm.client.sender.SenderUtil; -import com.sematext.spm.client.tracing.agent.config.DefaultServiceConfigurer; -import com.sematext.spm.client.tracing.agent.config.ServiceLocator; -import com.sematext.spm.client.tracing.agent.sampling.Stats; -import com.sematext.spm.client.tracing.agent.sampling.StatsReporter; -import com.sematext.spm.client.unlogger.dynamic.BehaviorDescription; -import com.sematext.spm.client.unlogger.dynamic.BehaviorState; -import com.sematext.spm.client.util.FifoInterface; - -public class AgentInitializer { - private static final Log LOG = LogFactory.getLog(AgentInitializer.class); - - public static void premain(String args, Instrumentation instrumentation) throws Exception { - init(args, instrumentation, true, true); - } - - private static void startFifo() { - final String fifoPath = System.getProperty("spm.tracing.agent.fifo"); - if (fifoPath != null && new File(fifoPath).exists()) { - final TracingAgentControlImpl ctl = (TracingAgentControlImpl) ServiceLocator.getTracingAgentControl(); - LOG.info("Starting FIFO debug interface for " + fifoPath); - - FifoInterface.create() - .addHandler("enableTracing", new FifoInterface.Handler() { - @Override - public void handle(String... args) { - LOG.info("Got enable tracing command. Tracing enabled: " + ctl.enable()); - } - }) - .addHandler("disableTracing", new FifoInterface.Handler() { - @Override - public void handle(String... args) { - LOG.info("Got disable tracing command. Tracing disabled: " + ctl.disable()); - } - }) - .addHandler("statistics", new FifoInterface.Handler() { - @Override - public void handle(String... args) { - LOG.info(ctl.getStatistics()); - } - }) - .addHandler("getWeavedClasses", new FifoInterface.Handler() { - @Override - public void handle(String[] arguments) { - LOG.info(ctl.getWeavedClasses()); - } - }) - .addHandler("instrumentMethod", new FifoInterface.Handler() { - @Override - public void handle(String[] args) { - if (args.length == 1) { - String signature = args[0]; - - ctl.getInstrumentationSettings() - .updateBehaviorState(new BehaviorDescription(signature), new BehaviorState(true, true)); - LOG.info("Got updateBehaviorState command: " + ctl.applyInstrumentationSettings()); - } - } - }) - .addHandler("uninstrumentMethod", new FifoInterface.Handler() { - @Override - public void handle(String[] args) { - if (args.length == 1) { - String signature = args[0]; - - ctl.getInstrumentationSettings() - .updateBehaviorState(new BehaviorDescription(signature), new BehaviorState(false, false)); - LOG.info("Got uninstrumentMethod command: " + ctl.applyInstrumentationSettings()); - } - } - }) - .start(fifoPath); - } - } - - public static void init(String args, Instrumentation instrumentation, boolean tracingEnabled, boolean initLogging) - throws Exception { - ServiceLocator.configure(DefaultServiceConfigurer - .embeddedAgentConfigurer(args, instrumentation, tracingEnabled, AgentInitializer.class - .getClassLoader())); - - // createRuntimeConfig(); - - if (initLogging) { - MonitorUtil.MonitorArgs monitorArgs = MonitorUtil.extractMonitorArgs(args); - Integer processOrdinal = MonitorUtil - .obtainMonitorLock(monitorArgs.getToken(), monitorArgs.getJvmName(), monitorArgs.getSubType()); - - if (SenderUtil.isInContainer() || SenderUtil.isInKubernetes()) { - LogFactory.initStdoutLogger(System.getProperty("spm.tracing.loglevel", "INFO"), DataFormat.PLAIN_TEXT); - } else { - LogFactory.initFileLogger(ServiceLocator.getConfig().getLogPath(), 1024 * 1024 * 100, 10, - System.getProperty("spm.tracing.loglevel", "INFO"), DataFormat.PLAIN_TEXT, - processOrdinal); - } - } - - startFifo(); - - LOG.info("SPM Tracing Agent Initialized."); - - if (Boolean.getBoolean("spm.tracing.sampler.stats")) { - StatsReporter.start(Stats.INSTANCE, Long.getLong("spm.tracing.sampler.interval", 500), TimeUnit.MILLISECONDS); - } - } -} diff --git a/spm-tracing-agent-impl/src/main/java/com/sematext/spm/client/tracing/agent/impl/AsyncFileCallSink.java b/spm-tracing-agent-impl/src/main/java/com/sematext/spm/client/tracing/agent/impl/AsyncFileCallSink.java deleted file mode 100644 index 84dbc03..0000000 --- a/spm-tracing-agent-impl/src/main/java/com/sematext/spm/client/tracing/agent/impl/AsyncFileCallSink.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.impl; - -import java.util.concurrent.ArrayBlockingQueue; -import java.util.concurrent.TimeUnit; - -import com.sematext.spm.client.Log; -import com.sematext.spm.client.LogFactory; -import com.sematext.spm.client.tracing.BinarySequentialLog; -import com.sematext.spm.client.tracing.BinarySequentialSender; -import com.sematext.spm.client.tracing.agent.Sink; -import com.sematext.spm.client.tracing.agent.model.PartialTransaction; - -public final class AsyncFileCallSink implements Sink { - private static final Log LOG = LogFactory.getLog(AsyncFileCallSink.class); - - private final ArrayBlockingQueue calls = new ArrayBlockingQueue(1000); - private volatile boolean running = true; - private final BinarySequentialSender binaryLog; - - private AsyncFileCallSink(BinarySequentialSender binaryLog) { - this.binaryLog = binaryLog; - } - - private Thread sinkThread = new Thread() { - @Override - public void run() { - while (running) { - try { - final byte[] call = calls.poll(10, TimeUnit.MILLISECONDS); - if (call != null) { - binaryLog.write(call); - } - } catch (InterruptedException e) { - LOG.warn("Sink thread was interrupted.", e); - } - } - if (LOG.isTraceEnabled()) { - LOG.trace("Sink thread exited."); - } - } - }; - - @Override - public void sink(PartialTransaction transaction) { - try { - if (!calls.offer(ThriftPartialTransactionSerializer.serialize(transaction), 10, TimeUnit.MILLISECONDS)) { - if (LOG.isTraceEnabled()) { - LOG.trace("Queue is full, can't offer new call."); - } - } - } catch (Throwable e) { - LOG.warn("Call offer was interrupted.", e); - } - } - - public static AsyncFileCallSink create(String basedir, int maxFileSize, int retentionCount) { - final AsyncFileCallSink sink = new AsyncFileCallSink( - new BinarySequentialSender(BinarySequentialLog - .create(basedir, "tracing", ".bin", maxFileSize, retentionCount))); - sink.sinkThread.setDaemon(true); - sink.sinkThread.setName("spm-tracing-sink-thread"); - sink.sinkThread.start(); - return sink; - } -} diff --git a/spm-tracing-agent-impl/src/main/java/com/sematext/spm/client/tracing/agent/impl/AsyncLockFreeCallSink.java b/spm-tracing-agent-impl/src/main/java/com/sematext/spm/client/tracing/agent/impl/AsyncLockFreeCallSink.java deleted file mode 100644 index 534a235..0000000 --- a/spm-tracing-agent-impl/src/main/java/com/sematext/spm/client/tracing/agent/impl/AsyncLockFreeCallSink.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.impl; - -//import com.sematext.spm.client.tracing.BinarySequentialSender; - -public class AsyncLockFreeCallSink /*implements Sink*/ { -// -// private static final Log LOG = LogFactory.getLog(AsyncFileCallSink.class); -// -// private final ConcurrentLinkedQueue calls = new ConcurrentLinkedQueue(); -// private final BinarySequentialSender binaryLog; -// private volatile boolean running = true; -// private Thread sinkThread = new Thread() { -// @Override -// public void run() { -// while (running) { -// final Call call = calls.poll(); -// if (call != null) { -// binaryLog.write(ThriftCallSerializer.serialize(call)); -// } -// } -// if (LOG.isTraceEnabled()) { -// LOG.trace("Sink thread exited."); -// } -// } -// }; -// -// private AsyncLockFreeCallSink(BinarySequentialSender binaryLog) { -// this.binaryLog = binaryLog; -// } -// -// public static AsyncLockFreeCallSink create(String basedir, int maxFileSize, int retentionCount) { -// final AsyncLockFreeCallSink sink = new AsyncLockFreeCallSink( -// new BinarySequentialSender(BinarySequentialLog.create(basedir, "tracing", ".bin", maxFileSize, retentionCount))); -// sink.sinkThread.setDaemon(true); -// sink.sinkThread.setName("spm-tracing-sink-thread"); -// sink.sinkThread.start(); -// return sink; -// } -// -// @Override -// public void sink(PartialTransaction transaction) { -// throw new IllegalStateException("not implemented."); -// } -} diff --git a/spm-tracing-agent-impl/src/main/java/com/sematext/spm/client/tracing/agent/impl/DisruptorFileCallSink.java b/spm-tracing-agent-impl/src/main/java/com/sematext/spm/client/tracing/agent/impl/DisruptorFileCallSink.java deleted file mode 100644 index 5cee2ae..0000000 --- a/spm-tracing-agent-impl/src/main/java/com/sematext/spm/client/tracing/agent/impl/DisruptorFileCallSink.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.impl; - -import com.lmax.disruptor.EventFactory; -import com.lmax.disruptor.EventHandler; -import com.lmax.disruptor.RingBuffer; -import com.lmax.disruptor.dsl.Disruptor; - -import java.util.concurrent.Executors; -import java.util.concurrent.ThreadFactory; - -import com.sematext.spm.client.tracing.BinarySequentialLog; -import com.sematext.spm.client.tracing.BinarySequentialSender; -import com.sematext.spm.client.tracing.agent.Sink; -import com.sematext.spm.client.tracing.agent.model.PartialTransaction; -import com.sematext.spm.client.tracing.agent.sampling.SamplerStatistics; - -public final class DisruptorFileCallSink implements Sink { - private static final EventFactory NEW_PARTIAL_TRANSACTION = new EventFactory() { - @Override - public PartialTransaction newInstance() { - return new PartialTransaction(); - } - }; - private static final ThreadFactory DAEMON_THREAD_FACTORY = new ThreadFactory() { - @Override - public Thread newThread(final Runnable r) { - final Thread t = new Thread(r, "disruptor-file-call-sink"); - t.setDaemon(true); - return t; - } - }; - - private final BinarySequentialSender binaryLog; - private final EventHandler eventHandler = new EventHandler() { - @Override - public void onEvent(PartialTransaction transaction, long sequence, boolean endOfBatch) throws Exception { - long t = System.nanoTime(); - binaryLog.write(ThriftPartialTransactionSerializer.serialize(transaction)); - SamplerStatistics.INSTANCE.update(System.nanoTime() - t); - } - }; - - private final Disruptor disruptor; - - private DisruptorFileCallSink(BinarySequentialSender binaryLog) { - this.binaryLog = binaryLog; - this.disruptor = new Disruptor(NEW_PARTIAL_TRANSACTION, 1024, - Executors.newSingleThreadExecutor(DAEMON_THREAD_FACTORY)); - } - - public static Sink create(String basedir, int maxFileSize, int retentionCount) { - BinarySequentialSender log = new BinarySequentialSender(BinarySequentialLog - .create(basedir, "tracing", ".bin", maxFileSize, retentionCount)); - final DisruptorFileCallSink sink = new DisruptorFileCallSink(log); - sink.start(); - return sink; - } - - @SuppressWarnings("unchecked") - private void start() { - this.disruptor.handleEventsWith(eventHandler); - this.disruptor.start(); - } - - @Override - public void sink(PartialTransaction transaction) { - final RingBuffer buffer = this.disruptor.getRingBuffer(); - long seq = buffer.next(); - try { - final PartialTransaction event = buffer.get(seq); - transaction.copy(event); - } finally { - buffer.publish(seq); - } - } -} diff --git a/spm-tracing-agent-impl/src/main/java/com/sematext/spm/client/tracing/agent/impl/DisruptorThriftEventSink.java b/spm-tracing-agent-impl/src/main/java/com/sematext/spm/client/tracing/agent/impl/DisruptorThriftEventSink.java deleted file mode 100644 index e698032..0000000 --- a/spm-tracing-agent-impl/src/main/java/com/sematext/spm/client/tracing/agent/impl/DisruptorThriftEventSink.java +++ /dev/null @@ -1,183 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.impl; - -import com.lmax.disruptor.EventFactory; -import com.lmax.disruptor.EventHandler; -import com.lmax.disruptor.RingBuffer; -import com.lmax.disruptor.dsl.Disruptor; - -import org.apache.thrift.TException; - -import java.util.concurrent.Executors; -import java.util.concurrent.ThreadFactory; - -import com.sematext.spm.client.Log; -import com.sematext.spm.client.LogFactory; -import com.sematext.spm.client.tracing.BinarySequentialLog; -import com.sematext.spm.client.tracing.BinarySequentialSender; -import com.sematext.spm.client.tracing.agent.Sink; -import com.sematext.spm.client.tracing.agent.SinkEvent; -import com.sematext.spm.client.tracing.agent.errors.TracingError; -import com.sematext.spm.client.tracing.agent.model.PartialTransaction; -import com.sematext.spm.client.tracing.thrift.TTracingEvent; -import com.sematext.spm.client.tracing.thrift.TTracingEventType; -import com.sematext.spm.client.util.Preconditions; - -public final class DisruptorThriftEventSink implements Sink { - - private static final Log LOG = LogFactory.getLog(DisruptorThriftEventSink.class); - - private static class Event { - private EventDescriptor descriptor; - private final PartialTransaction partialTransaction = new PartialTransaction(); - private final TracingError tracingError = new TracingError(); - - public EventDescriptor getDescriptor() { - return descriptor; - } - - public PartialTransaction getPartialTransaction() { - return partialTransaction; - } - - public TracingError getTracingError() { - return tracingError; - } - } - - private static enum EventDescriptor { - PARTIAL_TRANSACTION(PartialTransaction.class) { - @Override - void copy(Object from, Event event) { - ((PartialTransaction) from).copy(event.getPartialTransaction()); - event.descriptor = this; - } - - @Override - byte[] toThrift(Event event) throws TException { - final TTracingEvent thriftEvent = new TTracingEvent(TTracingEventType.PARTIAL_TRANSACTION); - thriftEvent.setPartialTransaction(ThriftPartialTransactionSerializer.toThrift(event.getPartialTransaction())); - return ThriftUtils.binaryProtocolSerializer().serialize(thriftEvent); - } - }, - TRACING_ERROR(TracingError.class) { - @Override - void copy(Object from, Event event) { - ((TracingError) from).copy(event.getTracingError()); - event.descriptor = this; - } - - @Override - byte[] toThrift(Event event) throws TException { - final TTracingEvent thriftEvent = new TTracingEvent(TTracingEventType.TRACING_ERROR); - thriftEvent.setTracingError(ThriftTracingErrorSerializer.toThrift(event.getTracingError())); - return ThriftUtils.binaryProtocolSerializer().serialize(thriftEvent); - } - }; - - final Class klass; - - abstract void copy(Object from, Event event); - - abstract byte[] toThrift(Event event) throws TException; - - EventDescriptor(Class klass) { - this.klass = klass; - } - - static EventDescriptor get(Class klass) { - for (EventDescriptor descriptor : values()) { - if (descriptor.klass.equals(klass)) { - return descriptor; - } - } - throw new IllegalArgumentException("Unknown event type: " + klass); - } - } - - private final EventFactory eventFactory = new EventFactory() { - @Override - public Event newInstance() { - return new Event(); - } - }; - - private static final ThreadFactory DAEMON_THREAD_FACTORY = new ThreadFactory() { - @Override - public Thread newThread(final Runnable r) { - final Thread t = new Thread(r, "disruptor-thrift-event-sink"); - t.setDaemon(true); - return t; - } - }; - - private final EventHandler eventHandler = new EventHandler() { - @Override - public void onEvent(Event event, long sequence, boolean endOfBatch) throws Exception { - try { - binaryLog.write(event.getDescriptor().toThrift(event)); - } catch (Exception e) { - LOG.error("Can't write event to binary log. Event = " + event + ".", e); - } - } - }; - - private final BinarySequentialSender binaryLog; - private final Disruptor disruptor; - - private DisruptorThriftEventSink(BinarySequentialSender binaryLog) { - this.binaryLog = binaryLog; - this.disruptor = new Disruptor(eventFactory, 1024, Executors.newSingleThreadExecutor(DAEMON_THREAD_FACTORY)); - } - - private void start() { - this.disruptor.handleEventsWith(eventHandler); - this.disruptor.start(); - } - - public static DisruptorThriftEventSink create(String basedir, int maxFileSize, int retentionCount) { - return create(basedir, "tracing", ".bin", maxFileSize, retentionCount); - } - - public static DisruptorThriftEventSink create(String basedir, String prefix, String suffix, int maxFileSize, - int retentionCount) { - BinarySequentialSender log = new BinarySequentialSender(BinarySequentialLog - .create(basedir, prefix, suffix, maxFileSize, retentionCount)); - final DisruptorThriftEventSink sink = new DisruptorThriftEventSink(log); - sink.start(); - return sink; - } - - @Override - public void sink(SinkEvent sinkEvent) { - Preconditions.checkNotNull(sinkEvent); - - final Object obj = sinkEvent.getObj(); - final EventDescriptor descriptor = EventDescriptor.get(obj.getClass()); - final RingBuffer ringBuffer = this.disruptor.getRingBuffer(); - final long seq = ringBuffer.next(); - try { - descriptor.copy(obj, ringBuffer.get(seq)); - } finally { - ringBuffer.publish(seq); - } - } -} diff --git a/spm-tracing-agent-impl/src/main/java/com/sematext/spm/client/tracing/agent/impl/HasTransfomedClasses.java b/spm-tracing-agent-impl/src/main/java/com/sematext/spm/client/tracing/agent/impl/HasTransfomedClasses.java deleted file mode 100644 index b93e203..0000000 --- a/spm-tracing-agent-impl/src/main/java/com/sematext/spm/client/tracing/agent/impl/HasTransfomedClasses.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.impl; - -import java.util.Set; - -public interface HasTransfomedClasses { - Set getTransformedClasses(); -} diff --git a/spm-tracing-agent-impl/src/main/java/com/sematext/spm/client/tracing/agent/impl/ThriftAnnotationSerializer.java b/spm-tracing-agent-impl/src/main/java/com/sematext/spm/client/tracing/agent/impl/ThriftAnnotationSerializer.java deleted file mode 100644 index 0cc0002..0000000 --- a/spm-tracing-agent-impl/src/main/java/com/sematext/spm/client/tracing/agent/impl/ThriftAnnotationSerializer.java +++ /dev/null @@ -1,199 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.impl; - -import org.apache.thrift.TException; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; - -import com.sematext.spm.client.tracing.agent.model.Call; -import com.sematext.spm.client.tracing.agent.model.ESAction; -import com.sematext.spm.client.tracing.agent.model.InetAddress; -import com.sematext.spm.client.tracing.agent.model.SolrAnnotation; -import com.sematext.spm.client.tracing.agent.model.annotation.ESAnnotation; -import com.sematext.spm.client.tracing.agent.model.annotation.HTTPRequestAnnotation; -import com.sematext.spm.client.tracing.agent.model.annotation.JPAAnnotation; -import com.sematext.spm.client.tracing.agent.model.annotation.JSPAnnotation; -import com.sematext.spm.client.tracing.agent.model.annotation.SQLAnnotation; -import com.sematext.spm.client.tracing.thrift.*; - -public final class ThriftAnnotationSerializer { - private static interface Ser { - byte[] serialize(T annotation) throws TException; - } - - private static class SQLAnnotationSer implements Ser { - @Override - public byte[] serialize(SQLAnnotation annotation) throws TException { - TSQLAnnotation thrift = new TSQLAnnotation(); - thrift.setType(annotation.getType()); - if (annotation.getSql() != null) { - thrift.setSql(annotation.getSql()); - } else { - thrift.setSqlIsSet(false); - } - if (annotation.getUrl() != null) { - thrift.setUrl(annotation.getUrl()); - } else { - thrift.setUrlIsSet(false); - } - thrift.setCount(annotation.getCount()); - thrift.setTable(annotation.getTable()); - if (annotation.getOperation() != null) { - thrift.setOperation(TSqlStatementOperation.valueOf(annotation.getOperation().name())); - } - return ThriftUtils.binaryProtocolSerializer().serialize(thrift); - } - } - - private static class JPAAnnotationSer implements Ser { - @Override - public byte[] serialize(JPAAnnotation annotation) throws TException { - TJPAAnnotation thrift = new TJPAAnnotation(); - thrift.setType(annotation.getType()); - if (annotation.getQuery() != null) { - thrift.setQuery(annotation.getQuery()); - } else { - thrift.setQueryIsSet(false); - } - if (annotation.getObject() != null) { - thrift.setObject(annotation.getObject()); - } else { - thrift.setObjectIsSet(false); - } - thrift.setCount(annotation.getCount()); - return ThriftUtils.binaryProtocolSerializer().serialize(thrift); - } - } - - private static class JSPAnnotationSer implements Ser { - @Override - public byte[] serialize(JSPAnnotation annotation) throws TException { - TJSPAnnotation thrift = new TJSPAnnotation(); - if (annotation.getPath() != null) { - thrift.setPath(annotation.getPath()); - } else { - thrift.setPathIsSet(false); - } - return ThriftUtils.binaryProtocolSerializer().serialize(thrift); - } - } - - private static class HTTPRequestAnnotationSer implements Ser { - @Override - public byte[] serialize(HTTPRequestAnnotation annotation) throws TException { - THTTPRequestAnnotation thrift = new THTTPRequestAnnotation(); - if (annotation.getUrl() != null) { - thrift.setUrl(annotation.getUrl()); - } else { - thrift.setUrlIsSet(false); - } - if (annotation.getMethod() != null) { - thrift.setMethod(annotation.getMethod()); - } else { - thrift.setMethodIsSet(false); - } - thrift.setResponseCode(annotation.getResponseCode()); - return ThriftUtils.binaryProtocolSerializer().serialize(thrift); - } - } - - private static class ESAnnotationSer implements Ser { - @Override - public byte[] serialize(ESAnnotation annotation) throws TException { - TESAnnotation thrift = new TESAnnotation(); - final List inetAddresses = new ArrayList(); - for (InetAddress address : annotation.getAddresses()) { - inetAddresses.add(new TInetAddress(address.getHost(), address.getPort())); - } - thrift.setAddresses(inetAddresses); - if (annotation.getActions() != null) { - List thriftActions = new ArrayList(); - for (ESAction action : annotation.getActions()) { - final TESAction thriftAction = new TESAction(); - thriftAction.setOperationType(TESOperationType.valueOf(action.getOperationType().name())); - thriftAction.setType(action.getType()); - thriftAction.setIndex(action.getIndex()); - thriftAction.setQuery(action.getQuery()); - thriftAction.setCount(action.getCount()); - - thriftActions.add(thriftAction); - } - thrift.setActions(thriftActions); - } else { - thrift.setActions(Collections.EMPTY_LIST); - } - thrift.setIndex(annotation.getIndex()); - thrift.setRequestType(TESRequestType.valueOf(annotation.getRequestType().name())); - return ThriftUtils.binaryProtocolSerializer().serialize(thrift); - } - } - - private static class SolrAnnotationSer implements Ser { - @Override - public byte[] serialize(SolrAnnotation annotation) throws TException { - final TSolrAnnotation thrift = new TSolrAnnotation(); - thrift.setUrl(annotation.getUrl()); - thrift.setParams(new HashMap(annotation.getParams())); - thrift.setCollection(annotation.getCollection()); - thrift.setResponseStatus((short) annotation.getResponseStatus()); - thrift.setSucceed(annotation.isSucceed()); - thrift.setRequestType(TSolrRequestType.valueOf(annotation.getRequestType().name())); - return ThriftUtils.binaryProtocolSerializer().serialize(thrift); - } - } - - private static enum Serializers { - SQL(Call.CallTag.SQL_QUERY, new SQLAnnotationSer()), - JPA(Call.CallTag.JPA, new JPAAnnotationSer()), - JSP(Call.CallTag.JSP, new JSPAnnotationSer()), - HTTP_REQUEST(Call.CallTag.HTTP_REQUEST, new HTTPRequestAnnotationSer()), - ES(Call.CallTag.ES, new ESAnnotationSer()), - SOLR(Call.CallTag.SOLR, new SolrAnnotationSer()); - - private final Call.CallTag tag; - private final Ser ser; - - Serializers(Call.CallTag tag, Ser ser) { - this.tag = tag; - this.ser = ser; - } - - public static Ser find(Call.CallTag tag) { - for (Serializers ser : Serializers.values()) { - if (ser.tag == tag) { - return ser.ser; - } - } - return null; - } - } - - public static byte[] serialize(Call.CallTag tag, Object annotation) throws TException { - Ser ser = Serializers.find(tag); - if (ser != null) { - return ser.serialize(annotation); - } - return null; - } -} diff --git a/spm-tracing-agent-impl/src/main/java/com/sematext/spm/client/tracing/agent/impl/ThriftCallSerializer.java b/spm-tracing-agent-impl/src/main/java/com/sematext/spm/client/tracing/agent/impl/ThriftCallSerializer.java deleted file mode 100644 index 3d30ce9..0000000 --- a/spm-tracing-agent-impl/src/main/java/com/sematext/spm/client/tracing/agent/impl/ThriftCallSerializer.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.impl; - -import org.apache.thrift.TException; - -import com.sematext.spm.client.tracing.agent.model.Call; -import com.sematext.spm.client.tracing.thrift.TCall; -import com.sematext.spm.client.tracing.thrift.TCallTag; - -public final class ThriftCallSerializer { - private ThriftCallSerializer() { - } - - public static TCall toThrift(Call call) throws TException { - TCall thriftCall = new TCall(); - - thriftCall.setCallId(call.getCallId()); - thriftCall.setParentCallId(call.getParentCallId()); - thriftCall.setLevel(call.getLevel()); - thriftCall.setStartTimestamp(call.getStartTimestamp()); - thriftCall.setEndTimestamp(call.getEndTimestamp()); - thriftCall.setDuration(call.getDuration()); - thriftCall.setSelfDuration(call.getSelfDuration()); - thriftCall.setSignature(call.getSignature()); - if (call.getFailed() != null) { - thriftCall.setFailed(call.getFailed()); - } else { - thriftCall.setFailedIsSet(false); - } - if (call.getExternal() != null) { - thriftCall.setExternal(call.getExternal()); - } else { - thriftCall.setExternalIsSet(false); - } - if (call.getCallTag() != null) { - thriftCall.setTag(TCallTag.valueOf(call.getCallTag().name())); - } else { - thriftCall.setTagIsSet(false); - } - thriftCall.setEntryPoint(call.isEntryPoint()); - thriftCall.setCrossAppToken(call.getCrossAppToken()); - if (call.getCrossAppCallId() != null) { - thriftCall.setCrossAppCallId(call.getCrossAppCallId()); - } else { - thriftCall.setCrossAppCallIdIsSet(false); - } - if (call.getCrossAppParentCallId() != null) { - thriftCall.setCrossAppParentCallId(call.getCrossAppParentCallId()); - } else { - thriftCall.setCrossAppParentCallIdIsSet(false); - } - if (call.getCrossAppDuration() != null) { - thriftCall.setCrossAppDuration(call.getCrossAppDuration()); - } else { - thriftCall.setCrossAppDurationIsSet(false); - } - - thriftCall.setCrossAppSampled(call.isCrossAppSampled()); - - if (call.getAnnotation() != null) { - byte[] ser = ThriftAnnotationSerializer.serialize(call.getCallTag(), call.getAnnotation()); - if (ser != null) { - thriftCall.setAnnotation(ser); - } - } - - thriftCall.setParameters(call.getParameters()); - - return thriftCall; - } - - public static byte[] serialize(Call call) { - try { - TCall thriftCall = toThrift(call); - return ThriftUtils.binaryProtocolSerializer().serialize(thriftCall); - } catch (TException e) { - throw new RuntimeException("Can't serialize call.", e); - } - } - -} diff --git a/spm-tracing-agent-impl/src/main/java/com/sematext/spm/client/tracing/agent/impl/ThriftPartialTransactionSerializer.java b/spm-tracing-agent-impl/src/main/java/com/sematext/spm/client/tracing/agent/impl/ThriftPartialTransactionSerializer.java deleted file mode 100644 index c5d7026..0000000 --- a/spm-tracing-agent-impl/src/main/java/com/sematext/spm/client/tracing/agent/impl/ThriftPartialTransactionSerializer.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.impl; - -import org.apache.thrift.TException; - -import java.io.ByteArrayOutputStream; -import java.io.PrintWriter; -import java.util.ArrayList; -import java.util.List; - -import com.sematext.spm.client.tracing.agent.model.Call; -import com.sematext.spm.client.tracing.agent.model.PartialTransaction; -import com.sematext.spm.client.tracing.thrift.TCall; -import com.sematext.spm.client.tracing.thrift.TEndpoint; -import com.sematext.spm.client.tracing.thrift.TFailureType; -import com.sematext.spm.client.tracing.thrift.TPartialTransaction; -import com.sematext.spm.client.tracing.thrift.TTransactionType; - -public class ThriftPartialTransactionSerializer { - public static TPartialTransaction toThrift(PartialTransaction transaction) throws TException { - TPartialTransaction thrift = new TPartialTransaction(); - thrift.setCallId(transaction.getCallId()); - thrift.setParentCallId(transaction.getParentCallId()); - thrift.setTraceId(transaction.getTraceId()); - thrift.setRequest(transaction.getRequest()); - thrift.setStartTimestamp(transaction.getStartTimestamp()); - thrift.setEndTimestamp(transaction.getEndTimestamp()); - thrift.setDuration(transaction.getDuration()); - thrift.setToken(transaction.getToken()); - thrift.setFailed(transaction.isFailed()); - thrift.setEntryPoint(transaction.isEntryPoint()); - thrift.setAsynchronous(transaction.isAsynchronous()); - thrift.setTransactionType(TTransactionType.valueOf(transaction.getTransactionType().name())); - - if (transaction.getTransactionSummary() != null) { - byte[] summary = ThriftTransactionSummarySerializer.serialize(transaction.getTransactionType(), - transaction.getTransactionSummary()); - thrift.setTransactionSummary(summary); - } - - if (transaction.getEndpoint() != null) { - TEndpoint endpoint = new TEndpoint(); - endpoint.setHostname(transaction.getEndpoint().getHostname()); - endpoint.setAddress(transaction.getEndpoint().getAddress()); - thrift.setEndpoint(endpoint); - } - - final List thriftCalls = new ArrayList(); - - for (Call call : transaction.getCalls()) { - TCall thriftCall = ThriftCallSerializer.toThrift(call); - thriftCalls.add(thriftCall); - } - - thrift.setCalls(thriftCalls); - - if (transaction.getExceptionStackTrace() != null) { - final ByteArrayOutputStream os = new ByteArrayOutputStream(); - final PrintWriter writer = new PrintWriter(os); - transaction.getExceptionStackTrace().printStackTrace(writer); - writer.flush(); - - thrift.setExceptionStackTrace(os.toByteArray()); - } - - if (transaction.getFailureType() != null) { - final TFailureType type = TFailureType.valueOf(transaction.getFailureType().name()); - thrift.setFailureType(type); - } - - thrift.setParameters(transaction.getParameters()); - - return thrift; - } - - public static byte[] serialize(PartialTransaction transaction) throws TException { - return ThriftUtils.binaryProtocolSerializer().serialize(toThrift(transaction)); - } -} diff --git a/spm-tracing-agent-impl/src/main/java/com/sematext/spm/client/tracing/agent/impl/ThriftTracingErrorSerializer.java b/spm-tracing-agent-impl/src/main/java/com/sematext/spm/client/tracing/agent/impl/ThriftTracingErrorSerializer.java deleted file mode 100644 index 318bce4..0000000 --- a/spm-tracing-agent-impl/src/main/java/com/sematext/spm/client/tracing/agent/impl/ThriftTracingErrorSerializer.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.impl; - -import org.apache.thrift.TException; - -import java.util.HashMap; - -import com.sematext.spm.client.tracing.agent.errors.TracingError; -import com.sematext.spm.client.tracing.thrift.TTracingError; - -public class ThriftTracingErrorSerializer { - public static TTracingError toThrift(TracingError tracingError) { - TTracingError thrift = new TTracingError(); - thrift.setToken(tracingError.getToken()); - thrift.setTraceId(tracingError.getTraceId()); - thrift.setParentCallId(tracingError.getParentCallId()); - thrift.setCallId(tracingError.getCallId()); - thrift.setTimestamp(tracingError.getTimestamp()); - thrift.setSampled(tracingError.isSampled()); - thrift.setParameters(new HashMap(tracingError.getParameters())); - return thrift; - } - - public static byte[] serialize(TracingError tracingError) throws TException { - return ThriftUtils.binaryProtocolSerializer().serialize(toThrift(tracingError)); - } -} diff --git a/spm-tracing-agent-impl/src/main/java/com/sematext/spm/client/tracing/agent/impl/ThriftTransactionSummarySerializer.java b/spm-tracing-agent-impl/src/main/java/com/sematext/spm/client/tracing/agent/impl/ThriftTransactionSummarySerializer.java deleted file mode 100644 index 9178fd6..0000000 --- a/spm-tracing-agent-impl/src/main/java/com/sematext/spm/client/tracing/agent/impl/ThriftTransactionSummarySerializer.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.impl; - -import org.apache.thrift.TException; - -import com.sematext.spm.client.tracing.agent.model.Call; -import com.sematext.spm.client.tracing.agent.model.WebTransactionSummary; -import com.sematext.spm.client.tracing.thrift.TWebTransactionSummary; - -public final class ThriftTransactionSummarySerializer { - private ThriftTransactionSummarySerializer() { - } - - private static interface Ser { - byte[] serialize(T summary) throws TException; - } - - private static class WebTransactionSummarySer implements Ser { - @Override - public byte[] serialize(WebTransactionSummary summary) throws TException { - TWebTransactionSummary thrift = new TWebTransactionSummary(); - thrift.setRequest(summary.getRequest()); - thrift.setQueryString(summary.getQueryString()); - thrift.setRequestMethod(summary.getRequestMethod()); - thrift.setResponseCode(summary.getResponseCode()); - return ThriftUtils.binaryProtocolSerializer().serialize(thrift); - } - } - - private static enum Serializers { - WEB(Call.TransactionType.WEB, new WebTransactionSummarySer()); - - private final Call.TransactionType type; - private final Ser ser; - - Serializers(Call.TransactionType type, Ser ser) { - this.type = type; - this.ser = ser; - } - - public static Ser find(Call.TransactionType type) { - for (Serializers ser : Serializers.values()) { - if (ser.type == type) { - return ser.ser; - } - } - return null; - } - } - - @SuppressWarnings("unchecked") - public static byte[] serialize(Call.TransactionType type, Object summary) throws TException { - Ser ser = Serializers.find(type); - if (ser != null) { - return ser.serialize(summary); - } - return null; - } - -} diff --git a/spm-tracing-agent-impl/src/main/java/com/sematext/spm/client/tracing/agent/impl/ThriftUtils.java b/spm-tracing-agent-impl/src/main/java/com/sematext/spm/client/tracing/agent/impl/ThriftUtils.java deleted file mode 100644 index 98672f3..0000000 --- a/spm-tracing-agent-impl/src/main/java/com/sematext/spm/client/tracing/agent/impl/ThriftUtils.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.impl; - -import org.apache.thrift.TDeserializer; -import org.apache.thrift.TSerializer; -import org.apache.thrift.protocol.TBinaryProtocol; -import org.apache.thrift.transport.TTransportException; - -public final class ThriftUtils { - private ThriftUtils() { - } - - private static final ThreadLocal BINARY_PROTOCOL_SERIALIZER = new ThreadLocal() { - @Override - protected TSerializer initialValue() { - try { - return new TSerializer(new TBinaryProtocol.Factory()); - } catch (TTransportException tte) { - throw new RuntimeException(tte); - } - } - }; - - public static TSerializer binaryProtocolSerializer() { - return BINARY_PROTOCOL_SERIALIZER.get(); - } - - private static final ThreadLocal THRIFT_DESERIALIZER = new ThreadLocal() { - @Override - protected TDeserializer initialValue() { - try { - return new TDeserializer(new TBinaryProtocol.Factory()); - } catch (TTransportException tte) { - throw new RuntimeException(tte); - } - } - }; - - public static TDeserializer binaryProtocolDeserializer() { - return THRIFT_DESERIALIZER.get(); - } - -} diff --git a/spm-tracing-agent-impl/src/main/java/com/sematext/spm/client/tracing/agent/impl/TracingAgentControlImpl.java b/spm-tracing-agent-impl/src/main/java/com/sematext/spm/client/tracing/agent/impl/TracingAgentControlImpl.java deleted file mode 100644 index 94462b9..0000000 --- a/spm-tracing-agent-impl/src/main/java/com/sematext/spm/client/tracing/agent/impl/TracingAgentControlImpl.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.impl; - -import java.lang.instrument.Instrumentation; -import java.util.Set; - -import com.sematext.spm.client.Log; -import com.sematext.spm.client.LogFactory; -import com.sematext.spm.client.tracing.agent.TracingAgentControl; -import com.sematext.spm.client.tracing.agent.config.Config; -import com.sematext.spm.client.unlogger.dynamic.AgentStatistics; -import com.sematext.spm.client.unlogger.dynamic.DynamicInstrumentation; -import com.sematext.spm.client.unlogger.dynamic.InstrumentationSettings; - -public final class TracingAgentControlImpl implements TracingAgentControl { - private final Log log = LogFactory.getLog(TracingAgentControlImpl.class); - - private final DynamicInstrumentation dynamicInstrumentation; - private final InstrumentationSettings instrumentationSettings = new InstrumentationSettings(); - private final AgentStatistics statistics = new AgentStatistics(); - - public TracingAgentControlImpl(boolean tracingEnabled, Instrumentation instrumentation, TracingArtifacts artifacts) { - dynamicInstrumentation = new DynamicInstrumentation(instrumentationSettings, statistics, artifacts - .getDynamicTransformers(), - artifacts - .getClassesToBeRetransformed(), instrumentation, tracingEnabled, artifacts - .getUserTracedMethodEntryPointDispatchId(), - artifacts.getUserTracedMethodNonEntryPointDispatchId()); - } - - private void initialize() { - dynamicInstrumentation.init(); - } - - @Override - public boolean enable() { - return dynamicInstrumentation.enable(); - } - - @Override - public boolean disable() { - return dynamicInstrumentation.disable(); - } - - @Override - public boolean isEnabled() { - return dynamicInstrumentation.isEnabled(); - } - - public AgentStatistics getStatistics() { - return statistics; - } - - public Set getWeavedClasses() { - return dynamicInstrumentation.getWeavedClasses(); - } - - @Override - public InstrumentationSettings getInstrumentationSettings() { - return instrumentationSettings; - } - - @Override - public boolean applyInstrumentationSettings() { - return dynamicInstrumentation.applyTransformationSettings(); - } - - public static TracingAgentControlImpl create(boolean tracingEnabled, Instrumentation instrumentation, - ClassLoader loader, Config config) { - final TracingAgentControlImpl control = new TracingAgentControlImpl(tracingEnabled, instrumentation, TracingArtifacts - .create(loader, config)); - control.initialize(); - return control; - } -} diff --git a/spm-tracing-agent-impl/src/main/java/com/sematext/spm/client/tracing/agent/impl/TracingArtifacts.java b/spm-tracing-agent-impl/src/main/java/com/sematext/spm/client/tracing/agent/impl/TracingArtifacts.java deleted file mode 100644 index 4569aef..0000000 --- a/spm-tracing-agent-impl/src/main/java/com/sematext/spm/client/tracing/agent/impl/TracingArtifacts.java +++ /dev/null @@ -1,215 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.impl; - -import static com.sematext.spm.client.unlogger.dispatch.DispatchUnit.registerDispatchUnit; - -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.AbstractExecutorService; -import java.util.concurrent.ThreadPoolExecutor; - -import com.sematext.spm.client.Log; -import com.sematext.spm.client.LogFactory; -import com.sematext.spm.client.tracing.agent.config.Config; -import com.sematext.spm.client.tracing.agent.pointcuts.custom.ExtensionPointcut; -import com.sematext.spm.client.tracing.agent.tracer.Tracer; -import com.sematext.spm.client.tracing.agent.tracer.Tracers; -import com.sematext.spm.client.tracing.agent.transformation.TracingClassDynamicTransformer; -import com.sematext.spm.client.tracing.agent.transformation.TracingTransform; -import com.sematext.spm.client.unlogger.Logspect; -import com.sematext.spm.client.unlogger.Pointcut; -import com.sematext.spm.client.unlogger.UnloggableLogger; -import com.sematext.spm.client.unlogger.dispatch.AdviceDispatcher; -import com.sematext.spm.client.unlogger.dispatch.LastInchOfTrampoline; -import com.sematext.spm.client.unlogger.dynamic.DynamicTransformer; -import com.sematext.spm.client.unlogger.dynamic.UnloggerDynamicTransformer; -import com.sematext.spm.client.unlogger.dynamic.WeavingClassTrackerDynamicTransformer; -import com.sematext.spm.client.unlogger.xml.CustomPointcutOptions; -import com.sematext.spm.client.unlogger.xml.InstrumentationLoaderException; -import com.sematext.spm.client.unlogger.xml.XMLInstrumentationDescriptorLoader; -import com.sematext.spm.client.util.ReflectionUtils; - -/** - * 'Artifacts' needed for tracing: - * - creates predefined logspects - * - creates user defined logspects (from .xml) - * - creates 'DynamicTransformer' instances for logspects - */ -public final class TracingArtifacts { - - private final Log log = LogFactory.getLog(TracingArtifacts.class); - - private final ClassLoader loader; - private final Config config; - private final List dynamicTransformers = new ArrayList(); - private int userTracedMethodEntryPointDispatchId; - private int userTracedMethodNonEntryPointDispatchId; - - private TracingArtifacts(ClassLoader loader, Config config) { - this.loader = loader; - this.config = config; - } - - private List loadExtensionLogspects(File file) throws IOException, InstrumentationLoaderException { - FileInputStream is = null; - try { - is = new FileInputStream(file); - final XMLInstrumentationDescriptorLoader loader = new XMLInstrumentationDescriptorLoader(ExtensionPointcut.class); - return loader.load(is).getLogspects(); - } finally { - if (is != null) { - is.close(); - } - } - } - - private List loadExtensionLogspects() { - final List logspects = new ArrayList(); - final File extensionsDir = new File(config.getExtensionsPath()); - if (!extensionsDir.exists()) { - log.info("Extensions dir '" + extensionsDir + "' not exists skipping loading extensions."); - } else { - File[] files = extensionsDir.listFiles(); - if (files != null) { - for (File file : files) { - if (file.getName().endsWith(".xml")) { - try { - logspects.addAll(loadExtensionLogspects(file)); - log.info("Loaded extension '" + file + "'."); - } catch (Exception e) { - log.error("Can't load extension '" + file + "'.", e); - } - } - } - } - } - return logspects; - } - - private Map registerLoggers(Collection loggers) { - final Map pointcutToDispatchId = new HashMap(); - for (Logspect logger : loggers) { - processLoggerClass(logger, pointcutToDispatchId); - } - - return pointcutToDispatchId; - } - - private static void processLoggerClass(Logspect logspect, Map toWeave) { - final UnloggableLogger logger = logspect.createUnlogger(); - - for (Pointcut pointcut : logspect.getPointcuts()) { - int dispatchId = registerDispatchUnit(logspect.getName(), pointcut, logger); - toWeave.put(pointcut, dispatchId); - } - } - - private static Integer registerUserTracedMethodLogspect(boolean entryPoint) { - final CustomPointcutOptions options = new CustomPointcutOptions(entryPoint, null); - final Logspect logspect = new Logspect( - "UserTracedMethodLogspectEntryPoint" + entryPoint, ExtensionPointcut.class, Collections.emptyList(), - ReflectionUtils.ClassValue.cv(CustomPointcutOptions.class, options)); - return registerDispatchUnit(logspect.getName(), null, logspect.createUnlogger()); - } - - private void initialize() { - final List structuralTransforms = new ArrayList(); - final List logspects = new ArrayList(); - - for (Tracers value : Tracers.values()) { - Tracer tracer = value.getTracer(); - if (tracer.enabled(config) && !Boolean.getBoolean("spm.tracer.disable." + tracer.getName())) { - logspects.addAll(tracer.createLogspects(loader)); - structuralTransforms.addAll(Arrays.asList(tracer.getStructuralTransforms())); - } else { - log.info("Skipping " + tracer.getName() + " tracer."); - } - } - - logspects.addAll(loadExtensionLogspects()); - - LastInchOfTrampoline.switchTo(AdviceDispatcher.Type.DEFAULT); - - final Set pointcuts = new HashSet(); - - for (Logspect logspect : logspects) { - pointcuts.addAll(logspect.getPointcuts()); - } - - /** - * Register special logspects which should be used to dynamically instrument - * custom methods. - */ - userTracedMethodEntryPointDispatchId = registerUserTracedMethodLogspect(true); - userTracedMethodNonEntryPointDispatchId = registerUserTracedMethodLogspect(false); - - final Map pointcutToDispatchId = registerLoggers(logspects); - - if (!Boolean.getBoolean("spm.disableTracingClassTransformer")) { - dynamicTransformers.add(new TracingClassDynamicTransformer(structuralTransforms)); - } else { - log.warn("Disabled TracingClassDynamicTransformer"); - } - if (!Boolean.getBoolean("spm.disableUnloggerTransformer")) { - dynamicTransformers.add(new UnloggerDynamicTransformer(pointcutToDispatchId)); - } else { - log.warn("Disabled UnloggerDynamicTransformer"); - } - if (!Boolean.getBoolean("spm.disableWeavingTransformer")) { - dynamicTransformers.add(new WeavingClassTrackerDynamicTransformer(pointcuts)); - } else { - log.warn("Disabled WeavingClassTrackerDynamicTransformer"); - } - } - - public int getUserTracedMethodEntryPointDispatchId() { - return userTracedMethodEntryPointDispatchId; - } - - public int getUserTracedMethodNonEntryPointDispatchId() { - return userTracedMethodNonEntryPointDispatchId; - } - - public List getDynamicTransformers() { - return dynamicTransformers; - } - - public List> getClassesToBeRetransformed() { - return Arrays.asList(Runnable.class, Thread.class, AbstractExecutorService.class, ThreadPoolExecutor.class); - } - - public static TracingArtifacts create(ClassLoader loader, Config config) { - final TracingArtifacts artifacts = new TracingArtifacts(loader, config); - artifacts.initialize(); - return artifacts; - } - -} diff --git a/spm-tracing-agent-impl/src/main/java/com/sematext/spm/client/tracing/agent/impl/TracingStatisticsImpl.java b/spm-tracing-agent-impl/src/main/java/com/sematext/spm/client/tracing/agent/impl/TracingStatisticsImpl.java deleted file mode 100644 index 113e740..0000000 --- a/spm-tracing-agent-impl/src/main/java/com/sematext/spm/client/tracing/agent/impl/TracingStatisticsImpl.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.impl; - -import java.util.Arrays; -import java.util.Collection; -import java.util.List; -import java.util.concurrent.CopyOnWriteArrayList; - -import com.sematext.spm.client.tracing.agent.model.PartialTransaction; -import com.sematext.spm.client.tracing.agent.stats.*; - -public final class TracingStatisticsImpl implements TracingStatistics { - - private static class StatisticsViewImpl implements StatisticsView { - private final CrossAppCallStatistics crossAppCallStatistics; - private final ExternalCallStatistics externalCallStatistics; - private final RequestComponentStatistics requestComponentStatistics; - private final RequestStatistics requestStatistics; - private final RequestErrorsStatistics requestErrorsStatistics; - private final DatabaseOperationStatistics databaseOperationStatistics; - private final List processors; - - private StatisticsViewImpl(MutableVarProvider varProvider) { - this.crossAppCallStatistics = new CrossAppCallStatistics(varProvider); - this.externalCallStatistics = new ExternalCallStatistics(varProvider); - this.requestComponentStatistics = new RequestComponentStatistics(varProvider); - this.requestStatistics = new RequestStatistics(varProvider); - this.requestErrorsStatistics = new RequestErrorsStatistics(varProvider); - this.databaseOperationStatistics = new DatabaseOperationStatistics(varProvider); - this.processors = Arrays.asList( - crossAppCallStatistics, - externalCallStatistics, - requestComponentStatistics, - requestStatistics, - requestErrorsStatistics, - databaseOperationStatistics - ); - } - - @Override - public Collection crossAppCalls() { - return crossAppCallStatistics.getCrossAppCalls(); - } - - @Override - public Collection externalCalls() { - return externalCallStatistics.getExternalCalls(); - } - - @Override - public Collection requestMetrics() { - return requestStatistics.values(); - } - - @Override - public Collection requestErrorMetrics() { - return requestErrorsStatistics.values(); - } - - @Override - public Collection requestComponentMetrics() { - return requestComponentStatistics.values(); - } - - @Override - public Collection databaseOperationMetrics() { - return databaseOperationStatistics.values(); - } - - private void update(PartialTransaction transaction) { - for (StatisticsProcessor processor : processors) { - processor.process(transaction); - } - } - } - - private final List callStatisticsViews = new CopyOnWriteArrayList(); - - @Override - public void record(PartialTransaction transaction) { - for (StatisticsViewImpl view : callStatisticsViews) { - view.update(transaction); - } - } - - @Override - public StatisticsView newCallStatisticsView(MutableVarProvider varProvider) { - final StatisticsViewImpl view = new StatisticsViewImpl(varProvider); - callStatisticsViews.add(view); - return view; - } -} diff --git a/spm-tracing-agent-impl/src/main/java/com/sematext/spm/client/tracing/agent/impl/WeavingTrackingTransformer.java b/spm-tracing-agent-impl/src/main/java/com/sematext/spm/client/tracing/agent/impl/WeavingTrackingTransformer.java deleted file mode 100644 index b730718..0000000 --- a/spm-tracing-agent-impl/src/main/java/com/sematext/spm/client/tracing/agent/impl/WeavingTrackingTransformer.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.impl; - -import java.io.ByteArrayInputStream; -import java.lang.instrument.ClassFileTransformer; -import java.lang.instrument.IllegalClassFormatException; -import java.security.ProtectionDomain; -import java.util.Collections; -import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; - -import com.sematext.spm.client.Log; -import com.sematext.spm.client.LogFactory; -import com.sematext.spm.client.unlogger.Pointcut; -import com.sematext.spm.client.unlogger.WeaverUtils; -import com.sematext.spm.client.util.ClassPools; - -import javassist.CtClass; - -public final class WeavingTrackingTransformer implements ClassFileTransformer, HasTransfomedClasses { - - private final Log log = LogFactory.getLog(WeavingTrackingTransformer.class); - - private final Set pointcuts; - private final Set transformedClasses = Collections.newSetFromMap(new ConcurrentHashMap()); - private volatile boolean enabled = false; - - public WeavingTrackingTransformer(Set pointcuts) { - this.pointcuts = pointcuts; - } - - @Override - public Set getTransformedClasses() { - return transformedClasses; - } - - public void enable() { - enabled = true; - } - - public void disable() { - enabled = false; - } - - @Override - public byte[] transform(ClassLoader loader, String className, Class classBeingRedefined, - ProtectionDomain protectionDomain, byte[] classfileBuffer) - throws IllegalClassFormatException { - if (enabled) { - try { - final CtClass klass = new ClassPools().getClassPool(loader) - .makeClass(new ByteArrayInputStream(classfileBuffer)); - if (!WeaverUtils.computeAffectedBehaviours(pointcuts, klass).isEmpty()) { - transformedClasses.add(className.replace('/', '.')); - } - } catch (Exception e) { - log.error("Can't compute affected behaviours.", e); - } - } - return null; - } -} diff --git a/spm-tracing-agent/pom.xml b/spm-tracing-agent/pom.xml deleted file mode 100644 index 5d9b80c..0000000 --- a/spm-tracing-agent/pom.xml +++ /dev/null @@ -1,164 +0,0 @@ - - 4.0.0 - - - com.sematext.spm - spm-client-parent - 3.0.0 - - - spm-tracing-agent - jar - SPM Tracing Agent - SPM system monitoring tool - http://maven.apache.org - - - 2.3.2 - - - - - - - - - com.sematext.spm - spm-monitor-utils - ${project.version} - - - - - - com.tngtech.java - junit-dataprovider - 1.10.0 - test - - - - com.h2database - h2 - 1.4.181 - test - - - - org.hsqldb - hsqldb - 2.3.2 - test - - - - com.mchange - c3p0 - [0.9.5.5,) - test - - - - org.hibernate - hibernate-entitymanager - 4.3.6.Final - test - - - - javax.servlet - javax.servlet-api - 3.1.0 - test - - - - com.google.guava - guava - 18.0 - test - - - - commons-httpclient - commons-httpclient - 3.1 - test - - - - org.apache.httpcomponents - httpclient - 4.5.13 - test - - - - solr-solrj - org.apache.solr - 5.3.0 - jar - test - - - org.slf4j - slf4j-api - - - org.slf4j - slf4j-log4j12 - - - - - org.apache.logging.log4j - log4j-core - 2.17.0 - compile - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.0 - - ${maven.compile.source} - ${maven.compile.target} - - - - org.apache.maven.plugins - maven-assembly-plugin - 2.4 - - - dist-classic - package - - single - - - ${project.artifactId}-${project.version}-withdeps - false - - jar-with-dependencies - - - - com.sematext.spm.tracing.TracingAgentBootstrap - true - - - - - - - - - - - diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/CallArray.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/CallArray.java deleted file mode 100644 index 25e8e34..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/CallArray.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent; - -import com.sematext.spm.client.tracing.agent.model.Call; - -public final class CallArray { - private Call[] array; - private int n = 0; - - public CallArray(int initialSize) { - array = new Call[initialSize]; - - for (int i = 0; i < initialSize; i++) { - array[i] = new Call(); - } - } - - public Call add() { - resizeIfNeed(); - return array[n++]; - } - - private void resizeIfNeed() { - if (n == array.length) { - final Call[] resized = new Call[array.length * 2]; - System.arraycopy(array, 0, resized, 0, array.length); - for (int i = array.length; i < resized.length; i++) { - resized[i] = new Call(); - } - - array = resized; - } - } - - public void clean() { - n = 0; - } - - public int size() { - return n; - } - - public Call get(int i) { - if (i < 0 || i >= n) { - throw new IllegalArgumentException("index should be >= 0 and < " + n + "."); - } - return array[i]; - } - -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/CallSinks.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/CallSinks.java deleted file mode 100644 index 4c08ce9..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/CallSinks.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent; - -import com.sematext.spm.client.tracing.agent.model.PartialTransaction; - -public final class CallSinks { - private CallSinks() { - } - - private static final Sink BLACKHOLE_SINK = new Sink() { - @Override - public void sink(PartialTransaction transaction) { - } - }; - - public static Sink blackholeSink() { - return BLACKHOLE_SINK; - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/CallStack.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/CallStack.java deleted file mode 100644 index 8b11398..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/CallStack.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent; - -import com.sematext.spm.client.tracing.agent.model.Call; - -public final class CallStack { - private Call[] calls; - private int n = 0; - - public CallStack(int size) { - this.calls = new Call[size]; - for (int i = 0; i < size; i++) { - this.calls[i] = new Call(); - } - } - - public Call push() { - if (n == calls.length) { - return null; - } - return calls[n++]; - } - - public Call pop() { - if (n == 0) { - return null; - } - return calls[--n]; - } - - public Call peek() { - if (n == 0) { - return null; - } - return calls[n - 1]; - } - - public void clear() { - n = 0; - } - - public int size() { - return n; - } - - public boolean isEmpty() { - return n == 0; - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/CrossAppOutInfo.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/CrossAppOutInfo.java deleted file mode 100644 index 38ac0ea..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/CrossAppOutInfo.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent; - -public final class CrossAppOutInfo { - private final long traceId; - private final long callId; - private final long parentCallId; - private final long startTs; - - private CrossAppOutInfo(long traceId, long callId, long parentCallId, long startTs) { - this.traceId = traceId; - this.callId = callId; - this.parentCallId = parentCallId; - this.startTs = startTs; - } - - public long getTraceId() { - return traceId; - } - - public long getCallId() { - return callId; - } - - public long getParentCallId() { - return parentCallId; - } - - public long getStartTs() { - return startTs; - } - - public static CrossAppOutInfo create(Trace trace) { - return new CrossAppOutInfo(trace.getTraceId(), trace.getCallId(), trace.getParentCallId(), System - .currentTimeMillis()); - } - - @Override - public String toString() { - return "CrossAppOutInfo{" + - "traceId=" + traceId + - ", callId=" + callId + - ", parentCallId=" + parentCallId + - ", startTs=" + startTs + - '}'; - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/EventsSink.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/EventsSink.java deleted file mode 100644 index 5f176b4..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/EventsSink.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent; - -public interface EventsSink> extends Sink { - -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/MuxSink.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/MuxSink.java deleted file mode 100644 index e0b327c..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/MuxSink.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent; - -public final class MuxSink implements Sink { - private final Sink centralSink; - - public MuxSink(Sink centralSink) { - this.centralSink = centralSink; - } - - @Override - public void sink(T t) { - centralSink.sink(new SinkEvent(t)); - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/NoTrace.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/NoTrace.java deleted file mode 100644 index f036ba9..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/NoTrace.java +++ /dev/null @@ -1,221 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent; - -import java.util.Collections; -import java.util.Map; - -import com.sematext.spm.client.tracing.agent.model.Call; -import com.sematext.spm.client.tracing.agent.model.FailureType; -import com.sematext.spm.client.tracing.agent.model.HttpHeaders; -import com.sematext.spm.client.unlogger.JoinPoint; - -public final class NoTrace implements Trace { - private static final NoTrace INSTANCE = new NoTrace(); - - private NoTrace() { - } - - public static NoTrace instance() { - return INSTANCE; - } - - @Override - public Boolean isSampled() { - return true; - } - - @Override - public long getTraceId() { - return 0; - } - - @Override - public long getCallId() { - return 0; - } - - @Override - public long getParentCallId() { - return 0; - } - - @Override - public Call getCurrentCall() { - return null; - } - - @Override - public void setResponseHeaders(ResponseHeaders metadata) { - - } - - @Override - public void sendCrossAppOutHeaders() { - - } - - @Override - public void newCall(JoinPoint joinPoint) { - - } - - @Override - public void newCall(String signature, long startTimestamp) { - - } - - @Override - public void setStartTimestamp(long startTimestamp) { - - } - - @Override - public void setFailed(Boolean failed) { - - } - - @Override - public void setFailureType(FailureType type) { - - } - - @Override - public void setException(Throwable t) { - - } - - @Override - public void setTransactionParameter(String key, String value) { - - } - - @Override - public Map getTransactionParameters() { - return Collections.emptyMap(); - } - - @Override - public Map getMethodParameters() { - return Collections.emptyMap(); - } - - @Override - public void setMethodParameter(String key, String value) { - - } - - @Override - public void setExternal(Boolean external) { - - } - - @Override - public void setSkipExternalTracingStatistics(boolean skip) { - - } - - @Override - public void setTag(Call.CallTag tag) { - - } - - @Override - public void setEntryPoint(boolean entryPoint) { - - } - - @Override - public void endCall() { - - } - - @Override - public void endCall(long endTimestamp) { - - } - - @Override - public void ignore() { - - } - - @Override - public void setCrossAppInHeader(HttpHeaders.CrossAppCallHeader header) { - - } - - @Override - public boolean callStackEmpty() { - return true; - } - - @Override - public boolean isLastCall() { - return false; - } - - @Override - public NoTrace fork() { - return INSTANCE; - } - - @Override - public void setCrossAppOutInfo(CrossAppOutInfo crossAppOutInfo) { - - } - - @Override - public void setAsync(boolean async) { - - } - - @Override - public void setAnnotation(Object annotation) { - - } - - @Override - public A getAnnotation() { - return null; - } - - @Override - public void setTransactionSummary(Object summary) { - - } - - @Override - public Object getTransactionSummary() { - return null; - } - - private static final TransactionNamer NAMER = new TransactionNamer(); - - @Override - public TransactionNamer getNamer() { - return NAMER; - } - - @Override - public void forceEnd(boolean failed) { - - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/ResponseHeaders.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/ResponseHeaders.java deleted file mode 100644 index 0c74b46..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/ResponseHeaders.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent; - -public interface ResponseHeaders { - void addHeader(String name, String value); -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/Sink.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/Sink.java deleted file mode 100644 index 34b04d9..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/Sink.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent; - -public interface Sink { - void sink(T t); -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/SinkEvent.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/SinkEvent.java deleted file mode 100644 index e6621f4..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/SinkEvent.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent; - -import com.sematext.spm.client.util.Preconditions; - -public final class SinkEvent { - private final T obj; - - public SinkEvent(T obj) { - Preconditions.checkNotNull(obj); - - this.obj = obj; - } - - public T getObj() { - return obj; - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/Trace.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/Trace.java deleted file mode 100644 index ec450a2..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/Trace.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent; - -import java.util.Map; - -import com.sematext.spm.client.tracing.agent.model.Call; -import com.sematext.spm.client.tracing.agent.model.FailureType; -import com.sematext.spm.client.tracing.agent.model.HttpHeaders; -import com.sematext.spm.client.unlogger.JoinPoint; - -public interface Trace { - long getTraceId(); - - long getCallId(); - - long getParentCallId(); - - Call getCurrentCall(); - - void setResponseHeaders(ResponseHeaders headers); - - void sendCrossAppOutHeaders(); - - void newCall(JoinPoint joinPoint); - - void newCall(String signature, long startTimestamp); - - void setStartTimestamp(long startTimestamp); - - void setFailed(Boolean failed); - - void setFailureType(FailureType type); - - void setException(Throwable t); - - void setTransactionParameter(String key, String value); - - Map getTransactionParameters(); - - void setMethodParameter(String key, String value); - - Map getMethodParameters(); - - void setExternal(Boolean external); - - void setSkipExternalTracingStatistics(boolean skip); - - void setTag(Call.CallTag tag); - - void setEntryPoint(boolean entryPoint); - - void endCall(); - - void endCall(long endTimestamp); - - void ignore(); - - void setCrossAppInHeader(HttpHeaders.CrossAppCallHeader header); - - void setAsync(boolean async); - - void setAnnotation(Object annotation); - - A getAnnotation(); - - void setTransactionSummary(Object summary); - - Object getTransactionSummary(); - - boolean callStackEmpty(); - - boolean isLastCall(); - - T fork(); - - Boolean isSampled(); - - void setCrossAppOutInfo(CrossAppOutInfo crossAppOutInfo); - - TransactionNamer getNamer(); - - void forceEnd(boolean failed); -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/Tracing.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/Tracing.java deleted file mode 100644 index 26f5225..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/Tracing.java +++ /dev/null @@ -1,541 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Random; - -import com.sematext.spm.client.Log; -import com.sematext.spm.client.LogFactory; -import com.sematext.spm.client.tracing.agent.config.ServiceLocator; -import com.sematext.spm.client.tracing.agent.model.Call; -import com.sematext.spm.client.tracing.agent.model.Call.TransactionType; -import com.sematext.spm.client.tracing.agent.model.Endpoint; -import com.sematext.spm.client.tracing.agent.model.FailureType; -import com.sematext.spm.client.tracing.agent.model.HttpHeaders; -import com.sematext.spm.client.tracing.agent.model.HttpHeaders.CrossAppCallHeader; -import com.sematext.spm.client.tracing.agent.model.PartialTransaction; -import com.sematext.spm.client.tracing.agent.util.AsyncContext; -import com.sematext.spm.client.tracing.agent.util.Hostname; -import com.sematext.spm.client.unlogger.JoinPoint; - -public final class Tracing { - - private static final Log LOG = LogFactory.getLog(Tracing.class); - - private static final ThreadLocal RANDOM = new ThreadLocal() { - @Override - protected Random initialValue() { - return new Random(); - } - }; - - private static final ThreadLocal CONTEXT = new ThreadLocal() { - @Override - protected Trace initialValue() { - return NoTrace.instance(); - } - }; - - private static final ThreadLocal CALL_STACK_POOL = new ThreadLocal() { - @Override - protected CallStack initialValue() { - return new CallStack(ServiceLocator.getConfig().getStackSizeThreshold()); - } - }; - - private static final ThreadLocal CALL_ARRAY_POOL = new ThreadLocal() { - @Override - protected CallArray initialValue() { - return new CallArray(100); - } - }; - - private static final Endpoint LOCAL_ENDPOINT = Hostname.getLocalEndpoint(); - - public static Trace newTrace(String request, TransactionType type) { - return newTrace(request, type, RANDOM.get().nextLong(), Call.ROOT_CALL_ID); - } - - public static Trace newTrace(String request, TransactionType type, long traceId, long parentCallId) { - return newTrace(request, type, traceId, parentCallId, ServiceLocator.getTransactionSampler().sample(request)); - } - - public static Trace newTrace(String request, TransactionType type, long traceId, long parentCallId, boolean sample) { - return newTrace(request, type, traceId, parentCallId, sample, false); - } - - public static Trace newTrace(String request, TransactionType type, long traceId, long parentCallId, boolean sample, - boolean forked) { - final ActiveTrace trace = new ActiveTrace(request, type, traceId, parentCallId, sample, forked); - CONTEXT.set(trace); - return trace; - } - - public static AsyncContext registerAsyncTrace(Object worker) { - // TODO mark root call for async trace (call.async = true), so in frontend timing can be recalculated - final Trace trace = Tracing.current(); - if (trace != NoTrace.instance()) { - final long parentCallId; - if (trace.getCurrentCall() == null) { - parentCallId = trace.getParentCallId(); - } else { - parentCallId = trace.getCallId(); - } - return AsyncContext.create(worker, trace.getTraceId(), parentCallId, trace.isSampled()); - } - return null; - } - - public static void setTrace(Trace trace) { - CONTEXT.set(trace); - } - - public static void endTrace() { - CONTEXT.remove(); - } - - public static Trace> current() { - return CONTEXT.get(); - } - - public static class ActiveTrace implements Trace { - private final long traceId; - private final long parentCallId; - private final CallStack stack; - private final String request; - private final boolean sampled; - private final CallArray sunkCalls; - private final boolean forked; - private final TransactionType type; - private ResponseHeaders responseHeaders; - private CrossAppOutInfo crossAppOutInfo; - private Object transactionSummary; - private final TransactionNamer namer = new TransactionNamer(); - private boolean async; - private FailureType failureType; - private Throwable exception; - private boolean ignore; - private final Map parameters = new HashMap(); - - public ActiveTrace(String request, TransactionType type, long traceId, long parentCallId, boolean sampled, - boolean forked) { - this.traceId = traceId; - this.parentCallId = parentCallId; - this.stack = CALL_STACK_POOL.get(); - this.stack.clear(); - this.request = request; - this.type = type; - this.sampled = sampled; - this.forked = forked; - this.sunkCalls = CALL_ARRAY_POOL.get(); - this.sunkCalls.clean(); - this.async = false; - this.failureType = null; - this.exception = null; - this.ignore = false; - } - - @Override - public Boolean isSampled() { - return sampled; - } - - @Override - public long getTraceId() { - return traceId; - } - - @Override - public long getCallId() { - final Call currentCall = getCurrentCall(); - if (currentCall != null) { - return currentCall.getCallId(); - } - return Call.ROOT_CALL_ID; - } - - @Override - public long getParentCallId() { - return parentCallId; - } - - @Override - public Call getCurrentCall() { - return stack.peek(); - } - - @Override - public void setCrossAppOutInfo(CrossAppOutInfo crossAppOutInfo) { - this.crossAppOutInfo = crossAppOutInfo; - } - - @Override - public void setResponseHeaders(ResponseHeaders metadata) { - this.responseHeaders = metadata; - } - - @Override - public void sendCrossAppOutHeaders() { - if (this.responseHeaders != null && this.crossAppOutInfo != null) { - long duration = System.currentTimeMillis() - crossAppOutInfo.getStartTs(); - boolean sampled = duration >= ServiceLocator.getConfig().getDurationThresholdMillis(); - final String header = HttpHeaders.encodeCrossAppCallHeader( - crossAppOutInfo.getCallId(), - crossAppOutInfo.getParentCallId(), - crossAppOutInfo.getTraceId(), - duration, - ServiceLocator.getConfig().getToken(), - request, - LOCAL_ENDPOINT, - sampled - ); - this.responseHeaders.addHeader(HttpHeaders.SPM_TRACING_CROSS_APP_CALL, header); - } - } - - @Override - public void newCall(JoinPoint jp) { - newCall(String.format("%s#%s()", jp.getType(), jp.getShortName()), System.currentTimeMillis()); - } - - @Override - public void newCall(String signature, long startTime) { - final Call currentCall = getCurrentCall(); - - if (stack.size() >= ServiceLocator.getConfig().getStackSizeThreshold()) { - LOG.warn(String.format("Call stack threshold [%s] exceeded for token %s", ServiceLocator.getConfig() - .getStackSizeThreshold(), ServiceLocator.getConfig().getToken())); - return; - } - - final Call call = stack.push(); - call.setChildDuration(0); - call.setSignature(signature); - call.setStartTimestamp(startTime); - call.setLevel(stack.size()); - call.setCallId(RANDOM.get().nextLong()); - call.setCallTag(Call.CallTag.REGULAR); - call.setParent(null); - call.setEntryPoint(false); - call.setCrossAppToken(null); - call.setCrossAppCallId(null); - call.setCrossAppParentCallId(null); - call.setCrossAppDuration(null); - call.setAnnotation(null); - call.setFailed(false); - call.setSkipExternalTracingStatistics(false); - call.getParameters().clear(); - - if (currentCall != null) { - call.setParentCallId(currentCall.getCallId()); - call.setParent(currentCall); - } else { - call.setParentCallId(parentCallId); - } - } - - @Override - public void setStartTimestamp(long startTimestamp) { - final Call currentCall = getCurrentCall(); - if (currentCall != null) { - currentCall.setStartTimestamp(startTimestamp); - } - } - - @Override - public void setFailed(Boolean failed) { - final Call currentCall = getCurrentCall(); - if (currentCall != null) { - currentCall.setFailed(failed); - } - } - - @Override - public void setFailureType(FailureType type) { - this.failureType = type; - } - - @Override - public void setException(Throwable t) { - this.exception = t; - } - - @Override - public void setTransactionParameter(String key, String value) { - this.parameters.put(key, value); - } - - @Override - public Map getTransactionParameters() { - return this.parameters; - } - - @Override - public void setMethodParameter(String key, String value) { - final Call currentCall = getCurrentCall(); - if (currentCall != null) { - currentCall.getParameters().put(key, value); - } - } - - @Override - public Map getMethodParameters() { - final Call currentCall = getCurrentCall(); - if (currentCall != null) { - return currentCall.getParameters(); - } - return Collections.emptyMap(); - } - - @Override - public void setExternal(Boolean external) { - final Call currentCall = getCurrentCall(); - if (currentCall != null) { - currentCall.setExternal(external); - } - } - - @Override - public void setSkipExternalTracingStatistics(boolean skip) { - final Call currentCall = getCurrentCall(); - if (currentCall != null) { - currentCall.setSkipExternalTracingStatistics(skip); - } - } - - @Override - public void setTag(Call.CallTag tag) { - final Call currentCall = getCurrentCall(); - if (currentCall != null) { - currentCall.setCallTag(tag); - } - } - - @Override - public void setEntryPoint(boolean entryPoint) { - final Call currentCall = getCurrentCall(); - if (currentCall != null) { - currentCall.setEntryPoint(entryPoint); - } - } - - @Override - public void setCrossAppInHeader(final CrossAppCallHeader header) { - final Call currentCall = getCurrentCall(); - if (currentCall != null && header != null) { - currentCall.setCrossAppToken(header.getToken()); - currentCall.setCrossAppCallId(header.getCallId()); - currentCall.setCrossAppParentCallId(header.getParentCallId()); - currentCall.setCrossAppDuration(header.getDuration()); - currentCall.setCrossAppEndpoint(header.getEndpoint()); - currentCall.setCrossAppRequest(header.getRequest()); - currentCall.setCrossAppSampled(header.isSampled()); - } - } - - @Override - public void setAsync(boolean async) { - this.async = async; - } - - @Override - public void setAnnotation(Object annotation) { - final Call currentCall = getCurrentCall(); - if (currentCall != null) { - currentCall.setAnnotation(annotation); - } - } - - @Override - public A getAnnotation() { - final Call currentCall = getCurrentCall(); - if (currentCall != null) { - return (A) currentCall.getAnnotation(); - } - return null; - } - - @Override - public void setTransactionSummary(Object summary) { - this.transactionSummary = summary; - } - - @Override - public Object getTransactionSummary() { - return transactionSummary; - } - - @Override - public void endCall() { - endCall(System.currentTimeMillis()); - } - - @Override - public void ignore() { - this.ignore = true; - } - - @Override - public TransactionNamer getNamer() { - return namer; - } - - private PartialTransaction createTransaction() { - final PartialTransaction transaction = new PartialTransaction(); - final Call rootCall = sunkCalls.get(sunkCalls.size() - 1); - transaction.setCallId(rootCall.getCallId()); - transaction.setParentCallId(rootCall.getParentCallId()); - transaction.setTraceId(traceId); - transaction.setEndpoint(LOCAL_ENDPOINT); - transaction.setAsynchronous(async); - transaction.setTransactionType(type); - transaction.setTransactionSummary(transactionSummary); - transaction.setStartTimestamp(rootCall.getStartTimestamp()); - transaction.setEndTimestamp(rootCall.getEndTimestamp()); - transaction.setDuration(rootCall.getDuration()); - transaction.setFailed(rootCall.getFailed()); - if (forked) { - transaction.setRequest(request); - } else { - transaction.setRequest(namer.getName()); - } - transaction.setToken(ServiceLocator.getConfig().getToken()); - transaction.setEntryPoint(rootCall.isEntryPoint()); - transaction.setExceptionStackTrace(exception); - transaction.setFailureType(failureType); - transaction.setParameters(parameters); - - final List calls = new ArrayList(); - for (int i = 0; i < sunkCalls.size(); i++) { - final Call call = new Call(); - sunkCalls.get(i).copy(call); - calls.add(call); - } - - transaction.setCalls(calls); - - return transaction; - } - - @Override - public void endCall(long endTimestamp) { - final Call currentCall = getCurrentCall(); - if (currentCall != null) { - currentCall.setEndTimestamp(endTimestamp); - final long duration = endTimestamp - currentCall.getStartTimestamp(); - currentCall.setDuration(duration); - currentCall.setSelfDuration(duration - currentCall.getChildDuration()); - if (currentCall.getParent() != null) { - long childDuration = currentCall.getParent().getChildDuration(); - - currentCall.getParent().setChildDuration(childDuration + duration); - currentCall.setParent(null); - } - - currentCall.copy(sunkCalls.add()); - } - stack.pop(); - - if (stack.isEmpty()) { - if (!ignore) { - final PartialTransaction transaction = createTransaction(); - ServiceLocator.getTracingStatistics().record(transaction); - - if (currentCall != null && (forked || currentCall.getDuration() >= ServiceLocator.getConfig() - .getDurationThresholdMillis())) { - sinkTransaction(transaction); - } - - if (currentCall == null && LOG.isDebugEnabled()) { - LOG.debug( - "Transaction will not be sinked because current call is null, endpoint: " + transaction.getEndpoint()); - } - - if (currentCall != null && LOG.isDebugEnabled()) { - LOG.debug("Transaction will not be sinked because it is under threshold, duration is: " + currentCall - .getDuration() + ", endpoint is: " + transaction.getEndpoint()); - } - } - - sunkCalls.clean(); - } - - } - - private void sinkTransaction(PartialTransaction transaction) { - if (sampled) { - for (Sink sink : ServiceLocator.getTransactionSinks()) { - try { - sink.sink(transaction); - } catch (Throwable e) { - LOG.warn("Can't sink transaction", e); - } - } - } - } - - @Override - public boolean callStackEmpty() { - return stack.isEmpty(); - } - - @Override - public boolean isLastCall() { - return stack.size() == 1; - } - - @Override - public ActiveTrace fork() { - return new ActiveTrace(request, type, getTraceId(), getCallId(), sampled, true); - } - - @Override - public void forceEnd(boolean failed) { - while (stack.size() > 1) { - endCall(); - } - if (!stack.isEmpty()) { - stack.peek().setFailed(failed); - endCall(); - } - } - - @Override - public String toString() { - return "ActiveTrace{" + - "traceId=" + traceId + - ", parentCallId=" + parentCallId + - ", request='" + request + '\'' + - ", sampled=" + sampled + - ", forked=§" + forked + - ", type=" + type + - ", responseHeaders=" + responseHeaders + - ", crossAppOutInfo=" + crossAppOutInfo + - ", async=" + async + - ", failureType=" + failureType + - '}'; - } - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/TracingAgentControl.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/TracingAgentControl.java deleted file mode 100644 index 265289d..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/TracingAgentControl.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent; - -import com.sematext.spm.client.unlogger.dynamic.InstrumentationSettings; - -public interface TracingAgentControl { - boolean enable(); - - boolean disable(); - - boolean isEnabled(); - - InstrumentationSettings getInstrumentationSettings(); - - boolean applyInstrumentationSettings(); -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/TransactionNamer.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/TransactionNamer.java deleted file mode 100644 index 47a2e05..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/TransactionNamer.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent; - -import com.sematext.spm.client.unlogger.JoinPoint; - -public final class TransactionNamer { - private String servlet; - private String framework; - private String customName; - - public static String format(JoinPoint jp) { - return String.format("%s#%s", jp.getType(), jp.getShortName()); - } - - public void asServlet(JoinPoint jp) { - this.servlet = format(jp); - } - - public void asFramework(JoinPoint jp) { - this.framework = format(jp); - } - - public void redefined(String customName) { - this.customName = customName; - } - - public String getName() { - if (customName != null) { - return customName; - } - if (framework != null) { - return framework; - } - return servlet; - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/TransactionSink.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/TransactionSink.java deleted file mode 100644 index 34ce2b1..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/TransactionSink.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent; - -import com.sematext.spm.client.tracing.agent.model.PartialTransaction; - -public interface TransactionSink extends Sink { - -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/api/TransactionAccess.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/api/TransactionAccess.java deleted file mode 100644 index 1e6676e..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/api/TransactionAccess.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.api; - -import java.util.Collections; -import java.util.Map; - -import com.sematext.spm.client.tracing.TracingParameters; -import com.sematext.spm.client.tracing.agent.Tracing; -import com.sematext.spm.client.tracing.agent.config.ServiceLocator; -import com.sematext.spm.client.tracing.agent.errors.ErrorsTracker; -import com.sematext.spm.client.tracing.agent.model.FailureType; -import com.sematext.spm.client.util.Preconditions; - -public final class TransactionAccess { - - private TransactionAccess() { - } - - public static void setName(String name) { - Preconditions.checkNotNull(name); - - Tracing.current().getNamer().redefined(name); - } - - public static void ignore() { - Tracing.current().ignore(); - } - - private static void forceTransactionEnd(FailureType type, Throwable throwable, String message) { - Tracing.current().setFailureType(type); - - if (throwable != null) { - Tracing.current().setException(throwable); - } - - if (message != null) { - Tracing.current().setTransactionParameter(TracingParameters.ERROR_MESSAGE.getKey(), message); - } - - Tracing.current().forceEnd(true); - Tracing.endTrace(); - } - - public static void noticeError(Throwable th) { - Preconditions.checkNotNull(th); - - ErrorsTracker.track(th, null); - forceTransactionEnd(FailureType.EXCEPTION, th, null); - } - - public static void noticeError(String message) { - Preconditions.checkNotNull(message); - - ErrorsTracker.track(null, message); - forceTransactionEnd(FailureType.CUSTOM, null, message); - } - - public static void setTransactionParameter(String key, String value) { - Preconditions.checkNotNull(key); - Preconditions.checkNotNull(value); - Preconditions.check(key.length() > 0 && key.length() <= ServiceLocator.getConfig().getMaxCustomParameterKeyLength(), - "Key length should be > 0 and <= " + ServiceLocator.getConfig() - .getMaxCustomParameterKeyLength()); - Preconditions - .check(value.length() > 0 && value.length() <= ServiceLocator.getConfig().getMaxCustomParameterValueLength(), - "Value length should be > 0 and <= " + ServiceLocator.getConfig().getMaxCustomParameterValueLength()); - - Preconditions.check(Tracing.current().getTransactionParameters().size() < ServiceLocator.getConfig() - .getMaxCustomTransactionParametersCount(), - "Parameters count should be <= " + ServiceLocator.getConfig() - .getMaxCustomTransactionParametersCount()); - Tracing.current().setTransactionParameter(key, value); - } - - public static Map getTransactionParameters() { - return Collections.unmodifiableMap(Tracing.current().getTransactionParameters()); - } - - public static void setMethodParameter(String key, String value) { - Preconditions.checkNotNull(key); - Preconditions.checkNotNull(value); - Preconditions.check(key.length() > 0 && key.length() <= ServiceLocator.getConfig().getMaxCustomParameterKeyLength(), - "Key length should be > 0 and <= " + ServiceLocator.getConfig() - .getMaxCustomParameterKeyLength()); - Preconditions - .check(value.length() > 0 && value.length() <= ServiceLocator.getConfig().getMaxCustomParameterValueLength(), - "Value length should be > 0 and <= " + ServiceLocator.getConfig().getMaxCustomParameterValueLength()); - - Preconditions.check(Tracing.current().getTransactionParameters().size() < ServiceLocator.getConfig() - .getMaxCustomMethodParametersCount(), - "Parameters count should be <= " + ServiceLocator.getConfig() - .getMaxCustomMethodParametersCount()); - Tracing.current().setMethodParameter(key, value); - } - - public static Map getMethodParameters() { - return Collections.unmodifiableMap(Tracing.current().getMethodParameters()); - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/config/Config.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/config/Config.java deleted file mode 100644 index fe81cb0..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/config/Config.java +++ /dev/null @@ -1,249 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.config; - -import java.io.File; -import java.util.Map; - -import com.sematext.spm.client.Log; -import com.sematext.spm.client.LogFactory; -import com.sematext.spm.client.monitor.MonitorFileNames; -import com.sematext.spm.client.util.AgentArgsParser; -import com.sematext.spm.client.util.FileUtil; -import com.sematext.spm.client.util.PropertiesReader; - -public class Config { - private static final Log LOG = LogFactory.getLog(Config.class); - - private static final int MAX_CUSTOM_PARAMETERS_COUNT = 10; - private static final int MAX_CUSTOM_PARAMETER_LENGTH = 256; - - private static final long THRESHOLD_LOWER_BOUND = 0; - private static final int STACK_THRESHOLD_LOWER_BOUND = 1000; - private static final String THRESHOLD_KEY = "MIN_TRANSACTION_DURATION_RECORD_THRESHOLD"; - private static final String STACK_SIZE_THRESHOLD_KEY = "CALL_STACK_SIZE_THRESHOLD"; - private static final String THREAD_INSTRUMENTATION_ENABLED_KEY = "THREAD_INSTRUMENTATION_ENABLED"; - - private long durationThresholdMillis; - private int stackSizeThreshold = STACK_THRESHOLD_LOWER_BOUND; - private String token; - private String jvm; - private String subType; - private String spmMonitorHome; - private String logPath; - private String confPath; - private String extensionsPath; - private boolean threadInstrumentationEnabled; - private int maxCustomParameterKeyLength = MAX_CUSTOM_PARAMETER_LENGTH; - private int maxCustomParameterValueLength = MAX_CUSTOM_PARAMETER_LENGTH; - private int maxCustomTransactionParametersCount = MAX_CUSTOM_PARAMETERS_COUNT; - private int maxCustomMethodParametersCount = MAX_CUSTOM_PARAMETERS_COUNT; - - public Config() { - } - - public long getDurationThresholdMillis() { - return durationThresholdMillis; - } - - public int getStackSizeThreshold() { - return stackSizeThreshold; - } - - public String getToken() { - return token; - } - - public void setToken(String token) { - this.token = token; - } - - public String getJvm() { - return jvm; - } - - public void setJvm(String jvm) { - this.jvm = jvm; - } - - public String getSpmMonitorHome() { - return spmMonitorHome; - } - - public void setSpmMonitorHome(String spmMonitorHome) { - this.spmMonitorHome = spmMonitorHome; - } - - public String getLogPath() { - return logPath; - } - - public void setLogPath(String logPath) { - this.logPath = logPath; - } - - public String getConfPath() { - return confPath; - } - - public void setConfPath(String confPath) { - this.confPath = confPath; - } - - public String getExtensionsPath() { - return extensionsPath; - } - - public boolean isThreadInstrumentationEnabled() { - return threadInstrumentationEnabled; - } - - public void setThreadInstrumentationEnabled(boolean threadInstrumentationEnabled) { - this.threadInstrumentationEnabled = threadInstrumentationEnabled; - } - - public void setDurationThresholdMillis(long durationThresholdMillis) { - this.durationThresholdMillis = durationThresholdMillis; - } - - public void setStackSizeThreshold(int stackSizeThreshold) { - this.stackSizeThreshold = stackSizeThreshold; - } - - public void setExtensionsPath(String extensionsPath) { - this.extensionsPath = extensionsPath; - } - - public int getMaxCustomParameterKeyLength() { - return maxCustomParameterKeyLength; - } - - public void setMaxCustomParameterKeyLength(int maxCustomParameterKeyLength) { - this.maxCustomParameterKeyLength = maxCustomParameterKeyLength; - } - - public int getMaxCustomParameterValueLength() { - return maxCustomParameterValueLength; - } - - public void setMaxCustomParameterValueLength(int maxCustomParameterValueLength) { - this.maxCustomParameterValueLength = maxCustomParameterValueLength; - } - - public int getMaxCustomTransactionParametersCount() { - return maxCustomTransactionParametersCount; - } - - public void setMaxCustomTransactionParametersCount(int maxCustomTransactionParametersCount) { - this.maxCustomTransactionParametersCount = maxCustomTransactionParametersCount; - } - - public int getMaxCustomMethodParametersCount() { - return maxCustomMethodParametersCount; - } - - public void setMaxCustomMethodParametersCount(int maxCustomMethodParametersCount) { - this.maxCustomMethodParametersCount = maxCustomMethodParametersCount; - } - - public static Config getConfig(String args) { - Config config = new Config(); - config.durationThresholdMillis = 0; - final Map agentArgs = AgentArgsParser.parseColonSeparated(args); - config.token = agentArgs.get("token"); - config.jvm = agentArgs.get("jvm-name"); - if (config.jvm == null) { - config.jvm = "default"; - } - config.spmMonitorHome = FileUtil.path(System.getProperty("spm.home", "/opt/spm"), "spm-monitor"); - if (config.subType != null) { - config.logPath = FileUtil - .path(config.spmMonitorHome, "logs", "applications", config.token, config.jvm, config.subType); - } else { - config.logPath = FileUtil.path(config.spmMonitorHome, "logs", "applications", config.token, config.jvm); - } - config.confPath = FileUtil.path(config.spmMonitorHome, "conf"); - return config; - } - - public static Config embeddedAgentConfig(String args) { - final Config config = new Config(); - final Map agentArgs = AgentArgsParser.parseColonSeparated(args); - config.token = agentArgs.get("token"); - config.jvm = agentArgs.get("jvm-name"); - if (config.jvm == null) { - config.jvm = "default"; - } - config.subType = agentArgs.get("sub-type"); - config.spmMonitorHome = FileUtil.path(System.getProperty("spm.home", "/opt/spm"), "spm-monitor"); - if (config.subType == null) { - config.logPath = FileUtil.path(config.spmMonitorHome, "logs", "applications", config.token, config.jvm); - } else { - config.logPath = FileUtil - .path(config.spmMonitorHome, "logs", "applications", config.token, config.jvm, config.subType); - } - config.confPath = FileUtil.path(config.spmMonitorHome, "conf"); - config.extensionsPath = FileUtil.path(config.spmMonitorHome, "ext", "tracing"); - - final String configFilename = MonitorFileNames.config(null, config.token, config.jvm); - final Map properties = PropertiesReader - .tryRead(new File(FileUtil.path(config.confPath, configFilename))); - - final String durationThresholdMillis = properties.get(THRESHOLD_KEY); - final String stackSizeThreshold = properties.get(STACK_SIZE_THRESHOLD_KEY); - - if (durationThresholdMillis != null) { - try { - config.durationThresholdMillis = Integer.parseInt(durationThresholdMillis); - } catch (NumberFormatException e) { - /* */ - } - - if (config.durationThresholdMillis < THRESHOLD_LOWER_BOUND) { - LOG.warn(THRESHOLD_KEY + " property has wrong value: " + durationThresholdMillis + ", using default value: " - + THRESHOLD_LOWER_BOUND + "."); - config.durationThresholdMillis = THRESHOLD_LOWER_BOUND; - } - } else { - config.durationThresholdMillis = THRESHOLD_LOWER_BOUND; - LOG.warn(THRESHOLD_KEY + " property is not set, using default value: " + THRESHOLD_LOWER_BOUND + "."); - } - - if (stackSizeThreshold != null) { - try { - config.stackSizeThreshold = Integer.parseInt(stackSizeThreshold); - } catch (NumberFormatException e) { - /* */ - } - } else { - config.stackSizeThreshold = STACK_THRESHOLD_LOWER_BOUND; - } - - final String isThreadInstrumentationEnabled = properties.get(THREAD_INSTRUMENTATION_ENABLED_KEY); - config.threadInstrumentationEnabled = - isThreadInstrumentationEnabled == null || Boolean.valueOf(isThreadInstrumentationEnabled); - - if (!config.threadInstrumentationEnabled) { - LOG.info("Thread instrumentation is disabled."); - } - - return config; - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/config/ServiceConfigurer.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/config/ServiceConfigurer.java deleted file mode 100644 index b84a4ce..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/config/ServiceConfigurer.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.config; - -import java.util.List; - -import com.sematext.spm.client.tracing.agent.Sink; -import com.sematext.spm.client.tracing.agent.TracingAgentControl; -import com.sematext.spm.client.tracing.agent.errors.TracingError; -import com.sematext.spm.client.tracing.agent.model.PartialTransaction; -import com.sematext.spm.client.tracing.agent.sampling.Sampler; -import com.sematext.spm.client.tracing.agent.stats.TracingStatistics; - -public interface ServiceConfigurer { - Config getConfig(); - - Sampler getTransactionSampler(); - - Sampler getTracingErrorSampler(); - - List> getTransactionSinks(); - - TracingStatistics getTracingStatistics(); - - List> getErrorSinks(); - - TracingAgentControl getTracingAgentControl(); -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/config/ServiceLocator.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/config/ServiceLocator.java deleted file mode 100644 index e2d121b..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/config/ServiceLocator.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.config; - -import java.util.List; - -import com.sematext.spm.client.tracing.agent.Sink; -import com.sematext.spm.client.tracing.agent.TracingAgentControl; -import com.sematext.spm.client.tracing.agent.errors.TracingError; -import com.sematext.spm.client.tracing.agent.model.PartialTransaction; -import com.sematext.spm.client.tracing.agent.sampling.Sampler; -import com.sematext.spm.client.tracing.agent.stats.NoOpTracingStatistics; -import com.sematext.spm.client.tracing.agent.stats.TracingStatistics; - -public class ServiceLocator { - private static ServiceConfigurer CONFIGURER; - - public static void configure(ServiceConfigurer configurer) { - CONFIGURER = configurer; - } - - public static Config getConfig() { - return CONFIGURER.getConfig(); - } - - public static Sampler getTransactionSampler() { - return CONFIGURER.getTransactionSampler(); - } - - public static Sampler getTracingErrorSampler() { - return CONFIGURER.getTracingErrorSampler(); - } - - public static List> getTransactionSinks() { - return CONFIGURER.getTransactionSinks(); - } - - public static List> getErrorSinks() { - return CONFIGURER.getErrorSinks(); - } - - public static TracingStatistics getTracingStatistics() { - if (CONFIGURER == null || CONFIGURER.getTracingStatistics() == null) { - return NoOpTracingStatistics.noOp(); - } - return CONFIGURER.getTracingStatistics(); - } - - public static TracingAgentControl getTracingAgentControl() { - return CONFIGURER.getTracingAgentControl(); - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/errors/ErrorSink.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/errors/ErrorSink.java deleted file mode 100644 index 44ad4c0..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/errors/ErrorSink.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.errors; - -public interface ErrorSink { - void sink(TracingError tracingError); -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/errors/ErrorsTracker.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/errors/ErrorsTracker.java deleted file mode 100644 index 659ffe8..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/errors/ErrorsTracker.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.errors; - -import java.util.HashMap; -import java.util.Map; - -import com.sematext.spm.client.tracing.TracingParameters; -import com.sematext.spm.client.tracing.agent.NoTrace; -import com.sematext.spm.client.tracing.agent.Sink; -import com.sematext.spm.client.tracing.agent.Trace; -import com.sematext.spm.client.tracing.agent.Tracing; -import com.sematext.spm.client.tracing.agent.config.ServiceLocator; -import com.sematext.spm.client.tracing.agent.util.Hostname; - -public class ErrorsTracker { - - public static void track(Throwable throwable, String message) { - final Trace> trace = Tracing.current(); - final String token = ServiceLocator.getConfig().getToken(); - - final Long traceId = trace == NoTrace.instance() ? null : trace.getTraceId(); - final Long callId = trace == NoTrace.instance() ? null : trace.getCallId(); - final Long parentCallId = trace == NoTrace.instance() ? null : trace.getParentCallId(); - final boolean sampled = trace.isSampled(); - final Map parameters = new HashMap(trace.getTransactionParameters()); - if (message != null) { - parameters.put(TracingParameters.ERROR_MESSAGE.getKey(), message); - } - if (throwable != null) { - parameters.put(TracingParameters.ERROR_CLASS.getKey(), throwable.getClass().getName()); - } - parameters.put(TracingParameters.HOST.getKey(), Hostname.getLocalEndpoint().getHostname()); - - final TracingError error = new TracingError(token, traceId, callId, parentCallId, - System.currentTimeMillis(), sampled, parameters); - - sink(error); - } - - private static void sink(TracingError tracingError) { - if (ServiceLocator.getErrorSinks() != null) { - for (Sink sink : ServiceLocator.getErrorSinks()) { - if (ServiceLocator.getTracingErrorSampler() == null || ServiceLocator.getTracingErrorSampler() - .sample(tracingError)) { - sink.sink(tracingError); - } - } - } - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/errors/TracingError.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/errors/TracingError.java deleted file mode 100644 index dc6b78c..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/errors/TracingError.java +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.errors; - -import java.util.HashMap; -import java.util.Map; - -public class TracingError { - private String token; - private Long traceId; - private Long callId; - private Long parentCallId; - private long timestamp; - private boolean sampled; - private Map parameters; - - public TracingError() { - } - - public TracingError(String token, Long traceId, Long callId, Long parentCallId, long timestamp, boolean sampled, - Map parameters) { - this.token = token; - this.traceId = traceId; - this.callId = callId; - this.parentCallId = parentCallId; - this.timestamp = timestamp; - this.sampled = sampled; - this.parameters = parameters; - } - - public String getToken() { - return token; - } - - public void setToken(String token) { - this.token = token; - } - - public Long getTraceId() { - return traceId; - } - - public void setTraceId(Long traceId) { - this.traceId = traceId; - } - - public Long getCallId() { - return callId; - } - - public void setCallId(Long callId) { - this.callId = callId; - } - - public Long getParentCallId() { - return parentCallId; - } - - public void setParentCallId(Long parentCallId) { - this.parentCallId = parentCallId; - } - - public long getTimestamp() { - return timestamp; - } - - public void setTimestamp(long timestamp) { - this.timestamp = timestamp; - } - - public boolean isSampled() { - return sampled; - } - - public void setSampled(boolean sampled) { - this.sampled = sampled; - } - - public Map getParameters() { - return parameters; - } - - public void setParameters(Map parameters) { - this.parameters = parameters; - } - - public void copy(TracingError to) { - to.token = token; - to.traceId = traceId; - to.callId = callId; - to.parentCallId = parentCallId; - to.timestamp = timestamp; - to.sampled = sampled; - to.parameters = new HashMap(parameters); - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/es/transport/ESAsyncActions.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/es/transport/ESAsyncActions.java deleted file mode 100644 index 39b5c1a..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/es/transport/ESAsyncActions.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.es.transport; - -import com.sematext.spm.client.tracing.agent.model.annotation.ESAnnotation; - -public final class ESAsyncActions { - private final Long traceId; - private final Long parentCallId; - private final Long startTs; - private final boolean sampled; - private final ESAnnotation annotation; - - public ESAsyncActions(ESAnnotation annotation, Long traceId, Long parentCallId, Long startTs, boolean sampled) { - this.annotation = annotation; - this.traceId = traceId; - this.parentCallId = parentCallId; - this.startTs = startTs; - this.sampled = sampled; - } - - public ESAnnotation getAnnotation() { - return annotation; - } - - public Long getTraceId() { - return traceId; - } - - public Long getParentCallId() { - return parentCallId; - } - - public Long getStartTs() { - return startTs; - } - - public boolean isSampled() { - return sampled; - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/es/transport/SpmActionRequestBuilderAccess.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/es/transport/SpmActionRequestBuilderAccess.java deleted file mode 100644 index 52b715d..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/es/transport/SpmActionRequestBuilderAccess.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.es.transport; - -import com.sematext.spm.client.instrumentation.Delegate; -import com.sematext.spm.client.instrumentation.Getter; -import com.sematext.spm.client.instrumentation.Setter; - -public interface SpmActionRequestBuilderAccess { - @Delegate(method = "request") - Object _$spm_tracing$_getRequest(); - - @Setter(value = "_$spm_tracing$_client") - void _$spm_tracing$_setClient(Object client); - - @Getter(value = "_$spm_tracing$_client") - Object _$spm_tracing$_getClient(); -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/es/transport/SpmBulkRequestAccess.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/es/transport/SpmBulkRequestAccess.java deleted file mode 100644 index 5c0ec9b..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/es/transport/SpmBulkRequestAccess.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.es.transport; - -import java.util.List; - -import com.sematext.spm.client.instrumentation.Delegate; - -public interface SpmBulkRequestAccess { - @Delegate(method = "requests") - List _$spm_tracing$_getRequests(); -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/es/transport/SpmDeleteRequestAccess.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/es/transport/SpmDeleteRequestAccess.java deleted file mode 100644 index 280bb1f..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/es/transport/SpmDeleteRequestAccess.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.es.transport; - -import com.sematext.spm.client.instrumentation.Delegate; - -public interface SpmDeleteRequestAccess extends SpmShardReplicationOperationRequestAccess { - @Delegate(method = "type") - String _$spm_tracing$_getType(); -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/es/transport/SpmGetRequestAccess.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/es/transport/SpmGetRequestAccess.java deleted file mode 100644 index 7a72d79..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/es/transport/SpmGetRequestAccess.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.es.transport; - -import com.sematext.spm.client.instrumentation.Delegate; - -public interface SpmGetRequestAccess extends SpmSingleShardOperationRequestAccess { - @Delegate(method = "type") - String _$spm_tracing$_getType(); -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/es/transport/SpmIndexRequestAccess.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/es/transport/SpmIndexRequestAccess.java deleted file mode 100644 index b32c8ea..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/es/transport/SpmIndexRequestAccess.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.es.transport; - -import com.sematext.spm.client.instrumentation.Delegate; - -public interface SpmIndexRequestAccess extends SpmShardReplicationOperationRequestAccess { - @Delegate(method = "type") - String _$spm_tracing$_getType(); -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/es/transport/SpmInstanceShardOperationRequestAccess.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/es/transport/SpmInstanceShardOperationRequestAccess.java deleted file mode 100644 index 5dde1c8..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/es/transport/SpmInstanceShardOperationRequestAccess.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.es.transport; - -import com.sematext.spm.client.instrumentation.Delegate; - -public interface SpmInstanceShardOperationRequestAccess { - @Delegate(method = "index") - String _$spm_tracing$_getIndex(); -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/es/transport/SpmListenableActionFutureAccess.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/es/transport/SpmListenableActionFutureAccess.java deleted file mode 100644 index f2e9c6c..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/es/transport/SpmListenableActionFutureAccess.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.es.transport; - -import com.sematext.spm.client.instrumentation.Getter; -import com.sematext.spm.client.instrumentation.Setter; - -public interface SpmListenableActionFutureAccess { - // TODO: smells like multiple threads should read this variable, volatile? - @Setter(value = "_$spm_tracing$_asyncActions") - void _$spm_tracing$_setESAsyncActions(ESAsyncActions action); - - @Getter(value = "_$spm_tracing$_asyncActions") - ESAsyncActions _$spm_tracing$_getESAsyncActions(); -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/es/transport/SpmSearchRequestAccess.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/es/transport/SpmSearchRequestAccess.java deleted file mode 100644 index 7ee50dd..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/es/transport/SpmSearchRequestAccess.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.es.transport; - -import com.sematext.spm.client.instrumentation.Delegate; -import com.sematext.spm.client.instrumentation.Getter; -import com.sematext.spm.client.instrumentation.Setter; - -public interface SpmSearchRequestAccess { - @Delegate(method = "types") - String[] _$spm_tracing$_getTypes(); - - @Delegate(method = "indices") - String[] _$spm_tracing$_getIndices(); - - @Getter(value = "_$spm_tracing$_searchRequestBuilder") - Object _$spm_tracing$_getSearchRequestBuilder(); - - @Setter(value = "_$spm_tracing$_searchRequestBuilder") - void _$spm_tracing$_setSearchRequestBuilder(Object builder); -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/es/transport/SpmShardReplicationOperationRequestAccess.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/es/transport/SpmShardReplicationOperationRequestAccess.java deleted file mode 100644 index 21f6e5a..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/es/transport/SpmShardReplicationOperationRequestAccess.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.es.transport; - -import com.sematext.spm.client.instrumentation.Delegate; - -public interface SpmShardReplicationOperationRequestAccess { - @Delegate(method = "index") - String _$spm_tracing$_getIndex(); -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/es/transport/SpmSingleShardOperationRequestAccess.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/es/transport/SpmSingleShardOperationRequestAccess.java deleted file mode 100644 index 6bdbeb2..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/es/transport/SpmSingleShardOperationRequestAccess.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.es.transport; - -import com.sematext.spm.client.instrumentation.Delegate; - -public interface SpmSingleShardOperationRequestAccess { - @Delegate(method = "index") - String _$spm_tracing$_getIndex(); -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/es/transport/SpmUpdateRequestAccess.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/es/transport/SpmUpdateRequestAccess.java deleted file mode 100644 index ee56855..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/es/transport/SpmUpdateRequestAccess.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.es.transport; - -import com.sematext.spm.client.instrumentation.Delegate; - -public interface SpmUpdateRequestAccess extends SpmInstanceShardOperationRequestAccess { - @Delegate(method = "type") - String _$spm_tracing$_getType(); -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/httpclient3/HeaderAccess.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/httpclient3/HeaderAccess.java deleted file mode 100644 index fa6a4d9..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/httpclient3/HeaderAccess.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.httpclient3; - -import com.sematext.spm.client.instrumentation.Delegate; - -public interface HeaderAccess { - @Delegate(method = "getValue") - String _$spm_tracing$_getValue(); -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/httpclient3/HostConfigurationAccess.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/httpclient3/HostConfigurationAccess.java deleted file mode 100644 index 6fc8fb7..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/httpclient3/HostConfigurationAccess.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.httpclient3; - -import com.sematext.spm.client.instrumentation.Delegate; - -public interface HostConfigurationAccess { - @Delegate(method = "getHostURL") - String _$spm_tracing$_getHostURL(); -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/httpclient3/HttpClientAccess.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/httpclient3/HttpClientAccess.java deleted file mode 100644 index a5c3e5c..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/httpclient3/HttpClientAccess.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.httpclient3; - -public interface HttpClientAccess extends HttpClientSolrAccess { -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/httpclient3/HttpClientSolrAccess.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/httpclient3/HttpClientSolrAccess.java deleted file mode 100644 index 9d57932..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/httpclient3/HttpClientSolrAccess.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.httpclient3; - -import com.sematext.spm.client.instrumentation.Getter; -import com.sematext.spm.client.instrumentation.Setter; - -public interface HttpClientSolrAccess { - @Getter("_$spm_tracing$_solrClient") - boolean _$spm_tracing$_isSolrClient(); - - @Setter("_$spm_tracing$_solrClient") - void _$spm_tracing$_setSolrClient(boolean solrClient); -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/httpclient3/HttpMethodAccess.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/httpclient3/HttpMethodAccess.java deleted file mode 100644 index 7716f0c..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/httpclient3/HttpMethodAccess.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.httpclient3; - -import com.sematext.spm.client.instrumentation.Delegate; -import com.sematext.spm.client.instrumentation.Getter; -import com.sematext.spm.client.instrumentation.Setter; - -public interface HttpMethodAccess { - @Delegate(method = "getName") - String _$spm_tracing$_getName(); - - @Delegate(method = "getPath") - String _$spm_tracing$_getPath(); - - @Delegate(method = "getStatusCode") - int _$spm_tracing$_getStatusCode(); - - @Delegate(method = "setRequestHeader") - void _$spm_tracing$_setRequestHeader(String name, String value); - - @Delegate(method = "getResponseHeader") - HeaderAccess _$spm_tracing$_getResponseHeader(String name); - - @Getter("_$spm_tracing$_solrClient") - boolean _$spm_tracing$_isSolrClient(); - - @Setter("_$spm_tracing$_solrClient") - void _$spm_tracing$_setSolrClient(boolean solrClient); -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/httpclient3/HttpMethodDirectorAccess.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/httpclient3/HttpMethodDirectorAccess.java deleted file mode 100644 index 5c9a5ff..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/httpclient3/HttpMethodDirectorAccess.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.httpclient3; - -import com.sematext.spm.client.instrumentation.Delegate; - -public interface HttpMethodDirectorAccess { - @Delegate(method = "getHostConfiguration") - HostConfigurationAccess _$spm_tracing$_getHostConfiguration(); -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/httpclient4/AbstractHttpClientAccess.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/httpclient4/AbstractHttpClientAccess.java deleted file mode 100644 index 69fbe19..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/httpclient4/AbstractHttpClientAccess.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.httpclient4; - -import com.sematext.spm.client.tracing.agent.httpclient3.HttpClientSolrAccess; - -public interface AbstractHttpClientAccess extends HttpClientSolrAccess { - -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/httpclient4/CloseableHttpClientAccess.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/httpclient4/CloseableHttpClientAccess.java deleted file mode 100644 index 6f40fa5..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/httpclient4/CloseableHttpClientAccess.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.httpclient4; - -import com.sematext.spm.client.tracing.agent.httpclient3.HttpClientSolrAccess; - -public interface CloseableHttpClientAccess extends HttpClientSolrAccess { -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/httpclient4/Header4Access.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/httpclient4/Header4Access.java deleted file mode 100644 index 9cb67b4..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/httpclient4/Header4Access.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.httpclient4; - -import com.sematext.spm.client.instrumentation.Delegate; - -public interface Header4Access { - @Delegate(method = "getValue") - String _$spm_tracing$_getValue(); -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/httpclient4/HttpClientURL.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/httpclient4/HttpClientURL.java deleted file mode 100644 index 7ef2a14..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/httpclient4/HttpClientURL.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.httpclient4; - -import java.net.URI; -import java.net.URISyntaxException; - -public final class HttpClientURL { - private HttpClientURL() { - } - - public static String makeUrl(HttpHostAccess host, RequestLineAccess line) { - final String requestUri = line._$spm_tracing$_getUri(); - try { - final URI uri = new URI(requestUri); - if (uri.isAbsolute()) { - return requestUri; - } else { - final URI absoluteUri = new URI(host._$spm_tracing$_getSchemeName(), null, - host._$spm_tracing$_getHostName(), host._$spm_tracing$_getPort(), uri - .getPath(), uri.getQuery(), uri.getFragment()); - return absoluteUri.toString(); - } - } catch (URISyntaxException e) { - return null; - } - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/httpclient4/HttpHostAccess.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/httpclient4/HttpHostAccess.java deleted file mode 100644 index ae7b472..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/httpclient4/HttpHostAccess.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.httpclient4; - -import com.sematext.spm.client.instrumentation.Delegate; - -public interface HttpHostAccess { - @Delegate(method = "getHostName") - String _$spm_tracing$_getHostName(); - - @Delegate(method = "getPort") - int _$spm_tracing$_getPort(); - - @Delegate(method = "getSchemeName") - String _$spm_tracing$_getSchemeName(); -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/httpclient4/HttpMessageAccess.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/httpclient4/HttpMessageAccess.java deleted file mode 100644 index c237539..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/httpclient4/HttpMessageAccess.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.httpclient4; - -import com.sematext.spm.client.instrumentation.Delegate; - -public interface HttpMessageAccess { - @Delegate(method = "setHeader") - void _$spm_tracing$_setHeader(String key, String value); - - @Delegate(method = "getFirstHeader") - Header4Access _$spm_tracing$_getFirstHeader(String key); -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/httpclient4/HttpRequestAccess.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/httpclient4/HttpRequestAccess.java deleted file mode 100644 index 5f486f0..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/httpclient4/HttpRequestAccess.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.httpclient4; - -import com.sematext.spm.client.instrumentation.Delegate; - -public interface HttpRequestAccess extends HttpMessageAccess { - @Delegate(method = "getRequestLine") - RequestLineAccess _$spm_tracing$_getRequestLine(); -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/httpclient4/HttpResponseAccess.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/httpclient4/HttpResponseAccess.java deleted file mode 100644 index 5580ce8..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/httpclient4/HttpResponseAccess.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.httpclient4; - -import com.sematext.spm.client.instrumentation.Delegate; - -public interface HttpResponseAccess extends HttpMessageAccess { - @Delegate(method = "getStatusLine") - StatusLineAccess _$spm_tracing$_getStatusLine(); -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/httpclient4/RequestLineAccess.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/httpclient4/RequestLineAccess.java deleted file mode 100644 index aaab13a..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/httpclient4/RequestLineAccess.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.httpclient4; - -import com.sematext.spm.client.instrumentation.Delegate; - -public interface RequestLineAccess { - @Delegate(method = "getMethod") - String _$spm_tracing$_getMethod(); - - @Delegate(method = "getUri") - String _$spm_tracing$_getUri(); -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/httpclient4/StatusLineAccess.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/httpclient4/StatusLineAccess.java deleted file mode 100644 index f10656f..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/httpclient4/StatusLineAccess.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.httpclient4; - -import com.sematext.spm.client.instrumentation.Delegate; - -public interface StatusLineAccess { - @Delegate(method = "getStatusCode") - int _$spm_tracing$_getStatusCode(); -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/jpa/SpmQueryAccess.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/jpa/SpmQueryAccess.java deleted file mode 100644 index b3ef22c..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/jpa/SpmQueryAccess.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.jpa; - -import com.sematext.spm.client.instrumentation.Getter; -import com.sematext.spm.client.instrumentation.Setter; - -public interface SpmQueryAccess { - @Getter("_$spm_tracing$_query") - String _$spm_tracing$_query_get(); - - @Setter("_$spm_tracing$_query") - void _$spm_tracing$_query_set(String query); -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/model/Call.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/model/Call.java deleted file mode 100644 index 2667418..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/model/Call.java +++ /dev/null @@ -1,324 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.model; - -import java.util.HashMap; -import java.util.Map; - -public final class Call { - - public static enum CallTag { - REGULAR, SQL_QUERY, JPA, JSP, EXTERNAL, HTTP_REQUEST, ES, SOLR - } - - public static enum TransactionType { - WEB, BACKGROUND - } - - public static final long ROOT_CALL_ID = 0L; - - private long callId; - - private long parentCallId; - - private int level; - - private long startTimestamp; - - private long endTimestamp; - - private long duration; - - private long selfDuration; - - private String signature; - - private Boolean failed; - - private Boolean external; - - private CallTag callTag; - - private boolean entryPoint; - - private String crossAppToken; - - private Long crossAppCallId; - - private Long crossAppParentCallId; - - private Long crossAppDuration; - - private String crossAppRequest; - - private Endpoint crossAppEndpoint; - - private boolean crossAppSampled; - - private Object annotation; - - private Map parameters = new HashMap(); - - private transient long childDuration; - - private transient Call parent; - - private transient boolean skipExternalTracingStatistics; - - public Call() { - } - - public String getSignature() { - return signature; - } - - public void setSignature(String signature) { - this.signature = signature; - } - - public long getStartTimestamp() { - return startTimestamp; - } - - public void setStartTimestamp(long startTimestamp) { - this.startTimestamp = startTimestamp; - } - - public long getEndTimestamp() { - return endTimestamp; - } - - public void setEndTimestamp(long endTimestamp) { - this.endTimestamp = endTimestamp; - } - - public long getDuration() { - return duration; - } - - public void setDuration(long duration) { - this.duration = duration; - } - - public long getCallId() { - return callId; - } - - public void setCallId(long callId) { - this.callId = callId; - } - - public long getParentCallId() { - return parentCallId; - } - - public void setParentCallId(long parentCallId) { - this.parentCallId = parentCallId; - } - - public int getLevel() { - return level; - } - - public void setLevel(int level) { - this.level = level; - } - - public Boolean getFailed() { - return failed; - } - - public void setFailed(Boolean failed) { - this.failed = failed; - } - - public Boolean getExternal() { - return external; - } - - public void setExternal(Boolean external) { - this.external = external; - } - - public CallTag getCallTag() { - return callTag; - } - - public void setCallTag(CallTag callTag) { - this.callTag = callTag; - } - - public Boolean isEntryPoint() { - return entryPoint; - } - - public void setEntryPoint(boolean entryPoint) { - this.entryPoint = entryPoint; - } - - public long getSelfDuration() { - return selfDuration; - } - - public void setSelfDuration(long selfDuration) { - this.selfDuration = selfDuration; - } - - public String getCrossAppToken() { - return crossAppToken; - } - - public void setCrossAppToken(String crossAppToken) { - this.crossAppToken = crossAppToken; - } - - public Long getCrossAppCallId() { - return crossAppCallId; - } - - public void setCrossAppCallId(Long crossAppCallId) { - this.crossAppCallId = crossAppCallId; - } - - public Long getCrossAppParentCallId() { - return crossAppParentCallId; - } - - public void setCrossAppParentCallId(Long crossAppParentCallId) { - this.crossAppParentCallId = crossAppParentCallId; - } - - public Long getCrossAppDuration() { - return crossAppDuration; - } - - public void setCrossAppDuration(Long crossAppDuration) { - this.crossAppDuration = crossAppDuration; - } - - public String getCrossAppRequest() { - return crossAppRequest; - } - - public void setCrossAppRequest(String crossAppRequest) { - this.crossAppRequest = crossAppRequest; - } - - public Endpoint getCrossAppEndpoint() { - return crossAppEndpoint; - } - - public void setCrossAppEndpoint(Endpoint crossAppEndpoint) { - this.crossAppEndpoint = crossAppEndpoint; - } - - public boolean isCrossAppSampled() { - return crossAppSampled; - } - - public void setCrossAppSampled(boolean crossAppSampled) { - this.crossAppSampled = crossAppSampled; - } - - public long getChildDuration() { - return childDuration; - } - - public void setChildDuration(long childDuration) { - this.childDuration = childDuration; - } - - public Call getParent() { - return parent; - } - - public void setParent(Call parent) { - this.parent = parent; - } - - public boolean isSkipExternalTracingStatistics() { - return skipExternalTracingStatistics; - } - - public void setSkipExternalTracingStatistics(boolean skipExternalTracingStatistics) { - this.skipExternalTracingStatistics = skipExternalTracingStatistics; - } - - public Object getAnnotation() { - return annotation; - } - - public void setAnnotation(Object annotation) { - this.annotation = annotation; - } - - public Map getParameters() { - return parameters; - } - - public void setParameters(Map parameters) { - this.parameters = parameters; - } - - public void copy(Call to) { - to.setCallId(this.getCallId()); - to.setParentCallId(this.getParentCallId()); - to.setLevel(this.getLevel()); - to.setSignature(this.getSignature()); - to.setStartTimestamp(this.getStartTimestamp()); - to.setEndTimestamp(this.getEndTimestamp()); - to.setDuration(this.getDuration()); - to.setSelfDuration(this.getSelfDuration()); - to.setFailed(this.getFailed()); - to.setExternal(this.getExternal()); - to.setCallTag(this.getCallTag()); - to.setEntryPoint(this.isEntryPoint()); - to.setCrossAppToken(this.getCrossAppToken()); - to.setCrossAppCallId(this.getCrossAppCallId()); - to.setCrossAppParentCallId(this.getCrossAppParentCallId()); - to.setCrossAppDuration(this.getCrossAppDuration()); - to.setCrossAppRequest(this.getCrossAppRequest()); - to.setCrossAppEndpoint(this.getCrossAppEndpoint()); - to.setCrossAppSampled(this.isCrossAppSampled()); - to.setAnnotation(this.getAnnotation()); - to.setSkipExternalTracingStatistics(this.isSkipExternalTracingStatistics()); - for (final Map.Entry entry : parameters.entrySet()) { - to.getParameters().put(entry.getKey(), entry.getValue()); - } - } - - @Override - public String toString() { - return "Call{" + - "callId=" + callId + - ", parentCallId=" + parentCallId + - ", level=" + level + - ", startTimestamp=" + startTimestamp + - ", endTimestamp=" + endTimestamp + - ", duration=" + duration + - ", selfDuration=" + selfDuration + - ", signature='" + signature + '\'' + - ", failed=" + failed + - ", external=" + external + - ", callTag=" + callTag + - ", entryPoint='" + entryPoint + '\'' + - '}'; - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/model/CallJsonSerializer.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/model/CallJsonSerializer.java deleted file mode 100644 index 70a74c5..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/model/CallJsonSerializer.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.model; - -import java.io.StringWriter; - -import com.sematext.spm.client.tracing.agent.util.JSON; - -public final class CallJsonSerializer { - private CallJsonSerializer() { - } - - public static String toJson(Call call) { - final StringWriter json = new StringWriter(); - final JSON.JSONWriter writer = new JSON.JSONWriter(json); - writer.writeObjectStart(); - writer.writeKeyValue("parentCallId", call.getParentCallId()); - writer.writeKeyValue("callId", call.getCallId()); - writer.writeKeyValue("level", call.getLevel()); - writer.writeKeyValue("signature", call.getSignature()); - writer.writeKeyValue("startTimestamp", call.getStartTimestamp()); - writer.writeKeyValue("endTimestamp", call.getEndTimestamp()); - writer.writeObjectEnd(); - return json.toString(); - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/model/ESAction.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/model/ESAction.java deleted file mode 100644 index 861af92..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/model/ESAction.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.model; - -public final class ESAction { - - public static enum OperationType { - INDEX, DELETE, SEARCH, GET, UPDATE - } - - private final OperationType operationType; - private final String index; - private final String type; - private final String query; - private final int count; - - public ESAction(OperationType operationType, String index, String type, String query) { - this(operationType, index, type, query, 1); - } - - public ESAction(OperationType operationType, String index, String type, String query, int count) { - this.operationType = operationType; - this.index = index; - this.type = type; - this.query = query; - this.count = count; - } - - public OperationType getOperationType() { - return operationType; - } - - public String getIndex() { - return index; - } - - public String getType() { - return type; - } - - public String getQuery() { - return query; - } - - public int getCount() { - return count; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - ESAction esAction = (ESAction) o; - - if (count != esAction.count) return false; - if (index != null ? !index.equals(esAction.index) : esAction.index != null) return false; - if (operationType != esAction.operationType) return false; - if (query != null ? !query.equals(esAction.query) : esAction.query != null) return false; - if (type != null ? !type.equals(esAction.type) : esAction.type != null) return false; - - return true; - } - - @Override - public int hashCode() { - int result = operationType != null ? operationType.hashCode() : 0; - result = 31 * result + (index != null ? index.hashCode() : 0); - result = 31 * result + (type != null ? type.hashCode() : 0); - result = 31 * result + (query != null ? query.hashCode() : 0); - result = 31 * result + count; - return result; - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/model/Endpoint.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/model/Endpoint.java deleted file mode 100644 index 572c5ba..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/model/Endpoint.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.model; - -public class Endpoint { - private final String address; - private final String hostname; - - public Endpoint(String address, String hostname) { - this.address = address; - this.hostname = hostname; - } - - public String getAddress() { - return address; - } - - public String getHostname() { - return hostname; - } - - @Override - public String toString() { - return "Endpoint{" + - "address='" + address + '\'' + - ", hostname='" + hostname + '\'' + - '}'; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - Endpoint endpoint = (Endpoint) o; - - if (address != null ? !address.equals(endpoint.address) : endpoint.address != null) return false; - if (hostname != null ? !hostname.equals(endpoint.hostname) : endpoint.hostname != null) return false; - - return true; - } - - @Override - public int hashCode() { - int result = address != null ? address.hashCode() : 0; - result = 31 * result + (hostname != null ? hostname.hashCode() : 0); - return result; - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/model/FailureType.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/model/FailureType.java deleted file mode 100644 index a0f0ff3..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/model/FailureType.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.model; - -public enum FailureType { - EXCEPTION, HTTP_RESPONSE, CUSTOM -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/model/Http.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/model/Http.java deleted file mode 100644 index 9830343..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/model/Http.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.model; - -public final class Http { - private Http() { - } - - public static boolean is4xx(int code) { - return code / 100 == 4; - } - - public static boolean is5xx(int code) { - return code / 100 == 5; - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/model/HttpHeaders.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/model/HttpHeaders.java deleted file mode 100644 index 28f6b4d..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/model/HttpHeaders.java +++ /dev/null @@ -1,149 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.model; - -public final class HttpHeaders { - private HttpHeaders() { - } - - public static final String SPM_TRACING_TRACE_ID = "X-SPM-Tracing-TraceId"; - public static final String SPM_TRACING_CALL_ID = "X-SPM-Tracing-CallId"; - public static final String SPM_TRACING_CROSS_APP_CALL = "X-SPM-Tracing-Cross-App-Call"; - public static final String SPM_TRACING_SAMPLED = "X-SPM-Tracing-Sampled"; - - public static String encodeCrossAppCallHeader(Long callId, Long parentCallId, Long traceId, long duration, - String token, String request, Endpoint endpoint, boolean sampled) { - final StringBuilder header = new StringBuilder(); - header.append(token).append(";"); - header.append(callId).append(";"); - header.append(parentCallId).append(";"); - header.append(traceId).append(";"); - header.append(duration).append(";"); - header.append(request).append(";"); - header.append(endpoint.getAddress()).append(";"); - header.append(endpoint.getHostname()).append(";"); - header.append(sampled); - return header.toString(); - } - - public static CrossAppCallHeader decodeCrossAppCallHeader(String header) { - final String[] parts = header.split(";"); - if (parts.length < 8) { - return null; - } - final String token = parts[0]; - - final Long callId = parseLongSilently(parts[1]); - final Long parentCallId = parseLongSilently(parts[2]); - final Long traceId = parseLongSilently(parts[3]); - final Long duration = parseLongSilently(parts[4]); - if (callId == null || parentCallId == null || traceId == null || duration == null) { - return null; - } - - final String request = parts[5]; - final Endpoint endpoint = new Endpoint(parts[6], parts[7]); - boolean sampled = true; - if (parts.length >= 9) { - sampled = Boolean.valueOf(parts[8]); - } - return new CrossAppCallHeader(token, callId, parentCallId, traceId, duration, request, endpoint, sampled); - } - - private static Long parseLongSilently(final String v) { - if (v == null) { - return null; - } - try { - return Long.parseLong(v); - } catch (NumberFormatException e) { - return null; - } - } - - public static final class CrossAppCallHeader { - private final String token; - private final long callId; - private final long parentCallId; - private final long traceId; - private final long duration; - private final String request; - private final Endpoint endpoint; - private final boolean sampled; - - private CrossAppCallHeader(String token, long callId, long parentCallId, long traceId, long duration, - String request, Endpoint endpoint, boolean sampled) { - this.token = token; - this.callId = callId; - this.parentCallId = parentCallId; - this.traceId = traceId; - this.duration = duration; - this.request = request; - this.endpoint = endpoint; - this.sampled = sampled; - } - - public String getToken() { - return token; - } - - public long getCallId() { - return callId; - } - - public long getParentCallId() { - return parentCallId; - } - - public long getTraceId() { - return traceId; - } - - public long getDuration() { - return duration; - } - - public String getRequest() { - return request; - } - - public Endpoint getEndpoint() { - return endpoint; - } - - public boolean isSampled() { - return sampled; - } - - @Override - public String toString() { - return "CrossAppCallHeader{" + - "token='" + token + '\'' + - ", callId=" + callId + - ", parentCallId=" + parentCallId + - ", traceId=" + traceId + - ", duration=" + duration + - ", request='" + request + '\'' + - ", endpoint=" + endpoint + - ", sampled=" + sampled + - '}'; - } - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/model/InetAddress.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/model/InetAddress.java deleted file mode 100644 index 3b933f3..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/model/InetAddress.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.model; - -public final class InetAddress { - private final String host; - private final int port; - - public InetAddress(String host, int port) { - this.host = host; - this.port = port; - } - - public String getHost() { - return host; - } - - public int getPort() { - return port; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - InetAddress that = (InetAddress) o; - - if (port != that.port) return false; - if (host != null ? !host.equals(that.host) : that.host != null) return false; - - return true; - } - - @Override - public int hashCode() { - int result = host != null ? host.hashCode() : 0; - result = 31 * result + port; - return result; - } - - @Override - public String toString() { - return "InetAddress{" + - "host='" + host + '\'' + - ", port=" + port + - '}'; - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/model/PartialTransaction.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/model/PartialTransaction.java deleted file mode 100644 index 872740d..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/model/PartialTransaction.java +++ /dev/null @@ -1,217 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.model; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import com.sematext.spm.client.tracing.agent.model.Call.TransactionType; - -public final class PartialTransaction { - private long callId; - private long parentCallId; - private long traceId; - private String request; - private long startTimestamp; - private long endTimestamp; - private long duration; - private String token; - private boolean failed; - private boolean entryPoint; - private Endpoint endpoint; - private boolean asynchronous; - private TransactionType transactionType; - private Object transactionSummary; - private List calls; - private FailureType failureType; - private Throwable exceptionStackTrace; - private Map parameters = new HashMap(); - - public long getCallId() { - return callId; - } - - public void setCallId(long callId) { - this.callId = callId; - } - - public long getParentCallId() { - return parentCallId; - } - - public void setParentCallId(long parentCallId) { - this.parentCallId = parentCallId; - } - - public long getTraceId() { - return traceId; - } - - public void setTraceId(long traceId) { - this.traceId = traceId; - } - - public String getRequest() { - return request; - } - - public void setRequest(String request) { - this.request = request; - } - - public long getStartTimestamp() { - return startTimestamp; - } - - public void setStartTimestamp(long startTimestamp) { - this.startTimestamp = startTimestamp; - } - - public long getEndTimestamp() { - return endTimestamp; - } - - public void setEndTimestamp(long endTimestamp) { - this.endTimestamp = endTimestamp; - } - - public long getDuration() { - return duration; - } - - public void setDuration(long duration) { - this.duration = duration; - } - - public String getToken() { - return token; - } - - public void setToken(String token) { - this.token = token; - } - - public boolean isFailed() { - return failed; - } - - public void setFailed(boolean failed) { - this.failed = failed; - } - - public boolean isEntryPoint() { - return entryPoint; - } - - public void setEntryPoint(boolean entryPoint) { - this.entryPoint = entryPoint; - } - - public Endpoint getEndpoint() { - return endpoint; - } - - public void setEndpoint(Endpoint endpoint) { - this.endpoint = endpoint; - } - - public boolean isAsynchronous() { - return asynchronous; - } - - public void setAsynchronous(boolean asynchronous) { - this.asynchronous = asynchronous; - } - - public TransactionType getTransactionType() { - return transactionType; - } - - public void setTransactionType(TransactionType transactionType) { - this.transactionType = transactionType; - } - - public Object getTransactionSummary() { - return transactionSummary; - } - - public void setTransactionSummary(Object transactionSummary) { - this.transactionSummary = transactionSummary; - } - - public List getCalls() { - return calls; - } - - public void setCalls(List calls) { - this.calls = calls; - } - - public FailureType getFailureType() { - return failureType; - } - - public void setFailureType(FailureType failureType) { - this.failureType = failureType; - } - - public Throwable getExceptionStackTrace() { - return exceptionStackTrace; - } - - public void setExceptionStackTrace(Throwable exceptionStackTrace) { - this.exceptionStackTrace = exceptionStackTrace; - } - - public Map getParameters() { - return parameters; - } - - public void setParameters(Map parameters) { - this.parameters = parameters; - } - - public void copy(PartialTransaction to) { - to.setCallId(getCallId()); - to.setParentCallId(getParentCallId()); - to.setTraceId(getTraceId()); - to.setRequest(getRequest()); - to.setStartTimestamp(getStartTimestamp()); - to.setEndTimestamp(getEndTimestamp()); - to.setDuration(getDuration()); - to.setToken(getToken()); - to.setFailed(isFailed()); - to.setEntryPoint(isEntryPoint()); - to.setEndpoint(getEndpoint()); - to.setAsynchronous(isAsynchronous()); - to.setTransactionType(getTransactionType()); - to.setTransactionSummary(getTransactionSummary()); - to.setCalls(getCalls()); - to.setFailureType(getFailureType()); - to.setExceptionStackTrace(getExceptionStackTrace()); - if (to.getParameters() == null) { - to.setParameters(new HashMap()); - } - for (Map.Entry entry : parameters.entrySet()) { - to.getParameters().put(entry.getKey(), entry.getValue()); - } - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/model/SolrAnnotation.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/model/SolrAnnotation.java deleted file mode 100644 index 675139c..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/model/SolrAnnotation.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.model; - -import java.util.Map; - -public final class SolrAnnotation { - - public static enum RequestType { - SCHEMA, UPDATE, COLLECTION_ADMIN, CORE_ADMIN, ANALYSIS, OTHER, QUERY - } - - private String collection; - private boolean succeed; - private String url; - private Map params; - private RequestType requestType; - private int responseStatus; - - public String getCollection() { - return collection; - } - - public void setCollection(String collection) { - this.collection = collection; - } - - public boolean isSucceed() { - return succeed; - } - - public void setSucceed(boolean succeed) { - this.succeed = succeed; - } - - public String getUrl() { - return url; - } - - public void setUrl(String url) { - this.url = url; - } - - public Map getParams() { - return params; - } - - public void setParams(Map params) { - this.params = params; - } - - public RequestType getRequestType() { - return requestType; - } - - public void setRequestType(RequestType requestType) { - this.requestType = requestType; - } - - public int getResponseStatus() { - return responseStatus; - } - - public void setResponseStatus(int responseStatus) { - this.responseStatus = responseStatus; - } - - @Override - public String toString() { - return "SolrAnnotation{" + - "collection='" + collection + '\'' + - ", succeed=" + succeed + - ", baseURL='" + url + '\'' + - ", params=" + params + - ", requestType=" + requestType + - ", responseStatus=" + responseStatus + - '}'; - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/model/WebTransactionSummary.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/model/WebTransactionSummary.java deleted file mode 100644 index 3bafd51..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/model/WebTransactionSummary.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.model; - -public class WebTransactionSummary { - private String request; - private String queryString; - private String requestMethod; - private int responseCode; - - public String getRequest() { - return request; - } - - public void setRequest(String request) { - this.request = request; - } - - public String getQueryString() { - return queryString; - } - - public void setQueryString(String queryString) { - this.queryString = queryString; - } - - public String getRequestMethod() { - return requestMethod; - } - - public void setRequestMethod(String requestMethod) { - this.requestMethod = requestMethod; - } - - public int getResponseCode() { - return responseCode; - } - - public void setResponseCode(int responseCode) { - this.responseCode = responseCode; - } - - public static WebTransactionSummary handle(String request, String queryString, String requestMethod) { - WebTransactionSummary summary = new WebTransactionSummary(); - summary.setRequest(request); - summary.setQueryString(queryString); - summary.setRequestMethod(requestMethod); - return summary; - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/model/annotation/ESAnnotation.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/model/annotation/ESAnnotation.java deleted file mode 100644 index 566ba64..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/model/annotation/ESAnnotation.java +++ /dev/null @@ -1,198 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.model.annotation; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import com.sematext.spm.client.tracing.agent.model.ESAction; -import com.sematext.spm.client.tracing.agent.model.ESAction.OperationType; -import com.sematext.spm.client.tracing.agent.model.InetAddress; -import com.sematext.spm.client.util.Utils; - -public class ESAnnotation { - public static enum RequestType { - INDEX_BULK(true, OperationType.INDEX), - UPDATE_BULK(true, OperationType.UPDATE), - DELETE_BULK(true, OperationType.DELETE), - BULK(true, null), - INDEX(false, OperationType.INDEX), - DELETE(false, OperationType.DELETE), - SEARCH(false, OperationType.SEARCH), - GET(false, OperationType.GET), - UPDATE(false, OperationType.UPDATE); - - final boolean bulk; - final OperationType operationType; - - RequestType(boolean bulk, OperationType operationType) { - this.bulk = bulk; - this.operationType = operationType; - } - - public static RequestType find(boolean bulk, OperationType type) { - for (final RequestType opType : RequestType.values()) { - if (opType.bulk == bulk && opType.operationType == type) { - return opType; - } - } - throw new IllegalArgumentException( - "Can't find operation type corresponding to { bulk = " + bulk + ", type = " + type + "}"); - } - } - - private List actions; - private List addresses; - private String index; - private RequestType requestType; - private boolean bulk; - - public String getIndex() { - return index; - } - - public void setIndex(String index) { - this.index = index; - } - - public List getActions() { - return actions; - } - - public void setActions(List actions) { - this.actions = actions; - } - - public List getAddresses() { - return addresses; - } - - public void setAddresses(List addresses) { - this.addresses = addresses; - } - - public RequestType getRequestType() { - return requestType; - } - - public void setRequestType(RequestType requestType) { - this.requestType = requestType; - } - - public boolean isBulk() { - return bulk; - } - - public void setBulk(boolean bulk) { - this.bulk = bulk; - } - - private static class OperationTypeIndexAndType { - private final OperationType operationType; - private final String index; - private final String type; - - OperationTypeIndexAndType(OperationType operationType, String index, String type) { - this.operationType = operationType; - this.index = index; - this.type = type; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - OperationTypeIndexAndType that = (OperationTypeIndexAndType) o; - - if (index != null ? !index.equals(that.index) : that.index != null) return false; - if (operationType != that.operationType) return false; - if (type != null ? !type.equals(that.type) : that.type != null) return false; - - return true; - } - - @Override - public int hashCode() { - int result = operationType != null ? operationType.hashCode() : 0; - result = 31 * result + (index != null ? index.hashCode() : 0); - result = 31 * result + (type != null ? type.hashCode() : 0); - return result; - } - } - - public static ESAnnotation make(List addresses, boolean bulk, List actions) { - if (actions.isEmpty()) { - throw new IllegalArgumentException("Expected at least one action."); - } - - final ESAnnotation annotation = new ESAnnotation(); - annotation.setAddresses(addresses); - annotation.setBulk(bulk); - if (!bulk) { - annotation.setIndex(actions.get(0).getIndex()); - annotation.setRequestType(RequestType.find(false, actions.get(0).getOperationType())); - } else { - final Iterator iter = actions.iterator(); - ESAction action = iter.next(); - String index = action.getIndex(); - OperationType operationType = action.getOperationType(); - while (iter.hasNext()) { - action = iter.next(); - if (!Utils.equal(action.getIndex(), index)) { - index = null; - } - if (!Utils.equal(action.getOperationType(), operationType)) { - operationType = null; - } - } - annotation.setIndex(index); - annotation.setRequestType(RequestType.find(true, operationType)); - } - - if (bulk) { - final Map counts = new HashMap(); - for (ESAction action : actions) { - OperationTypeIndexAndType t = new OperationTypeIndexAndType(action.getOperationType(), action.getIndex(), action - .getType()); - Integer count = counts.get(t); - if (count == null) { - count = 0; - } - count++; - counts.put(t, count); - } - final List groupedActions = new ArrayList(); - for (final Map.Entry entry : counts.entrySet()) { - final OperationTypeIndexAndType key = entry.getKey(); - groupedActions.add(new ESAction(key.operationType, key.index, key.type, null, entry.getValue())); - - annotation.setActions(groupedActions); - } - } else { - annotation.setActions(actions); - } - - return annotation; - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/model/annotation/HTTPRequestAnnotation.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/model/annotation/HTTPRequestAnnotation.java deleted file mode 100644 index 6ad4388..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/model/annotation/HTTPRequestAnnotation.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.model.annotation; - -public class HTTPRequestAnnotation { - private String url; - private String method; - private int responseCode; - - public String getUrl() { - return url; - } - - public void setUrl(String url) { - this.url = url; - } - - public String getMethod() { - return method; - } - - public void setMethod(String method) { - this.method = method; - } - - public int getResponseCode() { - return responseCode; - } - - public void setResponseCode(int responseCode) { - this.responseCode = responseCode; - } - - public static HTTPRequestAnnotation request(String url) { - HTTPRequestAnnotation annotation = new HTTPRequestAnnotation(); - annotation.setUrl(url); - return annotation; - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/model/annotation/JPAAnnotation.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/model/annotation/JPAAnnotation.java deleted file mode 100644 index 65ebd16..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/model/annotation/JPAAnnotation.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.model.annotation; - -public final class JPAAnnotation { - private String type; - private String query; - private String object; - private int count; - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - public String getQuery() { - return query; - } - - public void setQuery(String query) { - this.query = query; - } - - public String getObject() { - return object; - } - - public void setObject(String object) { - this.object = object; - } - - public int getCount() { - return count; - } - - public void setCount(int count) { - this.count = count; - } - - public static JPAAnnotation find(String object) { - final JPAAnnotation annotation = new JPAAnnotation(); - annotation.setType("find"); - annotation.setObject(object); - return annotation; - } - - public static JPAAnnotation query(String query, String object) { - final JPAAnnotation annotation = new JPAAnnotation(); - annotation.setType("query"); - annotation.setObject(object); - annotation.setQuery(query); - return annotation; - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/model/annotation/JSPAnnotation.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/model/annotation/JSPAnnotation.java deleted file mode 100644 index 0d24cd3..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/model/annotation/JSPAnnotation.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.model.annotation; - -public final class JSPAnnotation { - private String path; - - public String getPath() { - return path; - } - - public void setPath(String path) { - this.path = path; - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/model/annotation/SQLAnnotation.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/model/annotation/SQLAnnotation.java deleted file mode 100644 index 712e267..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/model/annotation/SQLAnnotation.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.model.annotation; - -import com.sematext.spm.client.tracing.agent.sql.SqlStatement; -import com.sematext.spm.client.tracing.agent.sql.SqlStatementParser; - -public final class SQLAnnotation { - private String type; - private String sql; - private String url; - private int resultCount; - private String table; - private SqlStatement.Operation operation; - - private SQLAnnotation() { - } - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - public String getSql() { - return sql; - } - - public void setSql(String sql) { - this.sql = sql; - } - - public int getCount() { - return resultCount; - } - - public void setResultCount(int resultCount) { - this.resultCount = resultCount; - } - - public String getTable() { - return table; - } - - public void setTable(String table) { - this.table = table; - } - - public SqlStatement.Operation getOperation() { - return operation; - } - - public void setOperation(SqlStatement.Operation operation) { - this.operation = operation; - } - - public String getUrl() { - return url; - } - - public void setUrl(String url) { - this.url = url; - } - - public static SQLAnnotation make(String query, String url) { - final SQLAnnotation annotation = new SQLAnnotation(); - annotation.setType("query"); - annotation.setSql(query); - annotation.setUrl(url); - - final SqlStatement statement = SqlStatementParser.parse(query); - annotation.setTable(statement.getTable()); - annotation.setOperation(statement.getOperation()); - return annotation; - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/custom/ExtensionPointcut.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/custom/ExtensionPointcut.java deleted file mode 100644 index 12776b2..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/custom/ExtensionPointcut.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.pointcuts.custom; - -import com.sematext.spm.client.tracing.agent.Tracing; -import com.sematext.spm.client.tracing.agent.model.Call; -import com.sematext.spm.client.tracing.agent.model.FailureType; -import com.sematext.spm.client.unlogger.LoggerContext; -import com.sematext.spm.client.unlogger.UnloggableLogger; -import com.sematext.spm.client.unlogger.xml.CustomPointcutOptions; - -public class ExtensionPointcut implements UnloggableLogger { - - private final CustomPointcutOptions options; - - public ExtensionPointcut(CustomPointcutOptions options) { - this.options = options; - } - - @Override - public void logBefore(LoggerContext context) { - if (options.isEntryPoint()) { - Tracing.newTrace(context.getJoinPoint().getShortName(), Call.TransactionType.BACKGROUND); - } - Tracing.current().getNamer().asFramework(context.getJoinPoint()); - Tracing.current().getNamer().redefined(options.getTransactionName()); - - Tracing.current().newCall(context.getJoinPoint()); - Tracing.current().setTag(Call.CallTag.REGULAR); - Tracing.current().setEntryPoint(options.isEntryPoint()); - } - - @Override - public void logAfter(LoggerContext context, Object returnValue) { - Tracing.current().endCall(); - if (options.isEntryPoint()) { - Tracing.endTrace(); - } - } - - @Override - public void logThrow(LoggerContext context, Throwable throwable) { - Tracing.current().setFailed(true); - if (options.isEntryPoint()) { - Tracing.current().setFailureType(FailureType.EXCEPTION); - Tracing.current().setException(throwable); - } - Tracing.current().endCall(); - if (options.isEntryPoint()) { - Tracing.endTrace(); - } - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/custom/TracedMethodPointcut.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/custom/TracedMethodPointcut.java deleted file mode 100644 index dc7aab9..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/custom/TracedMethodPointcut.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.pointcuts.custom; - -import java.lang.annotation.Annotation; -import java.lang.reflect.Method; - -import com.sematext.spm.client.Log; -import com.sematext.spm.client.LogFactory; -import com.sematext.spm.client.tracing.agent.NoTrace; -import com.sematext.spm.client.tracing.agent.Tracing; -import com.sematext.spm.client.tracing.agent.model.Call; -import com.sematext.spm.client.unlogger.LoggerContext; -import com.sematext.spm.client.unlogger.UnloggableLogger; -import com.sematext.spm.client.unlogger.annotations.LoggerPointcuts; -import com.sematext.spm.client.util.ReflectionUtils; - -@LoggerPointcuts(name = "logger:traced-method", methodAnnotations = { - "com.sematext.spm.client.tracing.Trace" -}) -public class TracedMethodPointcut implements UnloggableLogger { - private static final Log LOG = LogFactory.getLog(TracedMethodPointcut.class); - - @Override - public void logBefore(LoggerContext context) { - boolean force = false; - try { - Class[] types = context.getJoinPoint().getParameterTypes(context.getThat().getClass().getClassLoader()); - Method method = ReflectionUtils - .getMethod(context.getThat().getClass(), context.getJoinPoint().getShortName(), types); - if (method != null) { - Annotation traced = null; - for (Annotation annotation : method.getDeclaredAnnotations()) { - if (annotation.annotationType().getName().equals("com.sematext.spm.client.tracing.Trace")) { - traced = annotation; - break; - } - } - if (traced != null) { - Method forceMethod = ReflectionUtils.getMethod(traced.annotationType(), "force"); - if (forceMethod != null) { - force = (Boolean) forceMethod.invoke(traced); - } else { - LOG.error("Missing 'force' parameter for annotation " + traced + "."); - } - } else { - LOG.error("Can't get @Traced annotation for method " + context.getJoinPoint().getShortName() + "."); - } - } else { - LOG.error("Can't get method: " + context.getJoinPoint().getShortName() + "."); - } - } catch (Exception e) { - LOG.error("Can't get annotation parameter.", e); - } - - boolean entryPoint = false; - if (Tracing.current() == NoTrace.instance() && force) { - Tracing.newTrace(context.getJoinPoint().getShortName(), Call.TransactionType.BACKGROUND); - Tracing.current().getNamer().asFramework(context.getJoinPoint()); - entryPoint = true; - } - Tracing.current().newCall(context.getJoinPoint()); - Tracing.current().setTag(Call.CallTag.REGULAR); - Tracing.current().setEntryPoint(entryPoint); - } - - @Override - public void logAfter(LoggerContext context, Object returnValue) { - Tracing.current().endCall(); - if (Tracing.current().callStackEmpty()) { - Tracing.endTrace(); - } - } - - @Override - public void logThrow(LoggerContext context, Throwable throwable) { - Tracing.current().endCall(); - if (Tracing.current().callStackEmpty()) { - Tracing.endTrace(); - } - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/es/transport/ActionRequestBuilderCtorPointcut.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/es/transport/ActionRequestBuilderCtorPointcut.java deleted file mode 100644 index 4e07fa6..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/es/transport/ActionRequestBuilderCtorPointcut.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.pointcuts.es.transport; - -import com.sematext.spm.client.tracing.agent.es.transport.SpmActionRequestBuilderAccess; -import com.sematext.spm.client.unlogger.LoggerContext; -import com.sematext.spm.client.unlogger.UnloggableLogger; -import com.sematext.spm.client.unlogger.annotations.LoggerPointcuts; - -@LoggerPointcuts(name = "es-transport:action-request-builder-ctor-pointcut", constructors = { - "org.elasticsearch.action.ActionRequestBuilder(org.elasticsearch.client.ElasticsearchClient client, org.elasticsearch.action.ActionRequest request)" -}) -public class ActionRequestBuilderCtorPointcut implements UnloggableLogger { - @Override - public void logBefore(LoggerContext context) { - ((SpmActionRequestBuilderAccess) context.getThat())._$spm_tracing$_setClient(context.getAllParams()[0]); - } - - @Override - public void logAfter(LoggerContext context, Object returnValue) { - - } - - @Override - public void logThrow(LoggerContext context, Throwable throwable) { - - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/es/transport/ActionRequestBuilderExecutePointcut.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/es/transport/ActionRequestBuilderExecutePointcut.java deleted file mode 100644 index 602e838..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/es/transport/ActionRequestBuilderExecutePointcut.java +++ /dev/null @@ -1,146 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.pointcuts.es.transport; - -import static com.sematext.spm.client.util.StringUtils.join; - -import java.lang.reflect.Method; -import java.net.InetSocketAddress; -import java.util.ArrayList; -import java.util.List; - -import com.sematext.spm.client.tracing.agent.Trace; -import com.sematext.spm.client.tracing.agent.Tracing; -import com.sematext.spm.client.tracing.agent.es.transport.SpmActionRequestBuilderAccess; -import com.sematext.spm.client.tracing.agent.es.transport.SpmBulkRequestAccess; -import com.sematext.spm.client.tracing.agent.es.transport.SpmDeleteRequestAccess; -import com.sematext.spm.client.tracing.agent.es.transport.SpmGetRequestAccess; -import com.sematext.spm.client.tracing.agent.es.transport.SpmIndexRequestAccess; -import com.sematext.spm.client.tracing.agent.es.transport.SpmSearchRequestAccess; -import com.sematext.spm.client.tracing.agent.es.transport.SpmUpdateRequestAccess; -import com.sematext.spm.client.tracing.agent.model.Call; -import com.sematext.spm.client.tracing.agent.model.ESAction; -import com.sematext.spm.client.tracing.agent.model.ESAction.OperationType; -import com.sematext.spm.client.tracing.agent.model.InetAddress; -import com.sematext.spm.client.tracing.agent.model.annotation.ESAnnotation; -import com.sematext.spm.client.unlogger.LoggerContext; -import com.sematext.spm.client.unlogger.UnloggableLogger; -import com.sematext.spm.client.unlogger.annotations.LoggerPointcuts; -import com.sematext.spm.client.util.ReflectionUtils; - -@LoggerPointcuts(name = "es-transport:action-request-builder-execute-pointcut", methods = { - "org.elasticsearch.action.ListenableActionFuture org.elasticsearch.action.ActionRequestBuilder#execute()" -}) -public class ActionRequestBuilderExecutePointcut implements UnloggableLogger { - - @SuppressWarnings("unchecked") - private static List getAddresses(Object builder) { - final List inetAddresses = new ArrayList(); - - Object client = ((SpmActionRequestBuilderAccess) builder)._$spm_tracing$_getClient(); - if (client == null) { - return inetAddresses; - } - if (client.getClass().getCanonicalName().equals("org.elasticsearch.client.transport.TransportClient")) { - Method transportAddresses = ReflectionUtils.getMethod(client.getClass(), "transportAddresses"); - List addresses = (List) ReflectionUtils.silentInvoke(transportAddresses, client); - if (addresses == null || addresses.isEmpty()) { - return inetAddresses; - } - - for (final Object address : addresses) { - if (address.getClass().getCanonicalName() - .equals("org.elasticsearch.common.transport.InetSocketTransportAddress")) { - Method getAddress = ReflectionUtils.getMethod(address.getClass(), "address"); - InetSocketAddress inetAddr = (InetSocketAddress) ReflectionUtils.silentInvoke(getAddress, address); - inetAddresses.add(new InetAddress(inetAddr.getHostName(), inetAddr.getPort())); - } - } - } - return inetAddresses; - } - - private static boolean isBulk(Object request) { - return request.getClass().getCanonicalName().equals("org.elasticsearch.action.bulk.BulkRequestBuilder"); - } - - private static void buildESActions(Object request, List actions) { - final String requestType = request.getClass().getCanonicalName(); - - if (requestType.equals("org.elasticsearch.action.index.IndexRequest")) { - final SpmIndexRequestAccess indexRequest = (SpmIndexRequestAccess) request; - actions.add(new ESAction(OperationType.INDEX, indexRequest._$spm_tracing$_getIndex(), indexRequest - ._$spm_tracing$_getType(), null)); - } else if (requestType.equals("org.elasticsearch.action.delete.DeleteRequest")) { - final SpmDeleteRequestAccess deleteRequest = (SpmDeleteRequestAccess) request; - actions.add(new ESAction(OperationType.DELETE, deleteRequest._$spm_tracing$_getIndex(), deleteRequest - ._$spm_tracing$_getType(), null)); - } else if (requestType.equals("org.elasticsearch.action.search.SearchRequest")) { - final SpmSearchRequestAccess searchRequest = (SpmSearchRequestAccess) request; - String query = null; - if (searchRequest._$spm_tracing$_getSearchRequestBuilder() != null) { - query = String.valueOf(searchRequest._$spm_tracing$_getSearchRequestBuilder()); - } - actions.add(new ESAction(OperationType.SEARCH, join(searchRequest._$spm_tracing$_getIndices(), ","), - join(searchRequest._$spm_tracing$_getTypes(), ","), query)); - } else if (requestType.equals("org.elasticsearch.action.get.GetRequest")) { - final SpmGetRequestAccess getRequest = (SpmGetRequestAccess) request; - actions.add(new ESAction(OperationType.GET, getRequest._$spm_tracing$_getIndex(), getRequest - ._$spm_tracing$_getType(), null)); - } else if (requestType.equals("org.elasticsearch.action.update.UpdateRequest")) { - final SpmUpdateRequestAccess updateRequest = (SpmUpdateRequestAccess) request; - actions.add(new ESAction(OperationType.UPDATE, updateRequest._$spm_tracing$_getIndex(), updateRequest - ._$spm_tracing$_getType(), null)); - } else if (requestType.equals("org.elasticsearch.action.bulk.BulkRequest")) { - final SpmBulkRequestAccess bulkRequest = (SpmBulkRequestAccess) request; - for (Object actionRequest : bulkRequest._$spm_tracing$_getRequests()) { - buildESActions(actionRequest, actions); - } - } - } - - public void logBefore(LoggerContext context) { - Trace trace = Tracing.current(); - - trace.newCall(context.getJoinPoint()); - trace.setTag(Call.CallTag.ES); - - final SpmActionRequestBuilderAccess builder = (SpmActionRequestBuilderAccess) context.getThat(); - final List actions = new ArrayList(); - buildESActions(builder._$spm_tracing$_getRequest(), actions); - - try { - trace.setAnnotation(ESAnnotation.make(getAddresses(context.getThat()), isBulk(context.getThat()), actions)); - } catch (IllegalArgumentException e) { - trace.setTag(Call.CallTag.REGULAR); - } - } - - @Override - public void logAfter(LoggerContext context, Object returnValue) { - Tracing.current().endCall(); - } - - @Override - public void logThrow(LoggerContext context, Throwable throwable) { - Tracing.current().setFailed(true); - Tracing.current().endCall(); - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/es/transport/AdapterActionFuturePointcut.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/es/transport/AdapterActionFuturePointcut.java deleted file mode 100644 index adafd90..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/es/transport/AdapterActionFuturePointcut.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.pointcuts.es.transport; - -import com.sematext.spm.client.tracing.agent.Tracing; -import com.sematext.spm.client.tracing.agent.es.transport.ESAsyncActions; -import com.sematext.spm.client.tracing.agent.es.transport.SpmListenableActionFutureAccess; -import com.sematext.spm.client.tracing.agent.model.Call; -import com.sematext.spm.client.unlogger.LoggerContext; -import com.sematext.spm.client.unlogger.UnloggableLogger; -import com.sematext.spm.client.unlogger.annotations.LoggerPointcuts; - -@LoggerPointcuts(name = "es:adapter-action-future-pointcut", methods = { - "void org.elasticsearch.action.support.AdapterActionFuture#onResponse(java.lang.Object r)", - "void org.elasticsearch.action.support.AdapterActionFuture#onThrowable(java.lang.Throwable r)" -}) -public class AdapterActionFuturePointcut implements UnloggableLogger { - @Override - public void logBefore(LoggerContext context) { - final SpmListenableActionFutureAccess future = (SpmListenableActionFutureAccess) context.getThat(); - final ESAsyncActions asyncAction = future._$spm_tracing$_getESAsyncActions(); - if (asyncAction != null) { - Tracing.newTrace("/", Call.TransactionType.BACKGROUND, asyncAction.getTraceId(), asyncAction - .getParentCallId(), asyncAction.isSampled(), true); - Tracing.current().newCall("Async", asyncAction.getStartTs()); - Tracing.current().setTag(Call.CallTag.ES); - Tracing.current().setAsync(true); - Tracing.current().setAnnotation(asyncAction.getAnnotation()); - if (context.getJoinPoint().getShortName().contains("onThrowable")) { - Tracing.current().setFailed(true); - } - Tracing.current().endCall(); - Tracing.endTrace(); - } - } - - @Override - public void logAfter(LoggerContext context, Object returnValue) { - } - - @Override - public void logThrow(LoggerContext context, Throwable throwable) { - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/es/transport/PlainListenableActionFuturePointcut.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/es/transport/PlainListenableActionFuturePointcut.java deleted file mode 100644 index 15969e8..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/es/transport/PlainListenableActionFuturePointcut.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.pointcuts.es.transport; - -import com.sematext.spm.client.tracing.agent.NoTrace; -import com.sematext.spm.client.tracing.agent.Trace; -import com.sematext.spm.client.tracing.agent.Tracing; -import com.sematext.spm.client.tracing.agent.es.transport.ESAsyncActions; -import com.sematext.spm.client.tracing.agent.es.transport.SpmListenableActionFutureAccess; -import com.sematext.spm.client.tracing.agent.model.annotation.ESAnnotation; -import com.sematext.spm.client.unlogger.LoggerContext; -import com.sematext.spm.client.unlogger.UnloggableLogger; -import com.sematext.spm.client.unlogger.annotations.LoggerPointcuts; - -@LoggerPointcuts(name = "es:plain-listenable-action-future", constructors = { - "org.elasticsearch.action.support.PlainListenableActionFuture(boolean p, org.elasticsearch.threadpool.ThreadPool pool)" -}) -public class PlainListenableActionFuturePointcut implements UnloggableLogger { - @Override - public void logBefore(LoggerContext context) { - final Trace trace = Tracing.current(); - - if (trace != NoTrace.instance() && trace.getCurrentCall() != null && trace.getAnnotation() != null) { - final SpmListenableActionFutureAccess future = (SpmListenableActionFutureAccess) context.getThat(); - - final ESAnnotation annotation = Tracing.current().getAnnotation(); - - /** - * make copy of actions here? is it possible to update es actions after request was built? - */ - final ESAsyncActions asyncActions = new ESAsyncActions(annotation, - trace.getTraceId(), trace.getCallId(), System - .currentTimeMillis(), - trace.isSampled()); - - future._$spm_tracing$_setESAsyncActions(asyncActions); - } - } - - @Override - public void logAfter(LoggerContext context, Object returnValue) { - } - - @Override - public void logThrow(LoggerContext context, Throwable throwable) { - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/es/transport/SearchRequestPointcut.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/es/transport/SearchRequestPointcut.java deleted file mode 100644 index 5cd1d23..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/es/transport/SearchRequestPointcut.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.pointcuts.es.transport; - -import com.sematext.spm.client.tracing.agent.es.transport.SpmSearchRequestAccess; -import com.sematext.spm.client.unlogger.LoggerContext; -import com.sematext.spm.client.unlogger.UnloggableLogger; -import com.sematext.spm.client.unlogger.annotations.LoggerPointcuts; - -@LoggerPointcuts(name = "es-transport:search-request-pointcut", methods = { - "org.elasticsearch.action.search.SearchRequest org.elasticsearch.action.search.SearchRequest#source(org.elasticsearch.search.builder.SearchSourceBuilder builder)" -}) -public class SearchRequestPointcut implements UnloggableLogger { - @Override - public void logBefore(LoggerContext context) { - ((SpmSearchRequestAccess) context.getThat())._$spm_tracing$_setSearchRequestBuilder(context.getAllParams()[0]); - } - - @Override - public void logAfter(LoggerContext context, Object returnValue) { - - } - - @Override - public void logThrow(LoggerContext context, Throwable throwable) { - - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/httpclient3/HttpClientPointcut.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/httpclient3/HttpClientPointcut.java deleted file mode 100644 index d024306..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/httpclient3/HttpClientPointcut.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.pointcuts.httpclient3; - -import com.sematext.spm.client.tracing.agent.httpclient3.HttpClientAccess; -import com.sematext.spm.client.tracing.agent.httpclient3.HttpMethodAccess; -import com.sematext.spm.client.tracing.agent.solrj5.SolrHttpClient; -import com.sematext.spm.client.unlogger.LoggerContext; -import com.sematext.spm.client.unlogger.UnloggableLogger; -import com.sematext.spm.client.unlogger.annotations.LoggerPointcuts; - -@LoggerPointcuts(name = "http-client-pointcut", methods = { - "int org.apache.commons.httpclient.HttpClient#executeMethod(org.apache.commons.httpclient.HttpMethod method)", - "int org.apache.commons.httpclient.HttpClient#executeMethod(org.apache.commons.httpclient.HostConfiguration config, org.apache.commons.httpclient.HttpMethod method)", - "int org.apache.commons.httpclient.HttpClient#executeMethod(org.apache.commons.httpclient.HostConfiguration config, org.apache.commons.httpclient.HttpMethod method, org.apache.commons.httpclient.HttpState state)" -}) -public class HttpClientPointcut implements UnloggableLogger { - @Override - public void logBefore(LoggerContext context) { - HttpClientAccess httpClient = (HttpClientAccess) context.getThat(); - if (httpClient._$spm_tracing$_isSolrClient()) { - - SolrHttpClient.markSolrClient(httpClient); - HttpMethodAccess method = context.getMethodParam("method"); - if (method != null) { - method._$spm_tracing$_setSolrClient(true); - } - } - } - - @Override - public void logAfter(LoggerContext context, Object returnValue) { - } - - @Override - public void logThrow(LoggerContext context, Throwable throwable) { - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/httpclient3/HttpMethodDirectorPointcut.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/httpclient3/HttpMethodDirectorPointcut.java deleted file mode 100644 index 60eb66d..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/httpclient3/HttpMethodDirectorPointcut.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.pointcuts.httpclient3; - -import com.sematext.spm.client.tracing.agent.Trace; -import com.sematext.spm.client.tracing.agent.Tracing; -import com.sematext.spm.client.tracing.agent.httpclient3.HeaderAccess; -import com.sematext.spm.client.tracing.agent.httpclient3.HttpMethodAccess; -import com.sematext.spm.client.tracing.agent.httpclient3.HttpMethodDirectorAccess; -import com.sematext.spm.client.tracing.agent.model.Call; -import com.sematext.spm.client.tracing.agent.model.HttpHeaders; -import com.sematext.spm.client.tracing.agent.model.HttpHeaders.CrossAppCallHeader; -import com.sematext.spm.client.tracing.agent.model.annotation.HTTPRequestAnnotation; -import com.sematext.spm.client.tracing.agent.pointcuts.solrj5.HttpClient3SolrRequest; -import com.sematext.spm.client.unlogger.LoggerContext; -import com.sematext.spm.client.unlogger.UnloggableLogger; -import com.sematext.spm.client.unlogger.annotations.LoggerPointcuts; - -@LoggerPointcuts(name = "http-method-director-pointcut", methods = { - "void org.apache.commons.httpclient.HttpMethodDirector#executeMethod(org.apache.commons.httpclient.HttpMethod method)" -}) -public class HttpMethodDirectorPointcut implements UnloggableLogger { - @Override - public void logBefore(LoggerContext context) { - Trace trace = Tracing.current(); - trace.newCall(context.getJoinPoint()); - trace.setTag(Call.CallTag.HTTP_REQUEST); - - final HttpMethodDirectorAccess that = (HttpMethodDirectorAccess) context.getThat(); - final HttpMethodAccess httpMethod = (HttpMethodAccess) context.getAllParams()[0]; - if (httpMethod != null) { - final String url = that._$spm_tracing$_getHostConfiguration()._$spm_tracing$_getHostURL(); - final String path = httpMethod._$spm_tracing$_getPath(); - if (httpMethod._$spm_tracing$_isSolrClient()) { - HttpClient3SolrRequest.before(trace, url + path); - } else { - final HTTPRequestAnnotation annotation = HTTPRequestAnnotation.request(url + path); - annotation.setMethod(httpMethod._$spm_tracing$_getName()); - trace.setAnnotation(annotation); - } - - httpMethod._$spm_tracing$_setRequestHeader(HttpHeaders.SPM_TRACING_SAMPLED, String.valueOf(trace.isSampled())); - httpMethod._$spm_tracing$_setRequestHeader(HttpHeaders.SPM_TRACING_TRACE_ID, String.valueOf(trace.getTraceId())); - httpMethod._$spm_tracing$_setRequestHeader(HttpHeaders.SPM_TRACING_CALL_ID, String.valueOf(trace.getCallId())); - } - } - - @Override - public void logAfter(LoggerContext context, Object returnValue) { - Trace trace = Tracing.current(); - final HttpMethodAccess httpMethod = (HttpMethodAccess) context.getAllParams()[0]; - if (httpMethod != null) { - if (httpMethod._$spm_tracing$_isSolrClient()) { - HttpClient3SolrRequest.after(trace, httpMethod); - } else { - final HTTPRequestAnnotation annotation = (HTTPRequestAnnotation) trace.getAnnotation(); - if (annotation != null) { - annotation.setResponseCode(httpMethod._$spm_tracing$_getStatusCode()); - } - } - HeaderAccess header = httpMethod._$spm_tracing$_getResponseHeader(HttpHeaders.SPM_TRACING_CROSS_APP_CALL); - if (header != null) { - final CrossAppCallHeader crossAppHeader = HttpHeaders - .decodeCrossAppCallHeader(header._$spm_tracing$_getValue()); - trace.setCrossAppInHeader(crossAppHeader); - } - } - trace.endCall(); - } - - @Override - public void logThrow(LoggerContext context, Throwable throwable) { - Trace trace = Tracing.current(); - final HttpMethodAccess method = (HttpMethodAccess) context.getThat(); - if (method._$spm_tracing$_isSolrClient()) { - HttpClient3SolrRequest.exception(trace); - } - trace.setFailed(true); - trace.endCall(); - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/httpclient4/CloseableHttpClientPointcut.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/httpclient4/CloseableHttpClientPointcut.java deleted file mode 100644 index 7fed29e..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/httpclient4/CloseableHttpClientPointcut.java +++ /dev/null @@ -1,149 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.pointcuts.httpclient4; - -import com.sematext.spm.client.Log; -import com.sematext.spm.client.LogFactory; -import com.sematext.spm.client.instrumentation.MixinCast; -import com.sematext.spm.client.tracing.agent.Trace; -import com.sematext.spm.client.tracing.agent.Tracing; -import com.sematext.spm.client.tracing.agent.httpclient4.CloseableHttpClientAccess; -import com.sematext.spm.client.tracing.agent.httpclient4.Header4Access; -import com.sematext.spm.client.tracing.agent.httpclient4.HttpClientURL; -import com.sematext.spm.client.tracing.agent.httpclient4.HttpHostAccess; -import com.sematext.spm.client.tracing.agent.httpclient4.HttpRequestAccess; -import com.sematext.spm.client.tracing.agent.httpclient4.HttpResponseAccess; -import com.sematext.spm.client.tracing.agent.httpclient4.RequestLineAccess; -import com.sematext.spm.client.tracing.agent.httpclient4.StatusLineAccess; -import com.sematext.spm.client.tracing.agent.model.Call; -import com.sematext.spm.client.tracing.agent.model.HttpHeaders; -import com.sematext.spm.client.tracing.agent.model.annotation.HTTPRequestAnnotation; -import com.sematext.spm.client.tracing.agent.pointcuts.solrj5.ConcurrentUpdateSolrClientHack; -import com.sematext.spm.client.tracing.agent.pointcuts.solrj5.HttpClient4SolrRequest; -import com.sematext.spm.client.tracing.agent.util.AsyncContext; -import com.sematext.spm.client.unlogger.LoggerContext; -import com.sematext.spm.client.unlogger.UnloggableLogger; -import com.sematext.spm.client.unlogger.annotations.LoggerPointcuts; - -@LoggerPointcuts(name = "closeable-http-client-pointcut", methods = { - "org.apache.http.client.methods.CloseableHttpResponse org.apache.http.impl.client.CloseableHttpClient#doExecute(org.apache.http.HttpHost host, " - + - "org.apache.http.HttpRequest request, org.apache.http.protocol.HttpContext context)" -}) -public class CloseableHttpClientPointcut implements UnloggableLogger { - private static final Log LOG = LogFactory.getLog(CloseableHttpClientPointcut.class); - - private static void maybeStartAsyncTransaction(LoggerContext context) { - final HttpRequestAccess request = context.getMethodParam("request"); - ConcurrentUpdateSolrClientHack - .maybeStartAsyncTransaction(request, request._$spm_tracing$_getRequestLine()._$spm_tracing$_getUri()); - } - - private static void maybeStopAsyncTransaction(LoggerContext context) { - final HttpRequestAccess request = context.getMethodParam("request"); - if (AsyncContext.clean(request) != null) { - Tracing.endTrace(); - } - } - - @Override - public void logBefore(LoggerContext context) { - maybeStartAsyncTransaction(context); - - final Trace tracing = Tracing.current(); - tracing.newCall(context.getJoinPoint()); - tracing.setTag(Call.CallTag.HTTP_REQUEST); - - final HttpRequestAccess httpRequest = context.getMethodParam("request"); - try { - final CloseableHttpClientAccess access = (CloseableHttpClientAccess) context.getThat(); - final HttpHostAccess host = context.getMethodParam("host"); - - if (access._$spm_tracing$_isSolrClient()) { - HttpClient4SolrRequest.before(tracing, host, httpRequest); - } else { - final RequestLineAccess requestLine = httpRequest._$spm_tracing$_getRequestLine(); - final HTTPRequestAnnotation annotation = HTTPRequestAnnotation - .request(HttpClientURL.makeUrl(host, requestLine)); - annotation.setMethod(requestLine._$spm_tracing$_getMethod()); - tracing.setAnnotation(annotation); - } - - httpRequest._$spm_tracing$_setHeader(HttpHeaders.SPM_TRACING_TRACE_ID, String.valueOf(tracing.getTraceId())); - httpRequest._$spm_tracing$_setHeader(HttpHeaders.SPM_TRACING_CALL_ID, String.valueOf(tracing.getCallId())); - httpRequest._$spm_tracing$_setHeader(HttpHeaders.SPM_TRACING_SAMPLED, String.valueOf(tracing.isSampled())); - } catch (Throwable e) { - LOG.error("Can't set http request annotation.", e); - } - } - - @Override - public void logAfter(LoggerContext context, Object returnValue) { - try { - /** - * Sometimes httpclient proxies org.apache.http.HttpResponse using org.apache.http.impl.client.CloseableHttpResponseProxy. - * It means, that all mixins are gone and CCE will be thrown at this place. It is possible to do a trick - - * access to proxy field which holds reference to HttpResponse and make another proxy to HttpResponseAccess which - * calls original object instead of proxied. - */ - final HttpResponseAccess httpResponse = MixinCast.cast(returnValue, HttpResponseAccess.class, "original"); - - final StatusLineAccess statusLine = httpResponse._$spm_tracing$_getStatusLine(); - - final CloseableHttpClientAccess client = (CloseableHttpClientAccess) context.getThat(); - if (client._$spm_tracing$_isSolrClient()) { - HttpClient4SolrRequest.after(Tracing.current(), httpResponse); - } else { - final HTTPRequestAnnotation annotation = (HTTPRequestAnnotation) Tracing.current().getAnnotation(); - - if (annotation != null) { - annotation.setResponseCode(statusLine._$spm_tracing$_getStatusCode()); - } - } - - final Header4Access crossAppCallHeader = httpResponse - ._$spm_tracing$_getFirstHeader(HttpHeaders.SPM_TRACING_CROSS_APP_CALL); - if (crossAppCallHeader != null) { - String value = crossAppCallHeader._$spm_tracing$_getValue(); - if (value != null) { - Tracing.current().setCrossAppInHeader(HttpHeaders.decodeCrossAppCallHeader(value)); - } - } - } catch (Throwable e) { - LOG.debug("Can't update http request annotation.", e); - } finally { - Tracing.current().endCall(); - - maybeStopAsyncTransaction(context); - } - } - - @Override - public void logThrow(LoggerContext context, Throwable throwable) { - Trace trace = Tracing.current(); - if (((CloseableHttpClientAccess) context.getThat())._$spm_tracing$_isSolrClient()) { - HttpClient4SolrRequest.exception(Tracing.current()); - } - trace.setFailed(true); - trace.endCall(); - - maybeStopAsyncTransaction(context); - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/httpclient42/AbstractHttpClientPointcut.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/httpclient42/AbstractHttpClientPointcut.java deleted file mode 100644 index 1419937..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/httpclient42/AbstractHttpClientPointcut.java +++ /dev/null @@ -1,119 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.pointcuts.httpclient42; - -import com.sematext.spm.client.Log; -import com.sematext.spm.client.LogFactory; -import com.sematext.spm.client.tracing.agent.Trace; -import com.sematext.spm.client.tracing.agent.Tracing; -import com.sematext.spm.client.tracing.agent.httpclient4.AbstractHttpClientAccess; -import com.sematext.spm.client.tracing.agent.httpclient4.Header4Access; -import com.sematext.spm.client.tracing.agent.httpclient4.HttpClientURL; -import com.sematext.spm.client.tracing.agent.httpclient4.HttpHostAccess; -import com.sematext.spm.client.tracing.agent.httpclient4.HttpRequestAccess; -import com.sematext.spm.client.tracing.agent.httpclient4.HttpResponseAccess; -import com.sematext.spm.client.tracing.agent.httpclient4.RequestLineAccess; -import com.sematext.spm.client.tracing.agent.httpclient4.StatusLineAccess; -import com.sematext.spm.client.tracing.agent.model.Call; -import com.sematext.spm.client.tracing.agent.model.HttpHeaders; -import com.sematext.spm.client.tracing.agent.model.annotation.HTTPRequestAnnotation; -import com.sematext.spm.client.tracing.agent.pointcuts.solrj5.HttpClient4SolrRequest; -import com.sematext.spm.client.unlogger.LoggerContext; -import com.sematext.spm.client.unlogger.UnloggableLogger; -import com.sematext.spm.client.unlogger.annotations.LoggerPointcuts; - -@LoggerPointcuts(name = "abstract-http-client-pointcut", methods = { - "org.apache.http.HttpResponse org.apache.http.impl.client.AbstractHttpClient#execute(org.apache.http.HttpHost target, " - + - "org.apache.http.HttpRequest request, org.apache.http.protocol.HttpContext context)" -}) -public class AbstractHttpClientPointcut implements UnloggableLogger { - private final Log LOG = LogFactory.getLog(AbstractHttpClientPointcut.class); - - @Override - public void logBefore(LoggerContext context) { - final Trace trace = Tracing.current(); - trace.newCall(context.getJoinPoint()); - trace.setTag(Call.CallTag.HTTP_REQUEST); - - final HttpRequestAccess httpRequest = context.getMethodParam("request"); - try { - final RequestLineAccess requestLine = httpRequest._$spm_tracing$_getRequestLine(); - final HttpHostAccess host = context.getMethodParam("target"); - - final AbstractHttpClientAccess client = (AbstractHttpClientAccess) context.getThat(); - if (client._$spm_tracing$_isSolrClient()) { - HttpClient4SolrRequest.before(trace, host, httpRequest); - } else { - final HTTPRequestAnnotation annotation = HTTPRequestAnnotation - .request(HttpClientURL.makeUrl(host, requestLine)); - annotation.setMethod(requestLine._$spm_tracing$_getMethod()); - trace.setAnnotation(annotation); - } - - httpRequest._$spm_tracing$_setHeader(HttpHeaders.SPM_TRACING_TRACE_ID, String.valueOf(trace.getTraceId())); - httpRequest._$spm_tracing$_setHeader(HttpHeaders.SPM_TRACING_CALL_ID, String.valueOf(trace.getCallId())); - httpRequest._$spm_tracing$_setHeader(HttpHeaders.SPM_TRACING_SAMPLED, String.valueOf(trace.isSampled())); - } catch (Throwable e) { - LOG.error("Can't set http request annotation.", e); - } - } - - @Override - public void logAfter(LoggerContext context, Object returnValue) { - try { - final HttpResponseAccess httpResponse = (HttpResponseAccess) returnValue; - final StatusLineAccess statusLine = httpResponse._$spm_tracing$_getStatusLine(); - - final AbstractHttpClientAccess client = (AbstractHttpClientAccess) context.getThat(); - - if (client._$spm_tracing$_isSolrClient()) { - HttpClient4SolrRequest.after(Tracing.current(), httpResponse); - } else { - final HTTPRequestAnnotation annotation = (HTTPRequestAnnotation) Tracing.current().getAnnotation(); - if (annotation != null) { - annotation.setResponseCode(statusLine._$spm_tracing$_getStatusCode()); - } - } - - final Header4Access crossAppCallHeader = httpResponse - ._$spm_tracing$_getFirstHeader(HttpHeaders.SPM_TRACING_CROSS_APP_CALL); - if (crossAppCallHeader != null) { - String value = crossAppCallHeader._$spm_tracing$_getValue(); - if (value != null) { - Tracing.current().setCrossAppInHeader(HttpHeaders.decodeCrossAppCallHeader(value)); - } - } - } catch (Throwable e) { - LOG.error("Can't update http request annotation.", e); - } finally { - Tracing.current().endCall(); - } - } - - @Override - public void logThrow(LoggerContext context, Throwable throwable) { - Tracing.current().setFailed(true); - if (((AbstractHttpClientAccess) context.getThat())._$spm_tracing$_isSolrClient()) { - HttpClient4SolrRequest.exception(Tracing.current()); - } - Tracing.current().endCall(); - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/jaxrs/JaxRsRequestMappingPointcut.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/jaxrs/JaxRsRequestMappingPointcut.java deleted file mode 100644 index 82b8c82..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/jaxrs/JaxRsRequestMappingPointcut.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.pointcuts.jaxrs; - -import com.sematext.spm.client.tracing.agent.Tracing; -import com.sematext.spm.client.tracing.agent.model.Call; -import com.sematext.spm.client.unlogger.LoggerContext; -import com.sematext.spm.client.unlogger.UnloggableLogger; -import com.sematext.spm.client.unlogger.annotations.LoggerPointcuts; - -@LoggerPointcuts(name = "logger:jax-rs-request-mapping-logger", methodAnnotations = { - "javax.ws.rs.GET", - "javax.ws.rs.PUT", - "javax.ws.rs.POST", - "javax.ws.rs.HEAD", - "javax.ws.rs.DELETE", - "javax.ws.rs.OPTIONS" -}) -public class JaxRsRequestMappingPointcut implements UnloggableLogger { - @Override - public void logBefore(LoggerContext context) { - Tracing.current().newCall(context.getJoinPoint()); - Tracing.current().setTag(Call.CallTag.REGULAR); - - Tracing.current().getNamer().asFramework(context.getJoinPoint()); - } - - @Override - public void logAfter(LoggerContext context, Object returnValue) { - Tracing.current().endCall(); - } - - @Override - public void logThrow(LoggerContext context, Throwable throwable) { - Tracing.current().setFailed(true); - Tracing.current().endCall(); - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/jdbc/JDBCConnectionCreateStatementPointcut.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/jdbc/JDBCConnectionCreateStatementPointcut.java deleted file mode 100644 index 2562968..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/jdbc/JDBCConnectionCreateStatementPointcut.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.pointcuts.jdbc; - -import com.sematext.spm.client.tracing.agent.Tracing; -import com.sematext.spm.client.tracing.agent.model.Call; -import com.sematext.spm.client.unlogger.LoggerContext; -import com.sematext.spm.client.unlogger.UnloggableLogger; -import com.sematext.spm.client.unlogger.annotations.LoggerPointcuts; - -@LoggerPointcuts(name = "jdbc:connection-logger", methods = { - "java.sql.Statement java.sql.Connection#createStatement()", - "java.sql.Statement java.sql.Connection#createStatement(int type, int concurrency)", - "java.sql.Statement java.sql.Connection#createStatement(int type, int concurrency, int holdability)" -}, ignorePatterns = JDBCPointcut.PROXY_PATTERN) -public class JDBCConnectionCreateStatementPointcut implements UnloggableLogger { - @Override - public void logBefore(LoggerContext context) { - Tracing.current().newCall(context.getJoinPoint()); - Tracing.current().setTag(Call.CallTag.REGULAR); - } - - @Override - public void logAfter(LoggerContext context, Object returnValue) { - Tracing.current().endCall(); - } - - @Override - public void logThrow(LoggerContext context, Throwable throwable) { - Tracing.current().endCall(); - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/jdbc/JDBCConnectionPrepareStatementPointcut.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/jdbc/JDBCConnectionPrepareStatementPointcut.java deleted file mode 100644 index 1b26329..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/jdbc/JDBCConnectionPrepareStatementPointcut.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.pointcuts.jdbc; - -import com.sematext.spm.client.tracing.agent.sql.SpmPreparedStatementAccess; -import com.sematext.spm.client.unlogger.LoggerContext; -import com.sematext.spm.client.unlogger.UnloggableLogger; -import com.sematext.spm.client.unlogger.annotations.LoggerPointcuts; - -@LoggerPointcuts(name = "jdbc:connection-logger", methods = { - "java.sql.PreparedStatement java.sql.Connection#prepareStatement(java.lang.String sql)", - "java.sql.PreparedStatement java.sql.Connection#prepareStatement(java.lang.String sql, int autoGeneratedKeys)", - "java.sql.PreparedStatement java.sql.Connection#prepareStatement(java.lang.String sql, int[] columnIndexes)", - "java.sql.PreparedStatement java.sql.Connection#prepareStatement(java.lang.String sql, java.lang.String[] columnNames)" -}, ignorePatterns = JDBCPointcut.PROXY_PATTERN) -public class JDBCConnectionPrepareStatementPointcut implements UnloggableLogger { - @Override - public void logBefore(LoggerContext context) { - } - - @Override - public void logAfter(LoggerContext context, Object returnValue) { - if (returnValue != null) { - SpmPreparedStatementAccess preparedStatement = (SpmPreparedStatementAccess) returnValue; - preparedStatement._$spm_tracing$_sql_query_set((String) context.getAllParams()[0]); - } - } - - @Override - public void logThrow(LoggerContext context, Throwable throwable) { - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/jdbc/JDBCDataSourcePointcut.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/jdbc/JDBCDataSourcePointcut.java deleted file mode 100644 index 93bb30c..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/jdbc/JDBCDataSourcePointcut.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.pointcuts.jdbc; - -import com.sematext.spm.client.tracing.agent.Tracing; -import com.sematext.spm.client.tracing.agent.model.Call; -import com.sematext.spm.client.unlogger.LoggerContext; -import com.sematext.spm.client.unlogger.UnloggableLogger; -import com.sematext.spm.client.unlogger.annotations.LoggerPointcuts; - -@LoggerPointcuts(name = "jdbc:data-source", methods = { - "java.sql.Connection javax.sql.DataSource#getConnection(java.lang.String username, java.lang.String password)", - "java.sql.Connection javax.sql.DataSource#getConnection()" -}, ignorePatterns = JDBCPointcut.PROXY_PATTERN) -public class JDBCDataSourcePointcut implements UnloggableLogger { - - @Override - public void logBefore(LoggerContext context) { - Tracing.current().newCall(context.getJoinPoint()); - Tracing.current().setTag(Call.CallTag.REGULAR); - } - - @Override - public void logAfter(LoggerContext context, Object returnValue) { - Tracing.current().endCall(); - } - - @Override - public void logThrow(LoggerContext context, Throwable throwable) { - Tracing.current().endCall(); - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/jdbc/JDBCDriverPointcut.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/jdbc/JDBCDriverPointcut.java deleted file mode 100644 index c2a38ce..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/jdbc/JDBCDriverPointcut.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.pointcuts.jdbc; - -import com.sematext.spm.client.tracing.agent.sql.SpmConnectionAccess; -import com.sematext.spm.client.unlogger.LoggerContext; -import com.sematext.spm.client.unlogger.UnloggableLogger; -import com.sematext.spm.client.unlogger.annotations.LoggerPointcuts; - -@LoggerPointcuts(name = "jdbc:driver-manager", methods = { - "java.sql.Connection java.sql.Driver#connect(java.lang.String url, java.util.Properties props)" -}, ignorePatterns = JDBCPointcut.PROXY_PATTERN) -public class JDBCDriverPointcut implements UnloggableLogger { - @Override - public void logBefore(LoggerContext context) { - } - - @Override - public void logAfter(LoggerContext context, Object returnValue) { - if (returnValue != null) { - SpmConnectionAccess connection = (SpmConnectionAccess) returnValue; - connection._$spm_tracing$_url_set((String) context.getAllParams()[0]); - } - } - - @Override - public void logThrow(LoggerContext context, Throwable throwable) { - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/jdbc/JDBCPointcut.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/jdbc/JDBCPointcut.java deleted file mode 100644 index 5a674bc..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/jdbc/JDBCPointcut.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.pointcuts.jdbc; - -public final class JDBCPointcut { - public static final String PROXY_PATTERN = ".*\\.?.*(P|p)roxy.*"; -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/jdbc/JDBCPreparedStatementPointcut.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/jdbc/JDBCPreparedStatementPointcut.java deleted file mode 100644 index 8acbdf4..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/jdbc/JDBCPreparedStatementPointcut.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.pointcuts.jdbc; - -import java.sql.SQLException; - -import com.sematext.spm.client.tracing.agent.Tracing; -import com.sematext.spm.client.tracing.agent.model.Call; -import com.sematext.spm.client.tracing.agent.model.annotation.SQLAnnotation; -import com.sematext.spm.client.tracing.agent.sql.SpmConnectionAccess; -import com.sematext.spm.client.tracing.agent.sql.SpmPreparedStatementAccess; -import com.sematext.spm.client.unlogger.LoggerContext; -import com.sematext.spm.client.unlogger.UnloggableLogger; -import com.sematext.spm.client.unlogger.annotations.LoggerPointcuts; - -@LoggerPointcuts(name = "jdbc:prepared-statement", methods = { - "java.sql.ResultSet java.sql.PreparedStatement#executeQuery()", - "boolean java.sql.PreparedStatement#execute()", - "int java.sql.PreparedStatement#executeUpdate()", - "int java.sql.PreparedStatement#executeUpdate()" -}, ignorePatterns = JDBCPointcut.PROXY_PATTERN) -public class JDBCPreparedStatementPointcut implements UnloggableLogger { - @Override - public void logBefore(LoggerContext context) { - Tracing.current().newCall(context.getJoinPoint()); - Tracing.current().setTag(Call.CallTag.SQL_QUERY); - - SpmPreparedStatementAccess preparedStatement = (SpmPreparedStatementAccess) context.getThat(); - - final String query = preparedStatement._$spm_tracing$_sql_query_get(); - try { - final SpmConnectionAccess connection = (SpmConnectionAccess) ((java.sql.PreparedStatement) context.getThat()) - .getConnection(); - //query can be null if connection was wrapped with other connection, but we inject query (by mixin) only to one object (to wrapper) - if (connection != null && query != null) { - Tracing.current().setAnnotation(SQLAnnotation.make(query, connection._$spm_tracing$_url_get())); - } - } catch (SQLException e) { - /* */ - } - } - - @Override - public void logAfter(LoggerContext context, Object returnValue) { - Tracing.current().endCall(); - } - - @Override - public void logThrow(LoggerContext context, Throwable throwable) { - Tracing.current().setFailed(true); - Tracing.current().endCall(); - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/jdbc/JDBCResultSetPointcut.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/jdbc/JDBCResultSetPointcut.java deleted file mode 100644 index 6970998..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/jdbc/JDBCResultSetPointcut.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.pointcuts.jdbc; - -import com.sematext.spm.client.tracing.agent.Tracing; -import com.sematext.spm.client.tracing.agent.model.Call; -import com.sematext.spm.client.unlogger.LoggerContext; -import com.sematext.spm.client.unlogger.UnloggableLogger; -import com.sematext.spm.client.unlogger.annotations.LoggerPointcuts; - -@LoggerPointcuts(name = "jdbc:result-set", methods = { - "boolean java.sql.ResultSet#next()", - "void java.sql.ResultSet#close()" -}, ignorePatterns = JDBCPointcut.PROXY_PATTERN) -public class JDBCResultSetPointcut implements UnloggableLogger { - @Override - public void logBefore(LoggerContext context) { - Tracing.current().newCall(context.getJoinPoint()); - Tracing.current().setTag(Call.CallTag.REGULAR); - } - - @Override - public void logAfter(LoggerContext context, Object returnValue) { - Tracing.current().endCall(); - } - - @Override - public void logThrow(LoggerContext context, Throwable throwable) { - Tracing.current().setFailed(true); - Tracing.current().endCall(); - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/jdbc/JDBCStatementPointcut.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/jdbc/JDBCStatementPointcut.java deleted file mode 100644 index 6ebda3e..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/jdbc/JDBCStatementPointcut.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.pointcuts.jdbc; - -import java.sql.SQLException; - -import com.sematext.spm.client.tracing.agent.Tracing; -import com.sematext.spm.client.tracing.agent.model.Call; -import com.sematext.spm.client.tracing.agent.model.annotation.SQLAnnotation; -import com.sematext.spm.client.tracing.agent.sql.SpmConnectionAccess; -import com.sematext.spm.client.unlogger.LoggerContext; -import com.sematext.spm.client.unlogger.UnloggableLogger; -import com.sematext.spm.client.unlogger.annotations.LoggerPointcuts; - -@LoggerPointcuts(name = "jdbc:logger", methods = { - "boolean java.sql.Statement#execute(java.lang.String sql)", - "boolean java.sql.Statement#execute(java.lang.String sql, int autoGeneratedKeys)", - "boolean java.sql.Statement#execute(java.lang.String sql, int[] columnIndexes)", - "boolean java.sql.Statement#execute(java.lang.String sql, java.lang.String[] columnNames)", - "java.sql.ResultSet java.sql.Statement#executeQuery(java.lang.String sql)", - "int java.sql.Statement#executeUpdate(java.lang.String sql)", - "int java.sql.Statement#executeUpdate(java.lang.String sql, int autoGeneratedKeys)", - "int java.sql.Statement#executeUpdate(java.lang.String sql, int[] columnIndexes)", - "int java.sql.Statement#executeUpdate(java.lang.String sql, java.lang.String[] columnNames)" -}, ignorePatterns = JDBCPointcut.PROXY_PATTERN) -public class JDBCStatementPointcut implements UnloggableLogger { - @Override - public void logBefore(LoggerContext context) { - Tracing.current().newCall(context.getJoinPoint()); - Tracing.current().setTag(Call.CallTag.SQL_QUERY); - final Object sql = context.getAllParams()[0]; - try { - final SpmConnectionAccess connection = (SpmConnectionAccess) ((java.sql.Statement) context.getThat()) - .getConnection(); - if (connection != null) { - Tracing.current().setAnnotation(SQLAnnotation.make((String) sql, connection._$spm_tracing$_url_get())); - Tracing.current().setExternal(true); - } - } catch (SQLException e) { - /* */ - } - } - - @Override - public void logAfter(LoggerContext context, Object returnValue) { - Tracing.current().endCall(); - } - - @Override - public void logThrow(LoggerContext context, Throwable throwable) { - Tracing.current().setFailed(true); - Tracing.current().endCall(); - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/jersey/JerseyResponseHeaders.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/jersey/JerseyResponseHeaders.java deleted file mode 100644 index 7bd8c32..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/jersey/JerseyResponseHeaders.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.pointcuts.jersey; - -import java.lang.reflect.Method; - -import com.sematext.spm.client.tracing.agent.ResponseHeaders; -import com.sematext.spm.client.util.ReflectionUtils; - -public final class JerseyResponseHeaders implements ResponseHeaders { - private Object responseWriter; - - public JerseyResponseHeaders(Object responseWriter) { - this.responseWriter = responseWriter; - } - - @Override - public void addHeader(String name, String value) { - Object response = ReflectionUtils.silentFieldGet(responseWriter, "response"); - if (response != null) { - Method setHeader = ReflectionUtils.getMethod(response.getClass(), "setHeader", String.class, String.class); - ReflectionUtils.silentInvoke(setHeader, response, name, value); - } - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/jersey/ResponseWriterPointcut.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/jersey/ResponseWriterPointcut.java deleted file mode 100644 index 6dbd2ff..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/jersey/ResponseWriterPointcut.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.pointcuts.jersey; - -import com.sematext.spm.client.tracing.agent.Tracing; -import com.sematext.spm.client.unlogger.LoggerContext; -import com.sematext.spm.client.unlogger.UnloggableLogger; -import com.sematext.spm.client.unlogger.annotations.LoggerPointcuts; - -@LoggerPointcuts(name = "jersey:response-pointcut", methods = { - "java.io.OutputStream org.glassfish.jersey.servlet.internal.ResponseWriter#writeResponseStatusAndHeaders(long contentLength, org.glassfish.jersey.server.ContainerResponse ctx)" -}) -public class ResponseWriterPointcut implements UnloggableLogger { - @Override - public void logBefore(LoggerContext context) { - Tracing.current().setResponseHeaders(new JerseyResponseHeaders(context.getThat())); - Tracing.current().sendCrossAppOutHeaders(); - } - - @Override - public void logAfter(LoggerContext context, Object returnValue) { - } - - @Override - public void logThrow(LoggerContext context, Throwable throwable) { - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/jetty7/Jetty73HttpConnectionPointcut.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/jetty7/Jetty73HttpConnectionPointcut.java deleted file mode 100644 index f94f392..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/jetty7/Jetty73HttpConnectionPointcut.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.pointcuts.jetty7; - -import com.sematext.spm.client.tracing.agent.Tracing; -import com.sematext.spm.client.unlogger.LoggerContext; -import com.sematext.spm.client.unlogger.UnloggableLogger; -import com.sematext.spm.client.unlogger.annotations.LoggerPointcuts; - -/** - * Tested on jetty 7.3.0 - */ -@LoggerPointcuts(name = "jetty-7-http-connection-pointcut", methods = { - "void org.eclipse.jetty.server.HttpConnection#commitResponse(boolean last)" -}) -public class Jetty73HttpConnectionPointcut implements UnloggableLogger { - @Override - public void logBefore(LoggerContext context) { - Tracing.current().sendCrossAppOutHeaders(); - } - - @Override - public void logAfter(LoggerContext context, Object returnValue) { - - } - - @Override - public void logThrow(LoggerContext context, Throwable throwable) { - - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/jetty8/AbstractHttpConnectionPointcut.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/jetty8/AbstractHttpConnectionPointcut.java deleted file mode 100644 index cea4cfc..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/jetty8/AbstractHttpConnectionPointcut.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.pointcuts.jetty8; - -import com.sematext.spm.client.tracing.agent.Tracing; -import com.sematext.spm.client.unlogger.LoggerContext; -import com.sematext.spm.client.unlogger.UnloggableLogger; -import com.sematext.spm.client.unlogger.annotations.LoggerPointcuts; - -/** - * Tested on 8.1.16, 7.6.16 - */ -@LoggerPointcuts(name = "jetty-8:abstract-http-connection", methods = { - "void org.eclipse.jetty.server.AbstractHttpConnection#commitResponse(boolean last)" -}) -public class AbstractHttpConnectionPointcut implements UnloggableLogger { - @Override - public void logBefore(LoggerContext context) { - Tracing.current().sendCrossAppOutHeaders(); - } - - @Override - public void logAfter(LoggerContext context, Object returnValue) { - } - - @Override - public void logThrow(LoggerContext context, Throwable throwable) { - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/jetty9/HttpConnectionPointcut.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/jetty9/HttpConnectionPointcut.java deleted file mode 100644 index 54762a1..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/jetty9/HttpConnectionPointcut.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.pointcuts.jetty9; - -import com.sematext.spm.client.tracing.agent.Tracing; -import com.sematext.spm.client.unlogger.LoggerContext; -import com.sematext.spm.client.unlogger.UnloggableLogger; -import com.sematext.spm.client.unlogger.annotations.LoggerPointcuts; - -/** - * Tested on jetty 9.2.2 - */ -@LoggerPointcuts(name = "jetty:http-connection-pointcut", methods = { - "void org.eclipse.jetty.server.HttpConnection#send(org.eclipse.jetty.http.HttpGenerator$ResponseInfo info, java.nio.ByteBuffer content, boolean lastContent, org.eclipse.jetty.util.Callback callback)", - "void org.eclipse.jetty.server.HttpConnection#send(java.nio.ByteBuffer content, boolean lastContent, org.eclipse.jetty.util.Callback callback)" -}) -public class HttpConnectionPointcut implements UnloggableLogger { - @Override - public void logBefore(LoggerContext context) { - Tracing.current().sendCrossAppOutHeaders(); - } - - @Override - public void logAfter(LoggerContext context, Object returnValue) { - } - - @Override - public void logThrow(LoggerContext context, Throwable throwable) { - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/jpa/JpaEntityManagerFindPointcut.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/jpa/JpaEntityManagerFindPointcut.java deleted file mode 100644 index 10453e6..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/jpa/JpaEntityManagerFindPointcut.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.pointcuts.jpa; - -import com.sematext.spm.client.tracing.agent.Tracing; -import com.sematext.spm.client.tracing.agent.model.Call; -import com.sematext.spm.client.tracing.agent.model.annotation.JPAAnnotation; -import com.sematext.spm.client.unlogger.LoggerContext; -import com.sematext.spm.client.unlogger.UnloggableLogger; -import com.sematext.spm.client.unlogger.annotations.LoggerPointcuts; - -@LoggerPointcuts(name = "jpa-entity-manager-find", methods = { - "java.lang.Object javax.persistence.EntityManager#find(java.lang.Class klass, java.lang.Object pk)", - "java.lang.Object javax.persistence.EntityManager#find(java.lang.Class klass, java.lang.Object pk, java.util.Map properties)", - "java.lang.Object javax.persistence.EntityManager#find(java.lang.Class klass, java.lang.Object pk, javax.persistence.LockModeType lockMode)", - "java.lang.Object javax.persistence.EntityManager#find(java.lang.Class klass, java.lang.Object pk, javax.persistence.LockModeType lockMode, java.util.Map properties)", - "java.lang.Object javax.persistence.EntityManager#find(java.lang.Class klass, java.lang.Object pk, javax.persistence.LockModeType lockMode, java.util.Map properties)" -}) -public class JpaEntityManagerFindPointcut implements UnloggableLogger { - @Override - public void logBefore(LoggerContext context) { - Tracing.current().newCall(context.getJoinPoint()); - Tracing.current().setTag(Call.CallTag.JPA); - - final Object obj = context.getAllParams()[0]; - String objectName; - if (obj == null) { - objectName = "null"; - } else { - objectName = obj.getClass().getName(); - } - Tracing.current().setAnnotation(JPAAnnotation.find(objectName)); - } - - @Override - public void logAfter(LoggerContext context, Object returnValue) { - Tracing.current().endCall(); - } - - @Override - public void logThrow(LoggerContext context, Throwable throwable) { - Tracing.current().setFailed(true); - Tracing.current().endCall(); - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/jpa/JpaEntityManagerPersistPointcut.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/jpa/JpaEntityManagerPersistPointcut.java deleted file mode 100644 index a1fcc4f..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/jpa/JpaEntityManagerPersistPointcut.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.pointcuts.jpa; - -import com.sematext.spm.client.tracing.agent.Tracing; -import com.sematext.spm.client.tracing.agent.model.Call; -import com.sematext.spm.client.unlogger.LoggerContext; -import com.sematext.spm.client.unlogger.UnloggableLogger; -import com.sematext.spm.client.unlogger.annotations.LoggerPointcuts; - -@LoggerPointcuts(name = "jpa:entity-manger-persist", methods = { - "void javax.persistence.EntityManager#persist(java.lang.Object entity)", - "java.lang.Object javax.persistence.EntityManager#merge(java.lang.Object entity)", - "void javax.persistence.EntityManager#remove(java.lang.Object entity)" -}) -public class JpaEntityManagerPersistPointcut implements UnloggableLogger { - @Override - public void logBefore(LoggerContext context) { - Tracing.current().newCall(context.getJoinPoint()); - Tracing.current().setTag(Call.CallTag.JPA); - } - - @Override - public void logAfter(LoggerContext context, Object returnValue) { - Tracing.current().endCall(); - } - - @Override - public void logThrow(LoggerContext context, Throwable throwable) { - Tracing.current().setFailed(true); - Tracing.current().endCall(); - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/jpa/JpaEntityManagerQueryPointcut.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/jpa/JpaEntityManagerQueryPointcut.java deleted file mode 100644 index 9334d7e..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/jpa/JpaEntityManagerQueryPointcut.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.pointcuts.jpa; - -import com.sematext.spm.client.tracing.agent.jpa.SpmQueryAccess; -import com.sematext.spm.client.unlogger.LoggerContext; -import com.sematext.spm.client.unlogger.UnloggableLogger; -import com.sematext.spm.client.unlogger.annotations.LoggerPointcuts; - -@LoggerPointcuts(name = "jpa:entity-manager-create-query", methods = { - "javax.persistence.Query javax.persistence.EntityManager#createNamedQuery(java.lang.String query)", - "javax.persistence.TypedQuery javax.persistence.EntityManager#createNamedQuery(java.lang.String query, java.lang.Class resultClass)", - "javax.persistence.Query javax.persistence.EntityManager#createQuery(java.lang.String query)", - "javax.persistence.TypedQuery javax.persistence.EntityManager#createQuery(java.lang.String query, java.lang.Class resultClass)", - "javax.persistence.Query javax.persistence.EntityManager#createNativeQuery(java.lang.String query)", - "javax.persistence.Query javax.persistence.EntityManager#createNativeQuery(java.lang.String query, java.lang.Class resultClass)", - "javax.persistence.Query javax.persistence.EntityManager#createNativeQuery(java.lang.String query, java.lang.String resultSetMapping)" -}) -public class JpaEntityManagerQueryPointcut implements UnloggableLogger { - @Override - public void logBefore(LoggerContext context) { - } - - @Override - public void logAfter(LoggerContext context, Object returnValue) { - SpmQueryAccess query = (SpmQueryAccess) returnValue; - if (query != null) { - query._$spm_tracing$_query_set((String) context.getMethodParam("query")); - - } - } - - @Override - public void logThrow(LoggerContext context, Throwable throwable) { - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/jpa/JpaQueryPointcut.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/jpa/JpaQueryPointcut.java deleted file mode 100644 index 2823334..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/jpa/JpaQueryPointcut.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.pointcuts.jpa; - -import com.sematext.spm.client.tracing.agent.Tracing; -import com.sematext.spm.client.tracing.agent.jpa.SpmQueryAccess; -import com.sematext.spm.client.tracing.agent.model.Call; -import com.sematext.spm.client.tracing.agent.model.annotation.JPAAnnotation; -import com.sematext.spm.client.unlogger.LoggerContext; -import com.sematext.spm.client.unlogger.UnloggableLogger; -import com.sematext.spm.client.unlogger.annotations.LoggerPointcuts; - -@LoggerPointcuts(name = "jpa:query", methods = { - "java.util.List javax.persistence.Query#getResultList()", - "int javax.persistence.Query#executeUpdate()", - "int javax.persistence.Query#getFirstResult()", - "java.lang.Object javax.persistence.Query#getSingleResult()" -}) -public class JpaQueryPointcut implements UnloggableLogger { - @Override - public void logBefore(LoggerContext context) { - Tracing.current().newCall(context.getJoinPoint()); - Tracing.current().setTag(Call.CallTag.JPA); - - final SpmQueryAccess query = (SpmQueryAccess) context.getThat(); - Tracing.current().setAnnotation(JPAAnnotation.query(query._$spm_tracing$_query_get(), null)); - } - - @Override - public void logAfter(LoggerContext context, Object returnValue) { - Tracing.current().endCall(); - } - - @Override - public void logThrow(LoggerContext context, Throwable throwable) { - Tracing.current().endCall(); - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/servlet/GetRequestDispatcherPointcut.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/servlet/GetRequestDispatcherPointcut.java deleted file mode 100644 index ca23f7e..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/servlet/GetRequestDispatcherPointcut.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.pointcuts.servlet; - -import com.sematext.spm.client.tracing.agent.servlet.SpmRequestDispatcherAccess; -import com.sematext.spm.client.unlogger.LoggerContext; -import com.sematext.spm.client.unlogger.UnloggableLogger; -import com.sematext.spm.client.unlogger.annotations.LoggerPointcuts; - -@LoggerPointcuts(name = "servlet:get-request-dispatcher", methods = { - "javax.servlet.RequestDispatcher javax.servlet.RequestDispatcher#getRequestDispatcher(java.lang.String path)" -}) -public class GetRequestDispatcherPointcut implements UnloggableLogger { - @Override - public void logBefore(LoggerContext context) { - } - - @Override - public void logAfter(LoggerContext context, Object returnValue) { - SpmRequestDispatcherAccess requestDispatcher = (SpmRequestDispatcherAccess) returnValue; - if (returnValue != null) { - requestDispatcher._$spm_tracing$_set_path((String) context.getMethodParam("path")); - } - } - - @Override - public void logThrow(LoggerContext context, Throwable throwable) { - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/servlet/RequestDispatcherPointcut.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/servlet/RequestDispatcherPointcut.java deleted file mode 100644 index 3248947..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/servlet/RequestDispatcherPointcut.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.pointcuts.servlet; - -import com.sematext.spm.client.tracing.agent.Tracing; -import com.sematext.spm.client.tracing.agent.model.Call; -import com.sematext.spm.client.unlogger.LoggerContext; -import com.sematext.spm.client.unlogger.UnloggableLogger; -import com.sematext.spm.client.unlogger.annotations.LoggerPointcuts; - -@LoggerPointcuts(name = "request-dispatcher:logger", methods = { - "void javax.servlet.RequestDispatcher#forward(javax.servlet.ServletRequest req, javax.servlet.ServletResponse resp)", - "void javax.servlet.RequestDispatcher#include(javax.servlet.ServletRequest req, javax.servlet.ServletResponse resp)" -}) -public class RequestDispatcherPointcut implements UnloggableLogger { - @Override - public void logBefore(LoggerContext context) { - Tracing.current().newCall(context.getJoinPoint()); - Tracing.current().setTag(Call.CallTag.JSP); - } - - @Override - public void logAfter(LoggerContext context, Object returnValue) { - Tracing.current().endCall(); - } - - @Override - public void logThrow(LoggerContext context, Throwable throwable) { - Tracing.current().endCall(); - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/servlet/ServletPointcut.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/servlet/ServletPointcut.java deleted file mode 100644 index 3d2474b..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/servlet/ServletPointcut.java +++ /dev/null @@ -1,189 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.pointcuts.servlet; - -import com.sematext.spm.client.Log; -import com.sematext.spm.client.LogFactory; -import com.sematext.spm.client.tracing.TracingParameters; -import com.sematext.spm.client.tracing.agent.CrossAppOutInfo; -import com.sematext.spm.client.tracing.agent.Tracing; -import com.sematext.spm.client.tracing.agent.api.TransactionAccess; -import com.sematext.spm.client.tracing.agent.model.Call; -import com.sematext.spm.client.tracing.agent.model.FailureType; -import com.sematext.spm.client.tracing.agent.model.Http; -import com.sematext.spm.client.tracing.agent.model.HttpHeaders; -import com.sematext.spm.client.tracing.agent.model.WebTransactionSummary; -import com.sematext.spm.client.tracing.agent.servlet.ServletResponseHeaders; -import com.sematext.spm.client.tracing.agent.servlet.SpmGenericServletAccess; -import com.sematext.spm.client.tracing.agent.servlet.SpmHttpServletRequestAccess; -import com.sematext.spm.client.tracing.agent.servlet.SpmHttpServletResponseAccess; -import com.sematext.spm.client.tracing.agent.servlet.SpmServletConfigAccess; -import com.sematext.spm.client.unlogger.LoggerContext; -import com.sematext.spm.client.unlogger.MethodPointcut; -import com.sematext.spm.client.unlogger.UnloggableLogger; -import com.sematext.spm.client.unlogger.annotations.LoggerPointcuts; -import com.sematext.spm.client.util.PrimitiveParsers; - -@LoggerPointcuts(name = "servlet:logger", methods = { - "void javax.servlet.Filter#doFilter(javax.servlet.ServletRequest req, javax.servlet.ServletResponse resp, javax.servlet.FilterChain chain)", - "void javax.servlet.http.HttpServlet#service(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp)" -}) -public class ServletPointcut implements UnloggableLogger { - - private static final String TRANSACTION_NAME_INIT_PARAM_NAME = "com.sematext.spm.client.tracing.agent.TRANSACTION_NAME"; - - private final Log log = LogFactory.getLog(ServletPointcut.class); - - @Override - public void logBefore(LoggerContext context) { - final SpmHttpServletRequestAccess request = (SpmHttpServletRequestAccess) context.getAllParams()[0]; - final SpmHttpServletResponseAccess response = (SpmHttpServletResponseAccess) context.getAllParams()[1]; - - if (request != null) { - //Don't create new trace if call stack is not empty. For example if JSP servlet is called from dispatcher - //it shouldn't create new trace - boolean callStackIsEmpty = Tracing.current().callStackEmpty(); - boolean crossAppCall = false; - - if (callStackIsEmpty) { - final String traceIdHeader = request._$spm_tracing$_getHeader(HttpHeaders.SPM_TRACING_TRACE_ID); - final String callIdHeader = request._$spm_tracing$_getHeader(HttpHeaders.SPM_TRACING_CALL_ID); - final String sampledHeader = request._$spm_tracing$_getHeader(HttpHeaders.SPM_TRACING_SAMPLED); - - final Long traceId = PrimitiveParsers.parseLongOrNull(traceIdHeader); - final Long callId = PrimitiveParsers.parseLongOrNull(callIdHeader); - final boolean sampled = Boolean.parseBoolean(sampledHeader); - - if (traceId != null && callId != null) { - Tracing.newTrace(request._$spm_tracing$_getRequestURI(), Call.TransactionType.WEB, traceId, callId, sampled); - - crossAppCall = true; - } else { - Tracing.newTrace(request._$spm_tracing$_getRequestURI(), Call.TransactionType.WEB); - if (log.isDebugEnabled()) { - log.debug("Created trace for " + request._$spm_tracing$_getRequestURI()); - } - } - } else { - if (log.isDebugEnabled()) { - log.debug("Skipping trace for " + request._$spm_tracing$_getRequestURI()); - } - } - - Tracing.current().newCall(context.getJoinPoint()); - Tracing.current().setTag(Call.CallTag.REGULAR); - - if (((MethodPointcut) context.getPointcut()).getTypeName().equals("javax.servlet.http.HttpServlet")) { - SpmGenericServletAccess servletAccess = (SpmGenericServletAccess) context.getThat(); - - try { - SpmServletConfigAccess servletConfig = servletAccess._$spm_tracing$_getServletConfig(); - String transactionName = servletConfig._$spm_tracing$_getInitParameter(TRANSACTION_NAME_INIT_PARAM_NAME); - Tracing.current().getNamer().redefined(transactionName); - } catch (Exception e) { - //can happen if servlet context wasn't initialized - } - } - - Tracing.current().getNamer().asServlet(context.getJoinPoint()); - - if (callStackIsEmpty) { - Tracing.current().setResponseHeaders(new ServletResponseHeaders(response)); - Tracing.current().setEntryPoint(true); - - Tracing.current().setTransactionSummary(WebTransactionSummary.handle( - request._$spm_tracing$_getRequestURI(), - request._$spm_tracing$_getQueryString(), - request._$spm_tracing$_getMethod() - )); - } - - if (crossAppCall) { - final CrossAppOutInfo crossAppOutInfo = CrossAppOutInfo.create(Tracing.current()); - Tracing.current().setCrossAppOutInfo(crossAppOutInfo); - } - } - } - - private void after(LoggerContext context, Throwable throwable) { - SpmHttpServletRequestAccess request = null; - int status = -1; - try { - request = (SpmHttpServletRequestAccess) context.getAllParams()[0]; - final SpmHttpServletResponseAccess response = (SpmHttpServletResponseAccess) context.getAllParams()[1]; - if (response != null) { - WebTransactionSummary summary = (WebTransactionSummary) Tracing.current().getTransactionSummary(); - if (summary != null) { - status = response._$spm_tracing$_getStatus(); - summary.setResponseCode(status); - - if (Http.is4xx(status) || Http.is5xx(status)) { - Tracing.current().setFailed(true); - Tracing.current().setFailureType(FailureType.HTTP_RESPONSE); - } - } - - Tracing.current().sendCrossAppOutHeaders(); - - if (Tracing.current().isLastCall()) { - //reset status after response is handled, some application servers using responses pool instead of creating new object each time - //they are reset internally, but variable added by SpmHttpServletResponseAccess mixin don't reset - response._$spm_tracing$_setStatus(0); - } - } - } finally { - if (throwable != null) { - Tracing.current() - .setTransactionParameter(TracingParameters.ERROR_CLASS.getKey(), throwable.getClass().getName()); - if (request != null) { - Tracing.current() - .setTransactionParameter(TracingParameters.REQUEST.getKey(), request._$spm_tracing$_getRequestURI()); - } - if (status != -1) { - Tracing.current().setTransactionParameter(TracingParameters.STATUS_CODE.getKey(), String.valueOf(status)); - } - if (Tracing.current().getCurrentCall() != null) { - long duration = System.currentTimeMillis() - Tracing.current().getCurrentCall().getStartTimestamp(); - Tracing.current().setTransactionParameter(TracingParameters.DURATION.getKey(), String.valueOf(duration)); - } - - Tracing.current().setFailed(true); - Tracing.current().setFailureType(FailureType.EXCEPTION); - Tracing.current().setException(throwable); - - TransactionAccess.noticeError(throwable); - } - Tracing.current().endCall(); - if (Tracing.current().callStackEmpty()) { - Tracing.endTrace(); - } - } - } - - @Override - public void logAfter(LoggerContext context, Object returnValue) { - after(context, null); - } - - @Override - public void logThrow(LoggerContext context, Throwable throwable) { - after(context, throwable); - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/solrj4/ConcurrentUpdateSolrServerPointcut.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/solrj4/ConcurrentUpdateSolrServerPointcut.java deleted file mode 100644 index e920b54..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/solrj4/ConcurrentUpdateSolrServerPointcut.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.pointcuts.solrj4; - -import com.sematext.spm.client.tracing.agent.Tracing; -import com.sematext.spm.client.tracing.agent.solrj5.SolrHttpClientParams; -import com.sematext.spm.client.tracing.agent.solrj5.UpdateRequestAccess; -import com.sematext.spm.client.unlogger.LoggerContext; -import com.sematext.spm.client.unlogger.UnloggableLogger; -import com.sematext.spm.client.unlogger.annotations.LoggerPointcuts; - -@LoggerPointcuts(name = "concurrent-update-solr-client-pointcut", methods = { - "org.apache.solr.common.util.NamedList org.apache.solr.client.solrj.impl.ConcurrentUpdateSolrServer#request(org.apache.solr.client.solrj.SolrRequest request, java.lang.String collection)", - "org.apache.solr.common.util.NamedList org.apache.solr.client.solrj.impl.ConcurrentUpdateSolrServer#request(org.apache.solr.client.solrj.SolrRequest request)" -}) -public class ConcurrentUpdateSolrServerPointcut implements UnloggableLogger { - @Override - public void logBefore(LoggerContext context) { - Object req = context.getMethodParam("request"); - if (req instanceof UpdateRequestAccess) { - UpdateRequestAccess updateRequest = (UpdateRequestAccess) req; - updateRequest._$spm_tracing$_setParam(SolrHttpClientParams.SPM_SOLR_TRACING_ASYNC, "true"); - updateRequest._$spm_tracing$_setParam(SolrHttpClientParams.SPM_SOLR_TRACING_TRACE_ID, String - .valueOf(Tracing.current().getTraceId())); - updateRequest._$spm_tracing$_setParam(SolrHttpClientParams.SPM_SOLR_TRACING_CALL_ID, String - .valueOf(Tracing.current().getCallId())); - updateRequest._$spm_tracing$_setParam(SolrHttpClientParams.SPM_SOLR_TRACING_SAMPLED, String - .valueOf(Tracing.current().isSampled())); - } - } - - @Override - public void logAfter(LoggerContext context, Object returnValue) { - } - - @Override - public void logThrow(LoggerContext context, Throwable throwable) { - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/solrj4/HttpSolrServerCtorPointcut.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/solrj4/HttpSolrServerCtorPointcut.java deleted file mode 100644 index b3e8ebe..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/solrj4/HttpSolrServerCtorPointcut.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.pointcuts.solrj4; - -import com.sematext.spm.client.tracing.agent.httpclient4.CloseableHttpClientAccess; -import com.sematext.spm.client.tracing.agent.solrj4.HttpSolrServerAccess; -import com.sematext.spm.client.tracing.agent.solrj5.SolrHttpClient; -import com.sematext.spm.client.unlogger.LoggerContext; -import com.sematext.spm.client.unlogger.UnloggableLogger; -import com.sematext.spm.client.unlogger.annotations.LoggerPointcuts; - -@LoggerPointcuts(name = "http-solr-client-ctor-pointcut", constructors = { - "org.apache.solr.client.solrj.impl.HttpSolrServer(java.lang.String url)", - "org.apache.solr.client.solrj.impl.HttpSolrServer(java.lang.String url, org.apache.http.client.HttpClient client)", - "org.apache.solr.client.solrj.impl.HttpSolrServer(java.lang.String url, org.apache.http.client.HttpClient client, org.apache.solr.client.solrj.ResponseParser parser)" -}) -public class HttpSolrServerCtorPointcut implements UnloggableLogger { - @Override - public void logBefore(LoggerContext context) { - } - - @Override - public void logAfter(LoggerContext context, Object returnValue) { - final HttpSolrServerAccess httpSolrClient = (HttpSolrServerAccess) context.getThat(); - final CloseableHttpClientAccess httpClient = (CloseableHttpClientAccess) httpSolrClient - ._$spm_tracing$_getHttpClient(); - SolrHttpClient.markSolrClient(httpClient); - } - - @Override - public void logThrow(LoggerContext context, Throwable throwable) { - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/solrj5/ConcurrentUpdateSolrClientHack.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/solrj5/ConcurrentUpdateSolrClientHack.java deleted file mode 100644 index 6805ca6..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/solrj5/ConcurrentUpdateSolrClientHack.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.pointcuts.solrj5; - -import static com.sematext.spm.client.util.PrimitiveParsers.parseLongOrNull; - -import java.net.URI; -import java.net.URISyntaxException; -import java.util.HashMap; -import java.util.Map; - -import com.sematext.spm.client.Log; -import com.sematext.spm.client.LogFactory; -import com.sematext.spm.client.tracing.agent.Tracing; -import com.sematext.spm.client.tracing.agent.model.Call; -import com.sematext.spm.client.tracing.agent.solrj5.SolrHttpClientParams; - -/** - * It is a trick to handle asynchronous calls made by crazy solrj api. - * https://gist.github.com/whiter4bbit/a0ba21e9315f1df8f9d1#file-concurrentupdatesolrclient-java-L154. - *

- * Tested just on one version may not work on other solrj version. - * {@link com.sematext.spm.client.tracing.agent.pointcuts.solrj5.ConcurrentUpdateSolrClientPointcut} adds fake request parameters to - * {@link org.apache.solr.client.solrj.request.UpdateRequest} to mark, that it should be called asynchronously. As consequence - * ConcurrentUpdateSolrClient uses all parameters (including fake ones) to build URL, then it calls apache http client with given - * url, {@link com.sematext.spm.client.tracing.agent.pointcuts.httpclient4.CloseableHttpClientPointcut} finds those fake request parameters - * and starts new transaction. - */ -public final class ConcurrentUpdateSolrClientHack { - private static final Log LOG = LogFactory.getLog(ConcurrentUpdateSolrClientHack.class); - - private ConcurrentUpdateSolrClientHack() { - } - - /** - * Starts asynchronous transaction if url contains solr-specific-update-request parameters {@link com.sematext.spm.client.tracing.agent.solrj5.SolrHttpClientParams}. - * This method not depends on any client implementation so can be reused for other clients. - * - * @param request request object which will be used as asynchronous transaction maker - * @param url url - * @return true if asynchronous transaction was started - */ - public static boolean maybeStartAsyncTransaction(Object request, String url) { - URI uri; - try { - uri = new URI(url); - String query = uri.getRawQuery(); - Map params = new HashMap(); - if (query != null) { - for (String pair : query.split("&")) { - String[] kv = pair.split("="); - if (kv.length == 2) { - params.put(kv[0], kv[1]); - } - } - } - if (Boolean.parseBoolean(params.get(SolrHttpClientParams.SPM_SOLR_TRACING_ASYNC))) { - Long traceId = parseLongOrNull(params.get(SolrHttpClientParams.SPM_SOLR_TRACING_TRACE_ID)); - Long callId = parseLongOrNull(params.get(SolrHttpClientParams.SPM_SOLR_TRACING_CALL_ID)); - Boolean sampled = Boolean.parseBoolean(params.get(SolrHttpClientParams.SPM_SOLR_TRACING_SAMPLED)); - if (traceId != null && callId != null) { - Tracing.registerAsyncTrace(request); - Tracing.newTrace("/", Call.TransactionType.BACKGROUND, traceId, callId, sampled, true); - Tracing.current().setAsync(true); - return true; - } - } - } catch (URISyntaxException e) { - LOG.error("Can't parse url.", e); - } - return false; - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/solrj5/ConcurrentUpdateSolrClientPointcut.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/solrj5/ConcurrentUpdateSolrClientPointcut.java deleted file mode 100644 index 214fcce..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/solrj5/ConcurrentUpdateSolrClientPointcut.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.pointcuts.solrj5; - -import com.sematext.spm.client.tracing.agent.Tracing; -import com.sematext.spm.client.tracing.agent.solrj5.SolrHttpClientParams; -import com.sematext.spm.client.tracing.agent.solrj5.UpdateRequestAccess; -import com.sematext.spm.client.unlogger.LoggerContext; -import com.sematext.spm.client.unlogger.UnloggableLogger; -import com.sematext.spm.client.unlogger.annotations.LoggerPointcuts; - -@LoggerPointcuts(name = "concurrent-update-solr-client-pointcut", methods = { - "org.apache.solr.common.util.NamedList org.apache.solr.client.solrj.impl.ConcurrentUpdateSolrClient#request(org.apache.solr.client.solrj.SolrRequest request, java.lang.String collection)", - "org.apache.solr.common.util.NamedList org.apache.solr.client.solrj.impl.ConcurrentUpdateSolrClient#request(org.apache.solr.client.solrj.SolrRequest request)" -}) -public class ConcurrentUpdateSolrClientPointcut implements UnloggableLogger { - - @Override - public void logBefore(LoggerContext context) { - Object req = context.getMethodParam("request"); - if (req instanceof UpdateRequestAccess) { - UpdateRequestAccess updateRequest = (UpdateRequestAccess) req; - updateRequest._$spm_tracing$_setParam(SolrHttpClientParams.SPM_SOLR_TRACING_ASYNC, "true"); - updateRequest._$spm_tracing$_setParam(SolrHttpClientParams.SPM_SOLR_TRACING_TRACE_ID, String - .valueOf(Tracing.current().getTraceId())); - updateRequest._$spm_tracing$_setParam(SolrHttpClientParams.SPM_SOLR_TRACING_CALL_ID, String - .valueOf(Tracing.current().getCallId())); - updateRequest._$spm_tracing$_setParam(SolrHttpClientParams.SPM_SOLR_TRACING_SAMPLED, String - .valueOf(Tracing.current().isSampled())); - } - } - - @Override - public void logAfter(LoggerContext context, Object returnValue) { - } - - @Override - public void logThrow(LoggerContext context, Throwable throwable) { - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/solrj5/HttpClient3SolrRequest.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/solrj5/HttpClient3SolrRequest.java deleted file mode 100644 index f3a3aae..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/solrj5/HttpClient3SolrRequest.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.pointcuts.solrj5; - -import com.sematext.spm.client.tracing.agent.Trace; -import com.sematext.spm.client.tracing.agent.httpclient3.HttpMethodAccess; -import com.sematext.spm.client.tracing.agent.model.Call; -import com.sematext.spm.client.tracing.agent.model.SolrAnnotation; -import com.sematext.spm.client.tracing.agent.solrj5.SolrAnnotationMaker; - -public final class HttpClient3SolrRequest { - private HttpClient3SolrRequest() { - } - - public static void before(Trace trace, String url) { - trace.setTag(Call.CallTag.SOLR); - trace.setAnnotation(SolrAnnotationMaker.fromHTTPRequest(url)); - } - - public static void after(Trace trace, HttpMethodAccess method) { - final SolrAnnotation annotation = (SolrAnnotation) trace.getAnnotation(); - if (annotation != null) { - int code = method._$spm_tracing$_getStatusCode(); - annotation.setResponseStatus(code); - annotation.setSucceed(code == 200); - } - } - - public static void exception(Trace trace) { - final SolrAnnotation annotation = (SolrAnnotation) trace.getAnnotation(); - if (annotation != null) { - annotation.setSucceed(false); - } - } - -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/solrj5/HttpClient4SolrRequest.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/solrj5/HttpClient4SolrRequest.java deleted file mode 100644 index 6ea31fc..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/solrj5/HttpClient4SolrRequest.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.pointcuts.solrj5; - -import com.sematext.spm.client.tracing.agent.Trace; -import com.sematext.spm.client.tracing.agent.httpclient4.HttpHostAccess; -import com.sematext.spm.client.tracing.agent.httpclient4.HttpRequestAccess; -import com.sematext.spm.client.tracing.agent.httpclient4.HttpResponseAccess; -import com.sematext.spm.client.tracing.agent.model.Call; -import com.sematext.spm.client.tracing.agent.model.SolrAnnotation; -import com.sematext.spm.client.tracing.agent.solrj5.SolrAnnotationMaker; - -public final class HttpClient4SolrRequest { - private HttpClient4SolrRequest() { - } - - public static void before(Trace trace, HttpHostAccess host, HttpRequestAccess request) { - trace.setTag(Call.CallTag.SOLR); - trace.setAnnotation(SolrAnnotationMaker.fromHttpRequest(host, request)); - } - - public static void after(Trace trace, HttpResponseAccess response) { - final SolrAnnotation annotation = (SolrAnnotation) trace.getAnnotation(); - if (annotation != null) { - int code = response._$spm_tracing$_getStatusLine()._$spm_tracing$_getStatusCode(); - annotation.setResponseStatus(code); - annotation.setSucceed(code == 200); - } - } - - public static void exception(Trace trace) { - final SolrAnnotation annotation = (SolrAnnotation) trace.getAnnotation(); - if (annotation != null) { - annotation.setSucceed(false); - } - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/solrj5/HttpSolrClientCtorPointcut.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/solrj5/HttpSolrClientCtorPointcut.java deleted file mode 100644 index c2c602e..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/solrj5/HttpSolrClientCtorPointcut.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.pointcuts.solrj5; - -import com.sematext.spm.client.tracing.agent.httpclient4.CloseableHttpClientAccess; -import com.sematext.spm.client.tracing.agent.solrj5.HttpSolrClientAccess; -import com.sematext.spm.client.tracing.agent.solrj5.SolrHttpClient; -import com.sematext.spm.client.unlogger.LoggerContext; -import com.sematext.spm.client.unlogger.UnloggableLogger; -import com.sematext.spm.client.unlogger.annotations.LoggerPointcuts; - -@LoggerPointcuts(name = "http-solr-client-ctor-pointcut", constructors = { - "org.apache.solr.client.solrj.impl.HttpSolrClient(java.lang.String url)", - "org.apache.solr.client.solrj.impl.HttpSolrClient(java.lang.String url, org.apache.http.client.HttpClient client)", - "org.apache.solr.client.solrj.impl.HttpSolrClient(java.lang.String url, org.apache.http.client.HttpClient client, org.apache.solr.client.solrj.ResponseParser parser)" -}) -public class HttpSolrClientCtorPointcut implements UnloggableLogger { - @Override - public void logBefore(LoggerContext context) { - } - - @Override - public void logAfter(LoggerContext context, Object returnValue) { - final HttpSolrClientAccess httpSolrClient = (HttpSolrClientAccess) context.getThat(); - final CloseableHttpClientAccess httpClient = (CloseableHttpClientAccess) httpSolrClient - ._$spm_tracing$_getHttpClient(); - SolrHttpClient.markSolrClient(httpClient); - } - - @Override - public void logThrow(LoggerContext context, Throwable throwable) { - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/solrj6/HttpSolrClientCtorPointcut.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/solrj6/HttpSolrClientCtorPointcut.java deleted file mode 100644 index 77f9c78..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/solrj6/HttpSolrClientCtorPointcut.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.pointcuts.solrj6; - -import com.sematext.spm.client.tracing.agent.httpclient4.CloseableHttpClientAccess; -import com.sematext.spm.client.tracing.agent.solrj5.HttpSolrClientAccess; -import com.sematext.spm.client.tracing.agent.solrj5.SolrHttpClient; -import com.sematext.spm.client.unlogger.LoggerContext; -import com.sematext.spm.client.unlogger.UnloggableLogger; -import com.sematext.spm.client.unlogger.annotations.LoggerPointcuts; - -@LoggerPointcuts(name = "http-solr-client-ctor-pointcut", constructors = { - "org.apache.solr.client.solrj.impl.HttpSolrClient(java.lang.String url, org.apache.http.client.HttpClient client, org.apache.solr.client.solrj.ResponseParser parser, boolean allowCompression, org.apache.solr.common.params.ModifiableSolrParams invariantParams)" -}) -public class HttpSolrClientCtorPointcut implements UnloggableLogger { - @Override - public void logBefore(LoggerContext context) { - } - - @Override - public void logAfter(LoggerContext context, Object returnValue) { - final HttpSolrClientAccess httpSolrClient = (HttpSolrClientAccess) context.getThat(); - final CloseableHttpClientAccess httpClient = (CloseableHttpClientAccess) httpSolrClient - ._$spm_tracing$_getHttpClient(); - SolrHttpClient.markSolrClient(httpClient); - } - - @Override - public void logThrow(LoggerContext context, Throwable throwable) { - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/solrj7/HttpSolrClientCtorPointcut.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/solrj7/HttpSolrClientCtorPointcut.java deleted file mode 100644 index 7c87cd2..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/solrj7/HttpSolrClientCtorPointcut.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) Sematext International - * All Rights Reserved - * - * THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF Sematext International - * The copyright notice above does not evidence any - * actual or intended publication of such source code. - */ -package com.sematext.spm.client.tracing.agent.pointcuts.solrj7; - -import com.sematext.spm.client.tracing.agent.httpclient4.CloseableHttpClientAccess; -import com.sematext.spm.client.tracing.agent.solrj5.HttpSolrClientAccess; -import com.sematext.spm.client.tracing.agent.solrj5.SolrHttpClient; -import com.sematext.spm.client.unlogger.LoggerContext; -import com.sematext.spm.client.unlogger.UnloggableLogger; -import com.sematext.spm.client.unlogger.annotations.LoggerPointcuts; - -@LoggerPointcuts(name = "http-solr7-client-ctor-pointcut", constructors = { - "org.apache.solr.client.solrj.impl.HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient$Builder builder)" -}) -public class HttpSolrClientCtorPointcut implements UnloggableLogger { - @Override - public void logBefore(LoggerContext context) { } - - @Override - public void logAfter(LoggerContext context, Object returnValue) { - final HttpSolrClientAccess httpSolrClient = (HttpSolrClientAccess) context.getThat(); - final CloseableHttpClientAccess httpClient = (CloseableHttpClientAccess) httpSolrClient._$spm_tracing$_getHttpClient(); - SolrHttpClient.markSolrClient(httpClient); - } - - @Override - public void logThrow(LoggerContext context, Throwable throwable) { } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/spring/SpringRequestMappingPointcut.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/spring/SpringRequestMappingPointcut.java deleted file mode 100644 index 6ec07f5..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/spring/SpringRequestMappingPointcut.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.pointcuts.spring; - -import com.sematext.spm.client.tracing.agent.Tracing; -import com.sematext.spm.client.tracing.agent.model.Call; -import com.sematext.spm.client.unlogger.LoggerContext; -import com.sematext.spm.client.unlogger.UnloggableLogger; -import com.sematext.spm.client.unlogger.annotations.LoggerPointcuts; - -@LoggerPointcuts(name = "logger:spring-request-mapping-logger", methodAnnotations = { - "org.springframework.web.bind.annotation.RequestMapping" -}) -public class SpringRequestMappingPointcut implements UnloggableLogger { - @Override - public void logBefore(LoggerContext context) { - Tracing.current().newCall(context.getJoinPoint()); - Tracing.current().setTag(Call.CallTag.REGULAR); - - Tracing.current().getNamer().asFramework(context.getJoinPoint()); - } - - @Override - public void logAfter(LoggerContext context, Object returnValue) { - Tracing.current().endCall(); - } - - @Override - public void logThrow(LoggerContext context, Throwable throwable) { - Tracing.current().setFailed(true); - Tracing.current().endCall(); - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/thread/ExecutorServiceInvokePointcut.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/thread/ExecutorServiceInvokePointcut.java deleted file mode 100644 index 0e29f4b..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/thread/ExecutorServiceInvokePointcut.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.pointcuts.thread; - -import java.util.Collection; - -import com.sematext.spm.client.tracing.agent.Tracing; -import com.sematext.spm.client.unlogger.LoggerContext; -import com.sematext.spm.client.unlogger.UnloggableLogger; -import com.sematext.spm.client.unlogger.annotations.LoggerPointcuts; - -@LoggerPointcuts(name = "executor-service-invoke-pointcut", methods = { - "java.util.List java.util.concurrent.ExecutorService#invokeAll(java.util.Collection tasks)", - "java.util.List java.util.concurrent.ExecutorService#invokeAll(java.util.Collection tasks, long timeout, java.util.concurrent.TimeUnit unit)", - "java.lang.Object java.util.concurrent.ExecutorService#invokeAny(java.util.Collection tasks)", - "java.lang.Object java.util.concurrent.ExecutorService#invokeAny(java.util.Collection tasks, long timeout, java.util.concurrent.TimeUnit unit)" -}) -public class ExecutorServiceInvokePointcut implements UnloggableLogger { - @Override - public void logBefore(LoggerContext context) { - Collection tasks = (Collection) context.getAllParams()[0]; - if (tasks != null) { - for (Object task : tasks) { - Tracing.registerAsyncTrace(task); - } - } - } - - @Override - public void logAfter(LoggerContext context, Object returnValue) { - } - - @Override - public void logThrow(LoggerContext context, Throwable throwable) { - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/thread/ExecutorServiceSubmitPointcut.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/thread/ExecutorServiceSubmitPointcut.java deleted file mode 100644 index 4f19ba0..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/thread/ExecutorServiceSubmitPointcut.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.pointcuts.thread; - -import com.sematext.spm.client.tracing.agent.Tracing; -import com.sematext.spm.client.unlogger.LoggerContext; -import com.sematext.spm.client.unlogger.UnloggableLogger; -import com.sematext.spm.client.unlogger.annotations.LoggerPointcuts; - -@LoggerPointcuts(name = "thread:executor-service-pointcut", methods = { - "void java.util.concurrent.Executor#execute(java.lang.Runnable command)", - "java.util.concurrent.Future java.util.concurrent.ExecutorService#submit(java.util.concurrent.Callable task)", - "java.util.concurrent.Future java.util.concurrent.ExecutorService#submit(java.lang.Runnable task, java.lang.Object result)", - "java.util.concurrent.Future java.util.concurrent.ExecutorService#submit(java.lang.Runnable task)" -}) -public class ExecutorServiceSubmitPointcut implements UnloggableLogger { - @Override - public void logBefore(LoggerContext context) { - Tracing.registerAsyncTrace(context.getAllParams()[0]); - } - - @Override - public void logAfter(LoggerContext context, Object returnValue) { - } - - @Override - public void logThrow(LoggerContext context, Throwable throwable) { - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/thread/RunnableAndCallablePointcut.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/thread/RunnableAndCallablePointcut.java deleted file mode 100644 index 25e0a35..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/thread/RunnableAndCallablePointcut.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.pointcuts.thread; - -import com.sematext.spm.client.tracing.agent.Tracing; -import com.sematext.spm.client.tracing.agent.model.Call; -import com.sematext.spm.client.tracing.agent.util.AsyncContext; -import com.sematext.spm.client.unlogger.LoggerContext; -import com.sematext.spm.client.unlogger.UnloggableLogger; -import com.sematext.spm.client.unlogger.annotations.LoggerPointcuts; - -@LoggerPointcuts(name = "thread:runnable-callable-pointcut", methods = { - "void java.lang.Runnable#run()", - "java.lang.Object java.util.concurrent.Callable#call()" -}) -public class RunnableAndCallablePointcut implements UnloggableLogger { - @Override - public void logBefore(LoggerContext context) { - final AsyncContext ctx = AsyncContext.get(context.getThat()); - if (ctx != null) { - Tracing.newTrace("/", Call.TransactionType.BACKGROUND, ctx.getTraceId(), ctx.getParentCallId(), ctx - .isSampled(), true); - Tracing.current().setAsync(true); - } - } - - @Override - public void logAfter(LoggerContext context, Object returnValue) { - if (AsyncContext.get(context.getThat()) != null) { - AsyncContext.clean(context.getThat()); - Tracing.endTrace(); - } - } - - @Override - public void logThrow(LoggerContext context, Throwable throwable) { - if (AsyncContext.get(context.getThat()) != null) { - AsyncContext.clean(context.getThat()); - Tracing.endTrace(); - } - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/thread/ThreadPointcut.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/thread/ThreadPointcut.java deleted file mode 100644 index ae13a2a..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/thread/ThreadPointcut.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.pointcuts.thread; - -import com.sematext.spm.client.tracing.agent.Tracing; -import com.sematext.spm.client.unlogger.LoggerContext; -import com.sematext.spm.client.unlogger.UnloggableLogger; -import com.sematext.spm.client.unlogger.annotations.LoggerPointcuts; -import com.sematext.spm.client.util.ReflectionUtils; - -@LoggerPointcuts(name = "thread:thread-pointcut", methods = { - "void java.lang.Thread#start()" -}) -public class ThreadPointcut implements UnloggableLogger { - @Override - public void logBefore(LoggerContext context) { - final Object r = ReflectionUtils.silentFieldGet(context.getThat(), "target"); - Object worker = context.getThat(); - if (r != null) { - worker = r; - } - - Tracing.registerAsyncTrace(worker); - } - - @Override - public void logAfter(LoggerContext context, Object returnValue) { - } - - @Override - public void logThrow(LoggerContext context, Throwable throwable) { - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/tomcat/ResponsePointcut.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/tomcat/ResponsePointcut.java deleted file mode 100644 index 0b8316a..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/tomcat/ResponsePointcut.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.pointcuts.tomcat; - -import com.sematext.spm.client.tracing.agent.Tracing; -import com.sematext.spm.client.tracing.agent.tomcat.TomcatResponseHeaders; -import com.sematext.spm.client.unlogger.LoggerContext; -import com.sematext.spm.client.unlogger.UnloggableLogger; -import com.sematext.spm.client.unlogger.annotations.LoggerPointcuts; - -/** - * Pointcut to catch point where tomcat commits headers and sends response to client. - * Tested on: Tomcat 6.0.43, 7.0.57, 8.0.17 - */ -@LoggerPointcuts(name = "tomcat:response-pointcut", methods = { - "void org.apache.coyote.Response#sendHeaders()" -}) -public class ResponsePointcut implements UnloggableLogger { - @Override - public void logBefore(LoggerContext context) { - Tracing.current().setResponseHeaders(new TomcatResponseHeaders(context.getThat())); - Tracing.current().sendCrossAppOutHeaders(); - } - - @Override - public void logAfter(LoggerContext context, Object returnValue) { - } - - @Override - public void logThrow(LoggerContext context, Throwable throwable) { - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/url/URLConnectionPointcut.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/url/URLConnectionPointcut.java deleted file mode 100644 index fc2a340..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/pointcuts/url/URLConnectionPointcut.java +++ /dev/null @@ -1,156 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.pointcuts.url; - -import java.io.IOException; -import java.net.HttpURLConnection; -import java.net.URLConnection; - -import com.sematext.spm.client.Log; -import com.sematext.spm.client.LogFactory; -import com.sematext.spm.client.tracing.agent.Tracing; -import com.sematext.spm.client.tracing.agent.model.Call; -import com.sematext.spm.client.tracing.agent.model.HttpHeaders; -import com.sematext.spm.client.tracing.agent.model.HttpHeaders.CrossAppCallHeader; -import com.sematext.spm.client.tracing.agent.model.annotation.HTTPRequestAnnotation; -import com.sematext.spm.client.unlogger.LoggerContext; -import com.sematext.spm.client.unlogger.UnloggableLogger; -import com.sematext.spm.client.unlogger.annotations.LoggerPointcuts; -import com.sematext.spm.client.util.ReflectionUtils; - -@LoggerPointcuts(name = "logger:java-net-url-connection", methods = { - "java.io.InputStream sun.net.www.protocol.http.HttpURLConnection#getInputStream()", - "java.io.OutputStream sun.net.www.protocol.http.HttpURLConnection#getOutputStream()", - "java.io.InputStream sun.net.www.protocol.https.DelegateHttpsURLConnection#getInputStream()", - "java.io.OutputStream sun.net.www.protocol.https.DelegateHttpsURLConnection#getOutputStream()" -}) -public class URLConnectionPointcut implements UnloggableLogger { - - private static final Log LOG = LogFactory.getLog(URLConnectionPointcut.class); - /** - * Workaround to avoid stackoverlfow, because of recursive calls. - * HttpURLConnection designed in way, that post-connection method calls getInputStream, but - * getInputStream also can be called itself. - * After getInputStream call need to get cross-app headers, as well as response code, but each of those calls - * also calls getInputStream as well. - */ - private static ThreadLocal LOCK = new ThreadLocal() { - @Override - protected Boolean initialValue() { - return false; - } - }; - - private static boolean isConnected(URLConnection connection) { - final Boolean connected = (Boolean) ReflectionUtils.silentFieldGet(connection, "connected"); - return connected != null && connected; - } - - private static boolean isConnecting(URLConnection connection) { - final Boolean connecting = (Boolean) ReflectionUtils.silentFieldGet(connection, "connecting"); - return connecting != null && connecting; - } - - private static String getUrl(URLConnection connection) { - return connection.getURL().toString(); - } - - @Override - public void logBefore(LoggerContext context) { - if (LOCK.get()) { - return; - } - - final URLConnection connection = (URLConnection) context.getThat(); - - Tracing.current().newCall(context.getJoinPoint()); - Tracing.current().setExternal(true); - /** - * Don't track 'getOutputStream' as external call on map, because cross-application call headers are accessed - * after 'getInputStream' call (which should be called after 'getOutputStream' call). - * In opposite situation in map will be displayed two kind of calls - external - * and cross-application call what is confusing. - */ - Tracing.current().setSkipExternalTracingStatistics(context.getJoinPoint().getShortName().equals("getOutputStream")); - Tracing.current().setTag(Call.CallTag.HTTP_REQUEST); - Tracing.current().setAnnotation(HTTPRequestAnnotation.request(getUrl(connection))); - - if (!isConnected(connection) && !isConnecting(connection)) { - connection.setRequestProperty(HttpHeaders.SPM_TRACING_SAMPLED, String.valueOf(Tracing.current().isSampled())); - connection.setRequestProperty(HttpHeaders.SPM_TRACING_TRACE_ID, String.valueOf(Tracing.current().getTraceId())); - connection.setRequestProperty(HttpHeaders.SPM_TRACING_CALL_ID, String.valueOf(Tracing.current().getCallId())); - } - } - - private void after(LoggerContext context, Throwable throwable) { - if (LOCK.get()) { - return; - } - - if (context.getJoinPoint().getShortName().contains("getInputStream")) { - final HttpURLConnection connection = (HttpURLConnection) context.getThat(); - try { - LOCK.set(true); - try { - final int responseCode = connection.getResponseCode(); - HTTPRequestAnnotation annotation = (HTTPRequestAnnotation) Tracing.current().getAnnotation(); - if (annotation != null) { - annotation.setResponseCode(responseCode); - } - } catch (IOException e) { - if (LOG.isDebugEnabled()) { - LOG.debug("Can't get response code.", e); - } - } - - final String crossAppCallHeader = connection.getHeaderField(HttpHeaders.SPM_TRACING_CROSS_APP_CALL); - if (crossAppCallHeader != null) { - final CrossAppCallHeader header = HttpHeaders.decodeCrossAppCallHeader(crossAppCallHeader); - if (header == null) { - if (LOG.isTraceEnabled()) { - LOG.trace("Cross app call header is empty."); - } - } else { - Tracing.current().setCrossAppInHeader(header); - if (LOG.isDebugEnabled()) { - LOG.debug("Cross app call header present: " + header + "."); - } - } - } - } finally { - LOCK.set(false); - } - } - if (throwable != null) { - Tracing.current().setFailed(true); - } - Tracing.current().endCall(); - } - - @Override - public void logAfter(LoggerContext context, Object returnValue) { - after(context, null); - } - - @Override - public void logThrow(LoggerContext context, Throwable throwable) { - after(context, throwable); - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/sampling/AdaptiveSampler.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/sampling/AdaptiveSampler.java deleted file mode 100644 index 668935c..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/sampling/AdaptiveSampler.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.sampling; - -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicLong; - -public final class AdaptiveSampler implements Sampler { - private final SamplerStatistics statistics; - private final long intervalNanos; - private final long intervalMillis; - private final AtomicLong eventsCount = new AtomicLong(0); - private final AtomicLong timestamp = new AtomicLong(0); - private final long samplingFactor = Long.getLong("spm.tracing.sampling.factor", 2); - - public AdaptiveSampler(SamplerStatistics statistics, long interval, TimeUnit timeUnit) { - this.statistics = statistics; - this.intervalNanos = timeUnit.toNanos(interval); - this.intervalMillis = timeUnit.toMillis(interval); - } - - @Override - public boolean sample(String request) { - double average = statistics.average(); - int maxEvents = (int) (intervalNanos / average); - long now = System.currentTimeMillis(); - long ts = timestamp.get(); - if ((ts + intervalMillis) < now) { - if (timestamp.compareAndSet(ts, now)) { - eventsCount.set(0); - } - } - Stats.INSTANCE.addTotal(); - if (eventsCount.incrementAndGet() * samplingFactor > maxEvents) { - Stats.INSTANCE.addSampled(); - return false; - } - return true; - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/sampling/FixedRateSampler.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/sampling/FixedRateSampler.java deleted file mode 100644 index f1a0d6e..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/sampling/FixedRateSampler.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.sampling; - -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicLong; - -public class FixedRateSampler implements Sampler { - private final long intervalMillis; - private final long target; - private final AtomicLong timestamp = new AtomicLong(0); - private final AtomicLong count = new AtomicLong(0); - - public FixedRateSampler(long interval, TimeUnit timeUnit, long target) { - this.intervalMillis = timeUnit.toMillis(interval); - this.target = target; - } - - @Override - public boolean sample(String request) { - long now = System.currentTimeMillis(); - long ts = timestamp.get(); - if ((ts + intervalMillis) < now) { - if (timestamp.compareAndSet(ts, now)) { - count.set(0); - } - } - Stats.INSTANCE.addTotal(); - if (count.incrementAndGet() > target) { - Stats.INSTANCE.addSampled(); - return false; - } - return true; - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/sampling/NoSampling.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/sampling/NoSampling.java deleted file mode 100644 index f6d177d..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/sampling/NoSampling.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.sampling; - -public final class NoSampling implements Sampler { - @Override - public boolean sample(E request) { - return true; - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/sampling/Sampler.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/sampling/Sampler.java deleted file mode 100644 index a80b671..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/sampling/Sampler.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.sampling; - -public interface Sampler { - boolean sample(E event); -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/sampling/SamplerStatistics.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/sampling/SamplerStatistics.java deleted file mode 100644 index 78b5597..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/sampling/SamplerStatistics.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.sampling; - -import java.util.concurrent.TimeUnit; - -public final class SamplerStatistics { - - public static final SamplerStatistics INSTANCE = new SamplerStatistics(10, TimeUnit.SECONDS); - - private volatile double avg; - private long count; - private long sum; - private long timestamp; - - private final long interval; - private final TimeUnit timeUnit; - - public SamplerStatistics(long interval, TimeUnit timeUnit) { - this.interval = interval; - this.timeUnit = timeUnit; - } - - public void update(long v) { - Stats.INSTANCE.updateWriteLatency(v); - long now = System.currentTimeMillis(); - if (timestamp + timeUnit.toMillis(interval) < now) { - count = 0; - sum = 0; - timestamp = now; - } - count++; - sum += v; - avg = ((double) sum) / count; - } - - public double average() { - return avg; - } -} - diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/sampling/Stats.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/sampling/Stats.java deleted file mode 100644 index 3761577..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/sampling/Stats.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.sampling; - -import java.util.concurrent.atomic.AtomicLong; - -public final class Stats { - public static final Stats INSTANCE = new Stats(); - - private final AtomicLong sampled = new AtomicLong(0); - private final AtomicLong total = new AtomicLong(0); - private final AtomicLong writeCount = new AtomicLong(0); - private final AtomicLong writeLatencySum = new AtomicLong(0); - private final AtomicLong sinkCount = new AtomicLong(0); - private final AtomicLong sinkLatencySum = new AtomicLong(0); - - public void addSampled() { - sampled.incrementAndGet(); - } - - public void addTotal() { - total.incrementAndGet(); - } - - public long getSampled() { - return sampled.get(); - } - - public long getTotal() { - return total.get(); - } - - public void updateWriteLatency(long writeLatency) { - writeCount.incrementAndGet(); - writeLatencySum.addAndGet(writeLatency); - } - - public double getAvgWriteLatency() { - long sum = writeLatencySum.get(); - long count = writeCount.get(); - if (count == 0) { - return 0d; - } - return ((double) sum) / count; - } - - public void updateSinkLatency(long sinkLatency) { - sinkCount.incrementAndGet(); - sinkLatencySum.addAndGet(sinkLatency); - } - - public double getAvgSinkLatency() { - long sum = sinkLatencySum.get(); - long count = sinkCount.get(); - if (count == 0) { - return 0d; - } - return ((double) sum) / count; - } - -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/sampling/StatsReporter.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/sampling/StatsReporter.java deleted file mode 100644 index 7b75e61..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/sampling/StatsReporter.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.sampling; - -import java.util.concurrent.TimeUnit; - -import com.sematext.spm.client.Log; -import com.sematext.spm.client.LogFactory; - -public final class StatsReporter { - private static final Log LOG = LogFactory.getLog(StatsReporter.class); - - public static void start(final Stats stats, final long interval, final TimeUnit timeUnit) { - final Thread t = new Thread() { - @Override - public void run() { - try { - while (true) { - final StringBuilder statistics = new StringBuilder(); - statistics.append("Sampled = ").append(stats.getSampled()).append(", ") - .append("Total = ").append(stats.getTotal()).append(", ") - .append("Avg write latency = ").append(stats.getAvgWriteLatency()).append(" ns").append(", ") - .append("Avg sink latency = ").append(stats.getAvgSinkLatency()).append(" ns"); - - LOG.info(statistics.toString()); - Thread.sleep(timeUnit.toMillis(interval)); - } - } catch (Exception e) { - /* */ - } - } - }; - t.setDaemon(true); - t.setName("spm-tracing-stats-reporter"); - - t.start(); - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/sampling/TracingErrorFixedRateSampler.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/sampling/TracingErrorFixedRateSampler.java deleted file mode 100644 index 9fd8628..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/sampling/TracingErrorFixedRateSampler.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.sampling; - -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicReference; - -import com.sematext.spm.client.tracing.agent.errors.TracingError; -import com.sematext.spm.client.util.Clock; -import com.sematext.spm.client.util.Clocks; - -public final class TracingErrorFixedRateSampler implements Sampler { - - private static class State { - final long startIntervalTsMs; - final long events; - - public State(long startIntervalTsMs, long events) { - this.startIntervalTsMs = startIntervalTsMs; - this.events = events; - } - } - - private final long maxEventsCount; - private final long intervalMillis; - private final Clock clock; - private final AtomicReference state = new AtomicReference(null); - - public TracingErrorFixedRateSampler(long maxEventsCount, long interval, TimeUnit intervalTU, Clock clock) { - this.maxEventsCount = maxEventsCount; - this.intervalMillis = intervalTU.toMillis(interval); - this.clock = clock; - } - - public TracingErrorFixedRateSampler(long maxEventsCount, long interval, TimeUnit intervalTU) { - this(maxEventsCount, interval, intervalTU, Clocks.WALL); - } - - @Override - public boolean sample(TracingError event) { - State currentState; - State nextState; - boolean sample; - - do { - sample = false; - currentState = state.get(); - - if (currentState == null) { - nextState = new State(clock.now(), 1); - sample = true; - } else if (clock.now() - currentState.startIntervalTsMs >= intervalMillis) { - nextState = new State(clock.now(), 1); - sample = true; - } else if (currentState.events < maxEventsCount) { - nextState = new State(currentState.startIntervalTsMs, currentState.events + 1); - sample = true; - } else { - nextState = currentState; - } - } while (!state.compareAndSet(currentState, nextState)); - - return sample; - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/sampling/WeightedFixedRateSampler.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/sampling/WeightedFixedRateSampler.java deleted file mode 100644 index 8bc93a2..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/sampling/WeightedFixedRateSampler.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.sampling; - -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.concurrent.atomic.AtomicLong; - -public final class WeightedFixedRateSampler implements Sampler { - - private final ConcurrentHashMap requestsCount = new ConcurrentHashMap(); - private final AtomicInteger total = new AtomicInteger(0); - private final AtomicLong timestamp = new AtomicLong(0); - private final long limit; - private final long rareCallsLimit; - private final long intervalMillis; - - public WeightedFixedRateSampler(long limit, long rareCallsLimit, long interval, TimeUnit timeUnit) { - this.limit = limit; - this.rareCallsLimit = rareCallsLimit; - this.intervalMillis = timeUnit.toMillis(interval); - } - - void cleanup() { - requestsCount.clear(); - total.set(0); - } - - @Override - public boolean sample(String request) { - long now = System.currentTimeMillis(); - long ts = timestamp.get(); - if ((ts + intervalMillis) < now) { - if (timestamp.compareAndSet(ts, now)) { - cleanup(); - } - } - AtomicInteger count = requestsCount.putIfAbsent(request, new AtomicInteger(0)); - if (count == null) { - count = requestsCount.get(request); - } - Stats.INSTANCE.addTotal(); - if (total.incrementAndGet() > limit - && count.incrementAndGet() > rareCallsLimit) { - Stats.INSTANCE.addSampled(); - return false; - } - return true; - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/servlet/AsyncListenerProxy.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/servlet/AsyncListenerProxy.java deleted file mode 100644 index baf3f98..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/servlet/AsyncListenerProxy.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.servlet; - -import java.lang.reflect.InvocationHandler; -import java.lang.reflect.Method; -import java.lang.reflect.Proxy; - -import com.sematext.spm.client.tracing.agent.Tracing; -import com.sematext.spm.client.tracing.agent.model.Call; - -public final class AsyncListenerProxy { - - private static final String ASYNC_LISTENER_CLASS = "javax.servlet.AsyncListener"; - - private AsyncListenerProxy() { - } - - private static void completeTransaction(Object asyncEvent, final Long traceId, final Long parentCallId, - final Long startTs, final boolean sampled) { - final SpmAsyncEventAccess event = (SpmAsyncEventAccess) asyncEvent; - final SpmHttpServletResponseAccess response = (SpmHttpServletResponseAccess) event.getResponse(); - -// response._$spm_tracing$_setHeader("X-SPM-Async-Processed", "true"); - - Tracing.newTrace("", Call.TransactionType.WEB, traceId, parentCallId, sampled); - Tracing.current().newCall("async", startTs); - Tracing.current().setTag(Call.CallTag.REGULAR); - Tracing.current().endCall(); - Tracing.endTrace(); - } - - public static Object newAsyncListener(final ClassLoader loader, final Long traceId, final Long parentCallId, - final Long startTs, final boolean sampled) - throws ClassNotFoundException { - final Class klass = Class.forName(ASYNC_LISTENER_CLASS, true, loader); - return Proxy.newProxyInstance(loader, new Class[] { klass }, new InvocationHandler() { - @Override - public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { - final String methodName = method.getName(); - if ("onComplete".equals(methodName) || "onError".equals(methodName)) { - completeTransaction(args[0], traceId, parentCallId, startTs, sampled); - return null; - } - return null; - } - }); - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/servlet/ServletResponseHeaders.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/servlet/ServletResponseHeaders.java deleted file mode 100644 index d0efc71..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/servlet/ServletResponseHeaders.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.servlet; - -import com.sematext.spm.client.tracing.agent.ResponseHeaders; - -public class ServletResponseHeaders implements ResponseHeaders { - private final SpmHttpServletResponseAccess response; - - public ServletResponseHeaders(SpmHttpServletResponseAccess response) { - this.response = response; - } - - @Override - public void addHeader(String name, String value) { - response._$spm_tracing$_setHeader(name, value); - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/servlet/SpmAsyncEventAccess.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/servlet/SpmAsyncEventAccess.java deleted file mode 100644 index c2c28f1..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/servlet/SpmAsyncEventAccess.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.servlet; - -import com.sematext.spm.client.instrumentation.Delegate; - -public interface SpmAsyncEventAccess { - @Delegate(method = "getSuppliedRequest") - Object getRequest(); - - @Delegate(method = "getSuppliedResponse") - Object getResponse(); -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/servlet/SpmGenericServletAccess.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/servlet/SpmGenericServletAccess.java deleted file mode 100644 index e059580..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/servlet/SpmGenericServletAccess.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.servlet; - -import com.sematext.spm.client.instrumentation.Delegate; - -public interface SpmGenericServletAccess { - @Delegate(method = "getServletConfig") - SpmServletConfigAccess _$spm_tracing$_getServletConfig(); -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/servlet/SpmHttpServletRequestAccess.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/servlet/SpmHttpServletRequestAccess.java deleted file mode 100644 index 5d9cf47..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/servlet/SpmHttpServletRequestAccess.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.servlet; - -import com.sematext.spm.client.instrumentation.Delegate; - -public interface SpmHttpServletRequestAccess { - @Delegate(method = "getHeader") - String _$spm_tracing$_getHeader(String header); - - @Delegate(method = "getRequestURI") - String _$spm_tracing$_getRequestURI(); - - @Delegate(method = "getMethod") - String _$spm_tracing$_getMethod(); - - @Delegate(method = "getQueryString") - String _$spm_tracing$_getQueryString(); -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/servlet/SpmHttpServletResponseAccess.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/servlet/SpmHttpServletResponseAccess.java deleted file mode 100644 index d6d12e2..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/servlet/SpmHttpServletResponseAccess.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.servlet; - -import com.sematext.spm.client.instrumentation.Delegate; -import com.sematext.spm.client.instrumentation.Mixins; -import com.sematext.spm.client.instrumentation.ParameterCapture; -import com.sematext.spm.client.instrumentation.Setter; - -public interface SpmHttpServletResponseAccess { - @ParameterCapture(methods = { "setStatus", "setStatusWithReason" }, initial = "200") - int _$spm_tracing$_getStatus(); - - @Setter(value = "_$spm_tracing$_getStatus", namer = Mixins.Namer.PARAMETER_CAPTURE_FIELD_NAMER) - void _$spm_tracing$_setStatus(int status); - - @Delegate(method = "setHeader") - void _$spm_tracing$_setHeader(String name, String value); -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/servlet/SpmRequestDispatcherAccess.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/servlet/SpmRequestDispatcherAccess.java deleted file mode 100644 index 1e66c3c..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/servlet/SpmRequestDispatcherAccess.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.servlet; - -import com.sematext.spm.client.instrumentation.Getter; -import com.sematext.spm.client.instrumentation.Setter; - -public interface SpmRequestDispatcherAccess { - @Getter("_$spm_tracing$_path") - String _$spm_tracing$_get_path(); - - @Setter("_$spm_tracing$_path") - void _$spm_tracing$_set_path(String path); -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/servlet/SpmServletConfigAccess.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/servlet/SpmServletConfigAccess.java deleted file mode 100644 index 462870f..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/servlet/SpmServletConfigAccess.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.servlet; - -import com.sematext.spm.client.instrumentation.Delegate; - -public interface SpmServletConfigAccess { - @Delegate(method = "getInitParameter") - String _$spm_tracing$_getInitParameter(String k); -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/solrj4/HttpSolrServerAccess.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/solrj4/HttpSolrServerAccess.java deleted file mode 100644 index eb01172..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/solrj4/HttpSolrServerAccess.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.solrj4; - -import com.sematext.spm.client.instrumentation.Delegate; - -public interface HttpSolrServerAccess { - @Delegate(method = "getHttpClient") - Object _$spm_tracing$_getHttpClient(); -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/solrj5/HttpSolrClientAccess.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/solrj5/HttpSolrClientAccess.java deleted file mode 100644 index d6d04aa..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/solrj5/HttpSolrClientAccess.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.solrj5; - -import com.sematext.spm.client.instrumentation.Delegate; - -public interface HttpSolrClientAccess { - @Delegate(method = "getBaseURL") - String _$spm_tracing$_getBaseURL(); - - @Delegate(method = "getHttpClient") - Object _$spm_tracing$_getHttpClient(); -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/solrj5/ModifiableSolrParamsAccess.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/solrj5/ModifiableSolrParamsAccess.java deleted file mode 100644 index 171ff11..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/solrj5/ModifiableSolrParamsAccess.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.solrj5; - -import java.util.Map; - -import com.sematext.spm.client.instrumentation.Delegate; - -public interface ModifiableSolrParamsAccess { - @Delegate(method = "getMap") - Map _$spm_tracing$_getMap(); -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/solrj5/SolrAnnotationMaker.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/solrj5/SolrAnnotationMaker.java deleted file mode 100644 index b6ffa8f..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/solrj5/SolrAnnotationMaker.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.solrj5; - -import java.net.URI; -import java.net.URISyntaxException; -import java.util.HashMap; -import java.util.Map; - -import com.sematext.spm.client.tracing.agent.httpclient4.HttpClientURL; -import com.sematext.spm.client.tracing.agent.httpclient4.HttpHostAccess; -import com.sematext.spm.client.tracing.agent.httpclient4.HttpRequestAccess; -import com.sematext.spm.client.tracing.agent.model.SolrAnnotation; - -public final class SolrAnnotationMaker { - private SolrAnnotationMaker() { - } - - private static enum RequestHandler { - SCHEMA("/schema", SolrAnnotation.RequestType.SCHEMA, true), - COLLECTION_ADMIN("/admin/collections", SolrAnnotation.RequestType.COLLECTION_ADMIN, true), - CORE_ADMIN("/admin/cores", SolrAnnotation.RequestType.CORE_ADMIN, false), - UPDATE("/update", SolrAnnotation.RequestType.UPDATE, true), - SELECT("/select", SolrAnnotation.RequestType.QUERY, true), - QUERY("/query", SolrAnnotation.RequestType.QUERY, true), - DOC_ANALYSIS("/analysis/field", SolrAnnotation.RequestType.ANALYSIS, true), - FIELD_ANALYSIS("/analysis/field", SolrAnnotation.RequestType.ANALYSIS, true); - - final SolrAnnotation.RequestType type; - final String prefix; - final boolean hasCollection; - - RequestHandler(String prefix, SolrAnnotation.RequestType type, boolean hasCollection) { - this.type = type; - this.prefix = prefix; - this.hasCollection = hasCollection; - } - } - - public static SolrAnnotation fromHttpRequest(HttpHostAccess host, HttpRequestAccess request) { - return fromHTTPRequest(HttpClientURL.makeUrl(host, request._$spm_tracing$_getRequestLine())); - } - - public static SolrAnnotation fromHTTPRequest(String url) { - URI uri; - try { - uri = new URI(url); - } catch (URISyntaxException e) { - return null; - } - String path = uri.getRawPath(); - if (path == null) { - return null; - } - if (path.endsWith("/")) { - path = path.substring(0, path.length()); - } - - String collection = null; - - SolrAnnotation.RequestType requestType = SolrAnnotation.RequestType.OTHER; - - for (RequestHandler h : RequestHandler.values()) { - if (path.endsWith(h.prefix)) { - if (h.hasCollection) { - String[] paths = path.substring(0, path.lastIndexOf(h.prefix)).split("/"); - if (paths.length > 0 && !paths[paths.length - 1].isEmpty()) { - collection = paths[paths.length - 1]; - } - } - requestType = h.type; - } - } - - final SolrAnnotation annotation = new SolrAnnotation(); - annotation.setUrl(url); - annotation.setRequestType(requestType); - annotation.setCollection(collection); - - final Map params = new HashMap(); - - if (uri.getRawQuery() != null) { - String[] pairs = uri.getRawQuery().split("&"); - for (String pair : pairs) { - String[] kv = pair.split("="); - - if (kv.length == 2) { - params.put(kv[0].trim(), kv[1].trim()); - } - } - } - - annotation.setParams(params); - - return annotation; - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/solrj5/SolrHttpClient.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/solrj5/SolrHttpClient.java deleted file mode 100644 index a36379b..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/solrj5/SolrHttpClient.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.solrj5; - -import com.sematext.spm.client.tracing.agent.httpclient3.HttpClientAccess; -import com.sematext.spm.client.tracing.agent.httpclient4.AbstractHttpClientAccess; -import com.sematext.spm.client.tracing.agent.httpclient4.CloseableHttpClientAccess; - -public final class SolrHttpClient { - private SolrHttpClient() { - } - - /** - * Mark apache httpclient 4 instance as solr client - all request will be tracked as solr requests. - * - * @param httpClient http client - */ - public static void markSolrClient(CloseableHttpClientAccess httpClient) { - httpClient._$spm_tracing$_setSolrClient(true); - } - - public static void markSolrClient(AbstractHttpClientAccess httpClient) { - httpClient._$spm_tracing$_setSolrClient(true); - } - - public static void markSolrClient(HttpClientAccess httpClient) { - httpClient._$spm_tracing$_setSolrClient(true); - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/solrj5/SolrHttpClientParams.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/solrj5/SolrHttpClientParams.java deleted file mode 100644 index d3458ab..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/solrj5/SolrHttpClientParams.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.solrj5; - -public final class SolrHttpClientParams { - private SolrHttpClientParams() { - } - - public static final String SPM_SOLR_TRACING_ASYNC = "spm_solr_tracing_async"; - public static final String SPM_SOLR_TRACING_TRACE_ID = "spm_solr_tracing_trace_id"; - public static final String SPM_SOLR_TRACING_CALL_ID = "spm_solr_tracing_call_id"; - public static final String SPM_SOLR_TRACING_SAMPLED = "spm_solr_tracing_sampled"; -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/solrj5/SolrParamsAccess.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/solrj5/SolrParamsAccess.java deleted file mode 100644 index efe5c6d..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/solrj5/SolrParamsAccess.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.solrj5; - -import java.util.Iterator; - -import com.sematext.spm.client.instrumentation.Delegate; - -public interface SolrParamsAccess { - @Delegate(method = "getParameterNamesIterator") - Iterator _$spm_tracing$_getParameterNamesIterator(); - - @Delegate(method = "get") - String _$spm_tracing$_get(String key); -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/solrj5/SolrRequestAccess.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/solrj5/SolrRequestAccess.java deleted file mode 100644 index fa46bc4..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/solrj5/SolrRequestAccess.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.solrj5; - -import java.util.Collection; - -import com.sematext.spm.client.instrumentation.Delegate; - -public interface SolrRequestAccess { - @Delegate(method = "getParams") - SolrParamsAccess _$spm_tracing$_getParams(); - - @Delegate(method = "getContentStreams") - Collection _$spm_tracing$_getContentStreams(); -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/solrj5/SolrResponseBaseAccess.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/solrj5/SolrResponseBaseAccess.java deleted file mode 100644 index 276107d..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/solrj5/SolrResponseBaseAccess.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.solrj5; - -import com.sematext.spm.client.instrumentation.Delegate; - -public interface SolrResponseBaseAccess { - @Delegate(method = "getStatus") - int _$spm_tracing$_getStatus(); -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/solrj5/UpdateRequestAccess.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/solrj5/UpdateRequestAccess.java deleted file mode 100644 index 53267a7..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/solrj5/UpdateRequestAccess.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.solrj5; - -import java.util.List; - -import com.sematext.spm.client.instrumentation.Delegate; - -public interface UpdateRequestAccess extends SolrRequestAccess { - @Delegate(method = "getDocuments") - List _$spm_tracing$_getDocuments(); - - @Delegate(method = "setParam") - void _$spm_tracing$_setParam(String key, String value); -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/sql/SpmConnectionAccess.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/sql/SpmConnectionAccess.java deleted file mode 100644 index a029dce..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/sql/SpmConnectionAccess.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.sql; - -import com.sematext.spm.client.instrumentation.Getter; -import com.sematext.spm.client.instrumentation.Setter; - -public interface SpmConnectionAccess { - @Getter("_$spm_tracing$_url") - String _$spm_tracing$_url_get(); - - @Setter("_$spm_tracing$_url") - void _$spm_tracing$_url_set(String url); -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/sql/SpmPreparedStatementAccess.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/sql/SpmPreparedStatementAccess.java deleted file mode 100644 index 354f088..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/sql/SpmPreparedStatementAccess.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.sql; - -import com.sematext.spm.client.instrumentation.Getter; -import com.sematext.spm.client.instrumentation.Setter; - -public interface SpmPreparedStatementAccess { - @Getter("_$spm_tracing$_sql_query") - String _$spm_tracing$_sql_query_get(); - - @Setter("_$spm_tracing$_sql_query") - void _$spm_tracing$_sql_query_set(String query); -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/sql/SqlQueryMask.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/sql/SqlQueryMask.java deleted file mode 100644 index 61dc55a..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/sql/SqlQueryMask.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.sql; - -/** - * Simple SQL Query Parameters 'Masker'. - */ -public final class SqlQueryMask { - - private static final char SQL_SINGLE_QUOTE = '\''; - private static final char SQL_DOUBLE_QUOTE = '\"'; - private static final char SQL_BACKSLASH = '\\'; - private static final char MASK_CHAR = '?'; - private static final char UNDERSCORE = '_'; - - private SqlQueryMask() { - } - - public static String mask(String sql) { - final StringBuilder masked = new StringBuilder(); - char[] query = sql.toCharArray(); - int i = 0; - while (i < query.length) { - char c = query[i]; - if (Character.isAlphabetic(c) || c == UNDERSCORE) { //identifier/keyword: [A-Z]+[A-Z0-9\_]* - do { - masked.append(query[i++]); - } while (i < query.length && (Character.isDigit(query[i]) || Character.isAlphabetic(query[i]) - || query[i] == '_')); - } else if (Character.isDigit(c)) { - do { - i++; - } while (i < query.length && Character.isDigit(query[i])); - masked.append(MASK_CHAR); - } else if (c == SQL_SINGLE_QUOTE || c == SQL_DOUBLE_QUOTE) { - char quote = c; - do { - i++; - if (i < query.length - 1 && query[i] == quote && query[i + 1] == quote) { //escape '' - i += 2; - } else if (i < query.length - 1 && query[i] == SQL_BACKSLASH && query[i + 1] == quote) { //escape \' - i += 2; - } - } while (i < query.length && query[i] != quote); - masked.append("?"); - i++; - } else { - masked.append(c); - i++; - } - } - return masked.toString(); - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/sql/SqlQueryMetadata.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/sql/SqlQueryMetadata.java deleted file mode 100644 index 8e99914..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/sql/SqlQueryMetadata.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.sql; - -public final class SqlQueryMetadata { - private SqlQueryMetadata() { - } - - public static enum Operation { - SELECT, INSERT, DELETE, UNKNOWN; - - public static Operation fromString(String op) { - for (Operation value : values()) { - if (value.name().equalsIgnoreCase(op)) { - return value; - } - } - - return UNKNOWN; - } - } - - public static final class Metadata { - private final String table; - private final Operation operation; - - public Metadata(Operation operation, String table) { - this.operation = operation; - this.table = table; - } - - public String getTable() { - return table; - } - - public Operation getOperation() { - return operation; - } - } - - public static Metadata extract(String query) { - if (query == null) { - throw new NullPointerException(); - } - final String expr = query.trim(); - int i = expr.indexOf(" "); - if (i >= 0) { - Operation op = Operation.fromString(expr.substring(0, i)); - if (Operation.DELETE == op) { - return parseDelete(expr.substring(i).trim()); - } else if (Operation.INSERT == op) { - return parseInsert(expr.substring(i).trim()); - } else if (Operation.SELECT == op) { - return parseSelect(expr.substring(i).trim()); - } - } - - return new Metadata(Operation.UNKNOWN, null); - } - - private static Metadata parseSelect(String expr) { - return null; - } - - private static Metadata parseInsert(String expr) { - String[] tokens = expr.split("[ \t\\(\\),]"); - if (tokens.length < 2) { - return null; - } - if (!tokens[0].equalsIgnoreCase("into")) { - return null; - } - return new Metadata(Operation.INSERT, tokens[1].toLowerCase()); - } - - private static Metadata parseDelete(String expr) { - String[] tokens = expr.split("[ \t\\(\\),]"); - if (tokens.length < 2) { - return null; - } - if (!tokens[0].equalsIgnoreCase("from")) { - return null; - } - return new Metadata(Operation.DELETE, tokens[1].toLowerCase()); - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/sql/SqlStatement.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/sql/SqlStatement.java deleted file mode 100644 index 8181b3e..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/sql/SqlStatement.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.sql; - -public final class SqlStatement { - - public static enum Operation { - SELECT, DELETE, UPDATE, INSERT, OTHER - } - - private final Operation operation; - private final String table; - - public SqlStatement(Operation operation, String table) { - this.operation = operation; - this.table = table; - } - - public Operation getOperation() { - return operation; - } - - public String getTable() { - return table; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - SqlStatement sqlQuery = (SqlStatement) o; - - if (operation != sqlQuery.operation) return false; - if (table != null ? !table.equals(sqlQuery.table) : sqlQuery.table != null) return false; - - return true; - } - - @Override - public int hashCode() { - int result = operation != null ? operation.hashCode() : 0; - result = 31 * result + (table != null ? table.hashCode() : 0); - return result; - } - - @Override - public String toString() { - return "SqlStatement{" + - "operation=" + operation + - ", table='" + table + '\'' + - '}'; - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/sql/SqlStatementParser.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/sql/SqlStatementParser.java deleted file mode 100644 index dcfd328..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/sql/SqlStatementParser.java +++ /dev/null @@ -1,209 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.sql; - -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import com.sematext.spm.client.util.Preconditions; - -public final class SqlStatementParser { - - private static final Pattern TABLE_NAME_RE = Pattern - .compile("(?:(?:(?:\"(?:(?:\"\")|[^\"])*\")|(?:`(?:(?:``)|[^`])*`)|(?:[a-zA-Z][a-zA-Z0-9]*))\\.)?((?:\"(?:(?:\"\")|[^\"])*\")|(?:`(?:(?:``)|[^`])*`)|(?:[a-zA-Z][a-zA-Z0-9]*)).*", Pattern.DOTALL); - - private static final Pattern ID_BRACKETS = Pattern.compile("^[\"`](.*)[`\"]$"); - - private static final Pattern ID_BRACKETS_ESCAPE = Pattern.compile("(`){2}|(\"){2}"); - - private static final Pattern MULTILINE_COMMENT = Pattern - .compile("\\s*/\\*.*?\\*/\\s*", Pattern.MULTILINE | Pattern.DOTALL); - - private static final Pattern ONE_LINE_COMMENT = Pattern.compile("--[^\r\n]*"); - - private static interface StatementParser { - SqlStatement.Operation getOperation(); - - Pattern operationPattern(); - - String getTableName(String tail); - } - - private static abstract class BaseStatementParser implements StatementParser { - private final Pattern operationPattern; - private final SqlStatement.Operation operation; - - BaseStatementParser(String operationRE, SqlStatement.Operation operation) { - this.operationPattern = Pattern - .compile(operationRE, Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL); - this.operation = operation; - } - - @Override - public SqlStatement.Operation getOperation() { - return operation; - } - - @Override - public Pattern operationPattern() { - return operationPattern; - } - } - - private static class SelectStatementParser extends BaseStatementParser { - - private static final Pattern INNER_SELECT = Pattern - .compile(".*\\(\\s*select\\s+.*?from.*", Pattern.DOTALL | Pattern.MULTILINE | Pattern.CASE_INSENSITIVE); - - private static final Pattern JOIN = Pattern - .compile("\\s*((?:\"(?:(?:\"\")|[^\"])*\")|(?:`(?:(?:``)|[^`])*`)|(?:[a-zA-Z][a-zA-Z0-9]*)).*?(?:,|(?:join)).*", - Pattern.DOTALL | Pattern.MULTILINE | Pattern.CASE_INSENSITIVE); - - public SelectStatementParser() { - super("^\\s*(select)\\s+.*?from\\s+(.*)", SqlStatement.Operation.SELECT); - } - - @Override - public String getTableName(String tail) { - Matcher innerSelectMatcher = INNER_SELECT.matcher(tail); - if (innerSelectMatcher.matches()) { // don't extract table name in case when inner select is used - return null; - } - Matcher tableNameMatcher = TABLE_NAME_RE.matcher(tail); - if (tableNameMatcher.matches() && tableNameMatcher.groupCount() == 1) { - String fromExpr = tail.substring(tableNameMatcher.end(1)); - if (JOIN.matcher(fromExpr).matches()) { // don't extract table name in case when join is used - return null; - } - return tableNameMatcher.group(1); - } - return null; - } - } - - private static class DeleteStatementParser extends BaseStatementParser { - public DeleteStatementParser() { - super("^\\s*(delete)\\s+from\\s+(.*)", SqlStatement.Operation.DELETE); - } - - @Override - public String getTableName(String tail) { - Matcher matcher = TABLE_NAME_RE.matcher(tail); - if (matcher.matches() && matcher.groupCount() == 1) { - return matcher.group(1); - } - return null; - } - } - - private static class InsertStatementParser extends BaseStatementParser { - public InsertStatementParser() { - super("^\\s*(insert)\\s+into\\s+(.*)", SqlStatement.Operation.INSERT); - } - - @Override - public String getTableName(String tail) { - Matcher matcher = TABLE_NAME_RE.matcher(tail); - if (matcher.matches() && matcher.groupCount() == 1) { - return matcher.group(1); - } - return null; - } - } - - private static class UpdateStatementParser extends BaseStatementParser { - public UpdateStatementParser() { - super("^\\s*(update)\\s+(.*)", SqlStatement.Operation.UPDATE); - } - - @Override - public String getTableName(String tail) { - Matcher matcher = TABLE_NAME_RE.matcher(tail); - if (matcher.matches() && matcher.groupCount() == 1) { - return matcher.group(1); - } - return null; - } - } - - private static enum Parser { - SELECT(new SelectStatementParser()), - DELETE(new DeleteStatementParser()), - INSERT(new InsertStatementParser()), - UPDATE(new UpdateStatementParser()), - OTHER(new StatementParser() { - @Override - public SqlStatement.Operation getOperation() { - return SqlStatement.Operation.OTHER; - } - - @Override - public Pattern operationPattern() { - return null; - } - - @Override - public String getTableName(String tail) { - return null; - } - }); - - final StatementParser parser; - - Parser(StatementParser parser) { - this.parser = parser; - } - } - - private static String normalizeTableName(String tableName) { - Preconditions.checkNotNull(tableName, "tableName should be defined"); - - tableName = ID_BRACKETS.matcher(tableName).replaceAll("$1"); - tableName = ID_BRACKETS_ESCAPE.matcher(tableName).replaceAll("$1"); - return tableName.toLowerCase(); - } - - public static SqlStatement parse(String sql) { - Preconditions.checkNotNull(sql); - - sql = MULTILINE_COMMENT.matcher(sql).replaceAll(""); - sql = ONE_LINE_COMMENT.matcher(sql).replaceAll(""); - - for (Parser p : Parser.values()) { - final StatementParser stmtParser = p.parser; - - if (stmtParser.operationPattern() != null) { - final Matcher matcher = stmtParser.operationPattern().matcher(sql); - if (matcher.matches()) { - if (matcher.groupCount() == 2) { - String tableName = stmtParser.getTableName(matcher.group(2)); - if (tableName != null) { - tableName = normalizeTableName(tableName); - } - return new SqlStatement(stmtParser.getOperation(), tableName); - } - } - } else { - break; - } - } - return new SqlStatement(SqlStatement.Operation.OTHER, null); - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/stats/ComponentMetric.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/stats/ComponentMetric.java deleted file mode 100644 index 6139bf8..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/stats/ComponentMetric.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.stats; - -import com.sematext.spm.client.tracing.agent.model.Call; -import com.sematext.spm.client.tracing.agent.model.PartialTransaction; - -public class ComponentMetric extends Statistics.Metric { - private final DiffCounterVar countRef; - - public ComponentMetric(String component, MutableVarProvider varProvider) { - super(component); - this.countRef = varProvider.newCounter(Long.class); - } - - public Long getCount() { - return countRef.get(); - } - - @Override - protected void update(PartialTransaction transaction) { - for (Call call : transaction.getCalls()) { - if (call.getCallTag().name().equals(getId())) { - countRef.increment(1L); - break; - } - } - } - - @Override - protected void update(PartialTransaction transaction, Call call) { - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/stats/ComponentStatistics.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/stats/ComponentStatistics.java deleted file mode 100644 index c0c35c1..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/stats/ComponentStatistics.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.stats; - -public class ComponentStatistics extends Statistics { - - private final MutableVarProvider varProvider; - - public ComponentStatistics(MutableVarProvider varProvider) { - this.varProvider = varProvider; - } - - @Override - protected ComponentMetric newMetric(String component) { - return new ComponentMetric(component, varProvider); - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/stats/Counters.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/stats/Counters.java deleted file mode 100644 index 6008fc0..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/stats/Counters.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.stats; - -import java.util.Map; -import java.util.concurrent.atomic.AtomicLong; - -public interface Counters { - long incr(String key, long value); - - long incr(String key); - - Map get(); -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/stats/CrossAppCall.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/stats/CrossAppCall.java deleted file mode 100644 index 52e82ac..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/stats/CrossAppCall.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.stats; - -public interface CrossAppCall { - String srcToken(); - - String dstToken(); - - String srcHostname(); - - String dstHostname(); - - Long srcDuration(); - - Long dstDuration(); - - Long callsCount(); - - String request(); - - String tag(); -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/stats/CrossAppCallStatistics.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/stats/CrossAppCallStatistics.java deleted file mode 100644 index f9d4e83..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/stats/CrossAppCallStatistics.java +++ /dev/null @@ -1,243 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.stats; - -import java.util.Collection; -import java.util.concurrent.TimeUnit; - -import com.sematext.spm.client.tracing.agent.model.Call; -import com.sematext.spm.client.tracing.agent.model.PartialTransaction; -import com.sematext.spm.client.util.TTLCache; - -public final class CrossAppCallStatistics implements StatisticsProcessor { - private static class CrossAppCallImpl implements CrossAppCall { - private final String srcToken; - private final String dstToken; - private final String srcHostname; - private final String dstHostname; - private final DiffCounterVar srcDurationVar; - private final DiffCounterVar dstDurationVar; - private final DiffCounterVar callsCountVar; - private final String tag; - private final String request; - - public CrossAppCallImpl(MutableVarProvider provider, Id id) { - this.srcToken = id.getSrcToken(); - this.dstToken = id.getDstToken(); - this.srcHostname = id.getSrcHostname(); - this.dstHostname = id.getDstHostname(); - this.tag = id.getTag(); - this.request = id.getRequest(); - this.srcDurationVar = provider.newCounter(Long.class); - this.dstDurationVar = provider.newCounter(Long.class); - this.callsCountVar = provider.newCounter(Long.class); - } - - @Override - public String srcToken() { - return srcToken; - } - - @Override - public String dstToken() { - return dstToken; - } - - @Override - public String srcHostname() { - return srcHostname; - } - - @Override - public String dstHostname() { - return dstHostname; - } - - @Override - public Long srcDuration() { - return srcDurationVar.get(); - } - - @Override - public Long dstDuration() { - return dstDurationVar.get(); - } - - @Override - public Long callsCount() { - return callsCountVar.get(); - } - - @Override - public String request() { - return request; - } - - @Override - public String tag() { - return tag; - } - - public void update(Long srcDuration, Long dstDuration) { - this.srcDurationVar.increment(srcDuration); - this.dstDurationVar.increment(dstDuration); - this.callsCountVar.increment(1L); - } - } - - private static class Id { - private final String srcToken; - private final String dstToken; - private final String srcHostname; - private final String dstHostname; - private final String tag; - private final String request; - - public Id(String request, String tag, String dstHostname, String srcHostname, String dstToken, String srcToken) { - this.request = request; - this.tag = tag; - this.dstHostname = dstHostname; - this.srcHostname = srcHostname; - this.dstToken = dstToken; - this.srcToken = srcToken; - } - - public String getSrcToken() { - return srcToken; - } - - public String getDstToken() { - return dstToken; - } - - public String getSrcHostname() { - return srcHostname; - } - - public String getDstHostname() { - return dstHostname; - } - - public String getTag() { - return tag; - } - - public String getRequest() { - return request; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - Id id = (Id) o; - - if (dstHostname != null ? !dstHostname.equals(id.dstHostname) : id.dstHostname != null) return false; - if (dstToken != null ? !dstToken.equals(id.dstToken) : id.dstToken != null) return false; - if (request != null ? !request.equals(id.request) : id.request != null) return false; - if (srcHostname != null ? !srcHostname.equals(id.srcHostname) : id.srcHostname != null) return false; - if (srcToken != null ? !srcToken.equals(id.srcToken) : id.srcToken != null) return false; - if (tag != null ? !tag.equals(id.tag) : id.tag != null) return false; - - return true; - } - - @Override - public int hashCode() { - int result = srcToken != null ? srcToken.hashCode() : 0; - result = 31 * result + (dstToken != null ? dstToken.hashCode() : 0); - result = 31 * result + (srcHostname != null ? srcHostname.hashCode() : 0); - result = 31 * result + (dstHostname != null ? dstHostname.hashCode() : 0); - result = 31 * result + (tag != null ? tag.hashCode() : 0); - result = 31 * result + (request != null ? request.hashCode() : 0); - return result; - } - } - - private final MutableVarProvider mutableVarProvider; - private final TTLCache calls = new TTLCache(TimeUnit.MINUTES.toMillis(2)); - - public CrossAppCallStatistics(MutableVarProvider mutableVarProvider) { - this.mutableVarProvider = mutableVarProvider; - } - - public boolean update(PartialTransaction transaction, Call call) { - if (call.getCrossAppCallId() == null || call.getCrossAppEndpoint() == null) { - return false; - } - - String tag = null; - if (call.getCallTag() != null) { - tag = call.getCallTag().name(); - } - - final Id id = new Id(call.getCrossAppRequest(), tag, call.getCrossAppEndpoint().getHostname(), transaction - .getEndpoint().getHostname(), - call.getCrossAppToken(), transaction.getToken()); - - CrossAppCallImpl crossAppCall = (CrossAppCallImpl) calls.get(id); - if (crossAppCall == null) { - crossAppCall = new CrossAppCallImpl(mutableVarProvider, id); - - CrossAppCallImpl existing = (CrossAppCallImpl) calls.putIfAbsent(id, crossAppCall); - if (existing != null) { - crossAppCall = existing; - } - } - - crossAppCall.update(call.getDuration(), call.getCrossAppDuration()); - return true; - } - - @Override - public void process(PartialTransaction transaction) { - for (Call call : transaction.getCalls()) { - if (call.getCrossAppCallId() == null || call.getCrossAppEndpoint() == null) { - continue; - } - - String tag = null; - if (call.getCallTag() != null) { - tag = call.getCallTag().name(); - } - - final Id id = new Id(call.getCrossAppRequest(), tag, call.getCrossAppEndpoint().getHostname(), transaction - .getEndpoint().getHostname(), - call.getCrossAppToken(), transaction.getToken()); - - CrossAppCallImpl crossAppCall = (CrossAppCallImpl) calls.get(id); - if (crossAppCall == null) { - crossAppCall = new CrossAppCallImpl(mutableVarProvider, id); - - CrossAppCallImpl existing = (CrossAppCallImpl) calls.putIfAbsent(id, crossAppCall); - if (existing != null) { - crossAppCall = existing; - } - } - - crossAppCall.update(call.getDuration(), call.getCrossAppDuration()); - } - } - - public Collection getCrossAppCalls() { - return calls.values(); - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/stats/DatabaseOperation.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/stats/DatabaseOperation.java deleted file mode 100644 index ab1032f..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/stats/DatabaseOperation.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.stats; - -public final class DatabaseOperation { - private final String database; - private final String operation; - - public DatabaseOperation(String database, String operation) { - this.database = database; - this.operation = operation; - } - - public String getDatabase() { - return database; - } - - public String getOperation() { - return operation; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - DatabaseOperation that = (DatabaseOperation) o; - - if (database != null ? !database.equals(that.database) : that.database != null) return false; - if (operation != null ? !operation.equals(that.operation) : that.operation != null) return false; - - return true; - } - - @Override - public int hashCode() { - int result = database != null ? database.hashCode() : 0; - result = 31 * result + (operation != null ? operation.hashCode() : 0); - return result; - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/stats/DatabaseOperationMetric.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/stats/DatabaseOperationMetric.java deleted file mode 100644 index 64c95f9..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/stats/DatabaseOperationMetric.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.stats; - -import static com.sematext.spm.client.tracing.agent.model.Call.CallTag.ES; -import static com.sematext.spm.client.tracing.agent.model.Call.CallTag.SOLR; -import static com.sematext.spm.client.tracing.agent.model.Call.CallTag.SQL_QUERY; - -import com.sematext.spm.client.tracing.agent.model.Call; -import com.sematext.spm.client.tracing.agent.model.PartialTransaction; - -public class DatabaseOperationMetric extends Statistics.Metric { - private final DiffCounterVar countVar; - private final DiffCounterVar durationVar; - - public DatabaseOperationMetric(DatabaseOperation operation, MutableVarProvider provider) { - super(operation); - this.countVar = provider.newCounter(Long.class); - this.durationVar = provider.newCounter(Long.class); - } - - public Long count() { - return countVar.get(); - } - - public Long duration() { - return durationVar.get(); - } - - @Override - protected void update(PartialTransaction transaction) { - } - - @Override - protected void update(PartialTransaction transaction, Call call) { - if ((call.getCallTag() == SOLR || call.getCallTag() == ES || call.getCallTag() == SQL_QUERY) - && call.getAnnotation() != null) { - countVar.increment(1L); - durationVar.increment(call.getDuration()); - } - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/stats/DatabaseOperationStatistics.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/stats/DatabaseOperationStatistics.java deleted file mode 100644 index 3a1b65a..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/stats/DatabaseOperationStatistics.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.stats; - -import com.sematext.spm.client.tracing.agent.model.Call; -import com.sematext.spm.client.tracing.agent.model.PartialTransaction; -import com.sematext.spm.client.tracing.agent.model.SolrAnnotation; -import com.sematext.spm.client.tracing.agent.model.annotation.ESAnnotation; -import com.sematext.spm.client.tracing.agent.model.annotation.SQLAnnotation; - -public class DatabaseOperationStatistics extends Statistics - implements StatisticsProcessor { - private final MutableVarProvider provider; - - public DatabaseOperationStatistics(MutableVarProvider provider) { - this.provider = provider; - } - - @Override - protected DatabaseOperationMetric newMetric(DatabaseOperation operation) { - return new DatabaseOperationMetric(operation, provider); - } - - @Override - public void process(PartialTransaction transaction) { - for (final Call call : transaction.getCalls()) { - if (call.getCallTag() == Call.CallTag.SOLR) { - SolrAnnotation annotation = (SolrAnnotation) call.getAnnotation(); - if (annotation != null) { - update(new DatabaseOperation("SOLR", annotation.getRequestType().name()), transaction, call); - } - } else if (call.getCallTag() == Call.CallTag.ES) { - ESAnnotation annotation = (ESAnnotation) call.getAnnotation(); - if (annotation != null) { - update(new DatabaseOperation("ELASTICSEARCH", annotation.getRequestType().name()), transaction, call); - } - } else if (call.getCallTag() == Call.CallTag.SQL_QUERY) { - SQLAnnotation annotation = (SQLAnnotation) call.getAnnotation(); - if (annotation != null) { - update(new DatabaseOperation("SQL", annotation.getOperation().name()), transaction, call); - } - } - } - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/stats/DiffCounterVar.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/stats/DiffCounterVar.java deleted file mode 100644 index c083e44..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/stats/DiffCounterVar.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.stats; - -public interface DiffCounterVar { - T increment(T diff); - - T get(); -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/stats/ExternalCall.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/stats/ExternalCall.java deleted file mode 100644 index 13bfe29..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/stats/ExternalCall.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.stats; - -public interface ExternalCall { - String srcToken(); - - String srcHostname(); - - String dstHostname(); - - Long callsCount(); - - Long duration(); - - String tag(); -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/stats/ExternalCallStatistics.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/stats/ExternalCallStatistics.java deleted file mode 100644 index c02119b..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/stats/ExternalCallStatistics.java +++ /dev/null @@ -1,263 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.stats; - -import static com.sematext.spm.client.tracing.agent.model.Call.CallTag.ES; -import static com.sematext.spm.client.tracing.agent.model.Call.CallTag.HTTP_REQUEST; -import static com.sematext.spm.client.tracing.agent.model.Call.CallTag.SOLR; -import static com.sematext.spm.client.tracing.agent.model.Call.CallTag.SQL_QUERY; - -import java.net.MalformedURLException; -import java.net.URL; -import java.util.Collection; -import java.util.concurrent.TimeUnit; - -import com.sematext.spm.client.tracing.agent.model.Call; -import com.sematext.spm.client.tracing.agent.model.PartialTransaction; -import com.sematext.spm.client.tracing.agent.model.SolrAnnotation; -import com.sematext.spm.client.tracing.agent.model.annotation.ESAnnotation; -import com.sematext.spm.client.tracing.agent.model.annotation.HTTPRequestAnnotation; -import com.sematext.spm.client.tracing.agent.model.annotation.SQLAnnotation; -import com.sematext.spm.client.tracing.agent.util.JdbcURL; -import com.sematext.spm.client.util.TTLCache; - -public final class ExternalCallStatistics implements StatisticsProcessor { - private static class ExternalCallImpl implements ExternalCall { - private final String srcToken; - private final String srcHostname; - private final String dstHostname; - private final String tag; - private final DiffCounterVar callsCountVar; - private final DiffCounterVar durationVar; - - public ExternalCallImpl(MutableVarProvider varProvider, Id id) { - this.srcToken = id.getSrcToken(); - this.srcHostname = id.getSrcHostname(); - this.dstHostname = id.getDstHostname(); - this.tag = id.getTag(); - this.callsCountVar = varProvider.newCounter(Long.class); - this.durationVar = varProvider.newCounter(Long.class); - } - - @Override - public String srcToken() { - return srcToken; - } - - @Override - public String srcHostname() { - return srcHostname; - } - - @Override - public String dstHostname() { - return dstHostname; - } - - @Override - public Long callsCount() { - return callsCountVar.get(); - } - - @Override - public Long duration() { - return durationVar.get(); - } - - @Override - public String tag() { - return tag; - } - - public void update(Long duration) { - this.durationVar.increment(duration); - this.callsCountVar.increment(1L); - } - } - - private static class Id { - private final String srcToken; - private final String srcHostname; - private final String dstHostname; - private final String tag; - - public Id(String srcToken, String srcHostname, String dstHostname, String tag) { - this.srcToken = srcToken; - this.srcHostname = srcHostname; - this.dstHostname = dstHostname; - this.tag = tag; - } - - public String getSrcToken() { - return srcToken; - } - - public String getSrcHostname() { - return srcHostname; - } - - public String getDstHostname() { - return dstHostname; - } - - public String getTag() { - return tag; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - Id id = (Id) o; - - if (dstHostname != null ? !dstHostname.equals(id.dstHostname) : id.dstHostname != null) return false; - if (srcHostname != null ? !srcHostname.equals(id.srcHostname) : id.srcHostname != null) return false; - if (srcToken != null ? !srcToken.equals(id.srcToken) : id.srcToken != null) return false; - if (tag != null ? !tag.equals(id.tag) : id.tag != null) return false; - - return true; - } - - @Override - public int hashCode() { - int result = srcToken != null ? srcToken.hashCode() : 0; - result = 31 * result + (srcHostname != null ? srcHostname.hashCode() : 0); - result = 31 * result + (dstHostname != null ? dstHostname.hashCode() : 0); - result = 31 * result + (tag != null ? tag.hashCode() : 0); - return result; - } - } - - private final MutableVarProvider varProvider; - private final TTLCache calls = new TTLCache(TimeUnit.MINUTES.toMillis(2)); - - public ExternalCallStatistics(MutableVarProvider varProvider) { - this.varProvider = varProvider; - } - - public boolean update(PartialTransaction transaction, Call call) { - if (call.isSkipExternalTracingStatistics()) { - return false; - } - - final String dstHostname = getDstHostname(call); - if (dstHostname == null) { - return false; - } - String tag = null; - if (call.getCallTag() != null) { - tag = call.getCallTag().name(); - } - final Id id = new Id(transaction.getToken(), transaction.getEndpoint().getHostname(), dstHostname, tag); - ExternalCallImpl externalCall = (ExternalCallImpl) calls.get(id); - if (externalCall == null) { - externalCall = new ExternalCallImpl(varProvider, id); - ExternalCallImpl existing = (ExternalCallImpl) calls.putIfAbsent(id, externalCall); - if (existing != null) { - externalCall = existing; - } - } - externalCall.update(call.getDuration()); - return true; - } - - public Collection getExternalCalls() { - return calls.values(); - } - - private String getDstHostname(Call call) { - if (call.getCrossAppCallId() != null) { - return null; - } - - if (HTTP_REQUEST == call.getCallTag()) { - HTTPRequestAnnotation annotation = (HTTPRequestAnnotation) call.getAnnotation(); - if (annotation == null) { - return null; - } - try { - return new URL(annotation.getUrl()).getHost(); - } catch (Exception e) { - return null; - } - } else if (ES == call.getCallTag()) { - ESAnnotation annotation = (ESAnnotation) call.getAnnotation(); - if (annotation == null) { - return null; - } - if (annotation.getAddresses().isEmpty()) { - return null; - } - return annotation.getAddresses().get(0).getHost(); - } else if (SQL_QUERY == call.getCallTag()) { - SQLAnnotation annotation = (SQLAnnotation) call.getAnnotation(); - if (annotation == null) { - return null; - } - if (annotation.getUrl() == null) { - return null; - } - return JdbcURL.getHostname(annotation.getUrl()); - } else if (SOLR == call.getCallTag()) { - SolrAnnotation annotation = (SolrAnnotation) call.getAnnotation(); - if (annotation == null) { - return null; - } - if (annotation.getUrl() == null) { - return null; - } - try { - return new URL(annotation.getUrl()).getHost(); - } catch (MalformedURLException e) { - return null; - } - } - return null; - } - - @Override - public void process(PartialTransaction transaction) { - for (Call call : transaction.getCalls()) { - if (call.isSkipExternalTracingStatistics()) { - continue; - } - - final String dstHostname = getDstHostname(call); - if (dstHostname == null) { - continue; - } - String tag = null; - if (call.getCallTag() != null) { - tag = call.getCallTag().name(); - } - final Id id = new Id(transaction.getToken(), transaction.getEndpoint().getHostname(), dstHostname, tag); - ExternalCallImpl externalCall = (ExternalCallImpl) calls.get(id); - if (externalCall == null) { - externalCall = new ExternalCallImpl(varProvider, id); - ExternalCallImpl existing = (ExternalCallImpl) calls.putIfAbsent(id, externalCall); - if (existing != null) { - externalCall = existing; - } - } - externalCall.update(call.getDuration()); - } - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/stats/MutableVarProvider.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/stats/MutableVarProvider.java deleted file mode 100644 index 47c5958..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/stats/MutableVarProvider.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.stats; - -public interface MutableVarProvider { - > DiffCounterVar newCounter(C klass); -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/stats/NoOpTracingStatistics.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/stats/NoOpTracingStatistics.java deleted file mode 100644 index 105df29..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/stats/NoOpTracingStatistics.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.stats; - -import java.util.Collection; -import java.util.Collections; - -import com.sematext.spm.client.tracing.agent.model.PartialTransaction; - -public final class NoOpTracingStatistics implements TracingStatistics { - private NoOpTracingStatistics() { - } - - private static final NoOpTracingStatistics INSTANCE = new NoOpTracingStatistics(); - - public static TracingStatistics noOp() { - return INSTANCE; - } - - private static final StatisticsView EMPTY_VIEW = new StatisticsView() { - @Override - public Collection crossAppCalls() { - return Collections.emptyList(); - } - - @Override - public Collection externalCalls() { - return Collections.emptyList(); - } - - @Override - public Collection requestMetrics() { - return Collections.emptyList(); - } - - @Override - public Collection requestComponentMetrics() { - return Collections.emptyList(); - } - - @Override - public Collection requestErrorMetrics() { - return Collections.emptyList(); - } - - @Override - public Collection databaseOperationMetrics() { - return Collections.emptyList(); - } - }; - - @Override - public void record(PartialTransaction transaction) { - } - - @Override - public StatisticsView newCallStatisticsView(MutableVarProvider varProvider) { - return EMPTY_VIEW; - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/stats/PathCounters.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/stats/PathCounters.java deleted file mode 100644 index 0259481..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/stats/PathCounters.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.stats; - -import java.util.Map; - -public interface PathCounters { - long incr(String seg1, String seg2, long value); - - long incr(String seg1, String seg2); - - Map get(); -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/stats/RequestComponentMetric.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/stats/RequestComponentMetric.java deleted file mode 100644 index 2d5ab54..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/stats/RequestComponentMetric.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.stats; - -import com.sematext.spm.client.tracing.agent.model.Call; -import com.sematext.spm.client.tracing.agent.model.PartialTransaction; - -public class RequestComponentMetric extends Statistics.Metric { - private final DiffCounterVar countVar; - private final DiffCounterVar durationVar; - - public RequestComponentMetric(RequestComponentStatistics.RequestComponent requestComponent, - MutableVarProvider varProvider) { - super(requestComponent); - this.countVar = varProvider.newCounter(Long.class); - this.durationVar = varProvider.newCounter(Long.class); - } - - public Long getCount() { - return countVar.get(); - } - - public Long getDuration() { - return durationVar.get(); - } - - @Override - protected void update(PartialTransaction transaction) { - } - - @Override - protected void update(PartialTransaction transaction, Call call) { - countVar.increment(1L); - durationVar.increment(call.getSelfDuration()); - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/stats/RequestComponentStatistics.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/stats/RequestComponentStatistics.java deleted file mode 100644 index 62b87dd..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/stats/RequestComponentStatistics.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.stats; - -import com.sematext.spm.client.tracing.agent.model.Call; -import com.sematext.spm.client.tracing.agent.model.PartialTransaction; - -public class RequestComponentStatistics - extends Statistics - implements StatisticsProcessor { - public static class RequestComponent { - private final String request; - private final String component; - - public RequestComponent(String request, String component) { - this.request = request; - this.component = component; - } - - public String getRequest() { - return request; - } - - public String getComponent() { - return component; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - RequestComponent requestComponent = (RequestComponent) o; - - if (component != null ? !component.equals(requestComponent.component) : requestComponent.component != null) - return false; - if (request != null ? !request.equals(requestComponent.request) : requestComponent.request != null) return false; - - return true; - } - - @Override - public int hashCode() { - int result = request != null ? request.hashCode() : 0; - result = 31 * result + (component != null ? component.hashCode() : 0); - return result; - } - } - - private final MutableVarProvider varProvider; - - public RequestComponentStatistics(MutableVarProvider varProvider) { - this.varProvider = varProvider; - } - - @Override - protected RequestComponentMetric newMetric(RequestComponent requestComponent) { - return new RequestComponentMetric(requestComponent, varProvider); - } - - @Override - public void process(PartialTransaction transaction) { - for (Call call : transaction.getCalls()) { - final RequestComponentStatistics.RequestComponent component = - new RequestComponentStatistics.RequestComponent(transaction.getRequest(), call.getCallTag().name()); - update(component, transaction, call); - } - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/stats/RequestErrorsMetric.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/stats/RequestErrorsMetric.java deleted file mode 100644 index bbc04b3..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/stats/RequestErrorsMetric.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.stats; - -import com.sematext.spm.client.tracing.agent.model.Call; -import com.sematext.spm.client.tracing.agent.model.FailureType; -import com.sematext.spm.client.tracing.agent.model.Http; -import com.sematext.spm.client.tracing.agent.model.PartialTransaction; -import com.sematext.spm.client.tracing.agent.model.WebTransactionSummary; - -public class RequestErrorsMetric extends Statistics.Metric { - private final DiffCounterVar exceptionsCountVar; - private final DiffCounterVar responseCode5xxCountVar; - private final DiffCounterVar responseCode4xxCountVar; - private final DiffCounterVar errorsCountVar; - - public RequestErrorsMetric(String request, MutableVarProvider provider) { - super(request); - this.exceptionsCountVar = provider.newCounter(Long.class); - this.responseCode5xxCountVar = provider.newCounter(Long.class); - this.responseCode4xxCountVar = provider.newCounter(Long.class); - this.errorsCountVar = provider.newCounter(Long.class); - } - - public Long getExceptionsCount() { - return exceptionsCountVar.get(); - } - - public Long getResponseCode5xxCount() { - return responseCode5xxCountVar.get(); - } - - public Long getResponseCode4xxCount() { - return responseCode4xxCountVar.get(); - } - - public Long getErrorsCount() { - return errorsCountVar.get(); - } - - private void updateHttpResponseStatusStatistics(PartialTransaction transaction) { - final WebTransactionSummary summary = (WebTransactionSummary) transaction.getTransactionSummary(); - if (summary != null) { - if (Http.is4xx(summary.getResponseCode())) { - responseCode4xxCountVar.increment(1L); - } else if (Http.is5xx(summary.getResponseCode())) { - responseCode5xxCountVar.increment(1L); - } - } - } - - @Override - protected void update(PartialTransaction transaction) { - if (transaction.isEntryPoint()) { - if (transaction.isFailed()) { - errorsCountVar.increment(1L); - - if (FailureType.EXCEPTION.equals(transaction.getFailureType())) { - exceptionsCountVar.increment(1L); - if (Call.TransactionType.WEB.equals(transaction.getTransactionType())) { - updateHttpResponseStatusStatistics(transaction); - } - } else if (FailureType.HTTP_RESPONSE.equals(transaction.getFailureType())) { - updateHttpResponseStatusStatistics(transaction); - } - } - } - } - - @Override - protected void update(PartialTransaction transaction, Call call) { - - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/stats/RequestErrorsStatistics.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/stats/RequestErrorsStatistics.java deleted file mode 100644 index 8cf2315..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/stats/RequestErrorsStatistics.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.stats; - -import com.sematext.spm.client.tracing.agent.model.PartialTransaction; - -public class RequestErrorsStatistics extends Statistics implements StatisticsProcessor { - private final MutableVarProvider provider; - - public RequestErrorsStatistics(MutableVarProvider provider) { - this.provider = provider; - } - - @Override - protected RequestErrorsMetric newMetric(String request) { - return new RequestErrorsMetric(request, provider); - } - - @Override - public void process(PartialTransaction transaction) { - update(transaction.getRequest(), transaction); - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/stats/RequestMetric.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/stats/RequestMetric.java deleted file mode 100644 index 0c4dff6..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/stats/RequestMetric.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.stats; - -import com.sematext.spm.client.tracing.agent.model.Call; -import com.sematext.spm.client.tracing.agent.model.PartialTransaction; - -public class RequestMetric extends Statistics.Metric { - private final DiffCounterVar countVar; - private final DiffCounterVar durationVar; - - public RequestMetric(String request, MutableVarProvider varProvider) { - super(request); - this.countVar = varProvider.newCounter(Long.class); - this.durationVar = varProvider.newCounter(Long.class); - } - - public Long getCount() { - return countVar.get(); - } - - public Long getDuration() { - return durationVar.get(); - } - - @Override - protected void update(PartialTransaction transaction) { - } - - @Override - protected void update(PartialTransaction transaction, Call call) { - if (call.isEntryPoint()) { - countVar.increment(1L); - durationVar.increment(call.getDuration()); - } - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/stats/RequestStatistics.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/stats/RequestStatistics.java deleted file mode 100644 index a1b26b6..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/stats/RequestStatistics.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.stats; - -import com.sematext.spm.client.tracing.agent.model.Call; -import com.sematext.spm.client.tracing.agent.model.PartialTransaction; - -public class RequestStatistics extends Statistics implements StatisticsProcessor { - - private final MutableVarProvider varProvider; - - public RequestStatistics(MutableVarProvider varProvider) { - this.varProvider = varProvider; - } - - @Override - protected RequestMetric newMetric(String request) { - return new RequestMetric(request, varProvider); - } - - @Override - public void process(PartialTransaction transaction) { - for (Call call : transaction.getCalls()) { - update(transaction.getRequest(), transaction, call); - } - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/stats/Statistics.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/stats/Statistics.java deleted file mode 100644 index 51909bb..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/stats/Statistics.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.stats; - -import java.util.Collection; -import java.util.concurrent.TimeUnit; - -import com.sematext.spm.client.tracing.agent.model.Call; -import com.sematext.spm.client.tracing.agent.model.PartialTransaction; -import com.sematext.spm.client.util.TTLCache; - -public abstract class Statistics> { - public static abstract class Metric { - private final ID id; - - public Metric(ID id) { - this.id = id; - } - - public ID getId() { - return id; - } - - protected abstract void update(PartialTransaction transaction); - - protected abstract void update(PartialTransaction transaction, Call call); - } - - private final TTLCache metrics = new TTLCache(TimeUnit.MINUTES.toMillis(2)); - - protected abstract M newMetric(ID id); - - private M getOrCreateMetric(ID id) { - M metric = metrics.get(id); - if (metric == null) { - metric = newMetric(id); - M existing = metrics.putIfAbsent(id, metric); - if (existing != null) { - metric = existing; - } - } else { - metrics.touch(id); - } - return metric; - } - - public final void update(ID id, PartialTransaction transaction, Call call) { - getOrCreateMetric(id).update(transaction, call); - } - - public final void update(ID id, PartialTransaction transaction) { - getOrCreateMetric(id).update(transaction); - } - - public final Collection values() { - return metrics.values(); - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/stats/StatisticsProcessor.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/stats/StatisticsProcessor.java deleted file mode 100644 index dd984bb..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/stats/StatisticsProcessor.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.stats; - -import com.sematext.spm.client.tracing.agent.model.PartialTransaction; - -public interface StatisticsProcessor { - void process(PartialTransaction transaction); -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/stats/StatisticsView.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/stats/StatisticsView.java deleted file mode 100644 index 95a13e0..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/stats/StatisticsView.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.stats; - -import java.util.Collection; - -public interface StatisticsView { - Collection crossAppCalls(); - - Collection externalCalls(); - - Collection requestMetrics(); - - Collection requestComponentMetrics(); - - Collection requestErrorMetrics(); - - Collection databaseOperationMetrics(); -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/stats/TracingStatistics.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/stats/TracingStatistics.java deleted file mode 100644 index 9b41f9d..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/stats/TracingStatistics.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.stats; - -import com.sematext.spm.client.tracing.agent.model.PartialTransaction; - -public interface TracingStatistics { - void record(PartialTransaction transaction); - - StatisticsView newCallStatisticsView(MutableVarProvider varProvider); -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/test/HttpService.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/test/HttpService.java deleted file mode 100644 index 128afc6..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/test/HttpService.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.test; - -import java.lang.reflect.Method; - -import com.sematext.spm.client.util.ReflectionUtils; - -public final class HttpService { - - private final JDBCService service; - - public HttpService(JDBCService jdbcService) { - this.service = jdbcService; - } - - private String executeSQL(String sql) { - final Method execute = ReflectionUtils.getMethod(service.getClass(), "execute", String.class); - ReflectionUtils.silentInvoke(execute, service, sql); - return sql; - } - - public void service(Request request, Response response) throws Exception { - if (request.getContextPath().endsWith("/user/") && request.getMethod().equals("GET")) { - executeSQL("select * from user"); - response.respond("ok", 200); - } else if (request.getContextPath().endsWith("/user/1") && request.getMethod().equals("GET")) { - executeSQL("select * from user where id = 1"); - response.respond("ok", 200); - } else if (request.getContextPath().endsWith("/user/") && request.getMethod().equals("POST")) { - executeSQL("insert into user(...) values (...)"); - response.respond("ok", 201); - } else if (request.getContextPath().endsWith("/user/1") && request.getMethod().equals("POST")) { - executeSQL("update user set ..."); - response.respond("ok", 200); - } else if (request.getContextPath().equals("/list/")) { - response.redirect("/user/"); - } else { - response.respond("error", 400); - } - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/test/JDBCService.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/test/JDBCService.java deleted file mode 100644 index ffcbc2f..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/test/JDBCService.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.test; - -public class JDBCService { - public String execute(String sql) { - return "result"; - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/test/Request.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/test/Request.java deleted file mode 100644 index 1651e0c..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/test/Request.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.test; - -public class Request { - private final String contextPath; - private final String method; - - public Request(String contextPath, String method) { - this.contextPath = contextPath; - this.method = method; - } - - public String getContextPath() { - return contextPath; - } - - public String getMethod() { - return method; - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/test/Response.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/test/Response.java deleted file mode 100644 index d326632..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/test/Response.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.test; - -public class Response { - private String content; - private int code; - private String redirect; - - public void respond(String content, int code) { - this.content = content; - this.code = code; - } - - public void redirect(String redirect) { - this.redirect = redirect; - } - - public String getContent() { - return content; - } - - public int getCode() { - return code; - } - - public String getRedirect() { - return redirect; - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/tomcat/TomcatResponseHeaders.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/tomcat/TomcatResponseHeaders.java deleted file mode 100644 index 81d5e89..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/tomcat/TomcatResponseHeaders.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.tomcat; - -import java.lang.reflect.Method; - -import com.sematext.spm.client.tracing.agent.ResponseHeaders; -import com.sematext.spm.client.util.ReflectionUtils; - -public class TomcatResponseHeaders implements ResponseHeaders { - private final Object response; - - public TomcatResponseHeaders(Object response) { - this.response = response; - } - - @Override - public void addHeader(String name, String value) { - final Method method = ReflectionUtils.getMethod(response.getClass(), "setHeader", String.class, String.class); - ReflectionUtils.silentInvoke(method, response, name, value); - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/tracer/Tracer.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/tracer/Tracer.java deleted file mode 100644 index 1c7f8b8..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/tracer/Tracer.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.tracer; - -import java.util.Collection; - -import com.sematext.spm.client.tracing.agent.config.Config; -import com.sematext.spm.client.tracing.agent.transformation.TracingTransform; -import com.sematext.spm.client.unlogger.Logspect; - -public interface Tracer { - String getName(); - - Collection createLogspects(ClassLoader loader); - - TracingTransform[] getStructuralTransforms(); - - boolean enabled(Config config); -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/tracer/Tracers.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/tracer/Tracers.java deleted file mode 100644 index 913f018..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/tracer/Tracers.java +++ /dev/null @@ -1,663 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.tracer; - -import java.util.Collection; - -import com.sematext.spm.client.tracing.agent.config.Config; -import com.sematext.spm.client.tracing.agent.es.transport.*; -import com.sematext.spm.client.tracing.agent.httpclient3.HeaderAccess; -import com.sematext.spm.client.tracing.agent.httpclient3.HostConfigurationAccess; -import com.sematext.spm.client.tracing.agent.httpclient3.HttpClientAccess; -import com.sematext.spm.client.tracing.agent.httpclient3.HttpMethodAccess; -import com.sematext.spm.client.tracing.agent.httpclient3.HttpMethodDirectorAccess; -import com.sematext.spm.client.tracing.agent.httpclient4.AbstractHttpClientAccess; -import com.sematext.spm.client.tracing.agent.httpclient4.CloseableHttpClientAccess; -import com.sematext.spm.client.tracing.agent.httpclient4.Header4Access; -import com.sematext.spm.client.tracing.agent.httpclient4.HttpHostAccess; -import com.sematext.spm.client.tracing.agent.httpclient4.HttpMessageAccess; -import com.sematext.spm.client.tracing.agent.httpclient4.HttpRequestAccess; -import com.sematext.spm.client.tracing.agent.httpclient4.HttpResponseAccess; -import com.sematext.spm.client.tracing.agent.httpclient4.RequestLineAccess; -import com.sematext.spm.client.tracing.agent.httpclient4.StatusLineAccess; -import com.sematext.spm.client.tracing.agent.jpa.SpmQueryAccess; -import com.sematext.spm.client.tracing.agent.pointcuts.custom.TracedMethodPointcut; -import com.sematext.spm.client.tracing.agent.pointcuts.es.transport.ActionRequestBuilderCtorPointcut; -import com.sematext.spm.client.tracing.agent.pointcuts.es.transport.ActionRequestBuilderExecutePointcut; -import com.sematext.spm.client.tracing.agent.pointcuts.es.transport.AdapterActionFuturePointcut; -import com.sematext.spm.client.tracing.agent.pointcuts.es.transport.PlainListenableActionFuturePointcut; -import com.sematext.spm.client.tracing.agent.pointcuts.es.transport.SearchRequestPointcut; -import com.sematext.spm.client.tracing.agent.pointcuts.httpclient3.HttpClientPointcut; -import com.sematext.spm.client.tracing.agent.pointcuts.httpclient3.HttpMethodDirectorPointcut; -import com.sematext.spm.client.tracing.agent.pointcuts.httpclient4.CloseableHttpClientPointcut; -import com.sematext.spm.client.tracing.agent.pointcuts.httpclient42.AbstractHttpClientPointcut; -import com.sematext.spm.client.tracing.agent.pointcuts.jaxrs.JaxRsRequestMappingPointcut; -import com.sematext.spm.client.tracing.agent.pointcuts.jdbc.JDBCConnectionPrepareStatementPointcut; -import com.sematext.spm.client.tracing.agent.pointcuts.jdbc.JDBCDriverPointcut; -import com.sematext.spm.client.tracing.agent.pointcuts.jdbc.JDBCPreparedStatementPointcut; -import com.sematext.spm.client.tracing.agent.pointcuts.jdbc.JDBCStatementPointcut; -import com.sematext.spm.client.tracing.agent.pointcuts.jersey.ResponseWriterPointcut; -import com.sematext.spm.client.tracing.agent.pointcuts.jetty7.Jetty73HttpConnectionPointcut; -import com.sematext.spm.client.tracing.agent.pointcuts.jetty8.AbstractHttpConnectionPointcut; -import com.sematext.spm.client.tracing.agent.pointcuts.jetty9.HttpConnectionPointcut; -import com.sematext.spm.client.tracing.agent.pointcuts.jpa.JpaEntityManagerFindPointcut; -import com.sematext.spm.client.tracing.agent.pointcuts.jpa.JpaEntityManagerPersistPointcut; -import com.sematext.spm.client.tracing.agent.pointcuts.jpa.JpaEntityManagerQueryPointcut; -import com.sematext.spm.client.tracing.agent.pointcuts.jpa.JpaQueryPointcut; -import com.sematext.spm.client.tracing.agent.pointcuts.servlet.GetRequestDispatcherPointcut; -import com.sematext.spm.client.tracing.agent.pointcuts.servlet.RequestDispatcherPointcut; -import com.sematext.spm.client.tracing.agent.pointcuts.servlet.ServletPointcut; -import com.sematext.spm.client.tracing.agent.pointcuts.solrj4.ConcurrentUpdateSolrServerPointcut; -import com.sematext.spm.client.tracing.agent.pointcuts.solrj4.HttpSolrServerCtorPointcut; -import com.sematext.spm.client.tracing.agent.pointcuts.solrj5.ConcurrentUpdateSolrClientPointcut; -import com.sematext.spm.client.tracing.agent.pointcuts.solrj5.HttpSolrClientCtorPointcut; -import com.sematext.spm.client.tracing.agent.pointcuts.spring.SpringRequestMappingPointcut; -import com.sematext.spm.client.tracing.agent.pointcuts.thread.ExecutorServiceInvokePointcut; -import com.sematext.spm.client.tracing.agent.pointcuts.thread.ExecutorServiceSubmitPointcut; -import com.sematext.spm.client.tracing.agent.pointcuts.thread.RunnableAndCallablePointcut; -import com.sematext.spm.client.tracing.agent.pointcuts.thread.ThreadPointcut; -import com.sematext.spm.client.tracing.agent.pointcuts.tomcat.ResponsePointcut; -import com.sematext.spm.client.tracing.agent.pointcuts.url.URLConnectionPointcut; -import com.sematext.spm.client.tracing.agent.servlet.SpmAsyncEventAccess; -import com.sematext.spm.client.tracing.agent.servlet.SpmGenericServletAccess; -import com.sematext.spm.client.tracing.agent.servlet.SpmHttpServletRequestAccess; -import com.sematext.spm.client.tracing.agent.servlet.SpmHttpServletResponseAccess; -import com.sematext.spm.client.tracing.agent.servlet.SpmRequestDispatcherAccess; -import com.sematext.spm.client.tracing.agent.servlet.SpmServletConfigAccess; -import com.sematext.spm.client.tracing.agent.solrj4.HttpSolrServerAccess; -import com.sematext.spm.client.tracing.agent.solrj5.HttpSolrClientAccess; -import com.sematext.spm.client.tracing.agent.solrj5.SolrParamsAccess; -import com.sematext.spm.client.tracing.agent.solrj5.SolrRequestAccess; -import com.sematext.spm.client.tracing.agent.solrj5.SolrResponseBaseAccess; -import com.sematext.spm.client.tracing.agent.solrj5.UpdateRequestAccess; -import com.sematext.spm.client.tracing.agent.sql.SpmConnectionAccess; -import com.sematext.spm.client.tracing.agent.sql.SpmPreparedStatementAccess; -import com.sematext.spm.client.tracing.agent.transformation.TracingTransform; -import com.sematext.spm.client.tracing.agent.transformation.transforms.MixinTransform; -import com.sematext.spm.client.unlogger.Logspect; - -public enum Tracers { - INTER_THREAD_COMMUNICATION(new InterThreadCommunication()), - JDBC(new JDBCTracer()), - JPA(new JpaTracer()), - SERVLET(new ServletTracer()), - JAVA_NET_URL(new JavaNetURLTracer()), - HTTP_CLIENT_3(new HttpClient3Tracer()), - HTTP_CLIENT_4(new HttpClient4Tracer()), - HTTP_CLIENT_4_2(new HttpClient42Tracer()), - SPRING_FRAMEWORK(new SpringFrameworkTracer()), - JAX_RS(new JaxRsTracer()), - TRACED_METHODS(new TracedMethodsTracer()), - JETTY(new JettyTracer()), - TOMCAT(new TomcatTracer()), - ES_TRANSPORT_CLIENT(new ESTransportClient()), - SOLR_7_CLIENT(new Solrj7Tracer()), - SOLR_6_CLIENT(new Solrj6Tracer()), - SOLR_5_CLIENT(new Solrj5Tracer()), - SOLR_4_CLIENT(new Solrj4Tracer()); - - private final Tracer tracer; - - Tracers(Tracer tracer) { - this.tracer = tracer; - } - - public Tracer getTracer() { - return tracer; - } - - private static abstract class BaseTracer implements Tracer { - public abstract String[] getUnloggers(); - - @Override - public Collection createLogspects(ClassLoader loader) { - return Logspect.make(getUnloggers(), loader); - } - } - - public static class InterThreadCommunication extends BaseTracer { - @Override - public String getName() { - return "inter-thread"; - } - - @Override - public String[] getUnloggers() { - return new String[] { - RunnableAndCallablePointcut.class.getName(), - ThreadPointcut.class.getName(), - ExecutorServiceSubmitPointcut.class.getName(), - ExecutorServiceInvokePointcut.class.getName() - }; - } - - @Override - public TracingTransform[] getStructuralTransforms() { - return new TracingTransform[0]; - } - - @Override - public boolean enabled(Config config) { - return config.isThreadInstrumentationEnabled(); - } - } - - public static class JavaNetURLTracer extends BaseTracer { - - @Override - public String getName() { - return "java-net-url"; - } - - @Override - public String[] getUnloggers() { - return new String[] { URLConnectionPointcut.class.getName() }; - } - - @Override - public TracingTransform[] getStructuralTransforms() { - return new TracingTransform[] {}; - } - - @Override - public boolean enabled(Config config) { - return true; - } - } - - public static class HttpClient3Tracer extends BaseTracer { - @Override - public String getName() { - return "http-client-3-tracer"; - } - - @Override - public String[] getUnloggers() { - return new String[] { - HttpClientPointcut.class.getName(), - HttpMethodDirectorPointcut.class.getName() - }; - } - - @Override - public TracingTransform[] getStructuralTransforms() { - return new TracingTransform[] { - new MixinTransform("org.apache.commons.httpclient.Header", HeaderAccess.class), - new MixinTransform("org.apache.commons.httpclient.HostConfiguration", HostConfigurationAccess.class), - new MixinTransform("org.apache.commons.httpclient.HttpMethod", HttpMethodAccess.class), - new MixinTransform("org.apache.commons.httpclient.HttpMethodDirector", HttpMethodDirectorAccess.class), - new MixinTransform("org.apache.commons.httpclient.HttpClient", HttpClientAccess.class) - }; - } - - @Override - public boolean enabled(Config config) { - return true; - } - } - - public static class HttpClient4Tracer extends BaseTracer { - @Override - public String getName() { - return "http-client-4-tracer"; - } - - @Override - public String[] getUnloggers() { - return new String[] { - CloseableHttpClientPointcut.class.getName() - }; - } - - @Override - public TracingTransform[] getStructuralTransforms() { - return new TracingTransform[] { - new MixinTransform("org.apache.http.Header", Header4Access.class), - new MixinTransform("org.apache.http.HttpHost", HttpHostAccess.class), - new MixinTransform("org.apache.http.HttpMessage", HttpMessageAccess.class), - new MixinTransform("org.apache.http.HttpRequest", HttpRequestAccess.class), - new MixinTransform("org.apache.http.HttpResponse", HttpResponseAccess.class), - new MixinTransform("org.apache.http.RequestLine", RequestLineAccess.class), - new MixinTransform("org.apache.http.StatusLine", StatusLineAccess.class), - new MixinTransform("org.apache.http.impl.client.CloseableHttpClient", CloseableHttpClientAccess.class) - }; - } - - @Override - public boolean enabled(Config config) { - return true; - } - } - - public static class HttpClient42Tracer extends BaseTracer { - @Override - public String getName() { - return "http-client-4.2-tracer"; - } - - @Override - public String[] getUnloggers() { - return new String[] { - AbstractHttpClientPointcut.class.getName() - }; - } - - @Override - public TracingTransform[] getStructuralTransforms() { - return new TracingTransform[] { - new MixinTransform("org.apache.http.Header", Header4Access.class), - new MixinTransform("org.apache.http.HttpHost", HttpHostAccess.class), - new MixinTransform("org.apache.http.HttpMessage", HttpMessageAccess.class), - new MixinTransform("org.apache.http.HttpRequest", HttpRequestAccess.class), - new MixinTransform("org.apache.http.HttpResponse", HttpResponseAccess.class), - new MixinTransform("org.apache.http.RequestLine", RequestLineAccess.class), - new MixinTransform("org.apache.http.StatusLine", StatusLineAccess.class), - new MixinTransform("org.apache.http.impl.client.AbstractHttpClient", AbstractHttpClientAccess.class) - }; - } - - @Override - public boolean enabled(Config config) { - return true; - } - } - - public static class JDBCTracer extends BaseTracer { - - @Override - public String getName() { - return "jdbc"; - } - - @Override - public String[] getUnloggers() { - return new String[] { - JDBCDriverPointcut.class.getName(), - JDBCStatementPointcut.class.getName(), - JDBCPreparedStatementPointcut.class.getName(), - JDBCConnectionPrepareStatementPointcut.class.getName() - }; - } - - @Override - public TracingTransform[] getStructuralTransforms() { - return new TracingTransform[] { - new MixinTransform("java.sql.Connection", SpmConnectionAccess.class), - new MixinTransform("java.sql.PreparedStatement", SpmPreparedStatementAccess.class) - }; - } - - @Override - public boolean enabled(Config config) { - return true; - } - - } - - public static class ServletTracer extends BaseTracer { - - @Override - public String getName() { - return "servlet"; - } - - @Override - public String[] getUnloggers() { - return new String[] { - ServletPointcut.class.getName(), - GetRequestDispatcherPointcut.class.getName(), - RequestDispatcherPointcut.class.getName() - }; - } - - @Override - public TracingTransform[] getStructuralTransforms() { - return new TracingTransform[] { - new MixinTransform("javax.servlet.http.HttpServletRequest", SpmHttpServletRequestAccess.class), - new MixinTransform("javax.servlet.http.HttpServletResponse", SpmHttpServletResponseAccess.class), - new MixinTransform("javax.servlet.RequestDispatcher", SpmRequestDispatcherAccess.class), - new MixinTransform("javax.servlet.AsyncEvent", SpmAsyncEventAccess.class), - new MixinTransform("javax.servlet.GenericServlet", SpmGenericServletAccess.class), - new MixinTransform("javax.servlet.ServletConfig", SpmServletConfigAccess.class) - }; - } - - @Override - public boolean enabled(Config config) { - return true; - } - } - - public static class TracedMethodsTracer extends BaseTracer { - - @Override - public String getName() { - return "annotation"; - } - - @Override - public String[] getUnloggers() { - return new String[] { TracedMethodPointcut.class.getName() }; - } - - @Override - public TracingTransform[] getStructuralTransforms() { - return new TracingTransform[0]; - } - - @Override - public boolean enabled(Config config) { - return true; - } - - } - - public static class SpringFrameworkTracer extends BaseTracer { - @Override - public String getName() { - return "spring-framework"; - } - - @Override - public String[] getUnloggers() { - return new String[] { SpringRequestMappingPointcut.class.getName() }; - } - - @Override - public TracingTransform[] getStructuralTransforms() { - return new TracingTransform[0]; - } - - @Override - public boolean enabled(Config config) { - return true; - } - } - - public static class JpaTracer extends BaseTracer { - @Override - public String getName() { - return "jpa"; - } - - @Override - public String[] getUnloggers() { - return new String[] { - JpaEntityManagerQueryPointcut.class.getName(), - JpaEntityManagerFindPointcut.class.getName(), - JpaEntityManagerPersistPointcut.class.getName(), - JpaQueryPointcut.class.getName() - }; - } - - @Override - public TracingTransform[] getStructuralTransforms() { - return new TracingTransform[] { - new MixinTransform("javax.persistence.Query", SpmQueryAccess.class) - }; - } - - @Override - public boolean enabled(Config config) { - return true; - } - } - - public static class JaxRsTracer extends BaseTracer { - @Override - public String[] getUnloggers() { - return new String[] { - JaxRsRequestMappingPointcut.class.getName(), - ResponseWriterPointcut.class.getName() - }; - } - - @Override - public String getName() { - return "jax-rs"; - } - - @Override - public TracingTransform[] getStructuralTransforms() { - return new TracingTransform[0]; - } - - @Override - public boolean enabled(Config config) { - return true; - } - } - - public static class JettyTracer extends BaseTracer { - @Override - public String getName() { - return "jetty"; - } - - @Override - public String[] getUnloggers() { - return new String[] { - Jetty73HttpConnectionPointcut.class.getName(), - HttpConnectionPointcut.class.getName(), - AbstractHttpConnectionPointcut.class.getName() - }; - } - - @Override - public TracingTransform[] getStructuralTransforms() { - return new TracingTransform[0]; - } - - @Override - public boolean enabled(Config config) { - return true; - } - } - - public static class TomcatTracer extends BaseTracer { - @Override - public String getName() { - return "tomcat"; - } - - @Override - public String[] getUnloggers() { - return new String[] { - ResponsePointcut.class.getName() - }; - } - - @Override - public TracingTransform[] getStructuralTransforms() { - return new TracingTransform[0]; - } - - @Override - public boolean enabled(Config config) { - return true; - } - } - - public static class ESTransportClient extends BaseTracer { - @Override - public String getName() { - return "es-transport-client"; - } - - @Override - public String[] getUnloggers() { - return new String[] { - ActionRequestBuilderExecutePointcut.class.getName(), - AdapterActionFuturePointcut.class.getName(), - PlainListenableActionFuturePointcut.class.getName(), - SearchRequestPointcut.class.getName(), - ActionRequestBuilderCtorPointcut.class.getName() - }; - } - - @Override - public TracingTransform[] getStructuralTransforms() { - return new TracingTransform[] { - new MixinTransform("org.elasticsearch.action.support.AdapterActionFuture", SpmListenableActionFutureAccess.class), - new MixinTransform("org.elasticsearch.action.index.IndexRequest", SpmIndexRequestAccess.class), - new MixinTransform("org.elasticsearch.action.ActionRequestBuilder", SpmActionRequestBuilderAccess.class), - new MixinTransform("org.elasticsearch.support.replication.ShardReplicationOperationRequest", SpmShardReplicationOperationRequestAccess.class), - new MixinTransform("org.elasticsearch.action.delete.DeleteRequest", SpmDeleteRequestAccess.class), - new MixinTransform("org.elasticsearch.action.search.SearchRequest", SpmSearchRequestAccess.class), - new MixinTransform("org.elasticsearch.action.update.UpdateRequest", SpmUpdateRequestAccess.class), - new MixinTransform("org.elasticsearch.action.get.GetRequest", SpmGetRequestAccess.class), - new MixinTransform("org.elasticsearch.action.bulk.BulkRequest", SpmBulkRequestAccess.class), - new MixinTransform("org.elasticsearch.action.support.single.instance.InstanceShardOperationRequest", SpmInstanceShardOperationRequestAccess.class), - new MixinTransform("org.elasticsearch.action.support.single.shard.SingleShardOperationRequest", SpmSingleShardOperationRequestAccess.class) - }; - } - - @Override - public boolean enabled(Config config) { - return true; - } - } - - public static class Solrj7Tracer extends BaseTracer { - @Override - public String[] getUnloggers() { - return new String[] { - com.sematext.spm.client.tracing.agent.pointcuts.solrj7.HttpSolrClientCtorPointcut.class.getName(), - ConcurrentUpdateSolrClientPointcut.class.getName() - }; - } - - @Override - public String getName() { - return "solr-7-client"; - } - - @Override - public TracingTransform[] getStructuralTransforms() { - return new TracingTransform[]{ - new MixinTransform("org.apache.solr.common.params.SolrParams", SolrParamsAccess.class), - new MixinTransform("org.apache.solr.client.solrj.impl.HttpSolrClient", HttpSolrClientAccess.class), - new MixinTransform("org.apache.solr.client.solrj.SolrRequest", SolrRequestAccess.class), - new MixinTransform("org.apache.solr.client.solrj.request.UpdateRequest", UpdateRequestAccess.class), - new MixinTransform("org.apache.solr.client.solrj.response.SolrResponseBase", SolrResponseBaseAccess.class) - }; - } - - @Override - public boolean enabled(Config config) { - return true; - } - } - - public static class Solrj6Tracer extends BaseTracer { - - @Override - public String[] getUnloggers() { - return new String[] { - com.sematext.spm.client.tracing.agent.pointcuts.solrj6.HttpSolrClientCtorPointcut.class.getName(), - ConcurrentUpdateSolrClientPointcut.class.getName() - - }; - } - - @Override - public String getName() { - return "solr-6-client"; - } - - @Override - public TracingTransform[] getStructuralTransforms() { - return new TracingTransform[] { - new MixinTransform("org.apache.solr.common.params.SolrParams", SolrParamsAccess.class), - new MixinTransform("org.apache.solr.client.solrj.impl.HttpSolrClient", HttpSolrClientAccess.class), - new MixinTransform("org.apache.solr.client.solrj.SolrRequest", SolrRequestAccess.class), - new MixinTransform("org.apache.solr.client.solrj.request.UpdateRequest", UpdateRequestAccess.class), - new MixinTransform("org.apache.solr.client.solrj.response.SolrResponseBase", SolrResponseBaseAccess.class) - }; - } - - @Override - public boolean enabled(Config config) { - return true; - } - } - - public static class Solrj5Tracer extends BaseTracer { - @Override - public String[] getUnloggers() { - return new String[] { - HttpSolrClientCtorPointcut.class.getName(), - ConcurrentUpdateSolrClientPointcut.class.getName() - }; - } - - @Override - public String getName() { - return "solr-52-client"; - } - - @Override - public TracingTransform[] getStructuralTransforms() { - return new TracingTransform[] { - new MixinTransform("org.apache.solr.common.params.SolrParams", SolrParamsAccess.class), - new MixinTransform("org.apache.solr.client.solrj.impl.HttpSolrClient", HttpSolrClientAccess.class), - new MixinTransform("org.apache.solr.client.solrj.SolrRequest", SolrRequestAccess.class), - new MixinTransform("org.apache.solr.client.solrj.request.UpdateRequest", UpdateRequestAccess.class), - new MixinTransform("org.apache.solr.client.solrj.response.SolrResponseBase", SolrResponseBaseAccess.class) - }; - } - - @Override - public boolean enabled(Config config) { - return true; - } - } - - public static class Solrj4Tracer extends BaseTracer { - @Override - public String[] getUnloggers() { - return new String[] { - HttpSolrServerCtorPointcut.class.getName(), - ConcurrentUpdateSolrServerPointcut.class.getName() - }; - } - - @Override - public String getName() { - return "solr-4-client"; - } - - @Override - public TracingTransform[] getStructuralTransforms() { - return new TracingTransform[] { - new MixinTransform("org.apache.solr.common.params.SolrParams", SolrParamsAccess.class), - new MixinTransform("org.apache.solr.client.solrj.impl.HttpSolrServer", HttpSolrServerAccess.class), - new MixinTransform("org.apache.solr.client.solrj.SolrRequest", SolrRequestAccess.class), - new MixinTransform("org.apache.solr.client.solrj.request.UpdateRequest", UpdateRequestAccess.class), - new MixinTransform("org.apache.solr.client.solrj.response.SolrResponseBase", SolrResponseBaseAccess.class) - }; - } - - @Override - public boolean enabled(Config config) { - return true; - } - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/transformation/TracingClassDynamicTransformer.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/transformation/TracingClassDynamicTransformer.java deleted file mode 100644 index 7d85cd1..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/transformation/TracingClassDynamicTransformer.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.transformation; - -import java.io.ByteArrayInputStream; -import java.lang.instrument.IllegalClassFormatException; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import com.sematext.spm.client.Log; -import com.sematext.spm.client.LogFactory; -import com.sematext.spm.client.unlogger.Pointcut; -import com.sematext.spm.client.unlogger.dynamic.DynamicTransformer; -import com.sematext.spm.client.util.ClassPools; -import com.sematext.spm.client.util.InstrumentationUtils; - -import javassist.CtClass; - -public final class TracingClassDynamicTransformer implements DynamicTransformer { - - private static final Log LOG = LogFactory.getLog(TracingClassDynamicTransformer.class); - - private final List transforms; - - public TracingClassDynamicTransformer(List transforms) { - this.transforms = transforms; - } - - @Override - public void reload(Map additionalPointcuts) { - - } - - @Override - public Set getWeavedClasses() { - return Collections.emptySet(); - } - - @Override - public byte[] transform(Parameters p) throws IllegalClassFormatException { - final long time = System.currentTimeMillis(); - try { - final CtClass ctClass = new ClassPools().getClassPool(p.getLoader()) - .makeClass(new ByteArrayInputStream(p.getClassfileBuffer())); - if (LOG.isTraceEnabled()) { - LOG.trace("Attempt to transform: " + ctClass.getName()); - } - final Set hierarchy = InstrumentationUtils.getHierarchy(ctClass); - boolean transformed = false; - for (final TracingTransform transform : transforms) { - if (transform.transform(ctClass, hierarchy)) { - transformed = true; - } - } - if (transformed) { - p.getStatistics().getTotalClassesLoaded().incrementAndGet(); - return ctClass.toBytecode(); - } - return null; - } catch (Throwable e) { - if (LOG.isTraceEnabled()) { - LOG.trace("Error while retransforming " + p.getClassName() + ".", e); - } - return null; - } finally { - p.getStatistics().getTransformationTimeSpentMs().addAndGet(System.currentTimeMillis() - time); - } - - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/transformation/TracingClassTransformer.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/transformation/TracingClassTransformer.java deleted file mode 100644 index 9a9172c..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/transformation/TracingClassTransformer.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.transformation; - -import java.io.ByteArrayInputStream; -import java.lang.instrument.ClassFileTransformer; -import java.lang.instrument.IllegalClassFormatException; -import java.security.ProtectionDomain; -import java.util.List; -import java.util.Set; - -import com.sematext.spm.client.Log; -import com.sematext.spm.client.LogFactory; -import com.sematext.spm.client.util.ClassPools; -import com.sematext.spm.client.util.InstrumentationUtils; - -import javassist.CtClass; - -public class TracingClassTransformer implements ClassFileTransformer { - - private static final Log LOG = LogFactory.getLog(TracingClassTransformer.class); - - private final List transforms; - - public TracingClassTransformer(List transforms) { - this.transforms = transforms; - } - - @Override - public byte[] transform(ClassLoader loader, String className, Class klass, - ProtectionDomain prot, byte[] buff) throws IllegalClassFormatException { - - try { - final CtClass ctClass = new ClassPools().getClassPool(loader).makeClass(new ByteArrayInputStream(buff)); - if (LOG.isTraceEnabled()) { - LOG.trace("Attempt to transform: " + ctClass.getName()); - } - final Set hierarchy = InstrumentationUtils.getHierarchy(ctClass); - boolean transformed = false; - for (final TracingTransform transform : transforms) { - if (transform.transform(ctClass, hierarchy)) { - transformed = true; - } - } - if (transformed) { - return ctClass.toBytecode(); - } - return null; - } catch (Throwable e) { - if (LOG.isTraceEnabled()) { - LOG.trace("Error while retransforming " + className + ".", e); - } - return null; - } - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/transformation/TracingTransform.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/transformation/TracingTransform.java deleted file mode 100644 index 4418e10..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/transformation/TracingTransform.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.transformation; - -import java.util.Set; - -import javassist.CtClass; - -public interface TracingTransform { - boolean transform(CtClass ctClass, Set hierarchy); -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/transformation/transforms/MixinTransform.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/transformation/transforms/MixinTransform.java deleted file mode 100644 index d6aef09..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/transformation/transforms/MixinTransform.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.transformation.transforms; - -import java.util.Set; - -import com.sematext.spm.client.Log; -import com.sematext.spm.client.LogFactory; -import com.sematext.spm.client.MonitorUtil; -import com.sematext.spm.client.instrumentation.Mixins; -import com.sematext.spm.client.tracing.agent.transformation.TracingTransform; - -import javassist.CtClass; - -public final class MixinTransform implements TracingTransform { - private static final Log LOG = LogFactory.getLog(MixinTransform.class); - - private final String target; - private final Class iface; - - public MixinTransform(String target, Class iface) { - this.target = target; - this.iface = iface; - } - - public Class getIface() { - return iface; - } - - @Override - public boolean transform(CtClass ctClass, Set hierarchy) { - if (!ctClass.isInterface() && hierarchy.contains(target)) { - try { - final boolean transformed = Mixins.mixin(ctClass, iface); - if (LOG.isDebugEnabled()) { - LOG.debug("Performed mixin transform for " + ctClass.getName() + ", (" + iface + ")"); - } - return transformed; - } catch (Exception e) { - if (MonitorUtil.JAVA_MAJOR_VERSION >= 9) { - if (LOG.isDebugEnabled()) { - LOG.debug("Can't perform mixin transform for " + ctClass.getName() + ", ( " + iface + "), error was: " + e - .getMessage()); - } - } else { - LOG.error("Can't perform mixin transform for " + ctClass.getName() + ", ( " + iface + ").", e); - } - } - } - return false; - } - - @Override - public String toString() { - return "Mixin transform { " + target + ", " + iface + " }"; - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/util/AsyncContext.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/util/AsyncContext.java deleted file mode 100644 index 6f44f61..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/util/AsyncContext.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.util; - -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; - -public final class AsyncContext { - private final Long traceId; - private final Long parentCallId; - private final boolean sampled; - - private static final class IdentityKey { - private final Object key; - private final int hashCode; - - public IdentityKey(Object key) { - this.key = key; - this.hashCode = System.identityHashCode(key); - } - - @Override - public boolean equals(Object obj) { - if (obj == this) return true; - if (obj == null || getClass() != obj.getClass()) return false; - return this.key == ((IdentityKey) obj).key; - } - - @Override - public int hashCode() { - return hashCode; - } - } - - private AsyncContext(Long traceId, Long parentCallId, boolean sampled) { - this.traceId = traceId; - this.parentCallId = parentCallId; - this.sampled = sampled; - } - - public Long getTraceId() { - return traceId; - } - - public Long getParentCallId() { - return parentCallId; - } - - public boolean isSampled() { - return sampled; - } - - private static final Map CONTEXT = new ConcurrentHashMap(); - - public static AsyncContext create(Object th, Long traceId, Long parentCallId, boolean sampled) { - final AsyncContext ctx = new AsyncContext(traceId, parentCallId, sampled); - CONTEXT.put(new IdentityKey(th), ctx); - return ctx; - } - - public static AsyncContext get(Object th) { - return CONTEXT.get(new IdentityKey(th)); - } - - public static AsyncContext clean(Object th) { - return CONTEXT.remove(new IdentityKey(th)); - } - - @Override - public String toString() { - return "AsyncContext{" + - "traceId=" + traceId + - ", parentCallId=" + parentCallId + - ", sampled=" + sampled + - '}'; - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/util/BinaryLog.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/util/BinaryLog.java deleted file mode 100644 index f286718..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/util/BinaryLog.java +++ /dev/null @@ -1,138 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.util; - -import java.io.BufferedOutputStream; -import java.io.DataOutputStream; -import java.io.File; -import java.io.FileDescriptor; -import java.io.FileOutputStream; -import java.io.IOException; - -import com.sematext.spm.client.Log; -import com.sematext.spm.client.LogFactory; - -public class BinaryLog { - private static final Log LOG = LogFactory.getLog(BinaryLog.class); - private DataOutputStream daos; - private FileDescriptor fd; - private final String baseDir; - private final String fileName; - private final long maxSize; - private final int maxBackups; - private long size; - private final File file; - - public BinaryLog(String baseDir, String fileName, long maxSize, int maxBackups) { - this.baseDir = baseDir; - this.fileName = fileName; - this.maxSize = maxSize; - this.maxBackups = maxBackups; - this.file = new File(baseDir, fileName); - this.size = file.length(); - - Runtime.getRuntime().addShutdownHook(new Thread() { - @Override - public void run() { - if (daos != null) { - try { - fd.sync(); - daos.close(); - } catch (IOException e) { - /* */ - } - } - } - }); - } - - private static void stderr(String msg) { - LOG.error(msg); - } - - private void maybeRollup() { - if (daos == null || size <= maxSize) { - return; - } - - final File oldestLog = new File(baseDir, fileName + "." + (maxBackups - 1)); - if (oldestLog.exists()) { - if (!oldestLog.delete()) { - stderr("Can't delete oldest file: " + oldestLog + "."); - } - } - - for (int i = maxBackups - 2; i >= 0; i--) { - final File rotatedFile = new File(baseDir, fileName + "." + i); - if (rotatedFile.exists()) { - int k = i + 1; - if (!rotatedFile.renameTo(new File(baseDir, fileName + "." + k))) { - stderr("Can't rotate file: " + rotatedFile + "."); - } - } - } - - try { - daos.close(); - daos = null; - } catch (IOException e) { - stderr("Can't close file " + file + " descriptor."); - } - - if (!file.renameTo(new File(baseDir, fileName + ".0"))) { - stderr("Can't rotate file: " + file + "."); - } - } - - public synchronized void write(byte[] b, int off, int len) { - maybeRollup(); - - if (daos == null) { - try { - final FileOutputStream fos = new FileOutputStream(file); - fd = fos.getFD(); - daos = new DataOutputStream(new BufferedOutputStream(fos, 1024)); - size = file.length(); - } catch (IOException e) { - stderr(": Can't create output stream for " + file + "."); - return; - } - } - - try { - daos.writeInt(len); - daos.write(b, off, len); - size += b.length; - } catch (IOException e) { - stderr("Can't write to log."); - - if (daos != null) { - try { - daos.close(); - } catch (IOException e1) { /* */ } - daos = null; - } - } - } - - public synchronized void write(byte[] b) { - write(b, 0, b.length); - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/util/BinarySequentialLog.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/util/BinarySequentialLog.java deleted file mode 100644 index a4710ff..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/util/BinarySequentialLog.java +++ /dev/null @@ -1,182 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.util; - -import java.io.BufferedOutputStream; -import java.io.DataOutputStream; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.util.ArrayDeque; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -import com.sematext.spm.client.Log; -import com.sematext.spm.client.LogFactory; - -public final class BinarySequentialLog { - private static final Log LOG = LogFactory.getLog(BinarySequentialLog.class); - - private final String baseDir; - private final String prefix; - private final String suffix; - private final long maxSize; - private final int retentionCount; - private int seqNo; - private DataOutputStream daos; - private long size; - private final ArrayDeque files; - - private BinarySequentialLog(String baseDir, String prefix, String suffix, long maxSize, int retentionCount, int seqNo, - ArrayDeque files) { - this.baseDir = baseDir; - this.prefix = prefix; - this.suffix = suffix; - this.maxSize = maxSize; - this.retentionCount = retentionCount; - this.seqNo = seqNo; - this.files = files; - } - - private static void stderr(String msg) { - LOG.error(msg); - } - - private File seqFile() { - return seqFile(seqNo); - } - - private File seqFile(int seqNo) { - return new File(baseDir, prefix + "-" + seqNo + suffix); - } - - private void cleanup() { - if (daos == null || size < maxSize) { - return; - } - - try { - daos.close(); - } catch (IOException e) { - stderr("Can't close file " + seqFile() + "."); - } - - daos = null; - - while (files.size() > retentionCount) { - File file = files.pop(); - try { - if (!file.delete()) { - stderr("Can't delete file " + file + "."); - } - } catch (Exception e) { - stderr("Can't delete file " + file + "."); - } - } - - seqNo++; - } - - public synchronized void write(byte[] b, int off, int len) { - cleanup(); - - if (daos == null) { - BufferedOutputStream bos = null; - try { - bos = new BufferedOutputStream(new FileOutputStream(seqFile()), 1024); - files.addLast(seqFile()); - } catch (IOException e) { - stderr("Can't create file " + seqFile() + "."); - return; - } - daos = new DataOutputStream(bos); - - size = 0; - } - - try { - daos.writeInt(len); - daos.write(b, off, len); - - size += 4; - size += len; - } catch (IOException e) { - stderr("Can't write to log " + seqFile() + "."); - try { - daos.close(); - } catch (IOException e1) { - stderr("Can't close file " + seqFile() + "."); - } - daos = null; - seqNo++; - } - } - - public synchronized void write(byte[] b) { - write(b, 0, b.length); - } - - // protected for tests - synchronized void flush() { - if (daos != null) { - try { - daos.flush(); - } catch (IOException e) { - stderr("Can't flush file."); - } - } - } - - public static BinarySequentialLog create(String baseDir, String prefix, String suffix, long maxSize, - int retentionCount) { - final List seqNumbers = new ArrayList(); - final File dir = new File(baseDir); - if (dir.isDirectory()) { - for (File file : dir.listFiles()) { - if (!file.isFile()) { - continue; - } - final String name = file.getName(); - if (name.startsWith(prefix) && name.endsWith(suffix)) { - final String seqNumber = name.substring(prefix.length() + 1, name.length() - suffix.length()); - int seqNo; - try { - seqNo = Integer.parseInt(seqNumber); - } catch (NumberFormatException e) { - continue; - } - seqNumbers.add(seqNo); - } - } - } - Collections.sort(seqNumbers); - final ArrayDeque existing = new ArrayDeque(); - for (Integer seqNo : seqNumbers) { - existing.addLast(new File(baseDir, prefix + "-" + seqNo + suffix)); - } - int maxSeqNo = -1; - if (!seqNumbers.isEmpty()) { - maxSeqNo = seqNumbers.get(seqNumbers.size() - 1); - } - return new BinarySequentialLog(baseDir, prefix, suffix, maxSize, retentionCount, maxSeqNo + 1, existing); - } - -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/util/Counter.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/util/Counter.java deleted file mode 100644 index 7b7bc8f..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/util/Counter.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.util; - -import com.sematext.spm.client.Log; -import com.sematext.spm.client.LogFactory; - -public class Counter { - private static final Log LOG = LogFactory.getLog(Counter.class); - - public static void boom() { - LOG.info("boom!"); - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/util/Hostname.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/util/Hostname.java deleted file mode 100644 index e51cc4f..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/util/Hostname.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.util; - -import java.net.InetAddress; -import java.net.UnknownHostException; - -import com.sematext.spm.client.tracing.agent.model.Endpoint; - -public final class Hostname { - private Hostname() { - } - - public static Endpoint getLocalEndpoint() { - try { - final InetAddress localHost = InetAddress.getLocalHost(); - return new Endpoint(localHost.getHostAddress(), localHost.getHostName()); - } catch (UnknownHostException e) { - /* */ - return null; - } - } - -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/util/JSON.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/util/JSON.java deleted file mode 100644 index e11f694..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/util/JSON.java +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.util; - -import java.io.IOException; -import java.io.Writer; - -public final class JSON { - private JSON() { - } - - /* Simple JSON writer without validation */ - public static class JSONWriter { - private static final String QUOTE = "\""; - private final Writer writer; - private boolean startObject = true; - - public JSONWriter(final Writer to) { - this.writer = to; - } - - public void writeObjectStart() { - begin(); - write("{"); - } - - public void writeKey(String key) { - begin(); - string(key); - write(":"); - } - - public void writeInt(int value) { - write(String.valueOf(value)); - end(); - } - - public void writeLong(long value) { - write(String.valueOf(value)); - end(); - } - - public void writeString(String value) { - string(value); - end(); - } - - public void writeKeyValue(String key, String value) { - if (value != null) { - writeKey(key); - writeString(value); - } - } - - public void writeKeyValue(String key, int value) { - writeKey(key); - writeInt(value); - } - - public void writeKeyValue(String key, long value) { - writeKey(key); - writeLong(value); - } - - public void writeArrayStart() { - begin(); - write("["); - } - - public void writeArrayEnd() { - write("]"); - end(); - } - - public void writeObjectEnd() { - write("}"); - end(); - } - - private void begin() { - if (!startObject) { - write(","); - } - startObject = true; - } - - private void end() { - startObject = false; - } - - private void string(String v) { - write(QUOTE + escape(v) + QUOTE); - } - - private static String escape(String val) { - if (val == null) { - return val; - } - // TODO replace with something faster - look at Gson's JsonWriter - return val.replaceAll("\"", "\\\\\"").replaceAll("\n", "\\\\n"); - } - - private void write(String str) { - try { - writer.write(str); - } catch (IOException e) { - throw new RuntimeException("Can't write.", e); - } - } - } - -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/util/JdbcURL.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/util/JdbcURL.java deleted file mode 100644 index 8b1fe35..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/util/JdbcURL.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.util; - -public final class JdbcURL { - private JdbcURL() { - } - - public static String getHostname(String url) { - int i = 0; - char[] urlChars = url.toCharArray(); - while (i < urlChars.length && urlChars[i] != '/') { - i++; - } - if (i < urlChars.length - 1 && urlChars[i] == '/' && urlChars[i + 1] == '/') { - i += 2; - } else { - return null; - } - final StringBuilder hostname = new StringBuilder(); - for (; i < urlChars.length && urlChars[i] != ':' && urlChars[i] != '/'; i++) { - hostname.append(urlChars[i]); - } - return hostname.toString(); - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/util/LocalVar.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/util/LocalVar.java deleted file mode 100644 index c17f889..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/util/LocalVar.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.util; - -import java.util.Map; - -import com.sematext.spm.client.tracing.agent.Trace; -import com.sematext.spm.client.tracing.agent.Tracing; -import com.sematext.spm.client.unlogger.utils.ConcurrentWeakHashMap; - -public final class LocalVar { - private LocalVar() { - } - - private static final Map vars = new ConcurrentWeakHashMap(); - - public static void put(Thread thread, Trace tracing) { - vars.put(thread, tracing); - } - - public static void put(Thread thread) { - put(thread, Tracing.current()); - } - - public static void preStart() { - try { - Trace t = vars.get(Thread.currentThread()); - if (t != null) { - Tracing.setTrace(t.fork()); - } - } catch (Exception e) { /* */ } - } - - public static void postStart() { - try { - vars.remove(Thread.currentThread()); - Tracing.endTrace(); - } catch (Exception e) { /* */ } - } - - public static Trace get(Thread thread) { - return vars.get(thread); - } - -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/util/LogChecker.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/util/LogChecker.java deleted file mode 100644 index c98d895..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/util/LogChecker.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.util; - -import java.io.BufferedInputStream; -import java.io.DataInputStream; -import java.io.EOFException; -import java.io.FileInputStream; - -import com.sematext.spm.client.Log; -import com.sematext.spm.client.LogFactory; - -public final class LogChecker { - private static final Log LOG = LogFactory.getLog(LogChecker.class); - - public static void main(String[] args) throws Exception { - final String path = args[0]; - final DataInputStream dais = new DataInputStream(new BufferedInputStream(new FileInputStream(path))); - - byte[] lastPayload = null; - Integer lastLength = null; - long position = 0; - try { - while (true) { - try { - lastPayload = null; - lastLength = dais.readInt(); - position += 4; - lastPayload = new byte[lastLength]; - int read = dais.read(lastPayload); - if (read != lastLength) { - LOG.info("Length = " + lastLength + ", available = " + read + "."); - throw new EOFException(); - } - position += read; - LOG.info("Position = " + position + ", Length = " + lastLength); - lastLength = null; - } catch (EOFException e) { - break; - } - } - } finally { - dais.close(); - } - - LOG.info(position + ", lastLength = " + lastLength + ", lastPayload = " + lastPayload); - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/util/TracedCallable.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/util/TracedCallable.java deleted file mode 100644 index 45164d3..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/util/TracedCallable.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.util; - -import java.util.concurrent.Callable; - -import com.sematext.spm.client.tracing.agent.Trace; -import com.sematext.spm.client.tracing.agent.Tracing; - -public class TracedCallable implements Callable { - private final Callable callable; - private final Trace trace; - - public TracedCallable(Callable callable) { - this.callable = callable; - this.trace = Tracing.current(); - } - - @Override - public V call() throws Exception { - try { - Tracing.setTrace(trace.fork()); - } catch (Exception e) { - /* pass */ - } - try { - return callable.call(); - } finally { - try { - Tracing.endTrace(); - } catch (Exception e) { - /* pass */ - } - } - } - - @SuppressWarnings("unchecked") - public static Callable tryCreate(Callable from) { - if (from == null) { - return null; - } - if (from.getClass().getInterfaces().length == 1 && from.getClass().getSuperclass().equals(Object.class)) { - return new TracedCallable(from); - } - return from; - } -} diff --git a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/util/TracedRunnable.java b/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/util/TracedRunnable.java deleted file mode 100644 index 907f3e3..0000000 --- a/spm-tracing-agent/src/main/java/com/sematext/spm/client/tracing/agent/util/TracedRunnable.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.util; - -import com.sematext.spm.client.tracing.agent.Trace; -import com.sematext.spm.client.tracing.agent.Tracing; - -public class TracedRunnable implements Runnable { - private final Runnable runnable; - private final Trace trace; - - public TracedRunnable(Runnable runnable) { - if (runnable.getClass().isAssignableFrom(TracedRunnable.class)) { - this.runnable = ((TracedRunnable) runnable).runnable; - } else { - this.runnable = runnable; - } - this.trace = Tracing.current(); - } - - @Override - public void run() { - try { - Tracing.setTrace(this.trace.fork()); - } catch (Exception e) { - /* pass */ - } - try { - runnable.run(); - } finally { - try { - Tracing.endTrace(); - } catch (Exception e) { - /* pass */ - } - } - } - - public static Runnable tryCreate(Runnable from) { - if (from == null) { - return null; - } - if (from.getClass().getInterfaces().length == 1 && from.getClass().getSuperclass().equals(Object.class)) { - return new TracedRunnable(from); - } - return from; - } - -} diff --git a/spm-tracing-agent/src/test/java/com/sematext/spm/client/tracing/agent/model/annotation/ESAnnotationTest.java b/spm-tracing-agent/src/test/java/com/sematext/spm/client/tracing/agent/model/annotation/ESAnnotationTest.java deleted file mode 100644 index a6d9860..0000000 --- a/spm-tracing-agent/src/test/java/com/sematext/spm/client/tracing/agent/model/annotation/ESAnnotationTest.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.model.annotation; - -import static java.util.Arrays.asList; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import com.tngtech.java.junit.dataprovider.DataProvider; -import com.tngtech.java.junit.dataprovider.DataProviderRunner; -import com.tngtech.java.junit.dataprovider.UseDataProvider; - -import org.junit.Test; -import org.junit.runner.RunWith; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.EnumSet; -import java.util.List; - -import com.sematext.spm.client.tracing.agent.model.ESAction; -import com.sematext.spm.client.tracing.agent.model.ESAction.OperationType; -import com.sematext.spm.client.tracing.agent.model.annotation.ESAnnotation.RequestType; - -@RunWith(DataProviderRunner.class) -public class ESAnnotationTest { - - @DataProvider - public static Object[][] bulkCasesProvider() { - final List cases = new ArrayList(); - EnumSet bulkOperations = EnumSet.of(OperationType.DELETE, OperationType.UPDATE, OperationType.INDEX); - for (OperationType operationType : bulkOperations) { - cases.add(new Object[] { - asList(new ESAction(operationType, "index", null, null), new ESAction(operationType, "index", null, null)), - RequestType.valueOf(operationType.name() + "_BULK"), - "index" - }); - cases.add(new Object[] { - asList(new ESAction(operationType, "index", null, null), new ESAction(operationType, "index-1", null, null)), - RequestType.valueOf(operationType.name() + "_BULK"), - null - }); - EnumSet complementActions = EnumSet.copyOf(bulkOperations); - complementActions.remove(operationType); - cases.add(new Object[] { - asList(new ESAction(operationType, "index", null, null), new ESAction(complementActions.iterator() - .next(), "index-1", null, null)), - RequestType.BULK, - null - }); - } - return cases.toArray(new Object[cases.size()][]); - } - - @Test - @UseDataProvider("bulkCasesProvider") - public void testMakeShouldDetectSpecialBulkCases(List actions, RequestType type, String index) - throws Exception { - final ESAnnotation annotation = ESAnnotation.make(Collections.EMPTY_LIST, true, actions); - assertEquals(annotation.getIndex(), index); - assertEquals(annotation.getRequestType(), type); - } - - @Test - public void testShouldGroupBulkActionsByOpTypeIndexAndType() throws Exception { - List actions = Arrays.asList( - new ESAction(OperationType.DELETE, "index-1", "type-1", null), - new ESAction(OperationType.DELETE, "index-1", "type-1", null), - new ESAction(OperationType.DELETE, "index-1", "type-2", null), - new ESAction(OperationType.INDEX, "index-3", "type-2", null), - new ESAction(OperationType.INDEX, "index-1", "type-2", null), - new ESAction(OperationType.INDEX, "index-1", "type-2", null) - ); - - final ESAnnotation annotation = ESAnnotation.make(Collections.EMPTY_LIST, true, actions); - - assertEquals(annotation.getActions().size(), 4); - assertTrue(annotation.getActions().contains(new ESAction(OperationType.DELETE, "index-1", "type-1", null, 2))); - assertTrue(annotation.getActions().contains(new ESAction(OperationType.DELETE, "index-1", "type-2", null, 1))); - assertTrue(annotation.getActions().contains(new ESAction(OperationType.INDEX, "index-3", "type-2", null, 1))); - assertTrue(annotation.getActions().contains(new ESAction(OperationType.INDEX, "index-1", "type-2", null, 2))); - } -} diff --git a/spm-tracing-agent/src/test/java/com/sematext/spm/client/tracing/agent/sampling/TracingErrorFixedRateSamplerTest.java b/spm-tracing-agent/src/test/java/com/sematext/spm/client/tracing/agent/sampling/TracingErrorFixedRateSamplerTest.java deleted file mode 100644 index c88e8a9..0000000 --- a/spm-tracing-agent/src/test/java/com/sematext/spm/client/tracing/agent/sampling/TracingErrorFixedRateSamplerTest.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.sampling; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import org.junit.Test; - -import java.util.concurrent.TimeUnit; - -import com.sematext.spm.client.tracing.agent.errors.TracingError; -import com.sematext.spm.client.util.Clocks; -import com.sematext.spm.client.util.Clocks.Mock; - -public class TracingErrorFixedRateSamplerTest { - - private final TracingError error = new TracingError(); - - @Test - public void testSample() throws Exception { - final Mock clock = Clocks.mock(); - final TracingErrorFixedRateSampler sampler = new TracingErrorFixedRateSampler(4, 10, TimeUnit.MILLISECONDS, clock); - - for (int i = 0; i < 4; i++) { - assertTrue(sampler.sample(error)); - clock.increment(); - } - - assertFalse(sampler.sample(error)); - - clock.set(10); - - for (int i = 0; i < 4; i++) { - assertTrue(i + " event should be sampled", sampler.sample(error)); - clock.increment(); - } - } - -} diff --git a/spm-tracing-agent/src/test/java/com/sematext/spm/client/tracing/agent/solrj5/SolrAnnotationMakerTest.java b/spm-tracing-agent/src/test/java/com/sematext/spm/client/tracing/agent/solrj5/SolrAnnotationMakerTest.java deleted file mode 100644 index eff9003..0000000 --- a/spm-tracing-agent/src/test/java/com/sematext/spm/client/tracing/agent/solrj5/SolrAnnotationMakerTest.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.solrj5; - -import org.junit.Test; - -import com.sematext.spm.client.tracing.agent.model.SolrAnnotation; -import com.sematext.spm.client.tracing.agent.model.SolrAnnotation.RequestType; - -import junit.framework.TestCase; - -public class SolrAnnotationMakerTest extends TestCase { - @Test - public void testExtractCollectionAndRequestTypeFromURL() throws Exception { - SolrAnnotation annotation = SolrAnnotationMaker.fromHTTPRequest("http://localhost:8983/solr/collection-1/update"); - - assertNotNull(annotation); - assertEquals(RequestType.UPDATE, annotation.getRequestType()); - assertEquals("collection-1", annotation.getCollection()); - } - - @Test - public void testIgnoreMissingCollectionPathSegment() throws Exception { - SolrAnnotation annotation = SolrAnnotationMaker.fromHTTPRequest("http://localhost:8983/update"); - - assertNotNull(annotation); - assertEquals(RequestType.UPDATE, annotation.getRequestType()); - assertEquals(null, annotation.getCollection()); - } - - @Test - public void sanity() throws Exception { - assertNull(SolrAnnotationMaker.fromHTTPRequest("http://localhost:8983/")); - assertNull(SolrAnnotationMaker.fromHTTPRequest("http://localhost:8983/unknown")); - assertNull(SolrAnnotationMaker.fromHTTPRequest("http://localhost:8983/admin")); - assertNull(SolrAnnotationMaker.fromHTTPRequest("http://localhost&&8983/admin")); - } -} diff --git a/spm-tracing-agent/src/test/java/com/sematext/spm/client/tracing/agent/sql/SqlStatementParserTest.java b/spm-tracing-agent/src/test/java/com/sematext/spm/client/tracing/agent/sql/SqlStatementParserTest.java deleted file mode 100644 index 579b672..0000000 --- a/spm-tracing-agent/src/test/java/com/sematext/spm/client/tracing/agent/sql/SqlStatementParserTest.java +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.sql; - -import static org.junit.Assert.assertEquals; - -import org.junit.Test; - -public class SqlStatementParserTest { - @Test - public void testParseSelect() throws Exception { - assertEquals(SqlStatementParser - .parse("select * from User"), new SqlStatement(SqlStatement.Operation.SELECT, "user")); - assertEquals(SqlStatementParser - .parse("select u1.name, u2.name from User u where id = 2"), new SqlStatement(SqlStatement.Operation.SELECT, "user")); - assertEquals(SqlStatementParser - .parse("select * from User u where u.id in (select userId from System where name = 'system-2')"), - new SqlStatement(SqlStatement.Operation.SELECT, null)); - assertEquals(SqlStatementParser - .parse("select u3.name, u3.name from User u, System s where u.id = s.userId where s.id < 100"), - new SqlStatement(SqlStatement.Operation.SELECT, null)); - assertEquals(SqlStatementParser.parse("select u.name as userName, s.name as systemName from User u join System s"), - new SqlStatement(SqlStatement.Operation.SELECT, null)); - } - - @Test - public void testParseDelete() throws Exception { - assertEquals(SqlStatementParser - .parse("delete from User where id = 10"), new SqlStatement(SqlStatement.Operation.DELETE, "user")); - assertEquals(SqlStatementParser - .parse("delete from `User` where id = 10"), new SqlStatement(SqlStatement.Operation.DELETE, "user")); - assertEquals(SqlStatementParser - .parse("delete from `U``ser` where id = 10"), new SqlStatement(SqlStatement.Operation.DELETE, "u`ser")); - assertEquals(SqlStatementParser - .parse("delete from `some``database```.`U``ser` where id = 10"), new SqlStatement(SqlStatement.Operation.DELETE, "u`ser")); - assertEquals(SqlStatementParser - .parse("delete from User where id in (select userId from System where name = 'system-1')"), new SqlStatement(SqlStatement.Operation.DELETE, "user")); - assertEquals(SqlStatementParser - .parse("delete from db1.User where id in (select userId from System where name = 'system-1')"), new SqlStatement(SqlStatement.Operation.DELETE, "user")); - } - - @Test - public void testParseInsert() throws Exception { - assertEquals(SqlStatementParser - .parse("insert into User(name, age) values('user-1', 42)"), new SqlStatement(SqlStatement.Operation.INSERT, "user")); - assertEquals(SqlStatementParser - .parse("insert into db1.User(name, age) values('user-1', 42)"), new SqlStatement(SqlStatement.Operation.INSERT, "user")); - assertEquals(SqlStatementParser - .parse("insert into db1.User values('user-1', 42)"), new SqlStatement(SqlStatement.Operation.INSERT, "user")); - assertEquals(SqlStatementParser - .parse("insert into User values('user-1', 42)"), new SqlStatement(SqlStatement.Operation.INSERT, "user")); - } - - @Test - public void testParseUpdate() throws Exception { - assertEquals(SqlStatementParser - .parse("update User set age = 42 where name = 'user-1"), new SqlStatement(SqlStatement.Operation.UPDATE, "user")); - assertEquals(SqlStatementParser - .parse("update db1.User set age = 42 where name = 'user-1"), new SqlStatement(SqlStatement.Operation.UPDATE, "user")); - } - - @Test - public void testParseOther() throws Exception { - assertEquals(SqlStatementParser - .parse("alter table User add column city varchar(1024)"), new SqlStatement(SqlStatement.Operation.OTHER, null)); - } - - @Test - public void testParseComments() throws Exception { - String sql1 = "/* remove me */ update User set /* and me */ age = 42 where name = 'user-1"; - assertEquals(SqlStatementParser.parse(sql1), new SqlStatement(SqlStatement.Operation.UPDATE, "user")); - - String sql2 = "/* multiline \n comment with lot of tabs \t\t\t \n*/ delete from User"; - assertEquals(SqlStatementParser.parse(sql2), new SqlStatement(SqlStatement.Operation.DELETE, "user")); - - String sql3 = "-- One line comment\t with tabs\ndelete from User\n-- All things are removed"; - assertEquals(SqlStatementParser.parse(sql3), new SqlStatement(SqlStatement.Operation.DELETE, "user")); - - String sql4 = "--One line comment\t with tabs\ndelete from User\n-- All things are removed"; - assertEquals(SqlStatementParser.parse(sql4), new SqlStatement(SqlStatement.Operation.DELETE, "user")); - } - - @Test - public void testParseMultiline() throws Exception { - String sql1 = "delete \nfrom User \n\twhere id in (select userId from System where name = 'system-1')"; - assertEquals(SqlStatementParser.parse(sql1), new SqlStatement(SqlStatement.Operation.DELETE, "user")); - } -} diff --git a/spm-tracing-testing/common/pom.xml b/spm-tracing-testing/common/pom.xml deleted file mode 100644 index d9d679a..0000000 --- a/spm-tracing-testing/common/pom.xml +++ /dev/null @@ -1,97 +0,0 @@ - - - - spm-tracing-testing - com.sematext.spm - 3.0.0 - - 4.0.0 - - common - - - - com.google.guava - guava - 18.0 - - - - - - com.h2database - h2 - 1.4.181 - test - - - - org.hsqldb - hsqldb - 2.3.2 - test - - - - com.mchange - c3p0 - [0.9.5.5,) - test - - - - org.hibernate - hibernate-entitymanager - 4.3.6.Final - test - - - - javax.servlet - javax.servlet-api - 3.1.0 - test - - - - commons-httpclient - commons-httpclient - 3.1 - test - - - - org.apache.httpcomponents - httpclient - 4.5.13 - test - - - - solr-solrj - org.apache.solr - 5.3.0 - jar - test - - - org.slf4j - slf4j-api - - - org.slf4j - slf4j-log4j12 - - - - - org.apache.logging.log4j - log4j-core - 2.17.0 - compile - - - - diff --git a/spm-tracing-testing/common/src/main/java/com/sematext/spm/client/tracing/TestingUnlogger.java b/spm-tracing-testing/common/src/main/java/com/sematext/spm/client/tracing/TestingUnlogger.java deleted file mode 100644 index b03e790..0000000 --- a/spm-tracing-testing/common/src/main/java/com/sematext/spm/client/tracing/TestingUnlogger.java +++ /dev/null @@ -1,198 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import com.sematext.spm.client.tracing.agent.CallSinks; -import com.sematext.spm.client.tracing.agent.NoTrace; -import com.sematext.spm.client.tracing.agent.Sink; -import com.sematext.spm.client.tracing.agent.Trace; -import com.sematext.spm.client.tracing.agent.Tracing; -import com.sematext.spm.client.tracing.agent.api.TransactionAccess; -import com.sematext.spm.client.tracing.agent.config.ServiceConfigurer; -import com.sematext.spm.client.tracing.agent.config.ServiceLocator; -import com.sematext.spm.client.tracing.agent.errors.TracingError; -import com.sematext.spm.client.tracing.agent.model.Call; -import com.sematext.spm.client.tracing.agent.model.ESAction; -import com.sematext.spm.client.tracing.agent.model.Endpoint; -import com.sematext.spm.client.tracing.agent.model.FailureType; -import com.sematext.spm.client.tracing.agent.model.InetAddress; -import com.sematext.spm.client.tracing.agent.model.PartialTransaction; -import com.sematext.spm.client.tracing.agent.model.SolrAnnotation; -import com.sematext.spm.client.tracing.agent.model.WebTransactionSummary; -import com.sematext.spm.client.tracing.agent.model.annotation.ESAnnotation; -import com.sematext.spm.client.tracing.agent.model.annotation.HTTPRequestAnnotation; -import com.sematext.spm.client.tracing.agent.model.annotation.SQLAnnotation; -import com.sematext.spm.client.tracing.agent.sql.SqlStatement; -import com.sematext.spm.client.tracing.agent.tracer.Tracer; -import com.sematext.spm.client.tracing.agent.transformation.TracingTransform; -import com.sematext.spm.client.tracing.agent.transformation.transforms.MixinTransform; -import com.sematext.spm.client.tracing.utils.TestServiceConfigurer; -import com.sematext.spm.client.unlogger.JoinPoint; -import com.sematext.spm.client.unlogger.LogPointWeaver; -import com.sematext.spm.client.unlogger.Logspect; -import com.sematext.spm.client.unlogger.Pointcut; -import com.sematext.spm.client.unlogger.dispatch.AdviceDispatcher; -import com.sematext.spm.client.unlogger.dispatch.DispatchUnit; -import com.sematext.spm.client.unlogger.dispatch.LastInchOfTrampoline; -import com.sematext.spm.client.util.InstrumentationUtils; - -import javassist.CannotCompileException; -import javassist.ClassPool; -import javassist.Loader; -import javassist.NotFoundException; -import javassist.Translator; - -public class TestingUnlogger { - - private final LogPointWeaver weaver; - private final ClassPool classPool = ClassPool.getDefault(); - private final List transforms = new ArrayList(); - private final Loader loader; - - private TestingUnlogger(Tracer[] tracers) throws Exception { - final List loggers = new ArrayList(); - final List logspects = new ArrayList(); - - for (final Tracer tracer : tracers) { - logspects.addAll(tracer.createLogspects(TestingUnlogger.class.getClassLoader())); - transforms.addAll(Arrays.asList(tracer.getStructuralTransforms())); - } - - final Map pointcuts = new HashMap(); - - for (final Logspect logspect : logspects) { - for (final Pointcut pointcut : logspect.getPointcuts()) { - int dispatchId = DispatchUnit.registerDispatchUnit(logspect.getName(), pointcut, logspect.createUnlogger()); - pointcuts.put(pointcut, dispatchId); - } - } - - ServiceLocator.configure(new TestServiceConfigurer("123")); - - weaver = new LogPointWeaver(pointcuts, LastInchOfTrampoline.class.getName()); - - loader = new Loader(classPool); - loader.doDelegation = true; - - loader.delegateLoadingOf(LastInchOfTrampoline.class.getName()); - loader.delegateLoadingOf(NoTrace.class.getName()); - loader.delegateLoadingOf(Tracing.class.getName()); - loader.delegateLoadingOf(Trace.class.getName()); - loader.delegateLoadingOf(PartialTransaction.class.getName()); - loader.delegateLoadingOf(JoinPoint.class.getName()); - loader.delegateLoadingOf("org.junit."); - loader.delegateLoadingOf("org.apache.commons.logging."); - loader.delegateLoadingOf(Call.class.getName()); - loader.delegateLoadingOf(Call.TransactionType.class.getName()); - loader.delegateLoadingOf(Call.CallTag.class.getName()); - loader.delegateLoadingOf(FailureType.class.getName()); - loader.delegateLoadingOf(Endpoint.class.getName()); - loader.delegateLoadingOf(CallSinks.class.getName()); - loader.delegateLoadingOf(Sink.class.getName()); - loader.delegateLoadingOf(TracingError.class.getName()); - loader.delegateLoadingOf(ESAction.class.getName()); - loader.delegateLoadingOf(ESAction.OperationType.class.getName()); - loader.delegateLoadingOf(ServiceLocator.class.getName()); - loader.delegateLoadingOf(ServiceConfigurer.class.getName()); - loader.delegateLoadingOf(WebTransactionSummary.class.getName()); - loader.delegateLoadingOf(ESAnnotation.class.getName()); - loader.delegateLoadingOf(ESAnnotation.RequestType.class.getName()); - loader.delegateLoadingOf(ESAction.class.getName()); - loader.delegateLoadingOf(SQLAnnotation.class.getName()); - loader.delegateLoadingOf(HTTPRequestAnnotation.class.getName()); - loader.delegateLoadingOf(SolrAnnotation.class.getName()); - loader.delegateLoadingOf(SolrAnnotation.RequestType.class.getName()); - loader.delegateLoadingOf(InetAddress.class.getName()); - loader.delegateLoadingOf(TransactionAccess.class.getName()); - loader.delegateLoadingOf(SqlStatement.class.getName()); - loader.delegateLoadingOf(SqlStatement.Operation.class.getName()); - - for (final Tracer tracer : tracers) { - for (TracingTransform transform : tracer.getStructuralTransforms()) { - if (transform instanceof MixinTransform) { - loader.delegateLoadingOf(((MixinTransform) transform).getIface().getName()); - } - } - } - - loader.addTranslator(classPool, new Translator() { - @Override - public void start(ClassPool pool) throws NotFoundException, CannotCompileException { - - } - - @Override - public void onLoad(ClassPool pool, String classname) throws NotFoundException, CannotCompileException { - try { - weaver.loadPointcutAsClass(pool, classname); - } catch (NotFoundException e) { - } catch (Throwable e) { - e.printStackTrace(); - } - for (final TracingTransform transform : transforms) { - try { - transform.transform(pool.get(classname), InstrumentationUtils.getHierarchy(pool.get(classname))); - } catch (NotFoundException e) { - } catch (Throwable t) { - t.printStackTrace(); - } - } - } - }); - - LastInchOfTrampoline.switchTo(AdviceDispatcher.Type.DEFAULT); - } - - public static TestingUnlogger create(Tracer[] tracer) { - try { - return new TestingUnlogger(tracer); - } catch (Exception e) { - throw new RuntimeException("Can't create testing unlogger.", e); - } - } - - public void weave(Class klass) { - try { - weaver.loadPointcutAsClass(classPool, klass.getName()); - } catch (Exception e) { - throw new RuntimeException("Can't weave class " + klass + ".", e); - } - } - - public Loader getLoader() { - return loader; - } - - public void forkTest(String className, String method) { - try { - Class clazz = loader.loadClass(className); - clazz.getMethod(method).invoke(clazz.newInstance()); - } catch (Exception e) { - throw new RuntimeException("Can't fork test.", e); - } - } - -} diff --git a/spm-tracing-testing/common/src/main/java/com/sematext/spm/client/tracing/Trace.java b/spm-tracing-testing/common/src/main/java/com/sematext/spm/client/tracing/Trace.java deleted file mode 100644 index 623ce84..0000000 --- a/spm-tracing-testing/common/src/main/java/com/sematext/spm/client/tracing/Trace.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.METHOD) -public @interface Trace { - boolean force() default false; -} diff --git a/spm-tracing-testing/common/src/main/java/com/sematext/spm/client/tracing/utils/CallDebug.java b/spm-tracing-testing/common/src/main/java/com/sematext/spm/client/tracing/utils/CallDebug.java deleted file mode 100644 index fa33850..0000000 --- a/spm-tracing-testing/common/src/main/java/com/sematext/spm/client/tracing/utils/CallDebug.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.utils; - -import com.google.common.base.Strings; -import com.google.common.collect.ArrayListMultimap; - -import java.util.ArrayDeque; -import java.util.ArrayList; -import java.util.List; - -import com.sematext.spm.client.tracing.agent.model.Call; -import com.sematext.spm.client.tracing.agent.model.PartialTransaction; -import com.sematext.spm.client.util.Tuple; - -public final class CallDebug { - - public static String print(List calls) { - StringBuilder tree = new StringBuilder(); - for (Call call : calls) { - if (call.getParentCallId() == Call.ROOT_CALL_ID) { - tree.append(printCallTree(calls, call)).append("\n"); - } - } - return tree.toString(); - } - - public static String printCallTree(List transactions) { - final List calls = new ArrayList(); - for (PartialTransaction transaction : transactions) { - for (Call call : transaction.getCalls()) { - calls.add(call); - } - } - return print(calls); - } - - private static String printCallTree(List calls, Call rootCall) { - final ArrayListMultimap callsByParentId = ArrayListMultimap.create(); - for (final Call call : calls) { - callsByParentId.put(call.getParentCallId(), call); - } - - ArrayDeque> deque = new ArrayDeque>(); - deque.add(Tuple.tuple(0, rootCall)); - - final StringBuilder builder = new StringBuilder(); - - while (!deque.isEmpty()) { - final Tuple callAndIndent = deque.poll(); - final int indent = callAndIndent.getFirst(); - final Call call = callAndIndent.getSecond(); - - builder.append(Strings.repeat(" ", indent)) - .append(" ") - .append(call.getSignature()) - .append(" - ") - .append(call.getDuration()) - .append("ms") - .append("\n"); - - for (Call child : callsByParentId.get(call.getCallId())) { - deque.push(Tuple.tuple(indent + 1, child)); - } - } - - return builder.toString(); - } -} diff --git a/spm-tracing-testing/common/src/main/java/com/sematext/spm/client/tracing/utils/MockSink.java b/spm-tracing-testing/common/src/main/java/com/sematext/spm/client/tracing/utils/MockSink.java deleted file mode 100644 index b4fcc4a..0000000 --- a/spm-tracing-testing/common/src/main/java/com/sematext/spm/client/tracing/utils/MockSink.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.utils; - -import java.util.ArrayList; -import java.util.List; - -import com.sematext.spm.client.tracing.agent.Sink; - -public class MockSink implements Sink { - private final List events = new ArrayList(); - - public List getEvents() { - return events; - } - - public int clean() { - int size = events.size(); - events.clear(); - return size; - } - - @Override - public void sink(E event) { - events.add(event); - } -} diff --git a/spm-tracing-testing/common/src/main/java/com/sematext/spm/client/tracing/utils/MockTransactionSink.java b/spm-tracing-testing/common/src/main/java/com/sematext/spm/client/tracing/utils/MockTransactionSink.java deleted file mode 100644 index 769096b..0000000 --- a/spm-tracing-testing/common/src/main/java/com/sematext/spm/client/tracing/utils/MockTransactionSink.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.utils; - -import java.util.ArrayList; -import java.util.List; - -import com.sematext.spm.client.tracing.agent.Sink; -import com.sematext.spm.client.tracing.agent.model.PartialTransaction; - -public class MockTransactionSink implements Sink { - private final List transactions = - new ArrayList(); - - public List getTransactions() { - return transactions; - } - - public int clean() { - int size = transactions.size(); - transactions.clear(); - return size; - } - - @Override - public void sink(PartialTransaction transaction) { - transactions.add(transaction); - } -} diff --git a/spm-tracing-testing/common/src/main/java/com/sematext/spm/client/tracing/utils/TestServiceConfigurer.java b/spm-tracing-testing/common/src/main/java/com/sematext/spm/client/tracing/utils/TestServiceConfigurer.java deleted file mode 100644 index 3e64c2a..0000000 --- a/spm-tracing-testing/common/src/main/java/com/sematext/spm/client/tracing/utils/TestServiceConfigurer.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.utils; - -import java.util.ArrayList; -import java.util.List; - -import com.sematext.spm.client.tracing.agent.Sink; -import com.sematext.spm.client.tracing.agent.TracingAgentControl; -import com.sematext.spm.client.tracing.agent.config.Config; -import com.sematext.spm.client.tracing.agent.config.ServiceConfigurer; -import com.sematext.spm.client.tracing.agent.errors.TracingError; -import com.sematext.spm.client.tracing.agent.model.PartialTransaction; -import com.sematext.spm.client.tracing.agent.sampling.NoSampling; -import com.sematext.spm.client.tracing.agent.sampling.Sampler; -import com.sematext.spm.client.tracing.agent.stats.TracingStatistics; - -public class TestServiceConfigurer implements ServiceConfigurer { - private final Config config; - private final Sampler transactionSampler; - private final Sampler tracingErrorSampler; - private final List> sinks = new ArrayList>(); - private final List> errorSinks = new ArrayList>(); - - public TestServiceConfigurer(String token) { - this.config = Config.getConfig("token=" + token); - this.transactionSampler = new NoSampling(); - this.tracingErrorSampler = new NoSampling(); - } - - @Override - public Config getConfig() { - return this.config; - } - - @Override - public Sampler getTransactionSampler() { - return this.transactionSampler; - } - - @Override - public Sampler getTracingErrorSampler() { - return this.tracingErrorSampler; - } - - @Override - public List> getTransactionSinks() { - return sinks; - } - - @Override - public List> getErrorSinks() { - return errorSinks; - } - - @Override - public TracingStatistics getTracingStatistics() { - return null; - } - - @Override - public TracingAgentControl getTracingAgentControl() { - return null; - } -} diff --git a/spm-tracing-testing/common/src/main/java/com/sematext/spm/client/tracing/utils/TracingContext.java b/spm-tracing-testing/common/src/main/java/com/sematext/spm/client/tracing/utils/TracingContext.java deleted file mode 100644 index 9d36e85..0000000 --- a/spm-tracing-testing/common/src/main/java/com/sematext/spm/client/tracing/utils/TracingContext.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.utils; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -import com.sematext.spm.client.tracing.agent.tracer.Tracer; - -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.TYPE) -public @interface TracingContext { - Class[] tracers(); -} diff --git a/spm-tracing-testing/common/src/main/java/com/sematext/spm/client/tracing/utils/TracingJUnit4ClassRunner.java b/spm-tracing-testing/common/src/main/java/com/sematext/spm/client/tracing/utils/TracingJUnit4ClassRunner.java deleted file mode 100644 index 80bccd9..0000000 --- a/spm-tracing-testing/common/src/main/java/com/sematext/spm/client/tracing/utils/TracingJUnit4ClassRunner.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.utils; - -import org.junit.runners.BlockJUnit4ClassRunner; - -import java.util.ArrayList; -import java.util.List; - -import com.sematext.spm.client.LogFactory; -import com.sematext.spm.client.LogWriter; -import com.sematext.spm.client.tracing.TestingUnlogger; -import com.sematext.spm.client.tracing.agent.tracer.Tracer; - -import javassist.Loader; - -public class TracingJUnit4ClassRunner extends BlockJUnit4ClassRunner { - - private static class StdOutLogWriter implements LogWriter { - @Override - public void write(String logLine) { - System.out.println(logLine); - } - - @Override - public void write(String logLine, Throwable throwable) { - System.out.println(logLine); - throwable.printStackTrace(System.out); - } - } - - private static class Initializer { - static Loader newLoader(Class testClass) throws Exception { - final TracingContext ctx = testClass.getAnnotation(TracingContext.class); - if (ctx == null) { - throw new RuntimeException("Missing TracingContext Annotation."); - } - - final List tracers = new ArrayList(); - for (final Class klass : ctx.tracers()) { - tracers.add(klass.newInstance()); - } - - final TestingUnlogger testing = TestingUnlogger.create(tracers.toArray(new Tracer[tracers.size()])); - - LogFactory.init(new StdOutLogWriter()); - LogFactory.setLoggingLevel("DEBUG"); - - return testing.getLoader(); - } - } - - public TracingJUnit4ClassRunner(Class klass) throws Exception { - super(Class.forName(klass.getName(), true, Initializer.newLoader(klass))); - } - -} diff --git a/spm-tracing-testing/common/src/main/java/com/sematext/spm/client/tracing/utils/TracingTesting.java b/spm-tracing-testing/common/src/main/java/com/sematext/spm/client/tracing/utils/TracingTesting.java deleted file mode 100644 index b05f635..0000000 --- a/spm-tracing-testing/common/src/main/java/com/sematext/spm/client/tracing/utils/TracingTesting.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.utils; - -import com.google.common.base.Function; -import com.google.common.base.Predicate; -import com.google.common.collect.Iterables; -import com.google.common.collect.Lists; - -import java.util.Collection; -import java.util.List; - -import com.sematext.spm.client.tracing.agent.config.ServiceLocator; -import com.sematext.spm.client.tracing.agent.model.Call; -import com.sematext.spm.client.tracing.agent.model.PartialTransaction; - -public final class TracingTesting { - - private TracingTesting() { - } - - public static Iterable getCalls(Collection transactions) { - final Iterable> calls = Iterables - .transform(transactions, new Function>() { - @Override - public List apply(PartialTransaction transaction) { - return transaction.getCalls(); - } - }); - return Iterables.concat(calls); - } - - public static List findMatching(final String regexp, List transactions) { - final Iterable filtered = Iterables.filter(getCalls(transactions), new Predicate() { - @Override - public boolean apply(Call call) { - return call.getSignature().matches(regexp); - } - }); - return Lists.newArrayList(filtered); - } - - public static List findAsync(List transactions) { - Iterable filtered = Iterables.filter(transactions, new Predicate() { - @Override - public boolean apply(PartialTransaction input) { - return input.isAsynchronous(); - } - }); - return Lists.newArrayList(filtered); - } - - public static MockTransactionSink setupSink() { - MockTransactionSink sink = new MockTransactionSink(); - ServiceLocator.getTransactionSinks().clear(); - ServiceLocator.getTransactionSinks().add(sink); - return sink; - } - -} diff --git a/spm-tracing-testing/common/src/test/java/com/sematext/spm/client/tracing/agent/CallArrayTest.java b/spm-tracing-testing/common/src/test/java/com/sematext/spm/client/tracing/agent/CallArrayTest.java deleted file mode 100644 index 9955cbb..0000000 --- a/spm-tracing-testing/common/src/test/java/com/sematext/spm/client/tracing/agent/CallArrayTest.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent; - -import static org.junit.Assert.assertEquals; - -import org.junit.Test; - -public class CallArrayTest { - @Test - public void testResize() { - CallArray array = new CallArray(2); - array.add().setSignature("request-1"); - array.add().setSignature("request-2"); - array.add().setSignature("request-3"); - - assertEquals("request-1", array.get(0).getSignature()); - assertEquals("request-2", array.get(1).getSignature()); - assertEquals("request-3", array.get(2).getSignature()); - } - -} diff --git a/spm-tracing-testing/common/src/test/java/com/sematext/spm/client/tracing/agent/CallStackTest.java b/spm-tracing-testing/common/src/test/java/com/sematext/spm/client/tracing/agent/CallStackTest.java deleted file mode 100644 index e6bda30..0000000 --- a/spm-tracing-testing/common/src/test/java/com/sematext/spm/client/tracing/agent/CallStackTest.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -import org.junit.Test; - -public class CallStackTest { - @Test - public void testStack() { - CallStack stack = new CallStack(1); - assertNotNull(stack.push()); - assertNotNull(stack.peek()); - stack.peek().setCallId(42); - assertEquals(42, stack.pop().getCallId()); - } -} diff --git a/spm-tracing-testing/common/src/test/java/com/sematext/spm/client/tracing/agent/TracingTest.java b/spm-tracing-testing/common/src/test/java/com/sematext/spm/client/tracing/agent/TracingTest.java deleted file mode 100644 index bb0986e..0000000 --- a/spm-tracing-testing/common/src/test/java/com/sematext/spm/client/tracing/agent/TracingTest.java +++ /dev/null @@ -1,246 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; - -import org.junit.Test; - -import java.util.ArrayDeque; -import java.util.Arrays; -import java.util.Deque; -import java.util.List; - -import com.sematext.spm.client.tracing.agent.api.TransactionAccess; -import com.sematext.spm.client.tracing.agent.config.Config; -import com.sematext.spm.client.tracing.agent.config.ServiceConfigurer; -import com.sematext.spm.client.tracing.agent.config.ServiceLocator; -import com.sematext.spm.client.tracing.agent.errors.TracingError; -import com.sematext.spm.client.tracing.agent.model.Call; -import com.sematext.spm.client.tracing.agent.model.PartialTransaction; -import com.sematext.spm.client.tracing.agent.sampling.Sampler; -import com.sematext.spm.client.tracing.agent.stats.TracingStatistics; -import com.sematext.spm.client.tracing.utils.MockTransactionSink; -import com.sematext.spm.client.unlogger.JoinPoint; - -public class TracingTest { - public static class Configurer implements ServiceConfigurer { - private final MockTransactionSink callSink = new MockTransactionSink(); - - private final Config config = new Config() {{ - setToken("123"); - }}; - - @Override - public Config getConfig() { - return config; - } - - @Override - public Sampler getTransactionSampler() { - return null; - } - - @Override - public Sampler getTracingErrorSampler() { - return null; - } - - @Override - public List> getTransactionSinks() { - return Arrays.>asList(callSink); - } - - @Override - public List> getErrorSinks() { - return null; - } - - public MockTransactionSink getCallSink() { - return callSink; - } - - @Override - public TracingStatistics getTracingStatistics() { - return null; - } - - @Override - public TracingAgentControl getTracingAgentControl() { - return null; - } - } - - @Test - public void testSelfDurationCalculatedCorrectly() { - final Configurer config = new Configurer(); - - ServiceLocator.configure(config); - - Tracing.newTrace("", Call.TransactionType.BACKGROUND, 1, 1, true); - - Tracing.current().newCall("Servlet", 1); - Tracing.current().newCall("JpaQuery-1", 2); - Tracing.current().newCall("JdbcQuery-1-1", 3); - Tracing.current().endCall(4); - - Tracing.current().newCall("JdbcQuery-1-2", 4); - Tracing.current().endCall(5); - - Tracing.current().endCall(6); //JpaQuery-1 - - Tracing.current().newCall("JpaQuery-2", 7); - Tracing.current().newCall("JdbcQuery-2-1", 8); - Tracing.current().endCall(9); - - Tracing.current().newCall("JdbcQuery-2-2", 10); - Tracing.current().endCall(11); - - Tracing.current().endCall(12); //JpaQuery-2 - - Tracing.current().endCall(13); //Servlet - - Deque stack = new ArrayDeque(config.getCallSink().getTransactions().get(0).getCalls()); - - assertEquals(1, stack.pop().getDuration()); //JdbcQuery-1-1 - assertEquals(1, stack.pop().getDuration()); //JdbcQuery-1-2 - - assertEquals(4, stack.peek().getDuration()); //JpaQuery-1 - assertEquals(2, stack.pop().getSelfDuration()); //JpaQuery-1 - - assertEquals(1, stack.pop().getDuration()); //JdbcQuery-2-1 - - assertEquals(1, stack.pop().getDuration()); // JdbcQuery-2-2 - - assertEquals(5, stack.peek().getDuration()); // JpaQuery-2 - assertEquals(3, stack.pop().getSelfDuration()); // JpaQuery-2 - - assertEquals(12, stack.peek().getDuration()); // Servlet - assertEquals(3, stack.pop().getSelfDuration()); // Servlet - } - - @Test - public void testSinkCallsByDuration() { - final Configurer config = new Configurer(); - config.getConfig().setDurationThresholdMillis(100); - - ServiceLocator.configure(config); - - Tracing.newTrace("", Call.TransactionType.BACKGROUND, 1, 1, true); - - Tracing.current().newCall("A", 0); - Tracing.current().newCall("B", 1); - Tracing.current().endCall(99); - Tracing.current().endCall(100); - - assertEquals(1, config.getCallSink().getTransactions().size()); - assertEquals(2, config.getCallSink().getTransactions().get(0).getCalls().size()); - - config.getCallSink().getTransactions().clear(); - - Tracing.current().newCall("A", 0); - Tracing.current().endCall(10); - - assertTrue(config.getCallSink().getTransactions().isEmpty()); - - Tracing.current().newCall("A", 0); - Tracing.current().endCall(100); - - assertEquals(1, config.getCallSink().getTransactions().size()); - assertEquals(1, config.getCallSink().getTransactions().get(0).getCalls().size()); - } - - @Test - public void testIgnore() { - final Configurer config = new Configurer(); - config.getConfig().setDurationThresholdMillis(100); - - ServiceLocator.configure(config); - - Tracing.newTrace("", Call.TransactionType.BACKGROUND, 1, 1, true); - - Tracing.current().newCall("A", 0); - Tracing.current().newCall("B", 1); - Tracing.current().endCall(99); - Tracing.current().endCall(100); - - assertEquals(1, config.getCallSink().getTransactions().size()); - config.getCallSink().getTransactions().clear(); - - Tracing.current().ignore(); - - Tracing.current().newCall("A", 0); - Tracing.current().newCall("B", 1); - Tracing.current().endCall(99); - Tracing.current().endCall(100); - - assertTrue(config.getCallSink().getTransactions().isEmpty()); - } - - @Test - public void testNaming() { - Configurer config = new Configurer(); - ServiceLocator.configure(config); - - Tracing.newTrace("transaction-1", Call.TransactionType.BACKGROUND, 1, 1, true); - Tracing.current().getNamer().asFramework(new JoinPoint("Framework", "entryPoint", "")); - - Tracing.current().newCall("A", 0); - Tracing.current().endCall(10); - - Tracing.endTrace(); - - assertEquals("Framework#entryPoint", config.getCallSink().getTransactions().get(0).getRequest()); - - Tracing.newTrace("", Call.TransactionType.BACKGROUND, 1, 1, true); - Tracing.current().getNamer().asFramework(new JoinPoint("Framework", "entryPoint", "")); - - TransactionAccess.setName("redefined"); - - Tracing.current().newCall("A", 0); - Tracing.current().endCall(10); - - Tracing.endTrace(); - - assertEquals("redefined", config.getCallSink().getTransactions().get(1).getRequest()); - } - - @Test - public void testForceTraceEnd() { - Configurer config = new Configurer(); - ServiceLocator.configure(config); - - Tracing.newTrace("transaction-1", Call.TransactionType.BACKGROUND, 1, 1, true); - Tracing.current().newCall("A", 0); - Tracing.current().newCall("B", 1); - Tracing.current().newCall("C", 2); - - assertNotEquals(NoTrace.instance(), Tracing.current()); - - Tracing.current().forceEnd(true); - - assertNull(Tracing.current().getCurrentCall()); - } - -} diff --git a/spm-tracing-testing/common/src/test/java/com/sematext/spm/client/tracing/agent/api/TransactionAccessTest.java b/spm-tracing-testing/common/src/test/java/com/sematext/spm/client/tracing/agent/api/TransactionAccessTest.java deleted file mode 100644 index 9cd5de5..0000000 --- a/spm-tracing-testing/common/src/test/java/com/sematext/spm/client/tracing/agent/api/TransactionAccessTest.java +++ /dev/null @@ -1,216 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.api; - -import static junit.framework.TestCase.assertFalse; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertTrue; - -import org.junit.Test; -import org.junit.runner.RunWith; - -import java.util.Collections; -import java.util.HashMap; -import java.util.List; - -import com.sematext.spm.client.tracing.Trace; -import com.sematext.spm.client.tracing.TracingParameters; -import com.sematext.spm.client.tracing.agent.NoTrace; -import com.sematext.spm.client.tracing.agent.Tracing; -import com.sematext.spm.client.tracing.agent.config.ServiceLocator; -import com.sematext.spm.client.tracing.agent.errors.TracingError; -import com.sematext.spm.client.tracing.agent.model.Call; -import com.sematext.spm.client.tracing.agent.model.FailureType; -import com.sematext.spm.client.tracing.agent.model.PartialTransaction; -import com.sematext.spm.client.tracing.agent.tracer.Tracers; -import com.sematext.spm.client.tracing.utils.MockSink; -import com.sematext.spm.client.tracing.utils.MockTransactionSink; -import com.sematext.spm.client.tracing.utils.TracingContext; -import com.sematext.spm.client.tracing.utils.TracingJUnit4ClassRunner; -import com.sematext.spm.client.tracing.utils.TracingTesting; - -@RunWith(TracingJUnit4ClassRunner.class) -@TracingContext(tracers = { Tracers.TracedMethodsTracer.class }) -public class TransactionAccessTest { - - @Trace(force = false) - private void tracedMethod() { - System.out.println("traced method"); - } - - @Test - public void testSetName() { - MockTransactionSink mockSink = new MockTransactionSink(); - ServiceLocator.getTransactionSinks().clear(); - ServiceLocator.getTransactionSinks().add(mockSink); - - Tracing.newTrace("generated-name", Call.TransactionType.BACKGROUND); - TransactionAccess.setName("custom-name"); - tracedMethod(); - Tracing.endTrace(); - - PartialTransaction trans = mockSink.getTransactions().get(0); - assertEquals("custom-name", trans.getRequest()); - } - - @Test - public void testIgnore() { - MockTransactionSink mockSink = new MockTransactionSink(); - ServiceLocator.getTransactionSinks().clear(); - ServiceLocator.getTransactionSinks().add(mockSink); - - Tracing.newTrace("ignored-transaction", Call.TransactionType.BACKGROUND); - TransactionAccess.ignore(); - tracedMethod(); - Tracing.endTrace(); - - assertTrue(mockSink.getTransactions().isEmpty()); - } - - @Test - public void testSetTransactionParameter() { - MockTransactionSink mockSink = new MockTransactionSink(); - ServiceLocator.getTransactionSinks().clear(); - ServiceLocator.getTransactionSinks().add(mockSink); - - Tracing.newTrace("parametrized-transaction", Call.TransactionType.BACKGROUND); - - TransactionAccess.setTransactionParameter("key-a", "value-a"); - TransactionAccess.setTransactionParameter("key-b", "value-b"); - - assertEquals("value-a", TransactionAccess.getTransactionParameters().get("key-a")); - assertEquals("value-b", TransactionAccess.getTransactionParameters().get("key-b")); - - tracedMethod(); - Tracing.endTrace(); - - final PartialTransaction trans = mockSink.getTransactions().get(0); - assertEquals(new HashMap() {{ - put("key-a", "value-a"); - put("key-b", "value-b"); - }}, trans.getParameters()); - } - - @Test - public void testSetMethodParameter() { - MockTransactionSink mockSink = new MockTransactionSink(); - ServiceLocator.getTransactionSinks().clear(); - ServiceLocator.getTransactionSinks().add(mockSink); - - Tracing.newTrace("parametrized-transaction", Call.TransactionType.BACKGROUND); - - Tracing.current().newCall("root-call", System.currentTimeMillis()); - - Tracing.current().newCall("call-1", System.currentTimeMillis()); - TransactionAccess.setMethodParameter("key-call-1", "call-1-value"); - assertEquals("call-1-value", TransactionAccess.getMethodParameters().get("key-call-1")); - Tracing.current().endCall(); - - Tracing.current().newCall("call-2", System.currentTimeMillis()); - TransactionAccess.setMethodParameter("key-call-2", "call-2-value"); - assertEquals("call-2-value", TransactionAccess.getMethodParameters().get("key-call-2")); - Tracing.current().endCall(); - - Tracing.current().endCall(); - Tracing.endTrace(); - - final List call1 = TracingTesting.findMatching("call-1", mockSink.getTransactions()); - assertFalse(call1.isEmpty()); - assertEquals(Collections.singletonMap("key-call-1", "call-1-value"), call1.get(0).getParameters()); - - final List call2 = TracingTesting.findMatching("call-2", mockSink.getTransactions()); - assertFalse(call2.isEmpty()); - assertEquals(Collections.singletonMap("key-call-2", "call-2-value"), call2.get(0).getParameters()); - } - - @Test - public void testNoticeErrorThrowable() { - MockSink errorsSink = new MockSink(); - ServiceLocator.getErrorSinks().clear(); - ServiceLocator.getErrorSinks().add(errorsSink); - - MockTransactionSink transactionsSink = new MockTransactionSink(); - ServiceLocator.getTransactionSinks().clear(); - ServiceLocator.getTransactionSinks().add(transactionsSink); - - Tracing.newTrace("parametrized-transaction", Call.TransactionType.BACKGROUND); - assertNotEquals(NoTrace.instance(), Tracing.current()); - - TransactionAccess.setTransactionParameter("alias", "trace-1"); - - Tracing.current().newCall("A", 0); - Tracing.current().newCall("B", 1); - - TransactionAccess.noticeError(new IllegalArgumentException()); - - assertEquals(NoTrace.instance(), Tracing.current()); - - assertEquals(1, transactionsSink.getTransactions().size()); - - PartialTransaction transaction = transactionsSink.getTransactions().get(0); - assertTrue(transaction.isFailed()); - assertEquals(FailureType.EXCEPTION, transaction.getFailureType()); - - assertEquals(1, errorsSink.getEvents().size()); - TracingError error = errorsSink.getEvents().get(0); - - assertEquals("java.lang.IllegalArgumentException", error.getParameters() - .get(TracingParameters.ERROR_CLASS.getKey())); - assertEquals("trace-1", error.getParameters().get("alias")); - } - - @Test - public void testNoticeErrorMessage() { - MockSink errorsSink = new MockSink(); - ServiceLocator.getErrorSinks().clear(); - ServiceLocator.getErrorSinks().add(errorsSink); - - MockTransactionSink transactionsSink = new MockTransactionSink(); - ServiceLocator.getTransactionSinks().clear(); - ServiceLocator.getTransactionSinks().add(transactionsSink); - - Tracing.newTrace("parametrized-transaction", Call.TransactionType.BACKGROUND); - assertNotEquals(NoTrace.instance(), Tracing.current()); - - TransactionAccess.setTransactionParameter("alias", "trace-1"); - - Tracing.current().newCall("A", 0); - Tracing.current().newCall("B", 1); - - TransactionAccess.noticeError("something-went-wrong"); - - assertEquals(NoTrace.instance(), Tracing.current()); - - assertEquals(1, transactionsSink.getTransactions().size()); - - PartialTransaction transaction = transactionsSink.getTransactions().get(0); - assertTrue(transaction.isFailed()); - assertEquals(FailureType.CUSTOM, transaction.getFailureType()); - assertEquals("something-went-wrong", transaction.getParameters().get(TracingParameters.ERROR_MESSAGE.getKey())); - - assertEquals(1, errorsSink.getEvents().size()); - TracingError error = errorsSink.getEvents().get(0); - - assertEquals("something-went-wrong", error.getParameters().get(TracingParameters.ERROR_MESSAGE.getKey())); - assertEquals("trace-1", error.getParameters().get("alias")); - } - -} diff --git a/spm-tracing-testing/common/src/test/java/com/sematext/spm/client/tracing/agent/httpclient4/HttpClientURLTest.java b/spm-tracing-testing/common/src/test/java/com/sematext/spm/client/tracing/agent/httpclient4/HttpClientURLTest.java deleted file mode 100644 index 8f13e10..0000000 --- a/spm-tracing-testing/common/src/test/java/com/sematext/spm/client/tracing/agent/httpclient4/HttpClientURLTest.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.httpclient4; - -import static com.sematext.spm.client.tracing.agent.httpclient4.HttpClientURL.makeUrl; -import static org.junit.Assert.assertEquals; - -import org.junit.Test; - -public class HttpClientURLTest { - private static final class Host implements HttpHostAccess { - private final String hostname; - private final int port; - - private Host(String hostname, int port) { - this.hostname = hostname; - this.port = port; - } - - @Override - public String _$spm_tracing$_getHostName() { - return hostname; - } - - @Override - public int _$spm_tracing$_getPort() { - return port; - } - - @Override - public String _$spm_tracing$_getSchemeName() { - return "http"; - } - } - - private static final class Line implements RequestLineAccess { - private final String uri; - - public Line(String uri) { - this.uri = uri; - } - - @Override - public String _$spm_tracing$_getMethod() { - return null; - } - - @Override - public String _$spm_tracing$_getUri() { - return uri; - } - } - - @Test - public void testMakeUrl() throws Exception { - assertEquals("http://localhost:2345/add-user", makeUrl(new Host("localhost", 2345), new Line("/add-user"))); - assertEquals(null, makeUrl(new Host("localhost", 2345), new Line("add-user"))); - assertEquals("http://localhost:2345/add-user", makeUrl(new Host("localhost", 2344), new Line("http://localhost:2345/add-user"))); - assertEquals("http://localhost:2345/add-user", makeUrl(null, new Line("http://localhost:2345/add-user"))); - assertEquals("http://localhost:2345/add-user?name=jack&age=53", makeUrl(new Host("localhost", 2345), new Line("/add-user?name=jack&age=53"))); - } -} diff --git a/spm-tracing-testing/common/src/test/java/com/sematext/spm/client/tracing/agent/impl/DisruptorThriftEventSinkTest.java b/spm-tracing-testing/common/src/test/java/com/sematext/spm/client/tracing/agent/impl/DisruptorThriftEventSinkTest.java deleted file mode 100644 index bdffbb1..0000000 --- a/spm-tracing-testing/common/src/test/java/com/sematext/spm/client/tracing/agent/impl/DisruptorThriftEventSinkTest.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.impl; - -import static org.junit.Assert.fail; - -import org.junit.Test; - -import java.util.Collections; - -import com.sematext.spm.client.tracing.agent.SinkEvent; -import com.sematext.spm.client.tracing.agent.errors.TracingError; -import com.sematext.spm.client.util.test.TmpFS; - -public class DisruptorThriftEventSinkTest { - @Test - public void testSink() throws Exception { - final TmpFS fs = TmpFS.fs(); - try { - final DisruptorThriftEventSink sink = DisruptorThriftEventSink - .create(fs.createDirectory().getPath(), "tracing", ".bin", 10000, 5); - TracingError error1 = new TracingError("token-1", -1L, -1L, -1L, System - .currentTimeMillis(), true, Collections.emptyMap()); - TracingError error2 = new TracingError("token-1", -1L, -1L, -1L, System - .currentTimeMillis(), true, Collections.emptyMap()); - sink.sink(new SinkEvent(error1)); - sink.sink(new SinkEvent(error2)); - - try { - sink.sink(new SinkEvent(new Object())); - fail("Sink shouldn't accept unknown events"); - } catch (IllegalArgumentException e) { - } - - } finally { - fs.cleanup(); - } - } -} diff --git a/spm-tracing-testing/common/src/test/java/com/sematext/spm/client/tracing/agent/model/HttpHeadersTest.java b/spm-tracing-testing/common/src/test/java/com/sematext/spm/client/tracing/agent/model/HttpHeadersTest.java deleted file mode 100644 index efde107..0000000 --- a/spm-tracing-testing/common/src/test/java/com/sematext/spm/client/tracing/agent/model/HttpHeadersTest.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.model; - -import static com.sematext.spm.client.tracing.agent.model.HttpHeaders.decodeCrossAppCallHeader; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; - -import org.junit.Test; - -import com.sematext.spm.client.tracing.agent.model.HttpHeaders.CrossAppCallHeader; - -public class HttpHeadersTest { - @Test - public void shouldEncodeCrossAppHeader() { - String encoded = HttpHeaders - .encodeCrossAppCallHeader(1L, 2L, 3L, 10L, "token", "request", new Endpoint("127.0.0.1", "localhost"), false); - assertEquals("token;1;2;3;10;request;127.0.0.1;localhost;false", encoded); - } - - @Test - public void shouldDecodeValidCrossAppHeader() { - String encoded = "token;1;2;3;10;request;127.0.0.1;localhost;false"; - CrossAppCallHeader header = decodeCrossAppCallHeader(encoded); - assertNotNull("valid header should be decoded", header); - assertEquals(1L, header.getCallId()); - assertEquals(2L, header.getParentCallId()); - assertEquals(3L, header.getTraceId()); - assertEquals(10L, header.getDuration()); - assertEquals("token", header.getToken()); - assertEquals("request", header.getRequest()); - assertEquals("127.0.0.1", header.getEndpoint().getAddress()); - assertEquals("localhost", header.getEndpoint().getHostname()); - assertFalse(header.isSampled()); - } - - @Test - public void shouldReturnNullIfHeaderIsNotValid() { - assertNull(decodeCrossAppCallHeader("token;1;2;3;10")); - assertNull(decodeCrossAppCallHeader("token;1;2;3;10;token;request")); - assertNull(decodeCrossAppCallHeader("token;1;2;3;10;request;127.0.0.1")); - } -} diff --git a/spm-tracing-testing/common/src/test/java/com/sematext/spm/client/tracing/agent/sql/SqlQueryMaskTest.java b/spm-tracing-testing/common/src/test/java/com/sematext/spm/client/tracing/agent/sql/SqlQueryMaskTest.java deleted file mode 100644 index 07ac6cb..0000000 --- a/spm-tracing-testing/common/src/test/java/com/sematext/spm/client/tracing/agent/sql/SqlQueryMaskTest.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.sql; - -import static com.sematext.spm.client.tracing.agent.sql.SqlQueryMask.mask; -import static org.junit.Assert.assertEquals; - -import org.junit.Test; - -public class SqlQueryMaskTest { - - @Test - public void testMask() throws Exception { - assertEquals(" ? ", mask(" 1234 ")); - assertEquals("select * from user where login = ? and password=?", mask("select * from user where login = 'user-12' and password='qwerty'")); - assertEquals("select * from user where name = ?", mask("select * from user where name = ''")); - assertEquals("select * from user where country = ? and age between(?, ?)", mask("select * from user where country = 'USA' and age between(30, 50)")); - assertEquals("select * from post where title = ?", mask("select * from post where title = 'Kafka, ''The Process'''")); - assertEquals("select * from post where title = ?", mask("select * from post where title = 'Kafka, \\'The Process\\''")); - - assertEquals("select * from post where title = ?", mask("select * from post where title = \"Kafka, \"\"The Process\"\"\"")); - - assertEquals("select owner1 from pets where pet_name = ?", mask("select owner1 from pets where pet_name = 10")); - - System.out.println(mask("select visits0_.pet_id as pet_id4_1_0_, visits0_.id as id1_6_0_, visits0_.id as" + - " id1_6_1_, visits0_.visit_date as visit_da2_6_1_, visits0_.description as descript3_6_1_, \n" - + - "visits0_.pet_id as pet_id4_6_1_ from visits visits0_ where visits0_.pet_id=?")); - } -} diff --git a/spm-tracing-testing/common/src/test/java/com/sematext/spm/client/tracing/agent/sql/SqlQueryMetadataTest.java b/spm-tracing-testing/common/src/test/java/com/sematext/spm/client/tracing/agent/sql/SqlQueryMetadataTest.java deleted file mode 100644 index 96752c9..0000000 --- a/spm-tracing-testing/common/src/test/java/com/sematext/spm/client/tracing/agent/sql/SqlQueryMetadataTest.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.sql; - -import static com.sematext.spm.client.tracing.agent.sql.SqlQueryMetadata.extract; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -import org.junit.Ignore; -import org.junit.Test; - -import com.sematext.spm.client.tracing.agent.sql.SqlQueryMetadata.Metadata; -import com.sematext.spm.client.tracing.agent.sql.SqlQueryMetadata.Operation; - -@Ignore("not implemented") -public class SqlQueryMetadataTest { - private static void assertMetadataEquals(Operation operation, String table, Metadata metadata) { - assertNotNull(metadata); - assertEquals(operation, metadata.getOperation()); - assertEquals(table, metadata.getTable()); - } - - @Test - public void testExtractOpAndTable() { - assertMetadataEquals(Operation.INSERT, "users", extract("insert into Users(id, name) values(1, 'pavel');")); - assertMetadataEquals(Operation.DELETE, "users", extract("delete from Users where id = 1 and name = 'pavel'")); - assertMetadataEquals(Operation.SELECT, "users", extract("select * from Users u")); - } - - @Test - public void testExtractOpWithoutTable() { - assertMetadataEquals(Operation.SELECT, null, extract("select * from Users u join Account a on a.id = u.accountId")); - } -} diff --git a/spm-tracing-testing/common/src/test/java/com/sematext/spm/client/tracing/agent/tracer/CustomDescriptionTracerTest.java b/spm-tracing-testing/common/src/test/java/com/sematext/spm/client/tracing/agent/tracer/CustomDescriptionTracerTest.java deleted file mode 100644 index dbf2434..0000000 --- a/spm-tracing-testing/common/src/test/java/com/sematext/spm/client/tracing/agent/tracer/CustomDescriptionTracerTest.java +++ /dev/null @@ -1,224 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.tracer; - -import static com.sematext.spm.client.tracing.utils.TracingTesting.findMatching; -import static com.sematext.spm.client.tracing.utils.TracingTesting.setupSink; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -import org.junit.Test; -import org.junit.runner.RunWith; - -import java.util.Collection; - -import com.sematext.spm.client.tracing.agent.Tracing; -import com.sematext.spm.client.tracing.agent.config.Config; -import com.sematext.spm.client.tracing.agent.model.Call; -import com.sematext.spm.client.tracing.agent.model.FailureType; -import com.sematext.spm.client.tracing.agent.model.PartialTransaction; -import com.sematext.spm.client.tracing.agent.pointcuts.custom.ExtensionPointcut; -import com.sematext.spm.client.tracing.agent.transformation.TracingTransform; -import com.sematext.spm.client.tracing.utils.MockTransactionSink; -import com.sematext.spm.client.tracing.utils.TracingContext; -import com.sematext.spm.client.tracing.utils.TracingJUnit4ClassRunner; -import com.sematext.spm.client.unlogger.Logspect; -import com.sematext.spm.client.unlogger.xml.InstrumentationDescriptor; -import com.sematext.spm.client.unlogger.xml.InstrumentationLoaderException; -import com.sematext.spm.client.unlogger.xml.XMLInstrumentationDescriptorLoader; - -@RunWith(TracingJUnit4ClassRunner.class) -@TracingContext(tracers = { CustomDescriptionTracerTest.CustomTracer.class }) -public class CustomDescriptionTracerTest { - - public static class CustomTracer implements Tracer { - private final InstrumentationDescriptor descriptor; - - public CustomTracer() { - XMLInstrumentationDescriptorLoader loader = new XMLInstrumentationDescriptorLoader(ExtensionPointcut.class); - try { - this.descriptor = loader - .load(CustomDescriptionTracerTest.class.getResourceAsStream("/custom-description-tracer-test.xml")); - } catch (InstrumentationLoaderException e) { - throw new IllegalStateException(e); - } - } - - @Override - public String getName() { - return descriptor.getName(); - } - - @Override - public Collection createLogspects(ClassLoader loader) { - return descriptor.getLogspects(); - } - - @Override - public TracingTransform[] getStructuralTransforms() { - return new TracingTransform[0]; - } - - @Override - public boolean enabled(Config config) { - return true; - } - } - - public void longWorker() { - System.out.println("Doing work"); - } - - public void fastWorker() { - System.out.println("Fast worker"); - } - - public void testMethodName1() { - System.out.println("testMethodName1"); - } - - @Test - public void testMethodMatch() throws Exception { - MockTransactionSink sink = setupSink(); - - Tracing.newTrace("/", Call.TransactionType.BACKGROUND, 1L, 0L, true); - - longWorker(); - fastWorker(); - testMethodName1(); - - assertEquals(1, findMatching(".*longWorker.*", sink.getTransactions()).size()); - assertEquals(1, findMatching(".*fastWorker.*", sink.getTransactions()).size()); - assertEquals(1, findMatching(".*testMethodName1.*", sink.getTransactions()).size()); - - Tracing.endTrace(); - } - - public static class Service { - public void loadUser() { - System.out.println("loadUser"); - } - - public void loadSystems(Long userId) { - System.out.println("loadSystems"); - } - } - - @Test - public void testWholeClassMatch() throws Exception { - MockTransactionSink sink = setupSink(); - - Tracing.newTrace("/", Call.TransactionType.BACKGROUND, 1L, 0L, true); - - final Service service = new Service(); - - service.loadSystems(10L); - service.loadUser(); - - assertEquals(1, findMatching(".*loadUser.*", sink.getTransactions()).size()); - assertEquals(1, findMatching(".*loadSystems.*", sink.getTransactions()).size()); - - Tracing.endTrace(); - } - - public static class Foo { - public Foo(int x) { - } - - public Foo(int x, int y) { - } - - public Foo(String name) { - } - } - - @Test - public void testConstructorMatch() throws Exception { - MockTransactionSink sink = setupSink(); - - Tracing.newTrace("/", Call.TransactionType.BACKGROUND, 1L, 0L, true); - - new Foo(42); - new Foo(42, 24); - new Foo("foo"); - - assertEquals(3, findMatching(".*Foo.*", sink.getTransactions()).size()); - - Tracing.endTrace(); - } - - public static class Job { - public void doJob() { - System.out.println("job"); - } - } - - @Test - public void testEntryPoint() throws Exception { - MockTransactionSink sink = setupSink(); - - new Job().doJob(); - - assertEquals(1, findMatching(".*doJob.*", sink.getTransactions()).size()); - assertEquals("com.sematext.spm.client.tracing.agent.tracer.CustomDescriptionTracerTest$Job#doJob", sink - .getTransactions().get(0).getRequest()); - } - - public static class CustomJob { - public void doJob() { - System.out.println("job"); - } - } - - @Test - public void testEntryPointTransactionName() throws Exception { - MockTransactionSink sink = setupSink(); - - new CustomJob().doJob(); - - assertEquals(1, findMatching(".*CustomJob.*", sink.getTransactions()).size()); - - assertEquals("CustomTransactionName", sink.getTransactions().get(0).getRequest()); - } - - public static class UnsuccessfulJob { - public void doJob() { - throw new IllegalStateException(); - } - } - - @Test - public void testEntryPointFailure() throws Exception { - MockTransactionSink sink = setupSink(); - - try { - new UnsuccessfulJob().doJob(); - } catch (Exception e) { /* pass */ } - - assertEquals(1, findMatching(".*UnsuccessfulJob.*", sink.getTransactions()).size()); - - PartialTransaction transaction = sink.getTransactions().get(0); - - assertTrue(transaction.isFailed()); - assertEquals(FailureType.EXCEPTION, transaction.getFailureType()); - assertNotNull(transaction.getExceptionStackTrace()); - } -} diff --git a/spm-tracing-testing/common/src/test/java/com/sematext/spm/client/tracing/agent/tracer/HttpClient3TracerTest.java b/spm-tracing-testing/common/src/test/java/com/sematext/spm/client/tracing/agent/tracer/HttpClient3TracerTest.java deleted file mode 100644 index 449aa6a..0000000 --- a/spm-tracing-testing/common/src/test/java/com/sematext/spm/client/tracing/agent/tracer/HttpClient3TracerTest.java +++ /dev/null @@ -1,228 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.tracer; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -import com.sun.net.httpserver.HttpExchange; -import com.sun.net.httpserver.HttpHandler; -import com.sun.net.httpserver.HttpServer; - -import org.apache.commons.httpclient.HttpClient; -import org.apache.commons.httpclient.HttpMethod; -import org.apache.commons.httpclient.methods.DeleteMethod; -import org.apache.commons.httpclient.methods.GetMethod; -import org.apache.commons.httpclient.methods.HeadMethod; -import org.apache.commons.httpclient.methods.PostMethod; -import org.apache.commons.httpclient.methods.PutMethod; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; - -import java.io.IOException; -import java.net.BindException; -import java.net.InetSocketAddress; -import java.net.ServerSocket; -import java.util.ArrayList; -import java.util.List; - -import com.sematext.spm.client.tracing.Trace; -import com.sematext.spm.client.tracing.agent.Tracing; -import com.sematext.spm.client.tracing.agent.config.ServiceLocator; -import com.sematext.spm.client.tracing.agent.httpclient3.HttpClientAccess; -import com.sematext.spm.client.tracing.agent.model.Call; -import com.sematext.spm.client.tracing.agent.model.HttpHeaders; -import com.sematext.spm.client.tracing.agent.model.PartialTransaction; -import com.sematext.spm.client.tracing.agent.model.annotation.HTTPRequestAnnotation; -import com.sematext.spm.client.tracing.agent.solrj5.SolrHttpClient; -import com.sematext.spm.client.tracing.agent.util.Hostname; -import com.sematext.spm.client.tracing.utils.MockTransactionSink; -import com.sematext.spm.client.tracing.utils.TracingContext; -import com.sematext.spm.client.tracing.utils.TracingJUnit4ClassRunner; - -@RunWith(TracingJUnit4ClassRunner.class) -@TracingContext(tracers = { Tracers.TracedMethodsTracer.class, Tracers.HttpClient3Tracer.class }) -public class HttpClient3TracerTest { - - private HttpServer server; - private int port; - - @Before - public void before() throws Exception { - port = 8080; - while (true) { - try { - ServerSocket socket = new ServerSocket(port); - socket.close(); - break; - } catch (BindException e) { - port++; - } - } - - System.out.println("Started on port " + port); - - server = HttpServer.create(); - server.createContext("/ping", new HttpHandler() { - @Override - public void handle(HttpExchange httpExchange) throws IOException { - httpExchange.sendResponseHeaders(200, 4); - httpExchange.getResponseBody().write("pong".getBytes()); - httpExchange.getResponseBody().close(); - httpExchange.close(); - } - }); - server.createContext("/not-found", new HttpHandler() { - @Override - public void handle(HttpExchange httpExchange) throws IOException { - httpExchange.sendResponseHeaders(404, 0); - httpExchange.close(); - } - }); - server.createContext("/cross-app", new HttpHandler() { - @Override - public void handle(HttpExchange httpExchange) throws IOException { - final Long traceId = Long - .parseLong(httpExchange.getRequestHeaders().getFirst(HttpHeaders.SPM_TRACING_TRACE_ID)); - final Long callId = Long.parseLong(httpExchange.getRequestHeaders().getFirst(HttpHeaders.SPM_TRACING_CALL_ID)); - - httpExchange.getResponseHeaders() - .set(HttpHeaders.SPM_TRACING_CROSS_APP_CALL, HttpHeaders.encodeCrossAppCallHeader( - 100L, callId, traceId, 10, "1234", "/cross-app", Hostname.getLocalEndpoint(), false - )); - - httpExchange.sendResponseHeaders(200, 0); - httpExchange.close(); - } - }); - server.bind(new InetSocketAddress("localhost", port), 0); - server.start(); - } - - @After - public void after() throws Exception { - server.stop(2); - } - - @Trace(force = true) - private void executeMethod(HttpMethod method) throws Exception { - HttpClient client = new HttpClient(); - client.executeMethod(method); - } - - private static List filter(Call.CallTag tag, List transactions) { - final List filtered = new ArrayList(); - for (PartialTransaction transaction : transactions) { - for (Call call : transaction.getCalls()) { - if (tag == call.getCallTag()) { - filtered.add(call); - } - } - } - return filtered; - } - - private void testExecuteMethod(String methodName, HttpMethod method, String url, int responseCode) throws Exception { - final MockTransactionSink sink = new MockTransactionSink(); - ServiceLocator.getTransactionSinks().clear(); - ServiceLocator.getTransactionSinks().add(sink); - - executeMethod(method); - - final List getCalls = filter(Call.CallTag.HTTP_REQUEST, sink.getTransactions()); - assertEquals(1, getCalls.size()); - - Call getCall = getCalls.get(0); - assertNotNull(getCall.getAnnotation()); - - HTTPRequestAnnotation annotation = (HTTPRequestAnnotation) getCall.getAnnotation(); - - assertEquals(methodName, annotation.getMethod()); - assertEquals(url, annotation.getUrl()); - assertEquals(responseCode, annotation.getResponseCode()); - } - - @Test - public void testExecuteMethod() throws Exception { - final String pingUrl = "http://localhost:" + port + "/ping"; - - testExecuteMethod("GET", new GetMethod(pingUrl), pingUrl, 200); - testExecuteMethod("POST", new PostMethod(pingUrl), pingUrl, 200); - testExecuteMethod("DELETE", new DeleteMethod(pingUrl), pingUrl, 200); - testExecuteMethod("HEAD", new HeadMethod(pingUrl), pingUrl, 200); - testExecuteMethod("PUT", new PutMethod(pingUrl), pingUrl, 200); - - final String notFoundUrl = "http://localhost:" + port + "/not-found"; - - testExecuteMethod("GET", new GetMethod(notFoundUrl), notFoundUrl, 404); - testExecuteMethod("POST", new PostMethod(notFoundUrl), notFoundUrl, 404); - testExecuteMethod("DELETE", new DeleteMethod(notFoundUrl), notFoundUrl, 404); - testExecuteMethod("HEAD", new HeadMethod(notFoundUrl), notFoundUrl, 404); - testExecuteMethod("PUT", new PutMethod(notFoundUrl), notFoundUrl, 404); - } - - @Trace(force = true) - public void crossAppCall() throws Exception { - HttpClient client = new HttpClient(); - client.executeMethod(new GetMethod("http://localhost:" + port + "/cross-app")); - } - - @Test - public void testCaptureCrossApplicationCall() throws Exception { - final MockTransactionSink sink = new MockTransactionSink(); - ServiceLocator.getTransactionSinks().clear(); - ServiceLocator.getTransactionSinks().add(sink); - - crossAppCall(); - - List calls = filter(Call.CallTag.HTTP_REQUEST, sink.getTransactions()); - assertEquals(1, calls.size()); - - Call httpRequestCall = calls.get(0); - - HTTPRequestAnnotation annotation = (HTTPRequestAnnotation) httpRequestCall.getAnnotation(); - assertNotNull(annotation); - - assertEquals("1234", httpRequestCall.getCrossAppToken()); - assertEquals(new Long(100L), httpRequestCall.getCrossAppCallId()); - assertEquals(new Long(10L), httpRequestCall.getCrossAppDuration()); - assertNotNull(httpRequestCall.getCrossAppParentCallId()); - } - - @Test - public void testCaptureSolrCalls() throws Exception { - Tracing.newTrace("test-request-type", Call.TransactionType.BACKGROUND); - final MockTransactionSink mockTransSink = new MockTransactionSink(); - ServiceLocator.getTransactionSinks().clear(); - ServiceLocator.getTransactionSinks().add(mockTransSink); - - HttpClient httpClient = new HttpClient(); - SolrHttpClient.markSolrClient((HttpClientAccess) httpClient); - - GetMethod select = new GetMethod("http://localhost:" + port + "/select"); - - httpClient.executeMethod(select); - - List solrCalls = filter(Call.CallTag.SOLR, mockTransSink.getTransactions()); - assertEquals(1, solrCalls.size()); - } -} diff --git a/spm-tracing-testing/common/src/test/java/com/sematext/spm/client/tracing/agent/tracer/HttpClient4TracerTest.java b/spm-tracing-testing/common/src/test/java/com/sematext/spm/client/tracing/agent/tracer/HttpClient4TracerTest.java deleted file mode 100644 index 9335181..0000000 --- a/spm-tracing-testing/common/src/test/java/com/sematext/spm/client/tracing/agent/tracer/HttpClient4TracerTest.java +++ /dev/null @@ -1,238 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.tracer; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -import com.sun.net.httpserver.HttpExchange; -import com.sun.net.httpserver.HttpHandler; -import com.sun.net.httpserver.HttpServer; - -import org.apache.http.HttpHost; -import org.apache.http.client.methods.HttpDelete; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.client.methods.HttpHead; -import org.apache.http.client.methods.HttpPost; -import org.apache.http.client.methods.HttpPut; -import org.apache.http.client.methods.HttpUriRequest; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClients; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; - -import java.io.IOException; -import java.net.BindException; -import java.net.InetSocketAddress; -import java.net.ServerSocket; -import java.util.ArrayList; -import java.util.List; - -import com.sematext.spm.client.tracing.Trace; -import com.sematext.spm.client.tracing.agent.config.ServiceLocator; -import com.sematext.spm.client.tracing.agent.model.Call; -import com.sematext.spm.client.tracing.agent.model.Call.CallTag; -import com.sematext.spm.client.tracing.agent.model.HttpHeaders; -import com.sematext.spm.client.tracing.agent.model.PartialTransaction; -import com.sematext.spm.client.tracing.agent.model.annotation.HTTPRequestAnnotation; -import com.sematext.spm.client.tracing.agent.util.Hostname; -import com.sematext.spm.client.tracing.utils.MockTransactionSink; -import com.sematext.spm.client.tracing.utils.TracingContext; -import com.sematext.spm.client.tracing.utils.TracingJUnit4ClassRunner; - -@RunWith(TracingJUnit4ClassRunner.class) -@TracingContext(tracers = { Tracers.TracedMethodsTracer.class, Tracers.HttpClient4Tracer.class }) -public class HttpClient4TracerTest { - - private HttpServer server; - private int port; - - @Before - public void before() throws Exception { - port = 8080; - while (true) { - try { - ServerSocket socket = new ServerSocket(port); - socket.close(); - break; - } catch (BindException e) { - port++; - } - } - - System.out.println("Started on port " + port); - - server = HttpServer.create(); - server.createContext("/ping", new HttpHandler() { - @Override - public void handle(HttpExchange httpExchange) throws IOException { - httpExchange.sendResponseHeaders(200, 4); - httpExchange.getResponseBody().write("pong".getBytes()); - httpExchange.getResponseBody().close(); - httpExchange.close(); - } - }); - server.createContext("/not-found", new HttpHandler() { - @Override - public void handle(HttpExchange httpExchange) throws IOException { - httpExchange.sendResponseHeaders(404, 0); - httpExchange.close(); - } - }); - server.createContext("/cross-app", new HttpHandler() { - @Override - public void handle(HttpExchange httpExchange) throws IOException { - final Long traceId = Long - .parseLong(httpExchange.getRequestHeaders().getFirst(HttpHeaders.SPM_TRACING_TRACE_ID)); - final Long callId = Long.parseLong(httpExchange.getRequestHeaders().getFirst(HttpHeaders.SPM_TRACING_CALL_ID)); - - httpExchange.getResponseHeaders() - .set(HttpHeaders.SPM_TRACING_CROSS_APP_CALL, HttpHeaders.encodeCrossAppCallHeader( - 100L, callId, traceId, 10, "1234", "/cross-app", Hostname.getLocalEndpoint(), false - )); - - httpExchange.sendResponseHeaders(200, 0); - httpExchange.close(); - } - }); - server.bind(new InetSocketAddress("localhost", port), 0); - server.start(); - } - - @After - public void after() throws Exception { - server.stop(2); - } - - @Trace(force = true) - private void executeRequest(HttpUriRequest request) throws Exception { - CloseableHttpClient client = HttpClients.createDefault(); - client.execute(request); - } - - private static List filter(CallTag tag, List transactions) { - final List filtered = new ArrayList(); - for (PartialTransaction transaction : transactions) { - for (Call call : transaction.getCalls()) { - if (tag == call.getCallTag()) { - filtered.add(call); - } - } - } - return filtered; - } - - private void testExecuteRequest(String methodName, HttpUriRequest request, String url, int responseCode) - throws Exception { - final MockTransactionSink sink = new MockTransactionSink(); - ServiceLocator.getTransactionSinks().clear(); - ServiceLocator.getTransactionSinks().add(sink); - - executeRequest(request); - - final List getCalls = filter(CallTag.HTTP_REQUEST, sink.getTransactions()); - assertEquals(1, getCalls.size()); - - Call getCall = getCalls.get(0); - assertNotNull(getCall.getAnnotation()); - - HTTPRequestAnnotation annotation = (HTTPRequestAnnotation) getCall.getAnnotation(); - - assertEquals(methodName, annotation.getMethod()); - assertEquals(url, annotation.getUrl()); - assertEquals(responseCode, annotation.getResponseCode()); - } - - @Test - public void testExecuteMethod() throws Exception { - final String pingUrl = "http://localhost:" + port + "/ping"; - - testExecuteRequest("GET", new HttpGet(pingUrl), pingUrl, 200); - testExecuteRequest("POST", new HttpPost(pingUrl), pingUrl, 200); - testExecuteRequest("DELETE", new HttpDelete(pingUrl), pingUrl, 200); - testExecuteRequest("HEAD", new HttpHead(pingUrl), pingUrl, 200); - testExecuteRequest("PUT", new HttpPut(pingUrl), pingUrl, 200); - - final String notFoundUrl = "http://localhost:" + port + "/not-found"; - - testExecuteRequest("GET", new HttpGet(notFoundUrl), notFoundUrl, 404); - testExecuteRequest("POST", new HttpPost(notFoundUrl), notFoundUrl, 404); - testExecuteRequest("DELETE", new HttpDelete(notFoundUrl), notFoundUrl, 404); - testExecuteRequest("HEAD", new HttpHead(notFoundUrl), notFoundUrl, 404); - testExecuteRequest("PUT", new HttpPut(notFoundUrl), notFoundUrl, 404); - } - - @Trace(force = true) - public void relativeUriCall() throws Exception { - CloseableHttpClient client = HttpClients.createDefault(); - client.execute(new HttpHost("localhost", port), new HttpGet("/ping")); - } - - @Test - public void testRelativeUri() throws Exception { - final MockTransactionSink sink = new MockTransactionSink(); - ServiceLocator.getTransactionSinks().clear(); - ServiceLocator.getTransactionSinks().add(sink); - - relativeUriCall(); - - List calls = filter(CallTag.HTTP_REQUEST, sink.getTransactions()); - assertEquals(1, calls.size()); - - Call httpRequest = calls.get(0); - HTTPRequestAnnotation annotation = (HTTPRequestAnnotation) httpRequest.getAnnotation(); - - assertEquals("GET", annotation.getMethod()); - assertEquals("http://localhost:" + port + "/ping", annotation.getUrl()); - assertEquals(200, annotation.getResponseCode()); - } - - @Trace(force = true) - public void crossAppCall() throws Exception { - CloseableHttpClient client = HttpClients.createDefault(); - client.execute(new HttpGet("http://localhost:" + port + "/cross-app")); - } - - @Test - public void testCaptureCrossApplicationCall() throws Exception { - final MockTransactionSink sink = new MockTransactionSink(); - ServiceLocator.getTransactionSinks().clear(); - ServiceLocator.getTransactionSinks().add(sink); - - crossAppCall(); - - List calls = filter(CallTag.HTTP_REQUEST, sink.getTransactions()); - assertEquals(1, calls.size()); - - Call httpRequestCall = calls.get(0); - - HTTPRequestAnnotation annotation = (HTTPRequestAnnotation) httpRequestCall.getAnnotation(); - assertNotNull(annotation); - assertEquals("http://localhost:" + port + "/cross-app", annotation.getUrl()); - - assertEquals("1234", httpRequestCall.getCrossAppToken()); - assertEquals(new Long(100L), httpRequestCall.getCrossAppCallId()); - assertEquals(new Long(10L), httpRequestCall.getCrossAppDuration()); - assertNotNull(httpRequestCall.getCrossAppParentCallId()); - } - -} diff --git a/spm-tracing-testing/common/src/test/java/com/sematext/spm/client/tracing/agent/tracer/JDBCTracerTest.java b/spm-tracing-testing/common/src/test/java/com/sematext/spm/client/tracing/agent/tracer/JDBCTracerTest.java deleted file mode 100644 index 3953077..0000000 --- a/spm-tracing-testing/common/src/test/java/com/sematext/spm/client/tracing/agent/tracer/JDBCTracerTest.java +++ /dev/null @@ -1,143 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.tracer; - -import static junit.framework.Assert.assertEquals; -import static junit.framework.Assert.assertNotNull; - -import com.mchange.v2.c3p0.ComboPooledDataSource; - -import org.junit.Test; -import org.junit.runner.RunWith; - -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.Statement; -import java.util.List; - -import com.sematext.spm.client.tracing.agent.Tracing; -import com.sematext.spm.client.tracing.agent.config.ServiceLocator; -import com.sematext.spm.client.tracing.agent.model.Call; -import com.sematext.spm.client.tracing.agent.model.annotation.SQLAnnotation; -import com.sematext.spm.client.tracing.agent.sql.SqlStatement; -import com.sematext.spm.client.tracing.utils.MockTransactionSink; -import com.sematext.spm.client.tracing.utils.TracingContext; -import com.sematext.spm.client.tracing.utils.TracingJUnit4ClassRunner; -import com.sematext.spm.client.tracing.utils.TracingTesting; -import com.sematext.spm.client.util.IOUtils; - -@RunWith(TracingJUnit4ClassRunner.class) -@TracingContext(tracers = Tracers.JDBCTracer.class) -public class JDBCTracerTest { - - public void testStatement(final Connection connection) throws Exception { - final Statement statement = connection.createStatement(); - final ResultSet rs = statement.executeQuery("select * from users"); - - while (rs.next()) { - } - - statement.execute("select * from users"); - } - - public void testPreparedStatement(final Connection connection) throws Exception { - final PreparedStatement statement = connection.prepareStatement("select * from users where id = ?"); - statement.setInt(1, 1); - statement.executeQuery().next(); - - statement.setInt(1, 2); - statement.executeQuery().next(); - - statement.setInt(1, 3); - statement.executeQuery().next(); - } - - @Test - @SuppressWarnings("unchecked") - public void test() throws Exception { - Tracing.newTrace("jdbc-trace", Call.TransactionType.BACKGROUND); - - Class.forName("org.h2.Driver"); - - final Connection connection = DriverManager.getConnection("jdbc:h2:mem:test"); - for (final String line : (List) IOUtils.readLines(getClass().getResourceAsStream("/users.sql"))) { - if (line.trim().isEmpty()) { - continue; - } - connection.createStatement().executeUpdate(line); - } - - final MockTransactionSink mockTransactionSink = new MockTransactionSink(); - ServiceLocator.getTransactionSinks().clear(); - ServiceLocator.getTransactionSinks().add(mockTransactionSink); - - testStatement(connection); - assertEquals(2, mockTransactionSink.getTransactions().size()); - - List calls = TracingTesting.findMatching(".*execute\\(\\)", mockTransactionSink.getTransactions()); - assertEquals(1, calls.size()); - - Call jdbcExecuteCall = calls.get(0); - assertNotNull(jdbcExecuteCall.getAnnotation()); - SQLAnnotation sqlAnnotation = (SQLAnnotation) jdbcExecuteCall.getAnnotation(); - assertEquals(SqlStatement.Operation.SELECT, sqlAnnotation.getOperation()); - assertEquals("users", sqlAnnotation.getTable()); - - mockTransactionSink.clean(); - - testPreparedStatement(connection); - assertEquals(3, mockTransactionSink.getTransactions().size()); - - calls = TracingTesting.findMatching(".*executeQuery\\(\\)", mockTransactionSink.getTransactions()); - - jdbcExecuteCall = calls.get(0); - assertNotNull(jdbcExecuteCall.getAnnotation()); - sqlAnnotation = (SQLAnnotation) jdbcExecuteCall.getAnnotation(); - assertEquals(SqlStatement.Operation.SELECT, sqlAnnotation.getOperation()); - assertEquals("users", sqlAnnotation.getTable()); - } - - @Test - public void testIgnoreProxyClasses() throws Exception { - Tracing.newTrace("jdbc-proxy-trace", Call.TransactionType.BACKGROUND); - - final ComboPooledDataSource cpds = new ComboPooledDataSource(); - cpds.setDriverClass("org.h2.Driver"); - cpds.setJdbcUrl("jdbc:h2:mem:test-proxy"); - - final Connection connection = cpds.getConnection(); - for (final String line : (List) IOUtils.readLines(getClass().getResourceAsStream("/users.sql"))) { - if (line.trim().isEmpty()) { - continue; - } - connection.createStatement().executeUpdate(line); - } - - final MockTransactionSink mockCallSink = new MockTransactionSink(); - ServiceLocator.getTransactionSinks().clear(); - ServiceLocator.getTransactionSinks().add(mockCallSink); - - testPreparedStatement(connection); - - assertEquals(3, mockCallSink.clean()); - } -} diff --git a/spm-tracing-testing/common/src/test/java/com/sematext/spm/client/tracing/agent/tracer/ServletTracerTest.java b/spm-tracing-testing/common/src/test/java/com/sematext/spm/client/tracing/agent/tracer/ServletTracerTest.java deleted file mode 100644 index 91b1dc2..0000000 --- a/spm-tracing-testing/common/src/test/java/com/sematext/spm/client/tracing/agent/tracer/ServletTracerTest.java +++ /dev/null @@ -1,217 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.tracer; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; - -import org.junit.Test; -import org.junit.runner.RunWith; - -import java.io.IOException; - -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import com.sematext.spm.client.tracing.TracingParameters; -import com.sematext.spm.client.tracing.agent.config.ServiceLocator; -import com.sematext.spm.client.tracing.agent.errors.TracingError; -import com.sematext.spm.client.tracing.agent.model.Call; -import com.sematext.spm.client.tracing.agent.model.HttpHeaders; -import com.sematext.spm.client.tracing.agent.model.HttpHeaders.CrossAppCallHeader; -import com.sematext.spm.client.tracing.agent.model.PartialTransaction; -import com.sematext.spm.client.tracing.agent.model.WebTransactionSummary; -import com.sematext.spm.client.tracing.agent.util.Hostname; -import com.sematext.spm.client.tracing.utils.MockHttpServletRequest; -import com.sematext.spm.client.tracing.utils.MockHttpServletResponse; -import com.sematext.spm.client.tracing.utils.MockSink; -import com.sematext.spm.client.tracing.utils.MockTransactionSink; -import com.sematext.spm.client.tracing.utils.TracingContext; -import com.sematext.spm.client.tracing.utils.TracingJUnit4ClassRunner; - -@RunWith(TracingJUnit4ClassRunner.class) -@TracingContext(tracers = Tracers.ServletTracer.class) -public class ServletTracerTest { - - public static class JspRenderServlet extends HttpServlet { - @Override - protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { - doGet(req, resp); - } - - @Override - protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { - } - } - - public static class DispatchServlet extends HttpServlet { - private final JspRenderServlet headerJsp; - private final JspRenderServlet footerJsp; - - public DispatchServlet(JspRenderServlet headerJsp, JspRenderServlet footerJsp) { - this.headerJsp = headerJsp; - this.footerJsp = footerJsp; - } - - @Override - protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { - doGet(req, resp); - } - - @Override - protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { - headerJsp.service(req, resp); - footerJsp.service(req, resp); - } - } - - public static class FailingServlet extends HttpServlet { - @Override - protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { - doGet(req, resp); - } - - @Override - protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { - throw new IllegalStateException(); - } - } - - @Test - public void testNestedServletCalls() throws Exception { - final MockTransactionSink sink = new MockTransactionSink(); - ServiceLocator.getTransactionSinks().clear(); - ServiceLocator.getTransactionSinks().add(sink); - - final JspRenderServlet headerJsp = new JspRenderServlet(); - final JspRenderServlet footerJsp = new JspRenderServlet(); - final DispatchServlet dispatcher = new DispatchServlet(headerJsp, footerJsp); - - final MockHttpServletResponse response = new MockHttpServletResponse(); - - dispatcher.service(new MockHttpServletRequest("/users/", "GET"), response); - - assertEquals(1, sink.getTransactions().size()); - - PartialTransaction transaction = sink.getTransactions().get(0); - - assertEquals(3, transaction.getCalls().size()); - - Call d = transaction.getCalls().get(2), jsp1 = transaction.getCalls().get(1), jsp2 = transaction.getCalls().get(0); - - assertEquals(0, d.getParentCallId()); - assertEquals(jsp1.getParentCallId(), d.getCallId()); - assertEquals(jsp2.getParentCallId(), d.getCallId()); - assertEquals(200, ((WebTransactionSummary) transaction.getTransactionSummary()).getResponseCode()); - - assertEquals("com.sematext.spm.client.tracing.agent.tracer.ServletTracerTest$JspRenderServlet#service", transaction - .getRequest()); - - //assertEquals("GET", ((WebTransactionSummary) d.getTransactionSummary()).getRequestMethod()); - - assertNull(response.getHeader(HttpHeaders.SPM_TRACING_CROSS_APP_CALL)); - } - - @Test - public void testCrossAppTracing() throws Exception { - final MockTransactionSink sink = new MockTransactionSink(); - ServiceLocator.getTransactionSinks().clear(); - ServiceLocator.getTransactionSinks().add(sink); - - final JspRenderServlet headerJsp = new JspRenderServlet(); - final JspRenderServlet footerJsp = new JspRenderServlet(); - final DispatchServlet dispatcher = new DispatchServlet(headerJsp, footerJsp); - - final MockHttpServletRequest request = new MockHttpServletRequest("com.sematext.spm.client.tracing.agent.tracer.ServletTracerTest$JspRenderServlet#doGet", "GET"); - request.setHeader(HttpHeaders.SPM_TRACING_CALL_ID, "1"); - request.setHeader(HttpHeaders.SPM_TRACING_TRACE_ID, "2"); - request.setHeader(HttpHeaders.SPM_TRACING_SAMPLED, "true"); - - final MockHttpServletResponse response = new MockHttpServletResponse(); - - dispatcher.service(request, response); - - final String crossAppCallHeader = response.getHeader(HttpHeaders.SPM_TRACING_CROSS_APP_CALL); - assertNotNull(crossAppCallHeader); - - assertEquals(1, sink.getTransactions().size()); - - PartialTransaction transaction = sink.getTransactions().get(0); - - Call dispatcherJspCall = transaction.getCalls().get(2); - Call headerJspCall = transaction.getCalls().get(1); - Call footerJspCall = transaction.getCalls().get(0); - - assertEquals(1L, dispatcherJspCall.getParentCallId()); - - final CrossAppCallHeader header = HttpHeaders.decodeCrossAppCallHeader(crossAppCallHeader); - assertNotNull(header); - - assertEquals(dispatcherJspCall.getCallId(), header.getCallId()); - assertEquals(dispatcherJspCall.getParentCallId(), header.getParentCallId()); - - assertEquals(dispatcherJspCall.getCallId(), headerJspCall.getParentCallId()); - - assertEquals(dispatcherJspCall.getCallId(), footerJspCall.getParentCallId()); - } - - @Test - public void testFailedServletTransactionParametersCapture() throws Exception { - final MockTransactionSink transactionSink = new MockTransactionSink(); - ServiceLocator.getTransactionSinks().clear(); - ServiceLocator.getTransactionSinks().add(transactionSink); - - final MockSink errorSink = new MockSink(); - ServiceLocator.getErrorSinks().clear(); - ServiceLocator.getErrorSinks().add(errorSink); - - final FailingServlet servlet = new FailingServlet(); - final MockHttpServletRequest request = new MockHttpServletRequest("/status", "GET"); - - final MockHttpServletResponse response = new MockHttpServletResponse(); - - try { - servlet.service(request, response); - } catch (Exception e) { - //pass - } - - assertEquals(1, transactionSink.getTransactions().size()); - - final PartialTransaction transaction = transactionSink.getTransactions().get(0); - - assertTrue(transaction.isFailed()); - - assertEquals(1, errorSink.getEvents().size()); - - final TracingError tracingError = errorSink.getEvents().get(0); - - assertEquals("/status", tracingError.getParameters().get(TracingParameters.REQUEST.getKey())); - assertEquals("java.lang.IllegalStateException", tracingError.getParameters() - .get(TracingParameters.ERROR_CLASS.getKey())); - assertNotNull(tracingError.getParameters().get(TracingParameters.DURATION.getKey())); - assertEquals(Hostname.getLocalEndpoint().getHostname(), tracingError.getParameters() - .get(TracingParameters.HOST.getKey())); - } -} diff --git a/spm-tracing-testing/common/src/test/java/com/sematext/spm/client/tracing/agent/tracer/ThreadTracingTest.java b/spm-tracing-testing/common/src/test/java/com/sematext/spm/client/tracing/agent/tracer/ThreadTracingTest.java deleted file mode 100644 index ff25293..0000000 --- a/spm-tracing-testing/common/src/test/java/com/sematext/spm/client/tracing/agent/tracer/ThreadTracingTest.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.tracer; - -import org.junit.Test; -import org.junit.runner.RunWith; - -import com.sematext.spm.client.tracing.Trace; -import com.sematext.spm.client.tracing.agent.Tracing; -import com.sematext.spm.client.tracing.agent.config.ServiceLocator; -import com.sematext.spm.client.tracing.agent.model.Call; -import com.sematext.spm.client.tracing.utils.MockTransactionSink; -import com.sematext.spm.client.tracing.utils.TracingContext; -import com.sematext.spm.client.tracing.utils.TracingJUnit4ClassRunner; - -@RunWith(TracingJUnit4ClassRunner.class) -@TracingContext(tracers = { Tracers.InterThreadCommunication.class, Tracers.TracedMethodsTracer.class }) -public class ThreadTracingTest { - - @Trace - public void forkThread() throws Exception { - final Runnable work = new Runnable() { - @Override - public void run() { - ThreadTracingTest.this.runJob(); - } - }; - final Thread thread = new Thread(work); - thread.start(); - thread.join(); - } - - @Trace - public void runJob() { - } - - @Test - public void testThread() throws Exception { - Tracing.newTrace("threading", Call.TransactionType.BACKGROUND); - - final MockTransactionSink mockCallSink = new MockTransactionSink(); - ServiceLocator.getTransactionSinks().clear(); - ServiceLocator.getTransactionSinks().add(mockCallSink); - - forkThread(); - - for (Call call : mockCallSink.getTransactions().get(0).getCalls()) { - System.out.println(call); - } - } -} diff --git a/spm-tracing-testing/common/src/test/java/com/sematext/spm/client/tracing/agent/tracer/TraceMethodsTracerTest.java b/spm-tracing-testing/common/src/test/java/com/sematext/spm/client/tracing/agent/tracer/TraceMethodsTracerTest.java deleted file mode 100644 index add837f..0000000 --- a/spm-tracing-testing/common/src/test/java/com/sematext/spm/client/tracing/agent/tracer/TraceMethodsTracerTest.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.tracer; - -import static com.sematext.spm.client.tracing.utils.TracingTesting.findMatching; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import org.junit.Test; -import org.junit.runner.RunWith; - -import com.sematext.spm.client.tracing.Trace; -import com.sematext.spm.client.tracing.agent.config.ServiceLocator; -import com.sematext.spm.client.tracing.utils.MockTransactionSink; -import com.sematext.spm.client.tracing.utils.TracingContext; -import com.sematext.spm.client.tracing.utils.TracingJUnit4ClassRunner; - -@RunWith(TracingJUnit4ClassRunner.class) -@TracingContext(tracers = Tracers.TracedMethodsTracer.class) -public class TraceMethodsTracerTest { - - @Trace(force = true) - public void method1() { - System.out.println("method1"); - } - - @Trace(force = false) - public void method2() { - System.out.println("method2"); - } - - @Trace(force = true) - public void service() { - daoCall(); - } - - @Trace - public void daoCall() { - System.out.println("daoCall()"); - } - - @Test - public void testCreateNewTransactionIfNotExists() throws Exception { - final MockTransactionSink sink = new MockTransactionSink(); - ServiceLocator.getTransactionSinks().clear(); - ServiceLocator.getTransactionSinks().add(sink); - - method1(); - - assertEquals(1, sink.getTransactions().size()); - assertEquals(1, sink.getTransactions().get(0).getCalls().size()); - assertTrue(sink.getTransactions().get(0).isEntryPoint()); - assertTrue(sink.getTransactions().get(0).getCalls().get(0).isEntryPoint()); - } - - @Test - public void testDoNotCreateTransactionIfForceIsFalse() { - final MockTransactionSink sink = new MockTransactionSink(); - ServiceLocator.getTransactionSinks().clear(); - ServiceLocator.getTransactionSinks().add(sink); - - method2(); - - assertTrue(sink.getTransactions().isEmpty()); - } - - @Test - public void testShouldKeepTransactionName() { - final MockTransactionSink sink = new MockTransactionSink(); - ServiceLocator.getTransactionSinks().clear(); - ServiceLocator.getTransactionSinks().add(sink); - - service(); - - assertEquals(1, sink.getTransactions().size()); - - assertEquals(2, sink.getTransactions().get(0).getCalls().size()); - assertEquals(1, findMatching(".*daoCall.*", sink.getTransactions()).size()); - assertEquals(1, findMatching(".*service.*", sink.getTransactions()).size()); - } -} diff --git a/spm-tracing-testing/common/src/test/java/com/sematext/spm/client/tracing/agent/tracer/jdbc/BaseEntity.java b/spm-tracing-testing/common/src/test/java/com/sematext/spm/client/tracing/agent/tracer/jdbc/BaseEntity.java deleted file mode 100644 index 205fa8d..0000000 --- a/spm-tracing-testing/common/src/test/java/com/sematext/spm/client/tracing/agent/tracer/jdbc/BaseEntity.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright 2002-2013 the original author or 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 com.sematext.spm.client.tracing.agent.tracer.jdbc; - -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.MappedSuperclass; - -/** - * Simple JavaBean domain object with an id property. Used as a base class for objects needing this property. - * - * @author Ken Krebs - * @author Juergen Hoeller - */ -@MappedSuperclass -public class BaseEntity { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - protected Integer id; - - public void setId(Integer id) { - this.id = id; - } - - public Integer getId() { - return id; - } - - public boolean isNew() { - return (this.id == null); - } - -} diff --git a/spm-tracing-testing/common/src/test/java/com/sematext/spm/client/tracing/agent/tracer/jdbc/JpaTracerTest.java b/spm-tracing-testing/common/src/test/java/com/sematext/spm/client/tracing/agent/tracer/jdbc/JpaTracerTest.java deleted file mode 100644 index 8a9ed14..0000000 --- a/spm-tracing-testing/common/src/test/java/com/sematext/spm/client/tracing/agent/tracer/jdbc/JpaTracerTest.java +++ /dev/null @@ -1,216 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.tracer.jdbc; - -import static com.sematext.spm.client.tracing.utils.CallDebug.printCallTree; -import static org.junit.Assert.assertEquals; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; - -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.Statement; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -import javax.persistence.EntityManager; -import javax.persistence.LockModeType; -import javax.persistence.Persistence; -import javax.persistence.Query; -import javax.persistence.TypedQuery; - -import com.sematext.spm.client.tracing.Trace; -import com.sematext.spm.client.tracing.agent.config.ServiceLocator; -import com.sematext.spm.client.tracing.agent.tracer.Tracers; -import com.sematext.spm.client.tracing.utils.MockTransactionSink; -import com.sematext.spm.client.tracing.utils.TracingContext; -import com.sematext.spm.client.tracing.utils.TracingJUnit4ClassRunner; -import com.sematext.spm.client.util.IOUtils; - -@RunWith(TracingJUnit4ClassRunner.class) -@TracingContext(tracers = { Tracers.TracedMethodsTracer.class, Tracers.JDBCTracer.class, Tracers.JpaTracer.class }) -public class JpaTracerTest { - - private void populateDB(String... scripts) throws Exception { - Class.forName("org.hsqldb.jdbcDriver"); - final Connection connection = DriverManager.getConnection("jdbc:hsqldb:mem:users"); - - for (String script : scripts) { - executeScript(connection, script); - } - } - - private List extractStatements(List lines) { - final List statements = new ArrayList(); - String statement = ""; - for (String line : lines) { - statement += line; - if (line.trim().endsWith(";")) { - statements.add(statement); - statement = ""; - } - } - return statements; - } - - private void executeScript(Connection c, String classPath) throws Exception { - final Statement script = c.createStatement(); - final List lines = (List) IOUtils.readLines(getClass().getResourceAsStream(classPath)); - for (final String sql : extractStatements(lines)) { - if (sql.trim().isEmpty()) continue; - try { - script.addBatch(sql); - } catch (Exception e) { - System.err.println("Invalid statement: [" + sql + "]"); - throw e; - } - } - try { - script.executeBatch(); - } catch (Exception e) { - } - } - - public static class JpaService { - final EntityManager em; - - public JpaService() { - Thread.currentThread().setContextClassLoader(JpaService.class.getClassLoader()); - - this.em = Persistence.createEntityManagerFactory("users").createEntityManager(); - } - - @Trace(force = true) - public int queryUsers() { - TypedQuery query = em.createQuery("select u from User u", User.class); - int i = 0; - for (User user : query.getResultList()) { - i++; - } - - return i; - } - - @Trace(force = true) - @SuppressWarnings("unchecked") - public void findUser() { - em.find(User.class, 1L); - em.find(User.class, 1L, LockModeType.NONE); - em.find(User.class, 1L, Collections.EMPTY_MAP); - em.find(User.class, 1L, LockModeType.NONE, Collections.EMPTY_MAP); - } - - @Trace - @SuppressWarnings("unchecked") - public void insertVets() { - Vet vet1 = new Vet(); - vet1.setFirstName("Vet"); - vet1.setLastName("Vet"); - - em.persist(vet1); - - vet1.setFirstName("NotVet"); - - em.merge(vet1); - - em.remove(vet1); - } - - @Trace - public List findOwners() { - Query query = this.em - .createQuery("SELECT DISTINCT owner FROM Owner owner left join fetch owner.pets WHERE owner.lastName LIKE :lastName"); - query.setParameter("lastName", "%"); - return query.getResultList(); - } - } - - @Before - public void before() throws Exception { - populateDB("/users.sql"); - populateDB("/initDB.sql", "/populateDB.sql"); - } - - @Test - public void testQueryUsers() throws Exception { - final MockTransactionSink mockCallSink = new MockTransactionSink(); - ServiceLocator.getTransactionSinks().clear(); - ServiceLocator.getTransactionSinks().add(mockCallSink); - - JpaService jpaService = new JpaService(); - - assertEquals(4, jpaService.queryUsers()); - - System.out.println(printCallTree(mockCallSink.getTransactions())); - - mockCallSink.clean(); - - assertEquals(4, jpaService.queryUsers()); - - System.out.println(printCallTree(mockCallSink.getTransactions())); - } - - @Test - public void testFindUsers() throws Exception { - final MockTransactionSink sink = new MockTransactionSink(); - ServiceLocator.getTransactionSinks().clear(); - ServiceLocator.getTransactionSinks().add(sink); - - JpaService loader = new JpaService(); - - loader.findUser(); - - System.out.println(printCallTree(sink.getTransactions())); - } - - @Test - public void testInsertVets() throws Exception { - final MockTransactionSink sink = new MockTransactionSink(); - ServiceLocator.getTransactionSinks().clear(); - ServiceLocator.getTransactionSinks().add(sink); - - JpaService service = new JpaService(); - - service.insertVets(); - - System.out.println(printCallTree(sink.getTransactions())); - } - - @Test - public void testListOwners() throws Exception { - - final MockTransactionSink mockCallSink = new MockTransactionSink(); - ServiceLocator.getTransactionSinks().clear(); - ServiceLocator.getTransactionSinks().add(mockCallSink); - - JpaService jpaService = new JpaService(); - - for (int i = 0; i < 1; i++) { - jpaService.findOwners(); - } - - System.out.println(printCallTree(mockCallSink.getTransactions())); - - } - -} diff --git a/spm-tracing-testing/common/src/test/java/com/sematext/spm/client/tracing/agent/tracer/jdbc/NamedEntity.java b/spm-tracing-testing/common/src/test/java/com/sematext/spm/client/tracing/agent/tracer/jdbc/NamedEntity.java deleted file mode 100644 index 53d2e50..0000000 --- a/spm-tracing-testing/common/src/test/java/com/sematext/spm/client/tracing/agent/tracer/jdbc/NamedEntity.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright 2002-2013 the original author or 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 com.sematext.spm.client.tracing.agent.tracer.jdbc; - -import javax.persistence.Column; -import javax.persistence.MappedSuperclass; - -/** - * Simple JavaBean domain object adds a name property to BaseEntity. Used as a base class for objects - * needing these properties. - * - * @author Ken Krebs - * @author Juergen Hoeller - */ -@MappedSuperclass -public class NamedEntity extends BaseEntity { - - @Column(name = "name") - private String name; - - public void setName(String name) { - this.name = name; - } - - public String getName() { - return this.name; - } - - @Override - public String toString() { - return this.getName(); - } - -} diff --git a/spm-tracing-testing/common/src/test/java/com/sematext/spm/client/tracing/agent/tracer/jdbc/Owner.java b/spm-tracing-testing/common/src/test/java/com/sematext/spm/client/tracing/agent/tracer/jdbc/Owner.java deleted file mode 100644 index 53949e5..0000000 --- a/spm-tracing-testing/common/src/test/java/com/sematext/spm/client/tracing/agent/tracer/jdbc/Owner.java +++ /dev/null @@ -1,137 +0,0 @@ -/* - * Copyright 2002-2013 the original author or 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 com.sematext.spm.client.tracing.agent.tracer.jdbc; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import javax.persistence.CascadeType; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.OneToMany; -import javax.persistence.Table; - -/** - * Simple JavaBean domain object representing an owner. - * - * @author Ken Krebs - * @author Juergen Hoeller - * @author Sam Brannen - * @author Michael Isvy - */ -@Entity -@Table(name = "owners") -public class Owner extends Person { - @Column(name = "address") - private String address; - - @Column(name = "city") - private String city; - - @Column(name = "telephone") - private String telephone; - - @OneToMany(cascade = CascadeType.ALL, mappedBy = "owner") - private Set pets; - - public String getAddress() { - return this.address; - } - - public void setAddress(String address) { - this.address = address; - } - - public String getCity() { - return this.city; - } - - public void setCity(String city) { - this.city = city; - } - - public String getTelephone() { - return this.telephone; - } - - public void setTelephone(String telephone) { - this.telephone = telephone; - } - - protected void setPetsInternal(Set pets) { - this.pets = pets; - } - - protected Set getPetsInternal() { - if (this.pets == null) { - this.pets = new HashSet(); - } - return this.pets; - } - - public List getPets() { - List sortedPets = new ArrayList(getPetsInternal()); - return Collections.unmodifiableList(sortedPets); - } - - public void addPet(Pet pet) { - getPetsInternal().add(pet); - pet.setOwner(this); - } - - /** - * Return the Pet with the given name, or null if none found for this Owner. - * - * @param name to test - * @return true if pet name is already in use - */ - public Pet getPet(String name) { - return getPet(name, false); - } - - /** - * Return the Pet with the given name, or null if none found for this Owner. - * - * @param name to test - * @return true if pet name is already in use - */ - public Pet getPet(String name, boolean ignoreNew) { - name = name.toLowerCase(); - for (Pet pet : getPetsInternal()) { - if (!ignoreNew || !pet.isNew()) { - String compName = pet.getName(); - compName = compName.toLowerCase(); - if (compName.equals(name)) { - return pet; - } - } - } - return null; - } - - @Override - public String toString() { - return "Owner{" + - "address='" + address + '\'' + - ", city='" + city + '\'' + - ", telephone='" + telephone + '\'' + - ", pets=" + pets + - '}'; - } -} diff --git a/spm-tracing-testing/common/src/test/java/com/sematext/spm/client/tracing/agent/tracer/jdbc/Person.java b/spm-tracing-testing/common/src/test/java/com/sematext/spm/client/tracing/agent/tracer/jdbc/Person.java deleted file mode 100644 index 06d7cd2..0000000 --- a/spm-tracing-testing/common/src/test/java/com/sematext/spm/client/tracing/agent/tracer/jdbc/Person.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 2002-2013 the original author or 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 com.sematext.spm.client.tracing.agent.tracer.jdbc; - -import javax.persistence.Column; -import javax.persistence.MappedSuperclass; - -/** - * Simple JavaBean domain object representing an person. - * - * @author Ken Krebs - */ -@MappedSuperclass -public class Person extends BaseEntity { - - @Column(name = "first_name") - protected String firstName; - - @Column(name = "last_name") - protected String lastName; - - public String getFirstName() { - return this.firstName; - } - - public void setFirstName(String firstName) { - this.firstName = firstName; - } - - public String getLastName() { - return this.lastName; - } - - public void setLastName(String lastName) { - this.lastName = lastName; - } - -} diff --git a/spm-tracing-testing/common/src/test/java/com/sematext/spm/client/tracing/agent/tracer/jdbc/Pet.java b/spm-tracing-testing/common/src/test/java/com/sematext/spm/client/tracing/agent/tracer/jdbc/Pet.java deleted file mode 100644 index acb4ae2..0000000 --- a/spm-tracing-testing/common/src/test/java/com/sematext/spm/client/tracing/agent/tracer/jdbc/Pet.java +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright 2002-2013 the original author or 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 com.sematext.spm.client.tracing.agent.tracer.jdbc; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.Date; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import javax.persistence.CascadeType; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.FetchType; -import javax.persistence.JoinColumn; -import javax.persistence.ManyToOne; -import javax.persistence.OneToMany; -import javax.persistence.Table; - -/** - * Simple business object representing a pet. - * - * @author Ken Krebs - * @author Juergen Hoeller - * @author Sam Brannen - */ -@Entity -@Table(name = "pets") -public class Pet extends NamedEntity { - - @Column(name = "birth_date") - private Date birthDate; - - @ManyToOne - @JoinColumn(name = "type_id") - private PetType type; - - @ManyToOne - @JoinColumn(name = "owner_id") - private Owner owner; - - @OneToMany(cascade = CascadeType.ALL, mappedBy = "pet", fetch = FetchType.EAGER) - private Set visits; - - public Date getBirthDate() { - return birthDate; - } - - public void setBirthDate(Date birthDate) { - this.birthDate = birthDate; - } - - public void setType(PetType type) { - this.type = type; - } - - public PetType getType() { - return this.type; - } - - protected void setOwner(Owner owner) { - this.owner = owner; - } - - public Owner getOwner() { - return this.owner; - } - - protected void setVisitsInternal(Set visits) { - this.visits = visits; - } - - protected Set getVisitsInternal() { - if (this.visits == null) { - this.visits = new HashSet(); - } - return this.visits; - } - - public List getVisits() { - List sortedVisits = new ArrayList(getVisitsInternal()); - return Collections.unmodifiableList(sortedVisits); - } - - public void addVisit(Visit visit) { - getVisitsInternal().add(visit); - visit.setPet(this); - } - -} diff --git a/spm-tracing-testing/common/src/test/java/com/sematext/spm/client/tracing/agent/tracer/jdbc/PetType.java b/spm-tracing-testing/common/src/test/java/com/sematext/spm/client/tracing/agent/tracer/jdbc/PetType.java deleted file mode 100644 index 10a41d2..0000000 --- a/spm-tracing-testing/common/src/test/java/com/sematext/spm/client/tracing/agent/tracer/jdbc/PetType.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright 2002-2013 the original author or 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 com.sematext.spm.client.tracing.agent.tracer.jdbc; - -import javax.persistence.Entity; -import javax.persistence.Table; - -/** - * @author Juergen Hoeller - */ -@Entity -@Table(name = "types") -public class PetType extends NamedEntity { - -} diff --git a/spm-tracing-testing/common/src/test/java/com/sematext/spm/client/tracing/agent/tracer/jdbc/Specialty.java b/spm-tracing-testing/common/src/test/java/com/sematext/spm/client/tracing/agent/tracer/jdbc/Specialty.java deleted file mode 100644 index d930b85..0000000 --- a/spm-tracing-testing/common/src/test/java/com/sematext/spm/client/tracing/agent/tracer/jdbc/Specialty.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright 2002-2013 the original author or 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 com.sematext.spm.client.tracing.agent.tracer.jdbc; - -import javax.persistence.Entity; -import javax.persistence.Table; - -/** - * Models a {@link Vet Vet's} specialty (for example, dentistry). - * - * @author Juergen Hoeller - */ -@Entity -@Table(name = "specialties") -public class Specialty extends NamedEntity { - -} diff --git a/spm-tracing-testing/common/src/test/java/com/sematext/spm/client/tracing/agent/tracer/jdbc/User.java b/spm-tracing-testing/common/src/test/java/com/sematext/spm/client/tracing/agent/tracer/jdbc/User.java deleted file mode 100644 index 353f3f2..0000000 --- a/spm-tracing-testing/common/src/test/java/com/sematext/spm/client/tracing/agent/tracer/jdbc/User.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.tracer.jdbc; - -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.Table; - -@Entity -@Table(name = "users") -public class User { - @Id - private Long id; - private String name; - private int age; - - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public int getAge() { - return age; - } - - public void setAge(int age) { - this.age = age; - } -} diff --git a/spm-tracing-testing/common/src/test/java/com/sematext/spm/client/tracing/agent/tracer/jdbc/Vet.java b/spm-tracing-testing/common/src/test/java/com/sematext/spm/client/tracing/agent/tracer/jdbc/Vet.java deleted file mode 100644 index f3ad561..0000000 --- a/spm-tracing-testing/common/src/test/java/com/sematext/spm/client/tracing/agent/tracer/jdbc/Vet.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright 2002-2013 the original author or 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 com.sematext.spm.client.tracing.agent.tracer.jdbc; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import javax.persistence.Entity; -import javax.persistence.FetchType; -import javax.persistence.JoinColumn; -import javax.persistence.JoinTable; -import javax.persistence.ManyToMany; -import javax.persistence.Table; -import javax.xml.bind.annotation.XmlElement; - -/** - * Simple JavaBean domain object representing a veterinarian. - * - * @author Ken Krebs - * @author Juergen Hoeller - * @author Sam Brannen - * @author Arjen Poutsma - */ -@Entity -@Table(name = "vets") -public class Vet extends Person { - - @ManyToMany(fetch = FetchType.EAGER) - @JoinTable(name = "vet_specialties", joinColumns = @JoinColumn(name = "vet_id"), - inverseJoinColumns = @JoinColumn(name = "specialty_id")) - private Set specialties; - - protected void setSpecialtiesInternal(Set specialties) { - this.specialties = specialties; - } - - protected Set getSpecialtiesInternal() { - if (this.specialties == null) { - this.specialties = new HashSet(); - } - return this.specialties; - } - - @XmlElement - public List getSpecialties() { - List sortedSpecs = new ArrayList(getSpecialtiesInternal()); - return Collections.unmodifiableList(sortedSpecs); - } - - public int getNrOfSpecialties() { - return getSpecialtiesInternal().size(); - } - - public void addSpecialty(Specialty specialty) { - getSpecialtiesInternal().add(specialty); - } - -} diff --git a/spm-tracing-testing/common/src/test/java/com/sematext/spm/client/tracing/agent/tracer/jdbc/Vets.java b/spm-tracing-testing/common/src/test/java/com/sematext/spm/client/tracing/agent/tracer/jdbc/Vets.java deleted file mode 100644 index 8bb5bff..0000000 --- a/spm-tracing-testing/common/src/test/java/com/sematext/spm/client/tracing/agent/tracer/jdbc/Vets.java +++ /dev/null @@ -1,44 +0,0 @@ -/* -/* - * Copyright 2002-2013 the original author or 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 com.sematext.spm.client.tracing.agent.tracer.jdbc; - -import java.util.ArrayList; -import java.util.List; - -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlRootElement; - -/** - * Simple domain object representing a list of veterinarians. Mostly here to be used for the 'vets' {@link - * org.springframework.web.servlet.view.xml.MarshallingView}. - * - * @author Arjen Poutsma - */ -@XmlRootElement -public class Vets { - - private List vets; - - @XmlElement - public List getVetList() { - if (vets == null) { - vets = new ArrayList(); - } - return vets; - } - -} diff --git a/spm-tracing-testing/common/src/test/java/com/sematext/spm/client/tracing/agent/tracer/jdbc/Visit.java b/spm-tracing-testing/common/src/test/java/com/sematext/spm/client/tracing/agent/tracer/jdbc/Visit.java deleted file mode 100644 index 72c275f..0000000 --- a/spm-tracing-testing/common/src/test/java/com/sematext/spm/client/tracing/agent/tracer/jdbc/Visit.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright 2002-2013 the original author or 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 com.sematext.spm.client.tracing.agent.tracer.jdbc; - -import java.util.Date; - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.JoinColumn; -import javax.persistence.ManyToOne; -import javax.persistence.Table; - -/** - * Simple JavaBean domain object representing a visit. - * - * @author Ken Krebs - */ -@Entity -@Table(name = "visits") -public class Visit extends BaseEntity { - - /** - * Holds value of property date. - */ - @Column(name = "visit_date") - private Date date; - - /** - * Holds value of property description. - */ - @Column(name = "description") - private String description; - - /** - * Holds value of property pet. - */ - @ManyToOne - @JoinColumn(name = "pet_id") - private Pet pet; - - /** - * Creates a new instance of Visit for the current date - */ - public Visit() { - this.date = new Date(); - } - - public Date getDate() { - return date; - } - - public void setDate(Date date) { - this.date = date; - } - - /** - * Getter for property description. - * - * @return Value of property description. - */ - public String getDescription() { - return this.description; - } - - /** - * Setter for property description. - * - * @param description New value of property description. - */ - public void setDescription(String description) { - this.description = description; - } - - /** - * Getter for property pet. - * - * @return Value of property pet. - */ - public Pet getPet() { - return this.pet; - } - - /** - * Setter for property pet. - * - * @param pet New value of property pet. - */ - public void setPet(Pet pet) { - this.pet = pet; - } - -} diff --git a/spm-tracing-testing/common/src/test/java/com/sematext/spm/client/tracing/agent/tracer/jdbc/package-info.java b/spm-tracing-testing/common/src/test/java/com/sematext/spm/client/tracing/agent/tracer/jdbc/package-info.java deleted file mode 100644 index 282089a..0000000 --- a/spm-tracing-testing/common/src/test/java/com/sematext/spm/client/tracing/agent/tracer/jdbc/package-info.java +++ /dev/null @@ -1,26 +0,0 @@ - -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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. - */ - -/** - * The classes in this package represent PetClinic's business layer. - */ -package com.sematext.spm.client.tracing.agent.tracer.jdbc; - diff --git a/spm-tracing-testing/common/src/test/java/com/sematext/spm/client/tracing/agent/tracer/solr4j/Solrj53TracerIntegrationTest.java b/spm-tracing-testing/common/src/test/java/com/sematext/spm/client/tracing/agent/tracer/solr4j/Solrj53TracerIntegrationTest.java deleted file mode 100644 index 4c86eea..0000000 --- a/spm-tracing-testing/common/src/test/java/com/sematext/spm/client/tracing/agent/tracer/solr4j/Solrj53TracerIntegrationTest.java +++ /dev/null @@ -1,182 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.tracer.solr4j; - -import static com.sematext.spm.client.tracing.utils.TracingTesting.setupSink; -import static java.util.Collections.singletonMap; -import static junit.framework.TestCase.assertTrue; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -import org.apache.http.HttpResponse; -import org.apache.solr.client.solrj.SolrClient; -import org.apache.solr.client.solrj.SolrRequest; -import org.apache.solr.client.solrj.impl.ConcurrentUpdateSolrClient; -import org.apache.solr.client.solrj.impl.HttpSolrClient; -import org.apache.solr.client.solrj.request.CollectionAdminRequest; -import org.apache.solr.client.solrj.request.ContentStreamUpdateRequest; -import org.apache.solr.client.solrj.request.DirectXmlRequest; -import org.apache.solr.client.solrj.request.QueryRequest; -import org.apache.solr.client.solrj.request.UpdateRequest; -import org.apache.solr.client.solrj.request.schema.SchemaRequest; -import org.apache.solr.client.solrj.response.CollectionAdminResponse; -import org.apache.solr.common.SolrInputDocument; -import org.apache.solr.common.params.MapSolrParams; -import org.apache.solr.common.util.ContentStreamBase; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; - -import java.util.List; -import java.util.concurrent.CountDownLatch; - -import com.sematext.spm.client.tracing.agent.Tracing; -import com.sematext.spm.client.tracing.agent.config.ServiceLocator; -import com.sematext.spm.client.tracing.agent.model.Call; -import com.sematext.spm.client.tracing.agent.model.PartialTransaction; -import com.sematext.spm.client.tracing.agent.model.SolrAnnotation; -import com.sematext.spm.client.tracing.agent.tracer.Tracers; -import com.sematext.spm.client.tracing.utils.MockTransactionSink; -import com.sematext.spm.client.tracing.utils.TracingContext; -import com.sematext.spm.client.tracing.utils.TracingJUnit4ClassRunner; -import com.sematext.spm.client.tracing.utils.TracingTesting; - -@RunWith(TracingJUnit4ClassRunner.class) -@TracingContext(tracers = { Tracers.Solrj5Tracer.class, Tracers.HttpClient4Tracer.class }) -public class Solrj53TracerIntegrationTest { - - private SolrClient getSolrClient() { - return new HttpSolrClient("http://localhost:8983/solr"); - } - - @Before - @SuppressWarnings("unchecked") - public void preStart() throws Exception { - final SolrClient client = getSolrClient(); - CollectionAdminResponse response = new CollectionAdminRequest.List().process(client); - - for (Object names : response.getResponse().getAll("collections")) { - for (String name : (List) names) { - if (name.equals("test-collection-1") || name.equals("test-collection-2")) { - new CollectionAdminRequest.Delete().setCollectionName(name).process(client); - } - } - } - - new CollectionAdminRequest.Create().setCollectionName("test-collection-1").setNumShards(1).process(client); - new CollectionAdminRequest.Create().setCollectionName("test-collection-2").setNumShards(1).process(client); - } - - private SolrAnnotation testRequestType(SolrRequest request, String collection, SolrAnnotation.RequestType expected) - throws Exception { - Tracing.newTrace("test-request-type", Call.TransactionType.BACKGROUND); - final MockTransactionSink mockTransSink = new MockTransactionSink(); - ServiceLocator.getTransactionSinks().clear(); - ServiceLocator.getTransactionSinks().add(mockTransSink); - - try { - request.process(getSolrClient(), collection); - - assertEquals(1, mockTransSink.getTransactions().size()); - assertEquals(1, mockTransSink.getTransactions().get(0).getCalls().size()); - - final Call call = mockTransSink.getTransactions().get(0).getCalls().get(0); - assertEquals(Call.CallTag.SOLR, call.getCallTag()); - - final SolrAnnotation annotation = (SolrAnnotation) call.getAnnotation(); - assertNotNull(annotation); - - assertEquals(expected, annotation.getRequestType()); - assertEquals(200, annotation.getResponseStatus()); - assertTrue(annotation.isSucceed()); - return annotation; - } finally { - Tracing.endTrace(); - } - } - - private static final String XML_DOC = "\n" + - "\n" + - " SOLR1000\n" + - " Solr, the Enterprise Search Server\n" + - "\n" + - "\n" + - "\n"; - - @Test - public void testRequestTypes() throws Exception { - SolrAnnotation annotation = testRequestType(new QueryRequest(new MapSolrParams(singletonMap("q", "*.*"))), "test-collection-1", SolrAnnotation.RequestType.QUERY); - final SolrInputDocument document = new SolrInputDocument(); - document.addField("firstName", "Corey"); - document.addField("lastName", "Taylor"); - annotation = testRequestType(new UpdateRequest() - .add(document), "test-collection-1", SolrAnnotation.RequestType.UPDATE); - assertEquals("test-collection-1", annotation.getCollection()); - - final ContentStreamUpdateRequest contentStreamRequest = new ContentStreamUpdateRequest("/update"); - contentStreamRequest.addContentStream(new ContentStreamBase.StringStream(XML_DOC, "application/xml")); - annotation = testRequestType(contentStreamRequest, "test-collection-1", SolrAnnotation.RequestType.UPDATE); - assertEquals("test-collection-1", annotation.getCollection()); - - final DirectXmlRequest xmlRequest = new DirectXmlRequest("/update", XML_DOC); - annotation = testRequestType(xmlRequest, "test-collection-1", SolrAnnotation.RequestType.UPDATE); - assertEquals("test-collection-1", annotation.getCollection()); - - final SchemaRequest.Fields fieldsRequest = new SchemaRequest.Fields(); - testRequestType(fieldsRequest, "test-collection-1", SolrAnnotation.RequestType.SCHEMA); - - testRequestType(new CollectionAdminRequest.List(), null, SolrAnnotation.RequestType.COLLECTION_ADMIN); - } - - @Test - public void testConcurrentUpdate() throws Exception { - Tracing.newTrace("test-request-type", Call.TransactionType.BACKGROUND); - final MockTransactionSink mockTransSink = setupSink(); - - final CountDownLatch latch = new CountDownLatch(10); - - final ConcurrentUpdateSolrClient client = new ConcurrentUpdateSolrClient("http://localhost:8983/solr/test-collection-1", 2, 10) { - @Override - public void onSuccess(HttpResponse resp) { - latch.countDown(); - } - - @Override - public void handleError(Throwable ex) { - ex.printStackTrace(); - latch.countDown(); - } - }; - - for (int i = 0; i < 10; i++) { - final SolrInputDocument document = new SolrInputDocument(); - document.addField("firstName", "Corey"); - document.addField("lastName", "Taylor"); - - new UpdateRequest("/test-collection-1/update").add(document).process(client, "test-collection-1"); - } - - latch.await(); - - List async = TracingTesting.findAsync(mockTransSink.getTransactions()); - assertEquals(10, async.size()); - } - -} diff --git a/spm-tracing-testing/common/src/test/java/com/sematext/spm/client/tracing/agent/util/AsyncContextTest.java b/spm-tracing-testing/common/src/test/java/com/sematext/spm/client/tracing/agent/util/AsyncContextTest.java deleted file mode 100644 index e2dc8a4..0000000 --- a/spm-tracing-testing/common/src/test/java/com/sematext/spm/client/tracing/agent/util/AsyncContextTest.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.util; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; - -import org.junit.Test; - -public class AsyncContextTest { - - private static class MyThread { - private int hashCodeCalled; - private int equalsCalled; - private final String name; - - public MyThread(String name) { - this.name = name; - } - - @Override - public boolean equals(Object o) { - equalsCalled++; - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - MyThread myThread = (MyThread) o; - - if (name != null ? !name.equals(myThread.name) : myThread.name != null) return false; - - return true; - } - - @Override - public int hashCode() { - hashCodeCalled++; - return name != null ? name.hashCode() : 0; - } - } - - @Test - public void testShouldStoreAsyncContextByObjectIdentity() { - final MyThread t1 = new MyThread("t1"); - final MyThread t2 = new MyThread("t2"); - - AsyncContext.create(t1, 1L, 2L, false); - - assertNull(AsyncContext.get(t2)); - assertEquals(new Long(1L), AsyncContext.get(t1).getTraceId()); - assertEquals(new Long(2L), AsyncContext.get(t1).getParentCallId()); - - AsyncContext.create(t2, 1L, 3L, false); - - assertEquals(new Long(2L), AsyncContext.get(t1).getParentCallId()); - assertEquals(new Long(3L), AsyncContext.get(t2).getParentCallId()); - - assertEquals(0, t1.equalsCalled); - assertEquals(0, t1.hashCodeCalled); - - assertEquals(0, t2.equalsCalled); - assertEquals(0, t2.hashCodeCalled); - } - -} diff --git a/spm-tracing-testing/common/src/test/java/com/sematext/spm/client/tracing/agent/util/BinarySequentialLogTest.java b/spm-tracing-testing/common/src/test/java/com/sematext/spm/client/tracing/agent/util/BinarySequentialLogTest.java deleted file mode 100644 index d4a63f5..0000000 --- a/spm-tracing-testing/common/src/test/java/com/sematext/spm/client/tracing/agent/util/BinarySequentialLogTest.java +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.util; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import org.junit.Test; - -import java.io.File; -import java.io.FilenameFilter; - -import com.sematext.spm.client.util.test.TmpFS; - -public class BinarySequentialLogTest { - @Test - public void testShouldCreateLogWithZeroSeqNoIfDirectoryIsEmpty() throws Exception { - final TmpFS fs = TmpFS.fs(); - try { - File dir = fs.createDirectory(); - BinarySequentialLog log = BinarySequentialLog.create(dir.getAbsolutePath(), "tracing", ".bin", 128, 1); - log.write(new byte[] { 1, 2, 3, 4 }); - log.flush(); - assertTrue(new File(dir, "tracing-0.bin").isFile()); - } finally { - fs.cleanup(); - } - } - - @Test - public void testShouldCreateLogWithNextSeqNoIfPreviousLogsExist() throws Exception { - final TmpFS fs = TmpFS.fs(); - try { - File dir = fs.createDirectory(); - fs.createFile(dir, "tracing-1.bin"); - BinarySequentialLog log = BinarySequentialLog.create(dir.getAbsolutePath(), "tracing", ".bin", 128, 1); - log.write(new byte[] { 1, 2, 3, 4 }); - log.flush(); - assertTrue(new File(dir, "tracing-2.bin").isFile()); - } finally { - fs.cleanup(); - } - } - - private static final FilenameFilter TRACING_LOG_FILTER = new FilenameFilter() { - @Override - public boolean accept(File dir, String name) { - return name.startsWith("tracing-") && name.endsWith(".bin"); - } - }; - - @Test - public void testShouldKeepGivenCountOfLogFilesAfterCleanup() throws Exception { - final TmpFS fs = TmpFS.fs(); - try { - File dir = fs.createDirectory(); - BinarySequentialLog log = BinarySequentialLog.create(dir.getAbsolutePath(), "tracing", ".bin", 8, 1); - log.write(new byte[] { 1, 2, 3, 4 }); //tracing-0.bin - log.write(new byte[] { 1, 2, 3, 4 }); //tracing-1.bin - log.write(new byte[] { 1, 2, 3, 4 }); //tracing-2.bin - - assertEquals(2, dir.list(TRACING_LOG_FILTER).length); - - assertTrue(new File(dir, "tracing-1.bin").isFile()); - assertTrue(new File(dir, "tracing-2.bin").isFile()); - } finally { - fs.cleanup(); - } - } - - @Test - public void testShoulKeepGivenCountOfLogFilesAfterCleanupWithPreexisting() throws Exception { - final TmpFS fs = TmpFS.fs(); - try { - File dir = fs.createDirectory(); - for (int i = 0; i < 5; i++) { - fs.createFile(dir, "tracing-" + i + ".bin"); - } - BinarySequentialLog log = BinarySequentialLog.create(dir.getAbsolutePath(), "tracing", ".bin", 16, 1); - log.write(new byte[] { 1, 2, 3, 4 }); //tracing-5.bin - log.write(new byte[] { 1, 2, 3, 4 }); //tracing-5.bin - log.write(new byte[] { 1, 2, 3, 4 }); //tracing-6.bin - log.write(new byte[] { 1, 2, 3, 4 }); //tracing-6.bin - log.write(new byte[] { 1, 2, 3, 4 }); //tracing-7.bin - log.write(new byte[] { 1, 2, 3, 4 }); //tracing-7.bin - - assertEquals(2, dir.list(TRACING_LOG_FILTER).length); - - assertTrue(new File(dir, "tracing-6.bin").isFile()); - assertTrue(new File(dir, "tracing-7.bin").isFile()); - } finally { - fs.cleanup(); - } - } -} diff --git a/spm-tracing-testing/common/src/test/java/com/sematext/spm/client/tracing/agent/util/JdbcURLTest.java b/spm-tracing-testing/common/src/test/java/com/sematext/spm/client/tracing/agent/util/JdbcURLTest.java deleted file mode 100644 index 5c9e2fe..0000000 --- a/spm-tracing-testing/common/src/test/java/com/sematext/spm/client/tracing/agent/util/JdbcURLTest.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.util; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; - -import org.junit.Test; - -public class JdbcURLTest { - @Test - public void testGetHostname() throws Exception { - assertEquals("some-rds.rds.amazonaws.com", JdbcURL - .getHostname("jdbc:mysql://some-rds.rds.amazonaws.com:3306/sematext_users_db?autoReconnect=true")); - assertEquals("some", JdbcURL.getHostname("jdbc://some:3306")); - assertEquals("some", JdbcURL.getHostname("jdbc://some/db")); - assertEquals("some", JdbcURL.getHostname("jdbc://some")); - assertNull(JdbcURL.getHostname("jdbc:/some")); - } -} diff --git a/spm-tracing-testing/common/src/test/java/com/sematext/spm/client/tracing/utils/MockHttpServletRequest.java b/spm-tracing-testing/common/src/test/java/com/sematext/spm/client/tracing/utils/MockHttpServletRequest.java deleted file mode 100644 index 5be1660..0000000 --- a/spm-tracing-testing/common/src/test/java/com/sematext/spm/client/tracing/utils/MockHttpServletRequest.java +++ /dev/null @@ -1,410 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.utils; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.UnsupportedEncodingException; -import java.security.Principal; -import java.util.Collection; -import java.util.Enumeration; -import java.util.HashMap; -import java.util.Locale; -import java.util.Map; - -import javax.servlet.AsyncContext; -import javax.servlet.DispatcherType; -import javax.servlet.RequestDispatcher; -import javax.servlet.ServletContext; -import javax.servlet.ServletException; -import javax.servlet.ServletInputStream; -import javax.servlet.ServletRequest; -import javax.servlet.ServletResponse; -import javax.servlet.http.Cookie; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.servlet.http.HttpSession; -import javax.servlet.http.HttpUpgradeHandler; -import javax.servlet.http.Part; - -public class MockHttpServletRequest implements HttpServletRequest { - private final String requestUri; - private final String requestMethod; - private final Map headers = new HashMap(); - - public MockHttpServletRequest(String requestUri, String requestMethod) { - this.requestUri = requestUri; - this.requestMethod = requestMethod; - } - - public MockHttpServletRequest() { - this("/", "GET"); - } - - @Override - public String getAuthType() { - return null; - } - - @Override - public Cookie[] getCookies() { - return new Cookie[0]; - } - - @Override - public long getDateHeader(String s) { - return 0; - } - - public void setHeader(String name, String value) { - headers.put(name, value); - } - - @Override - public String getHeader(String s) { - return headers.get(s); - } - - @Override - public Enumeration getHeaders(String s) { - return null; - } - - @Override - public Enumeration getHeaderNames() { - return null; - } - - @Override - public int getIntHeader(String s) { - return 0; - } - - @Override - public String getMethod() { - return requestMethod; - } - - @Override - public String getPathInfo() { - return null; - } - - @Override - public String getPathTranslated() { - return null; - } - - @Override - public String getContextPath() { - return null; - } - - @Override - public String getQueryString() { - return null; - } - - @Override - public String getRemoteUser() { - return null; - } - - @Override - public boolean isUserInRole(String s) { - return false; - } - - @Override - public Principal getUserPrincipal() { - return null; - } - - @Override - public String getRequestedSessionId() { - return null; - } - - @Override - public String getRequestURI() { - return requestUri; - } - - @Override - public StringBuffer getRequestURL() { - return null; - } - - @Override - public String getServletPath() { - return null; - } - - @Override - public HttpSession getSession(boolean b) { - return null; - } - - @Override - public HttpSession getSession() { - return null; - } - - @Override - public String changeSessionId() { - return null; - } - - @Override - public boolean isRequestedSessionIdValid() { - return false; - } - - @Override - public boolean isRequestedSessionIdFromCookie() { - return false; - } - - @Override - public boolean isRequestedSessionIdFromURL() { - return false; - } - - @Override - public boolean isRequestedSessionIdFromUrl() { - return false; - } - - @Override - public boolean authenticate(HttpServletResponse httpServletResponse) throws IOException, ServletException { - return false; - } - - @Override - public void login(String s, String s2) throws ServletException { - - } - - @Override - public void logout() throws ServletException { - - } - - @Override - public Collection getParts() throws IOException, ServletException { - return null; - } - - @Override - public Part getPart(String s) throws IOException, ServletException { - return null; - } - - @Override - public T upgrade(Class tClass) throws IOException, ServletException { - return null; - } - - @Override - public Object getAttribute(String s) { - return null; - } - - @Override - public Enumeration getAttributeNames() { - return null; - } - - @Override - public String getCharacterEncoding() { - return null; - } - - @Override - public void setCharacterEncoding(String s) throws UnsupportedEncodingException { - - } - - @Override - public int getContentLength() { - return 0; - } - - @Override - public long getContentLengthLong() { - return 0; - } - - @Override - public String getContentType() { - return null; - } - - @Override - public ServletInputStream getInputStream() throws IOException { - return null; - } - - @Override - public String getParameter(String s) { - return null; - } - - @Override - public Enumeration getParameterNames() { - return null; - } - - @Override - public String[] getParameterValues(String s) { - return new String[0]; - } - - @Override - public Map getParameterMap() { - return null; - } - - @Override - public String getProtocol() { - return null; - } - - @Override - public String getScheme() { - return null; - } - - @Override - public String getServerName() { - return null; - } - - @Override - public int getServerPort() { - return 0; - } - - @Override - public BufferedReader getReader() throws IOException { - return null; - } - - @Override - public String getRemoteAddr() { - return null; - } - - @Override - public String getRemoteHost() { - return null; - } - - @Override - public void setAttribute(String s, Object o) { - - } - - @Override - public void removeAttribute(String s) { - - } - - @Override - public Locale getLocale() { - return null; - } - - @Override - public Enumeration getLocales() { - return null; - } - - @Override - public boolean isSecure() { - return false; - } - - @Override - public RequestDispatcher getRequestDispatcher(String s) { - return null; - } - - @Override - public String getRealPath(String s) { - return null; - } - - @Override - public int getRemotePort() { - return 0; - } - - @Override - public String getLocalName() { - return null; - } - - @Override - public String getLocalAddr() { - return null; - } - - @Override - public int getLocalPort() { - return 0; - } - - @Override - public ServletContext getServletContext() { - return null; - } - - @Override - public AsyncContext startAsync() throws IllegalStateException { - return null; - } - - @Override - public AsyncContext startAsync(ServletRequest servletRequest, ServletResponse servletResponse) - throws IllegalStateException { - return null; - } - - @Override - public boolean isAsyncStarted() { - return false; - } - - @Override - public boolean isAsyncSupported() { - return false; - } - - @Override - public AsyncContext getAsyncContext() { - return null; - } - - @Override - public DispatcherType getDispatcherType() { - return null; - } -} diff --git a/spm-tracing-testing/common/src/test/java/com/sematext/spm/client/tracing/utils/MockHttpServletResponse.java b/spm-tracing-testing/common/src/test/java/com/sematext/spm/client/tracing/utils/MockHttpServletResponse.java deleted file mode 100644 index 6c484c5..0000000 --- a/spm-tracing-testing/common/src/test/java/com/sematext/spm/client/tracing/utils/MockHttpServletResponse.java +++ /dev/null @@ -1,220 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.utils; - -import java.io.IOException; -import java.io.PrintWriter; -import java.util.Collection; -import java.util.HashMap; -import java.util.Locale; -import java.util.Map; - -import javax.servlet.ServletOutputStream; -import javax.servlet.http.Cookie; -import javax.servlet.http.HttpServletResponse; - -public class MockHttpServletResponse implements HttpServletResponse { - private final Map headers = new HashMap(); - - @Override - public void addCookie(Cookie cookie) { - - } - - @Override - public boolean containsHeader(String s) { - return false; - } - - @Override - public String encodeURL(String s) { - return null; - } - - @Override - public String encodeRedirectURL(String s) { - return null; - } - - @Override - public String encodeUrl(String s) { - return null; - } - - @Override - public String encodeRedirectUrl(String s) { - return null; - } - - @Override - public void sendError(int i, String s) throws IOException { - - } - - @Override - public void sendError(int i) throws IOException { - - } - - @Override - public void sendRedirect(String s) throws IOException { - - } - - @Override - public void setDateHeader(String s, long l) { - - } - - @Override - public void addDateHeader(String s, long l) { - - } - - @Override - public void setHeader(String s, String s2) { - headers.put(s, s2); - } - - @Override - public void addHeader(String s, String s2) { - headers.put(s, s2); - } - - @Override - public void setIntHeader(String s, int i) { - - } - - @Override - public void addIntHeader(String s, int i) { - - } - - @Override - public void setStatus(int i) { - - } - - @Override - public void setStatus(int i, String s) { - - } - - @Override - public int getStatus() { - return 0; - } - - @Override - public String getHeader(String s) { - return headers.get(s); - } - - @Override - public Collection getHeaders(String s) { - return null; - } - - @Override - public Collection getHeaderNames() { - return null; - } - - @Override - public String getCharacterEncoding() { - return null; - } - - @Override - public String getContentType() { - return null; - } - - @Override - public ServletOutputStream getOutputStream() throws IOException { - return null; - } - - @Override - public PrintWriter getWriter() throws IOException { - return null; - } - - @Override - public void setCharacterEncoding(String s) { - - } - - @Override - public void setContentLength(int i) { - - } - - @Override - public void setContentLengthLong(long l) { - - } - - @Override - public void setContentType(String s) { - - } - - @Override - public void setBufferSize(int i) { - - } - - @Override - public int getBufferSize() { - return 0; - } - - @Override - public void flushBuffer() throws IOException { - - } - - @Override - public void resetBuffer() { - - } - - @Override - public boolean isCommitted() { - return false; - } - - @Override - public void reset() { - - } - - @Override - public void setLocale(Locale locale) { - - } - - @Override - public Locale getLocale() { - return null; - } -} diff --git a/spm-tracing-testing/common/src/test/resources/META-INF/persistence.xml b/spm-tracing-testing/common/src/test/resources/META-INF/persistence.xml deleted file mode 100644 index 2027989..0000000 --- a/spm-tracing-testing/common/src/test/resources/META-INF/persistence.xml +++ /dev/null @@ -1,26 +0,0 @@ - - - - com.sematext.spm.client.tracing.agent.tracer.jdbc.User - com.sematext.spm.client.tracing.agent.tracer.jdbc.Owner - com.sematext.spm.client.tracing.agent.tracer.jdbc.Person - com.sematext.spm.client.tracing.agent.tracer.jdbc.Pet - com.sematext.spm.client.tracing.agent.tracer.jdbc.PetType - com.sematext.spm.client.tracing.agent.tracer.jdbc.Specialty - com.sematext.spm.client.tracing.agent.tracer.jdbc.Vet - com.sematext.spm.client.tracing.agent.tracer.jdbc.Visit - - - - - - - - - - - diff --git a/spm-tracing-testing/common/src/test/resources/custom-description-tracer-test.xml b/spm-tracing-testing/common/src/test/resources/custom-description-tracer-test.xml deleted file mode 100644 index 44acc3a..0000000 --- a/spm-tracing-testing/common/src/test/resources/custom-description-tracer-test.xml +++ /dev/null @@ -1,24 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/spm-tracing-testing/common/src/test/resources/initDB.sql b/spm-tracing-testing/common/src/test/resources/initDB.sql deleted file mode 100644 index a16c42d..0000000 --- a/spm-tracing-testing/common/src/test/resources/initDB.sql +++ /dev/null @@ -1,64 +0,0 @@ -DROP TABLE vet_specialties IF EXISTS; -DROP TABLE vets IF EXISTS; -DROP TABLE specialties IF EXISTS; -DROP TABLE visits IF EXISTS; -DROP TABLE pets IF EXISTS; -DROP TABLE types IF EXISTS; -DROP TABLE owners IF EXISTS; - - -CREATE TABLE vets ( - id INTEGER IDENTITY PRIMARY KEY, - first_name VARCHAR(30), - last_name VARCHAR(30) -); -CREATE INDEX vets_last_name ON vets (last_name); - -CREATE TABLE specialties ( - id INTEGER IDENTITY PRIMARY KEY, - name VARCHAR(80) -); -CREATE INDEX specialties_name ON specialties (name); - -CREATE TABLE vet_specialties ( - vet_id INTEGER NOT NULL, - specialty_id INTEGER NOT NULL -); -ALTER TABLE vet_specialties ADD CONSTRAINT fk_vet_specialties_vets FOREIGN KEY (vet_id) REFERENCES vets (id); -ALTER TABLE vet_specialties ADD CONSTRAINT fk_vet_specialties_specialties FOREIGN KEY (specialty_id) REFERENCES specialties (id); - -CREATE TABLE types ( - id INTEGER IDENTITY PRIMARY KEY, - name VARCHAR(80) -); -CREATE INDEX types_name ON types (name); - -CREATE TABLE owners ( - id INTEGER IDENTITY PRIMARY KEY, - first_name VARCHAR(30), - last_name VARCHAR(30), - address VARCHAR(255), - city VARCHAR(80), - telephone VARCHAR(20) -); -CREATE INDEX owners_last_name ON owners (last_name); - -CREATE TABLE pets ( - id INTEGER IDENTITY PRIMARY KEY, - name VARCHAR(30), - birth_date DATE, - type_id INTEGER NOT NULL, - owner_id INTEGER NOT NULL -); -ALTER TABLE pets ADD CONSTRAINT fk_pets_owners FOREIGN KEY (owner_id) REFERENCES owners (id); -ALTER TABLE pets ADD CONSTRAINT fk_pets_types FOREIGN KEY (type_id) REFERENCES types (id); -CREATE INDEX pets_name ON pets (name); - -CREATE TABLE visits ( - id INTEGER IDENTITY PRIMARY KEY, - pet_id INTEGER NOT NULL, - visit_date DATE, - description VARCHAR(255) -); -ALTER TABLE visits ADD CONSTRAINT fk_visits_pets FOREIGN KEY (pet_id) REFERENCES pets (id); -CREATE INDEX visits_pet_id ON visits (pet_id); diff --git a/spm-tracing-testing/common/src/test/resources/populateDB.sql b/spm-tracing-testing/common/src/test/resources/populateDB.sql deleted file mode 100644 index 16dda3e..0000000 --- a/spm-tracing-testing/common/src/test/resources/populateDB.sql +++ /dev/null @@ -1,53 +0,0 @@ -INSERT INTO vets VALUES (1, 'James', 'Carter'); -INSERT INTO vets VALUES (2, 'Helen', 'Leary'); -INSERT INTO vets VALUES (3, 'Linda', 'Douglas'); -INSERT INTO vets VALUES (4, 'Rafael', 'Ortega'); -INSERT INTO vets VALUES (5, 'Henry', 'Stevens'); -INSERT INTO vets VALUES (6, 'Sharon', 'Jenkins'); - -INSERT INTO specialties VALUES (1, 'radiology'); -INSERT INTO specialties VALUES (2, 'surgery'); -INSERT INTO specialties VALUES (3, 'dentistry'); - -INSERT INTO vet_specialties VALUES (2, 1); -INSERT INTO vet_specialties VALUES (3, 2); -INSERT INTO vet_specialties VALUES (3, 3); -INSERT INTO vet_specialties VALUES (4, 2); -INSERT INTO vet_specialties VALUES (5, 1); - -INSERT INTO types VALUES (1, 'cat'); -INSERT INTO types VALUES (2, 'dog'); -INSERT INTO types VALUES (3, 'lizard'); -INSERT INTO types VALUES (4, 'snake'); -INSERT INTO types VALUES (5, 'bird'); -INSERT INTO types VALUES (6, 'hamster'); - -INSERT INTO owners VALUES (1, 'George', 'Franklin', '110 W. Liberty St.', 'Madison', '6085551023'); -INSERT INTO owners VALUES (2, 'Betty', 'Davis', '638 Cardinal Ave.', 'Sun Prairie', '6085551749'); -INSERT INTO owners VALUES (3, 'Eduardo', 'Rodriquez', '2693 Commerce St.', 'McFarland', '6085558763'); -INSERT INTO owners VALUES (4, 'Harold', 'Davis', '563 Friendly St.', 'Windsor', '6085553198'); -INSERT INTO owners VALUES (5, 'Peter', 'McTavish', '2387 S. Fair Way', 'Madison', '6085552765'); -INSERT INTO owners VALUES (6, 'Jean', 'Coleman', '105 N. Lake St.', 'Monona', '6085552654'); -INSERT INTO owners VALUES (7, 'Jeff', 'Black', '1450 Oak Blvd.', 'Monona', '6085555387'); -INSERT INTO owners VALUES (8, 'Maria', 'Escobito', '345 Maple St.', 'Madison', '6085557683'); -INSERT INTO owners VALUES (9, 'David', 'Schroeder', '2749 Blackhawk Trail', 'Madison', '6085559435'); -INSERT INTO owners VALUES (10, 'Carlos', 'Estaban', '2335 Independence La.', 'Waunakee', '6085555487'); - -INSERT INTO pets VALUES (1, 'Leo', '2010-09-07', 1, 1); -INSERT INTO pets VALUES (2, 'Basil', '2012-08-06', 6, 2); -INSERT INTO pets VALUES (3, 'Rosy', '2011-04-17', 2, 3); -INSERT INTO pets VALUES (4, 'Jewel', '2010-03-07', 2, 3); -INSERT INTO pets VALUES (5, 'Iggy', '2010-11-30', 3, 4); -INSERT INTO pets VALUES (6, 'George', '2010-01-20', 4, 5); -INSERT INTO pets VALUES (7, 'Samantha', '2012-09-04', 1, 6); -INSERT INTO pets VALUES (8, 'Max', '2012-09-04', 1, 6); -INSERT INTO pets VALUES (9, 'Lucky', '2011-08-06', 5, 7); -INSERT INTO pets VALUES (10, 'Mulligan', '2007-02-24', 2, 8); -INSERT INTO pets VALUES (11, 'Freddy', '2010-03-09', 5, 9); -INSERT INTO pets VALUES (12, 'Lucky', '2010-06-24', 2, 10); -INSERT INTO pets VALUES (13, 'Sly', '2012-06-08', 1, 10); - -INSERT INTO visits VALUES (1, 7, '2013-01-01', 'rabies shot'); -INSERT INTO visits VALUES (2, 8, '2013-01-02', 'rabies shot'); -INSERT INTO visits VALUES (3, 8, '2013-01-03', 'neutered'); -INSERT INTO visits VALUES (4, 7, '2013-01-04', 'spayed'); diff --git a/spm-tracing-testing/common/src/test/resources/users.sql b/spm-tracing-testing/common/src/test/resources/users.sql deleted file mode 100644 index 2c3eb54..0000000 --- a/spm-tracing-testing/common/src/test/resources/users.sql +++ /dev/null @@ -1,6 +0,0 @@ -create table users(id integer, name varchar(256), age integer); - -insert into users(id, name, age) values (1, 'katrin', 23); -insert into users(id, name, age) values (2, 'liza', 24); -insert into users(id, name, age) values (3, 'angelina', 27); -insert into users(id, name, age) values (4, 'maria', 30); diff --git a/spm-tracing-testing/pom.xml b/spm-tracing-testing/pom.xml deleted file mode 100644 index bdfa00b..0000000 --- a/spm-tracing-testing/pom.xml +++ /dev/null @@ -1,109 +0,0 @@ - - 4.0.0 - - - com.sematext.spm - spm-client-parent - 3.0.0 - - - - provided - compile - - - spm-tracing-testing - pom - SPM Tracing Testing Parent - http://maven.apache.org - - - common - solrj-550 - solrj-520 - solrj-510 - solrj-500 - solrj-4103 - - - - - com.sematext.spm - spm-tracing-agent - ${project.version} - - - - com.sematext.spm - spm-tracing-agent-impl - ${project.version} - - - - com.sematext.spm - spm-sender - ${project.version} - test - - - - junit - junit - ${junit.version} - - - - org.apache.flume - flume-ng-core - 1.5.0 - test - - - org.apache.logging.log4j - log4j-core - 2.17.0 - compile - - - - - - - org.apache.maven.plugins - maven-surefire-plugin - 2.18.1 - - false - - - - - - - - integrationTests - - - skipIntegrationTests - - true - - - - - org.apache.maven.plugins - maven-surefire-plugin - 2.18.1 - - false - - %regex[.*IntegrationTest.*] - - - - - - - - diff --git a/spm-tracing-testing/solrj-4103/pom.xml b/spm-tracing-testing/solrj-4103/pom.xml deleted file mode 100644 index 02572a7..0000000 --- a/spm-tracing-testing/solrj-4103/pom.xml +++ /dev/null @@ -1,40 +0,0 @@ - - - - spm-tracing-testing - com.sematext.spm - 3.0.0 - - 4.0.0 - - solrj-4103 - - - - org.apache.httpcomponents - httpclient - 4.5.13 - test - - - solr-solrj - org.apache.solr - 4.10.3 - jar - test - - - com.sematext.spm - common - 3.0.0 - - - org.apache.logging.log4j - log4j-core - 2.17.0 - compile - - - diff --git a/spm-tracing-testing/solrj-4103/src/test/java/com/sematext/spm/client/tracing/agent/tracer/solr4j/Solr4103TracerIntegrationTest.java b/spm-tracing-testing/solrj-4103/src/test/java/com/sematext/spm/client/tracing/agent/tracer/solr4j/Solr4103TracerIntegrationTest.java deleted file mode 100644 index 1dda670..0000000 --- a/spm-tracing-testing/solrj-4103/src/test/java/com/sematext/spm/client/tracing/agent/tracer/solr4j/Solr4103TracerIntegrationTest.java +++ /dev/null @@ -1,201 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.tracer.solr4j; - -import static com.sematext.spm.client.tracing.utils.TracingTesting.setupSink; -import static java.util.Collections.singletonMap; -import static junit.framework.TestCase.assertTrue; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -import org.apache.http.HttpResponse; -import org.apache.solr.client.solrj.SolrRequest; -import org.apache.solr.client.solrj.SolrServer; -import org.apache.solr.client.solrj.impl.ConcurrentUpdateSolrServer; -import org.apache.solr.client.solrj.impl.HttpSolrServer; -import org.apache.solr.client.solrj.request.CollectionAdminRequest; -import org.apache.solr.client.solrj.request.ContentStreamUpdateRequest; -import org.apache.solr.client.solrj.request.DirectXmlRequest; -import org.apache.solr.client.solrj.request.QueryRequest; -import org.apache.solr.client.solrj.request.UpdateRequest; -import org.apache.solr.client.solrj.response.CollectionAdminResponse; -import org.apache.solr.common.SolrInputDocument; -import org.apache.solr.common.params.CollectionParams; -import org.apache.solr.common.params.MapSolrParams; -import org.apache.solr.common.util.ContentStreamBase; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; - -import java.util.List; -import java.util.concurrent.CountDownLatch; - -import com.sematext.spm.client.tracing.agent.Tracing; -import com.sematext.spm.client.tracing.agent.config.ServiceLocator; -import com.sematext.spm.client.tracing.agent.model.Call; -import com.sematext.spm.client.tracing.agent.model.PartialTransaction; -import com.sematext.spm.client.tracing.agent.model.SolrAnnotation; -import com.sematext.spm.client.tracing.agent.tracer.Tracers; -import com.sematext.spm.client.tracing.utils.MockTransactionSink; -import com.sematext.spm.client.tracing.utils.TracingContext; -import com.sematext.spm.client.tracing.utils.TracingJUnit4ClassRunner; -import com.sematext.spm.client.tracing.utils.TracingTesting; - -@RunWith(TracingJUnit4ClassRunner.class) -@TracingContext(tracers = { Tracers.Solrj4Tracer.class, Tracers.HttpClient4Tracer.class }) -public class Solr4103TracerIntegrationTest { - - private SolrServer getSolrClient() { - return getSolrClient(null); - } - - private SolrServer getSolrClient(String collection) { - String url = "http://localhost:8983/solr"; - if (collection != null) { - url += "/" + collection; - } - return new HttpSolrServer(url); - } - - @Before - @SuppressWarnings("unchecked") - public void preStart() throws Exception { - final SolrServer client = getSolrClient(); - CollectionAdminRequest listAction = new CollectionAdminRequest(); - listAction.setAction(CollectionParams.CollectionAction.LIST); - CollectionAdminResponse response = listAction.process(client); - - for (Object names : response.getResponse().getAll("collections")) { - for (String name : (List) names) { - if (name.equals("test-collection-1") || name.equals("test-collection-2")) { - final CollectionAdminRequest.Delete request = new CollectionAdminRequest.Delete(); - request.setCollectionName(name); - request.process(client); - } - } - } - - CollectionAdminRequest.Create create1Request = new CollectionAdminRequest.Create(); - create1Request.setCollectionName("test-collection-1"); - create1Request.setNumShards(1); - create1Request.process(client); - - CollectionAdminRequest.Create create2Request = new CollectionAdminRequest.Create(); - create2Request.setCollectionName("test-collection-2"); - create2Request.setNumShards(1); - create2Request.process(client); - } - - private SolrAnnotation testRequestType(SolrRequest request, String collection, SolrAnnotation.RequestType expected) - throws Exception { - Tracing.newTrace("test-request-type", Call.TransactionType.BACKGROUND); - final MockTransactionSink mockTransSink = new MockTransactionSink(); - ServiceLocator.getTransactionSinks().clear(); - ServiceLocator.getTransactionSinks().add(mockTransSink); - - try { - request.process(getSolrClient(collection)); - - assertEquals(1, mockTransSink.getTransactions().size()); - assertEquals(1, mockTransSink.getTransactions().get(0).getCalls().size()); - - final Call call = mockTransSink.getTransactions().get(0).getCalls().get(0); - assertEquals(Call.CallTag.SOLR, call.getCallTag()); - - final SolrAnnotation annotation = (SolrAnnotation) call.getAnnotation(); - assertNotNull(annotation); - - assertEquals(expected, annotation.getRequestType()); - assertEquals(200, annotation.getResponseStatus()); - assertTrue(annotation.isSucceed()); - return annotation; - } finally { - Tracing.endTrace(); - } - } - - private static final String XML_DOC = "\n" + - "\n" + - " SOLR1000\n" + - " Solr, the Enterprise Search Server\n" + - "\n" + - "\n" + - "\n"; - - @Test - public void testRequestTypes() throws Exception { - testRequestType(new QueryRequest(new MapSolrParams(singletonMap("q", "*.*"))), "test-collection-1", SolrAnnotation.RequestType.QUERY); - - final SolrInputDocument document = new SolrInputDocument(); - document.addField("firstName", "Corey"); - document.addField("lastName", "Taylor"); - SolrAnnotation annotation = testRequestType(new UpdateRequest() - .add(document), "test-collection-1", SolrAnnotation.RequestType.UPDATE); - assertEquals("test-collection-1", annotation.getCollection()); - - final ContentStreamUpdateRequest contentStreamRequest = new ContentStreamUpdateRequest("/update"); - contentStreamRequest.addContentStream(new ContentStreamBase.StringStream(XML_DOC)); - annotation = testRequestType(contentStreamRequest, "test-collection-1", SolrAnnotation.RequestType.UPDATE); - assertEquals("test-collection-1", annotation.getCollection()); - - final DirectXmlRequest xmlRequest = new DirectXmlRequest("/update", XML_DOC); - annotation = testRequestType(xmlRequest, "test-collection-1", SolrAnnotation.RequestType.UPDATE); - assertEquals("test-collection-1", annotation.getCollection()); - - CollectionAdminRequest listAction = new CollectionAdminRequest(); - listAction.setAction(CollectionParams.CollectionAction.LIST); - testRequestType(listAction, null, SolrAnnotation.RequestType.COLLECTION_ADMIN); - } - - @Test - public void testConcurrentUpdate() throws Exception { - Tracing.newTrace("test-request-type", Call.TransactionType.BACKGROUND); - final MockTransactionSink mockTransSink = setupSink(); - - final CountDownLatch latch = new CountDownLatch(10); - - final ConcurrentUpdateSolrServer client = new ConcurrentUpdateSolrServer("http://localhost:8983/solr/test-collection-1", 2, 10) { - @Override - public void onSuccess(HttpResponse resp) { - latch.countDown(); - } - - @Override - public void handleError(Throwable ex) { - ex.printStackTrace(); - latch.countDown(); - } - }; - - for (int i = 0; i < 10; i++) { - final SolrInputDocument document = new SolrInputDocument(); - document.addField("firstName", "Corey"); - document.addField("lastName", "Taylor"); - - new UpdateRequest("/test-collection-1/update").add(document).process(client); - } - - latch.await(); - - List async = TracingTesting.findAsync(mockTransSink.getTransactions()); - assertEquals(10, async.size()); - } - -} diff --git a/spm-tracing-testing/solrj-500/pom.xml b/spm-tracing-testing/solrj-500/pom.xml deleted file mode 100644 index e4080cc..0000000 --- a/spm-tracing-testing/solrj-500/pom.xml +++ /dev/null @@ -1,40 +0,0 @@ - - - - spm-tracing-testing - com.sematext.spm - 3.0.0 - - 4.0.0 - - solrj-500 - - - - org.apache.httpcomponents - httpclient - 4.5.13 - test - - - solr-solrj - org.apache.solr - 5.0.0 - jar - test - - - com.sematext.spm - common - 3.0.0 - - - org.apache.logging.log4j - log4j-core - 2.17.0 - compile - - - diff --git a/spm-tracing-testing/solrj-500/src/test/java/com/sematext/spm/client/tracing/agent/tracer/solr4j/Solrj50TracerIntegrationTest.java b/spm-tracing-testing/solrj-500/src/test/java/com/sematext/spm/client/tracing/agent/tracer/solr4j/Solrj50TracerIntegrationTest.java deleted file mode 100644 index c73c32c..0000000 --- a/spm-tracing-testing/solrj-500/src/test/java/com/sematext/spm/client/tracing/agent/tracer/solr4j/Solrj50TracerIntegrationTest.java +++ /dev/null @@ -1,196 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.tracer.solr4j; - -import static com.sematext.spm.client.tracing.utils.TracingTesting.setupSink; -import static java.util.Collections.singletonMap; -import static junit.framework.TestCase.assertTrue; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -import org.apache.http.HttpResponse; -import org.apache.solr.client.solrj.SolrClient; -import org.apache.solr.client.solrj.SolrRequest; -import org.apache.solr.client.solrj.impl.ConcurrentUpdateSolrClient; -import org.apache.solr.client.solrj.impl.HttpSolrClient; -import org.apache.solr.client.solrj.request.CollectionAdminRequest; -import org.apache.solr.client.solrj.request.ContentStreamUpdateRequest; -import org.apache.solr.client.solrj.request.DirectXmlRequest; -import org.apache.solr.client.solrj.request.QueryRequest; -import org.apache.solr.client.solrj.request.UpdateRequest; -import org.apache.solr.client.solrj.response.CollectionAdminResponse; -import org.apache.solr.common.SolrInputDocument; -import org.apache.solr.common.params.MapSolrParams; -import org.apache.solr.common.util.ContentStreamBase; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; - -import java.util.List; -import java.util.concurrent.CountDownLatch; - -import com.sematext.spm.client.tracing.agent.Tracing; -import com.sematext.spm.client.tracing.agent.config.ServiceLocator; -import com.sematext.spm.client.tracing.agent.model.Call; -import com.sematext.spm.client.tracing.agent.model.PartialTransaction; -import com.sematext.spm.client.tracing.agent.model.SolrAnnotation; -import com.sematext.spm.client.tracing.agent.tracer.Tracers; -import com.sematext.spm.client.tracing.utils.MockTransactionSink; -import com.sematext.spm.client.tracing.utils.TracingContext; -import com.sematext.spm.client.tracing.utils.TracingJUnit4ClassRunner; -import com.sematext.spm.client.tracing.utils.TracingTesting; - -@RunWith(TracingJUnit4ClassRunner.class) -@TracingContext(tracers = { Tracers.Solrj5Tracer.class, Tracers.HttpClient4Tracer.class }) -public class Solrj50TracerIntegrationTest { - - private SolrClient getSolrClient() { - return getSolrClient(null); - } - - private SolrClient getSolrClient(String collection) { - String url = "http://localhost:8983/solr"; - if (collection != null) { - url += "/" + collection; - } - return new HttpSolrClient(url); - } - - @Before - @SuppressWarnings("unchecked") - public void preStart() throws Exception { - final SolrClient client = getSolrClient(); - CollectionAdminResponse response = new CollectionAdminRequest.List().process(client); - - for (Object names : response.getResponse().getAll("collections")) { - for (String name : (List) names) { - if (name.equals("test-collection-1") || name.equals("test-collection-2")) { - final CollectionAdminRequest.Delete request = new CollectionAdminRequest.Delete(); - request.setCollectionName(name); - request.process(client); - } - } - } - - CollectionAdminRequest.Create create1Request = new CollectionAdminRequest.Create(); - create1Request.setCollectionName("test-collection-1"); - create1Request.setNumShards(1); - create1Request.process(client); - - CollectionAdminRequest.Create create2Request = new CollectionAdminRequest.Create(); - create2Request.setCollectionName("test-collection-2"); - create2Request.setNumShards(1); - create2Request.process(client); - } - - private SolrAnnotation testRequestType(SolrRequest request, String collection, SolrAnnotation.RequestType expected) - throws Exception { - Tracing.newTrace("test-request-type", Call.TransactionType.BACKGROUND); - final MockTransactionSink mockTransSink = new MockTransactionSink(); - ServiceLocator.getTransactionSinks().clear(); - ServiceLocator.getTransactionSinks().add(mockTransSink); - - try { - request.process(getSolrClient(collection)); - - assertEquals(1, mockTransSink.getTransactions().size()); - assertEquals(1, mockTransSink.getTransactions().get(0).getCalls().size()); - - final Call call = mockTransSink.getTransactions().get(0).getCalls().get(0); - assertEquals(Call.CallTag.SOLR, call.getCallTag()); - - final SolrAnnotation annotation = (SolrAnnotation) call.getAnnotation(); - assertNotNull(annotation); - - assertEquals(expected, annotation.getRequestType()); - assertEquals(200, annotation.getResponseStatus()); - assertTrue(annotation.isSucceed()); - return annotation; - } finally { - Tracing.endTrace(); - } - } - - private static final String XML_DOC = "\n" + - "\n" + - " SOLR1000\n" + - " Solr, the Enterprise Search Server\n" + - "\n" + - "\n" + - "\n"; - - @Test - public void testRequestTypes() throws Exception { - testRequestType(new QueryRequest(new MapSolrParams(singletonMap("q", "*.*"))), "test-collection-1", SolrAnnotation.RequestType.QUERY); - - final SolrInputDocument document = new SolrInputDocument(); - document.addField("firstName", "Corey"); - document.addField("lastName", "Taylor"); - SolrAnnotation annotation = testRequestType(new UpdateRequest() - .add(document), "test-collection-1", SolrAnnotation.RequestType.UPDATE); - assertEquals("test-collection-1", annotation.getCollection()); - - final ContentStreamUpdateRequest contentStreamRequest = new ContentStreamUpdateRequest("/update"); - contentStreamRequest.addContentStream(new ContentStreamBase.StringStream(XML_DOC)); - annotation = testRequestType(contentStreamRequest, "test-collection-1", SolrAnnotation.RequestType.UPDATE); - assertEquals("test-collection-1", annotation.getCollection()); - - final DirectXmlRequest xmlRequest = new DirectXmlRequest("/update", XML_DOC); - annotation = testRequestType(xmlRequest, "test-collection-1", SolrAnnotation.RequestType.UPDATE); - assertEquals("test-collection-1", annotation.getCollection()); - - testRequestType(new CollectionAdminRequest.List(), null, SolrAnnotation.RequestType.COLLECTION_ADMIN); - } - - @Test - public void testConcurrentUpdate() throws Exception { - Tracing.newTrace("test-request-type", Call.TransactionType.BACKGROUND); - final MockTransactionSink mockTransSink = setupSink(); - - final CountDownLatch latch = new CountDownLatch(10); - - final ConcurrentUpdateSolrClient client = new ConcurrentUpdateSolrClient("http://localhost:8983/solr/test-collection-1", 2, 10) { - @Override - public void onSuccess(HttpResponse resp) { - latch.countDown(); - } - - @Override - public void handleError(Throwable ex) { - ex.printStackTrace(); - latch.countDown(); - } - }; - - for (int i = 0; i < 10; i++) { - final SolrInputDocument document = new SolrInputDocument(); - document.addField("firstName", "Corey"); - document.addField("lastName", "Taylor"); - - new UpdateRequest("/test-collection-1/update").add(document).process(client); - } - - latch.await(); - - List async = TracingTesting.findAsync(mockTransSink.getTransactions()); - assertEquals(10, async.size()); - } - -} diff --git a/spm-tracing-testing/solrj-510/pom.xml b/spm-tracing-testing/solrj-510/pom.xml deleted file mode 100644 index 8d9ac40..0000000 --- a/spm-tracing-testing/solrj-510/pom.xml +++ /dev/null @@ -1,40 +0,0 @@ - - - - spm-tracing-testing - com.sematext.spm - 3.0.0 - - 4.0.0 - - solrj-510 - - - - org.apache.httpcomponents - httpclient - 4.5.13 - test - - - solr-solrj - org.apache.solr - 5.1.0 - jar - test - - - com.sematext.spm - common - 3.0.0 - - - org.apache.logging.log4j - log4j-core - 2.17.0 - compile - - - diff --git a/spm-tracing-testing/solrj-510/src/test/java/com/sematext/spm/client/tracing/agent/tracer/solr4j/Solrj51TracerIntegrationTest.java b/spm-tracing-testing/solrj-510/src/test/java/com/sematext/spm/client/tracing/agent/tracer/solr4j/Solrj51TracerIntegrationTest.java deleted file mode 100644 index 14fdb9b..0000000 --- a/spm-tracing-testing/solrj-510/src/test/java/com/sematext/spm/client/tracing/agent/tracer/solr4j/Solrj51TracerIntegrationTest.java +++ /dev/null @@ -1,187 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.tracer.solr4j; - -import static com.sematext.spm.client.tracing.utils.TracingTesting.setupSink; -import static java.util.Collections.singletonMap; -import static junit.framework.TestCase.assertTrue; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -import org.apache.http.HttpResponse; -import org.apache.solr.client.solrj.SolrClient; -import org.apache.solr.client.solrj.SolrRequest; -import org.apache.solr.client.solrj.impl.ConcurrentUpdateSolrClient; -import org.apache.solr.client.solrj.impl.HttpSolrClient; -import org.apache.solr.client.solrj.request.CollectionAdminRequest; -import org.apache.solr.client.solrj.request.ContentStreamUpdateRequest; -import org.apache.solr.client.solrj.request.DirectXmlRequest; -import org.apache.solr.client.solrj.request.QueryRequest; -import org.apache.solr.client.solrj.request.UpdateRequest; -import org.apache.solr.client.solrj.response.CollectionAdminResponse; -import org.apache.solr.common.SolrInputDocument; -import org.apache.solr.common.params.MapSolrParams; -import org.apache.solr.common.util.ContentStreamBase; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; - -import java.util.List; -import java.util.concurrent.CountDownLatch; - -import com.sematext.spm.client.tracing.agent.Tracing; -import com.sematext.spm.client.tracing.agent.config.ServiceLocator; -import com.sematext.spm.client.tracing.agent.model.Call; -import com.sematext.spm.client.tracing.agent.model.PartialTransaction; -import com.sematext.spm.client.tracing.agent.model.SolrAnnotation; -import com.sematext.spm.client.tracing.agent.tracer.Tracers; -import com.sematext.spm.client.tracing.utils.MockTransactionSink; -import com.sematext.spm.client.tracing.utils.TracingContext; -import com.sematext.spm.client.tracing.utils.TracingJUnit4ClassRunner; -import com.sematext.spm.client.tracing.utils.TracingTesting; - -@RunWith(TracingJUnit4ClassRunner.class) -@TracingContext(tracers = { Tracers.Solrj5Tracer.class, Tracers.HttpClient4Tracer.class }) -public class Solrj51TracerIntegrationTest { - - private SolrClient getSolrClient() { - return new HttpSolrClient("http://localhost:8983/solr"); - } - - @Before - @SuppressWarnings("unchecked") - public void preStart() throws Exception { - final SolrClient client = getSolrClient(); - CollectionAdminResponse response = new CollectionAdminRequest.List().process(client); - - for (Object names : response.getResponse().getAll("collections")) { - for (String name : (List) names) { - if (name.equals("test-collection-1") || name.equals("test-collection-2")) { - final CollectionAdminRequest.Delete request = new CollectionAdminRequest.Delete(); - request.setCollectionName(name); - request.process(client); - } - } - } - - CollectionAdminRequest.Create create1Request = new CollectionAdminRequest.Create(); - create1Request.setCollectionName("test-collection-1"); - create1Request.setNumShards(1); - create1Request.process(client); - - CollectionAdminRequest.Create create2Request = new CollectionAdminRequest.Create(); - create2Request.setCollectionName("test-collection-2"); - create2Request.setNumShards(1); - create2Request.process(client); - } - - private SolrAnnotation testRequestType(SolrRequest request, String collection, SolrAnnotation.RequestType expected) - throws Exception { - Tracing.newTrace("test-request-type", Call.TransactionType.BACKGROUND); - final MockTransactionSink mockTransSink = new MockTransactionSink(); - ServiceLocator.getTransactionSinks().clear(); - ServiceLocator.getTransactionSinks().add(mockTransSink); - - try { - request.process(getSolrClient(), collection); - - assertEquals(1, mockTransSink.getTransactions().size()); - assertEquals(1, mockTransSink.getTransactions().get(0).getCalls().size()); - - final Call call = mockTransSink.getTransactions().get(0).getCalls().get(0); - assertEquals(Call.CallTag.SOLR, call.getCallTag()); - - final SolrAnnotation annotation = (SolrAnnotation) call.getAnnotation(); - assertNotNull(annotation); - - assertEquals(expected, annotation.getRequestType()); - assertEquals(200, annotation.getResponseStatus()); - assertTrue(annotation.isSucceed()); - return annotation; - } finally { - Tracing.endTrace(); - } - } - - private static final String XML_DOC = "\n" + - "\n" + - " SOLR1000\n" + - " Solr, the Enterprise Search Server\n" + - "\n" + - "\n" + - "\n"; - - @Test - public void testRequestTypes() throws Exception { - SolrAnnotation annotation = testRequestType(new QueryRequest(new MapSolrParams(singletonMap("q", "*.*"))), "test-collection-1", SolrAnnotation.RequestType.QUERY); - final SolrInputDocument document = new SolrInputDocument(); - document.addField("firstName", "Corey"); - document.addField("lastName", "Taylor"); - annotation = testRequestType(new UpdateRequest() - .add(document), "test-collection-1", SolrAnnotation.RequestType.UPDATE); - assertEquals("test-collection-1", annotation.getCollection()); - - final ContentStreamUpdateRequest contentStreamRequest = new ContentStreamUpdateRequest("/update"); - contentStreamRequest.addContentStream(new ContentStreamBase.StringStream(XML_DOC, "application/xml")); - annotation = testRequestType(contentStreamRequest, "test-collection-1", SolrAnnotation.RequestType.UPDATE); - assertEquals("test-collection-1", annotation.getCollection()); - - final DirectXmlRequest xmlRequest = new DirectXmlRequest("/update", XML_DOC); - annotation = testRequestType(xmlRequest, "test-collection-1", SolrAnnotation.RequestType.UPDATE); - assertEquals("test-collection-1", annotation.getCollection()); - - testRequestType(new CollectionAdminRequest.List(), null, SolrAnnotation.RequestType.COLLECTION_ADMIN); - } - - @Test - public void testConcurrentUpdate() throws Exception { - Tracing.newTrace("test-request-type", Call.TransactionType.BACKGROUND); - final MockTransactionSink mockTransSink = setupSink(); - - final CountDownLatch latch = new CountDownLatch(10); - - final ConcurrentUpdateSolrClient client = new ConcurrentUpdateSolrClient("http://localhost:8983/solr/test-collection-1", 2, 10) { - @Override - public void onSuccess(HttpResponse resp) { - latch.countDown(); - } - - @Override - public void handleError(Throwable ex) { - ex.printStackTrace(); - latch.countDown(); - } - }; - - for (int i = 0; i < 10; i++) { - final SolrInputDocument document = new SolrInputDocument(); - document.addField("firstName", "Corey"); - document.addField("lastName", "Taylor"); - - new UpdateRequest("/test-collection-1/update").add(document).process(client, "test-collection-1"); - } - - latch.await(); - - List async = TracingTesting.findAsync(mockTransSink.getTransactions()); - assertEquals(10, async.size()); - } - -} diff --git a/spm-tracing-testing/solrj-520/pom.xml b/spm-tracing-testing/solrj-520/pom.xml deleted file mode 100644 index 86a90eb..0000000 --- a/spm-tracing-testing/solrj-520/pom.xml +++ /dev/null @@ -1,40 +0,0 @@ - - - - spm-tracing-testing - com.sematext.spm - 3.0.0 - - 4.0.0 - - solrj-520 - - - - org.apache.httpcomponents - httpclient - 4.5.13 - test - - - solr-solrj - org.apache.solr - 5.2.0 - jar - test - - - com.sematext.spm - common - 3.0.0 - - - org.apache.logging.log4j - log4j-core - 2.17.0 - compile - - - diff --git a/spm-tracing-testing/solrj-520/src/test/java/com/sematext/spm/client/tracing/agent/tracer/solr4j/Solrj52TracerIntegrationTest.java b/spm-tracing-testing/solrj-520/src/test/java/com/sematext/spm/client/tracing/agent/tracer/solr4j/Solrj52TracerIntegrationTest.java deleted file mode 100644 index 7afc1e2..0000000 --- a/spm-tracing-testing/solrj-520/src/test/java/com/sematext/spm/client/tracing/agent/tracer/solr4j/Solrj52TracerIntegrationTest.java +++ /dev/null @@ -1,187 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.tracer.solr4j; - -import static com.sematext.spm.client.tracing.utils.TracingTesting.setupSink; -import static java.util.Collections.singletonMap; -import static junit.framework.TestCase.assertTrue; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -import org.apache.http.HttpResponse; -import org.apache.solr.client.solrj.SolrClient; -import org.apache.solr.client.solrj.SolrRequest; -import org.apache.solr.client.solrj.impl.ConcurrentUpdateSolrClient; -import org.apache.solr.client.solrj.impl.HttpSolrClient; -import org.apache.solr.client.solrj.request.CollectionAdminRequest; -import org.apache.solr.client.solrj.request.ContentStreamUpdateRequest; -import org.apache.solr.client.solrj.request.DirectXmlRequest; -import org.apache.solr.client.solrj.request.QueryRequest; -import org.apache.solr.client.solrj.request.UpdateRequest; -import org.apache.solr.client.solrj.response.CollectionAdminResponse; -import org.apache.solr.common.SolrInputDocument; -import org.apache.solr.common.params.MapSolrParams; -import org.apache.solr.common.util.ContentStreamBase; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; - -import java.util.List; -import java.util.concurrent.CountDownLatch; - -import com.sematext.spm.client.tracing.agent.Tracing; -import com.sematext.spm.client.tracing.agent.config.ServiceLocator; -import com.sematext.spm.client.tracing.agent.model.Call; -import com.sematext.spm.client.tracing.agent.model.PartialTransaction; -import com.sematext.spm.client.tracing.agent.model.SolrAnnotation; -import com.sematext.spm.client.tracing.agent.tracer.Tracers; -import com.sematext.spm.client.tracing.utils.MockTransactionSink; -import com.sematext.spm.client.tracing.utils.TracingContext; -import com.sematext.spm.client.tracing.utils.TracingJUnit4ClassRunner; -import com.sematext.spm.client.tracing.utils.TracingTesting; - -@RunWith(TracingJUnit4ClassRunner.class) -@TracingContext(tracers = { Tracers.Solrj5Tracer.class, Tracers.HttpClient4Tracer.class }) -public class Solrj52TracerIntegrationTest { - - private SolrClient getSolrClient() { - return new HttpSolrClient("http://localhost:8983/solr"); - } - - @Before - @SuppressWarnings("unchecked") - public void preStart() throws Exception { - final SolrClient client = getSolrClient(); - CollectionAdminResponse response = new CollectionAdminRequest.List().process(client); - - for (Object names : response.getResponse().getAll("collections")) { - for (String name : (List) names) { - if (name.equals("test_collection_1") || name.equals("test_collection_2")) { - final CollectionAdminRequest.Delete request = new CollectionAdminRequest.Delete(); - request.setCollectionName(name); - request.process(client); - } - } - } - - CollectionAdminRequest.Create create1Request = new CollectionAdminRequest.Create(); - create1Request.setCollectionName("test_collection_1"); - create1Request.setNumShards(1); - create1Request.process(client); - - CollectionAdminRequest.Create create2Request = new CollectionAdminRequest.Create(); - create2Request.setCollectionName("test_collection_2"); - create2Request.setNumShards(1); - create2Request.process(client); - } - - private SolrAnnotation testRequestType(SolrRequest request, String collection, SolrAnnotation.RequestType expected) - throws Exception { - Tracing.newTrace("test-request-type", Call.TransactionType.BACKGROUND); - final MockTransactionSink mockTransSink = new MockTransactionSink(); - ServiceLocator.getTransactionSinks().clear(); - ServiceLocator.getTransactionSinks().add(mockTransSink); - - try { - request.process(getSolrClient(), collection); - - assertEquals(1, mockTransSink.getTransactions().size()); - assertEquals(1, mockTransSink.getTransactions().get(0).getCalls().size()); - - final Call call = mockTransSink.getTransactions().get(0).getCalls().get(0); - assertEquals(Call.CallTag.SOLR, call.getCallTag()); - - final SolrAnnotation annotation = (SolrAnnotation) call.getAnnotation(); - assertNotNull(annotation); - - assertEquals(expected, annotation.getRequestType()); - assertEquals(200, annotation.getResponseStatus()); - assertTrue(annotation.isSucceed()); - return annotation; - } finally { - Tracing.endTrace(); - } - } - - private static final String XML_DOC = "\n" + - "\n" + - " SOLR1000\n" + - " Solr, the Enterprise Search Server\n" + - "\n" + - "\n" + - "\n"; - - @Test - public void testRequestTypes() throws Exception { - SolrAnnotation annotation = testRequestType(new QueryRequest(new MapSolrParams(singletonMap("q", "*.*"))), "test_collection_1", SolrAnnotation.RequestType.QUERY); - final SolrInputDocument document = new SolrInputDocument(); - document.addField("firstName", "Corey"); - document.addField("lastName", "Taylor"); - annotation = testRequestType(new UpdateRequest() - .add(document), "test_collection_1", SolrAnnotation.RequestType.UPDATE); - assertEquals("test_collection_1", annotation.getCollection()); - - final ContentStreamUpdateRequest contentStreamRequest = new ContentStreamUpdateRequest("/update"); - contentStreamRequest.addContentStream(new ContentStreamBase.StringStream(XML_DOC, "application/xml")); - annotation = testRequestType(contentStreamRequest, "test_collection_1", SolrAnnotation.RequestType.UPDATE); - assertEquals("test_collection_1", annotation.getCollection()); - - final DirectXmlRequest xmlRequest = new DirectXmlRequest("/update", XML_DOC); - annotation = testRequestType(xmlRequest, "test_collection_1", SolrAnnotation.RequestType.UPDATE); - assertEquals("test_collection_1", annotation.getCollection()); - - testRequestType(new CollectionAdminRequest.List(), null, SolrAnnotation.RequestType.COLLECTION_ADMIN); - } - - @Test - public void testConcurrentUpdate() throws Exception { - Tracing.newTrace("test-request-type", Call.TransactionType.BACKGROUND); - final MockTransactionSink mockTransSink = setupSink(); - - final CountDownLatch latch = new CountDownLatch(10); - - final ConcurrentUpdateSolrClient client = new ConcurrentUpdateSolrClient("http://localhost:8983/solr/test_collection_1", 2, 10) { - @Override - public void onSuccess(HttpResponse resp) { - latch.countDown(); - } - - @Override - public void handleError(Throwable ex) { - ex.printStackTrace(); - latch.countDown(); - } - }; - - for (int i = 0; i < 10; i++) { - final SolrInputDocument document = new SolrInputDocument(); - document.addField("firstName", "Corey"); - document.addField("lastName", "Taylor"); - - new UpdateRequest("/test_collection_1/update").add(document).process(client, "test_collection_1"); - } - - latch.await(); - - List async = TracingTesting.findAsync(mockTransSink.getTransactions()); - assertEquals(10, async.size()); - } - -} diff --git a/spm-tracing-testing/solrj-550/pom.xml b/spm-tracing-testing/solrj-550/pom.xml deleted file mode 100644 index 5ae6fb6..0000000 --- a/spm-tracing-testing/solrj-550/pom.xml +++ /dev/null @@ -1,46 +0,0 @@ - - - - spm-tracing-testing - com.sematext.spm - 3.0.0 - - - 4.0.0 - - solrj-550 - - - - org.apache.httpcomponents - httpclient - 4.5.13 - test - - - solr-solrj - org.apache.solr - 5.5.0 - jar - test - - - com.sematext.spm - common - 3.0.0 - - - org.slf4j - slf4j-log4j12 - 1.7.7 - - - org.apache.logging.log4j - log4j-core - 2.17.0 - compile - - - diff --git a/spm-tracing-testing/solrj-550/src/test/java/com/sematext/spm/client/tracing/agent/tracer/solr4j/Solrj55TracerIntegrationTest.java b/spm-tracing-testing/solrj-550/src/test/java/com/sematext/spm/client/tracing/agent/tracer/solr4j/Solrj55TracerIntegrationTest.java deleted file mode 100644 index 3a32a68..0000000 --- a/spm-tracing-testing/solrj-550/src/test/java/com/sematext/spm/client/tracing/agent/tracer/solr4j/Solrj55TracerIntegrationTest.java +++ /dev/null @@ -1,187 +0,0 @@ -/* - * Licensed to Sematext Group, Inc - * - * See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Sematext Group, Inc licenses this file to you 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 com.sematext.spm.client.tracing.agent.tracer.solr4j; - -import static com.sematext.spm.client.tracing.utils.TracingTesting.setupSink; -import static java.util.Collections.singletonMap; -import static junit.framework.TestCase.assertTrue; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -import org.apache.http.HttpResponse; -import org.apache.solr.client.solrj.SolrClient; -import org.apache.solr.client.solrj.SolrRequest; -import org.apache.solr.client.solrj.impl.ConcurrentUpdateSolrClient; -import org.apache.solr.client.solrj.impl.HttpSolrClient; -import org.apache.solr.client.solrj.request.CollectionAdminRequest; -import org.apache.solr.client.solrj.request.ContentStreamUpdateRequest; -import org.apache.solr.client.solrj.request.DirectXmlRequest; -import org.apache.solr.client.solrj.request.QueryRequest; -import org.apache.solr.client.solrj.request.UpdateRequest; -import org.apache.solr.client.solrj.response.CollectionAdminResponse; -import org.apache.solr.common.SolrInputDocument; -import org.apache.solr.common.params.MapSolrParams; -import org.apache.solr.common.util.ContentStreamBase; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; - -import java.util.List; -import java.util.concurrent.CountDownLatch; - -import com.sematext.spm.client.tracing.agent.Tracing; -import com.sematext.spm.client.tracing.agent.config.ServiceLocator; -import com.sematext.spm.client.tracing.agent.model.Call; -import com.sematext.spm.client.tracing.agent.model.PartialTransaction; -import com.sematext.spm.client.tracing.agent.model.SolrAnnotation; -import com.sematext.spm.client.tracing.agent.tracer.Tracers; -import com.sematext.spm.client.tracing.utils.MockTransactionSink; -import com.sematext.spm.client.tracing.utils.TracingContext; -import com.sematext.spm.client.tracing.utils.TracingJUnit4ClassRunner; -import com.sematext.spm.client.tracing.utils.TracingTesting; - -@RunWith(TracingJUnit4ClassRunner.class) -@TracingContext(tracers = { Tracers.Solrj5Tracer.class, Tracers.HttpClient4Tracer.class }) -public class Solrj55TracerIntegrationTest { - - private SolrClient getSolrClient() { - return new HttpSolrClient("http://localhost:8983/solr"); - } - - @Before - @SuppressWarnings("unchecked") - public void preStart() throws Exception { - final SolrClient client = getSolrClient(); - CollectionAdminResponse response = new CollectionAdminRequest.List().process(client); - - for (Object names : response.getResponse().getAll("collections")) { - for (String name : (List) names) { - if (name.equals("test_collection_1") || name.equals("test_collection_2")) { - final CollectionAdminRequest.Delete request = new CollectionAdminRequest.Delete(); - request.setCollectionName(name); - request.process(client); - } - } - } - - CollectionAdminRequest.Create create1Request = new CollectionAdminRequest.Create(); - create1Request.setCollectionName("test_collection_1"); - create1Request.setNumShards(1); - create1Request.process(client); - - CollectionAdminRequest.Create create2Request = new CollectionAdminRequest.Create(); - create2Request.setCollectionName("test_collection_2"); - create2Request.setNumShards(1); - create2Request.process(client); - } - - private SolrAnnotation testRequestType(SolrRequest request, String collection, SolrAnnotation.RequestType expected) - throws Exception { - Tracing.newTrace("test-request-type", Call.TransactionType.BACKGROUND); - final MockTransactionSink mockTransSink = new MockTransactionSink(); - ServiceLocator.getTransactionSinks().clear(); - ServiceLocator.getTransactionSinks().add(mockTransSink); - - try { - request.process(getSolrClient(), collection); - - assertEquals(1, mockTransSink.getTransactions().size()); - assertEquals(1, mockTransSink.getTransactions().get(0).getCalls().size()); - - final Call call = mockTransSink.getTransactions().get(0).getCalls().get(0); - assertEquals(Call.CallTag.SOLR, call.getCallTag()); - - final SolrAnnotation annotation = (SolrAnnotation) call.getAnnotation(); - assertNotNull(annotation); - - assertEquals(expected, annotation.getRequestType()); - assertEquals(200, annotation.getResponseStatus()); - assertTrue(annotation.isSucceed()); - return annotation; - } finally { - Tracing.endTrace(); - } - } - - private static final String XML_DOC = "\n" + - "\n" + - " SOLR1000\n" + - " Solr, the Enterprise Search Server\n" + - "\n" + - "\n" + - "\n"; - - @Test - public void testRequestTypes() throws Exception { - SolrAnnotation annotation = testRequestType(new QueryRequest(new MapSolrParams(singletonMap("q", "*.*"))), "test_collection_1", SolrAnnotation.RequestType.QUERY); - final SolrInputDocument document = new SolrInputDocument(); - document.addField("firstName", "Corey"); - document.addField("lastName", "Taylor"); - annotation = testRequestType(new UpdateRequest() - .add(document), "test_collection_1", SolrAnnotation.RequestType.UPDATE); - assertEquals("test_collection_1", annotation.getCollection()); - - final ContentStreamUpdateRequest contentStreamRequest = new ContentStreamUpdateRequest("/update"); - contentStreamRequest.addContentStream(new ContentStreamBase.StringStream(XML_DOC, "application/xml")); - annotation = testRequestType(contentStreamRequest, "test_collection_1", SolrAnnotation.RequestType.UPDATE); - assertEquals("test_collection_1", annotation.getCollection()); - - final DirectXmlRequest xmlRequest = new DirectXmlRequest("/update", XML_DOC); - annotation = testRequestType(xmlRequest, "test_collection_1", SolrAnnotation.RequestType.UPDATE); - assertEquals("test_collection_1", annotation.getCollection()); - - testRequestType(new CollectionAdminRequest.List(), null, SolrAnnotation.RequestType.COLLECTION_ADMIN); - } - - @Test - public void testConcurrentUpdate() throws Exception { - Tracing.newTrace("test-request-type", Call.TransactionType.BACKGROUND); - final MockTransactionSink mockTransSink = setupSink(); - - final CountDownLatch latch = new CountDownLatch(10); - - final ConcurrentUpdateSolrClient client = new ConcurrentUpdateSolrClient("http://localhost:8983/solr/test_collection_1", 2, 10) { - @Override - public void onSuccess(HttpResponse resp) { - latch.countDown(); - } - - @Override - public void handleError(Throwable ex) { - ex.printStackTrace(); - latch.countDown(); - } - }; - - for (int i = 0; i < 10; i++) { - final SolrInputDocument document = new SolrInputDocument(); - document.addField("firstName", "Corey"); - document.addField("lastName", "Taylor"); - - new UpdateRequest("/test_collection_1/update").add(document).process(client, "test_collection_1"); - } - - latch.await(); - - List async = TracingTesting.findAsync(mockTransSink.getTransactions()); - assertEquals(10, async.size()); - } - -} diff --git a/spm-transfer/pom.xml b/spm-transfer/pom.xml index 44af327..1db84e4 100644 --- a/spm-transfer/pom.xml +++ b/spm-transfer/pom.xml @@ -55,7 +55,7 @@ org.apache.logging.log4j log4j-core - 2.17.0 + 2.17.2 compile