From 22ead46dccece09eb323953ee96d85f9f62adeae Mon Sep 17 00:00:00 2001 From: ascrutae Date: Mon, 22 Jan 2018 19:56:22 +0800 Subject: [PATCH 01/26] [Agent] Support kafka framework --- .../trace/component/ComponentsDefine.java | 5 +- .../kafka-0.11.x-plugin/pom.xml | 40 +++++++ .../plugin/kafka/v11/CallbackInterceptor.java | 55 +++++++++ .../v11/ConsumerConstructorInterceptor.java | 34 ++++++ .../v11/ConsumerEnhanceRequiredInfo.java | 44 ++++++++ .../kafka/v11/KafkaConsumerInterceptor.java | 83 ++++++++++++++ .../kafka/v11/KafkaProducerInterceptor.java | 72 ++++++++++++ .../v11/ProducerConstructorInterceptor.java | 33 ++++++ .../ProducerRecordConstructorInterceptor.java | 30 +++++ .../kafka/v11/SubscribeMethodInterceptor.java | 48 ++++++++ .../v11/define/CallbackInstrumentation.java | 67 +++++++++++ .../define/KafkaConsumerInstrumentation.java | 104 ++++++++++++++++++ .../define/KafkaProducerInstrumentation.java | 91 +++++++++++++++ .../define/ProducerRecordInstrumentation.java | 64 +++++++++++ .../src/main/resources/skywalking-plugin.def | 4 + apm-sniffer/apm-sdk-plugin/pom.xml | 1 + 16 files changed, 774 insertions(+), 1 deletion(-) create mode 100644 apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/pom.xml create mode 100644 apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/CallbackInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/ConsumerConstructorInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/ConsumerEnhanceRequiredInfo.java create mode 100644 apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/KafkaConsumerInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/KafkaProducerInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/ProducerConstructorInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/ProducerRecordConstructorInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/SubscribeMethodInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/define/CallbackInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/define/KafkaConsumerInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/define/KafkaProducerInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/define/ProducerRecordInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/resources/skywalking-plugin.def diff --git a/apm-protocol/apm-network/src/main/java/org/apache/skywalking/apm/network/trace/component/ComponentsDefine.java b/apm-protocol/apm-network/src/main/java/org/apache/skywalking/apm/network/trace/component/ComponentsDefine.java index b23f30cf3..220b1062c 100644 --- a/apm-protocol/apm-network/src/main/java/org/apache/skywalking/apm/network/trace/component/ComponentsDefine.java +++ b/apm-protocol/apm-network/src/main/java/org/apache/skywalking/apm/network/trace/component/ComponentsDefine.java @@ -78,6 +78,8 @@ public class ComponentsDefine { public static final OfficialComponent HTTP_ASYNC_CLIENT = new OfficialComponent(26, "httpasyncclient"); + public static final OfficialComponent KAFKA = new OfficialComponent(27, "Kafka"); + private static ComponentsDefine INSTANCE = new ComponentsDefine(); private String[] components; @@ -87,7 +89,7 @@ public class ComponentsDefine { } public ComponentsDefine() { - components = new String[27]; + components = new String[28]; addComponent(TOMCAT); addComponent(HTTPCLIENT); addComponent(DUBBO); @@ -114,6 +116,7 @@ public class ComponentsDefine { addComponent(ELASTIC_JOB); addComponent(ROCKET_MQ); addComponent(HTTP_ASYNC_CLIENT); + addComponent(KAFKA); } private void addComponent(OfficialComponent component) { diff --git a/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/pom.xml b/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/pom.xml new file mode 100644 index 000000000..37699929d --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/pom.xml @@ -0,0 +1,40 @@ + + + + + + apm-sdk-plugin + org.apache.skywalking + 5.0.0-alpha + + 4.0.0 + + apm-kafka-0.11.x-plugin + + + + org.apache.kafka + kafka-clients + 0.11.0.0 + provided + + + \ No newline at end of file diff --git a/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/CallbackInterceptor.java b/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/CallbackInterceptor.java new file mode 100644 index 000000000..a0f81a084 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/CallbackInterceptor.java @@ -0,0 +1,55 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.skywalking.apm.plugin.kafka.v11; + +import java.lang.reflect.Method; +import org.apache.skywalking.apm.agent.core.context.ContextManager; +import org.apache.skywalking.apm.agent.core.context.ContextSnapshot; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; + +public class CallbackInterceptor implements InstanceMethodsAroundInterceptor { + @Override + public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + MethodInterceptResult result) throws Throwable { + AbstractSpan abstractSpan = ContextManager.createLocalSpan("Producer/Callback"); + + //Get the SnapshotContext + ContextSnapshot contextSnapshot = (ContextSnapshot)objInst.getSkyWalkingDynamicField(); + ContextManager.continued(contextSnapshot); + } + + @Override + public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + Object ret) throws Throwable { + Exception exceptions = (Exception)allArguments[1]; + if (exceptions != null) { + ContextManager.activeSpan().errorOccurred().log(exceptions); + } + ContextManager.stopSpan(); + return ret; + } + + @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + ContextManager.activeSpan().errorOccurred().log(t); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/ConsumerConstructorInterceptor.java b/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/ConsumerConstructorInterceptor.java new file mode 100644 index 000000000..fd3bc6c9e --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/ConsumerConstructorInterceptor.java @@ -0,0 +1,34 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.skywalking.apm.plugin.kafka.v11; + +import org.apache.kafka.clients.consumer.ConsumerConfig; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor; + +public class ConsumerConstructorInterceptor implements InstanceConstructorInterceptor { + + @Override public void onConstruct(EnhancedInstance objInst, Object[] allArguments) { + ConsumerConfig config = (ConsumerConfig)allArguments[0]; + // set the bootstrap server address + ConsumerEnhanceRequiredInfo requiredInfo = new ConsumerEnhanceRequiredInfo(); + requiredInfo.setBrokerServers(config.getList("bootstrap.servers")); + objInst.setSkyWalkingDynamicField(requiredInfo); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/ConsumerEnhanceRequiredInfo.java b/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/ConsumerEnhanceRequiredInfo.java new file mode 100644 index 000000000..2eb660137 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/ConsumerEnhanceRequiredInfo.java @@ -0,0 +1,44 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.skywalking.apm.plugin.kafka.v11; + +import java.util.Collection; +import java.util.List; +import org.apache.skywalking.apm.util.StringUtil; + +public class ConsumerEnhanceRequiredInfo { + private String brokerServers; + private String topics; + + public void setBrokerServers(List brokerServers) { + this.brokerServers = StringUtil.join(',', brokerServers.toArray(new String[0])); + } + + public void setTopics(Collection topics) { + this.topics = StringUtil.join(',', topics.toArray(new String[0])); + } + + public String getBrokerServers() { + return brokerServers; + } + + public String getTopics() { + return topics; + } +} diff --git a/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/KafkaConsumerInterceptor.java b/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/KafkaConsumerInterceptor.java new file mode 100644 index 000000000..f6804cc2f --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/KafkaConsumerInterceptor.java @@ -0,0 +1,83 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.skywalking.apm.plugin.kafka.v11; + +import java.lang.reflect.Method; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import org.apache.kafka.clients.consumer.ConsumerRecord; +import org.apache.kafka.common.TopicPartition; +import org.apache.kafka.common.header.Header; +import org.apache.skywalking.apm.agent.core.context.CarrierItem; +import org.apache.skywalking.apm.agent.core.context.ContextCarrier; +import org.apache.skywalking.apm.agent.core.context.ContextManager; +import org.apache.skywalking.apm.agent.core.context.tag.Tags; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; +import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; +import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; + +/** + * @autor zhang xin + */ +public class KafkaConsumerInterceptor implements InstanceMethodsAroundInterceptor { + @Override + public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + MethodInterceptResult result) throws Throwable { + AbstractSpan activeSpan = ContextManager.createEntrySpan("Kafka/Consumer/Poll", null); + ConsumerEnhanceRequiredInfo requiredInfo = (ConsumerEnhanceRequiredInfo)objInst.getSkyWalkingDynamicField(); + + activeSpan.setComponent(ComponentsDefine.KAFKA); + SpanLayer.asMQ(activeSpan); + Tags.MQ_BROKER.set(activeSpan, requiredInfo.getBrokerServers()); + Tags.MQ_TOPIC.set(activeSpan, requiredInfo.getTopics()); + } + + @Override + public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + Object ret) throws Throwable { + Map>> records = (Map>>)ret; + for (List> consumerRecords : records.values()) { + for (ConsumerRecord record : consumerRecords) { + ContextCarrier contextCarrier = new ContextCarrier(); + + CarrierItem next = contextCarrier.items(); + while (next.hasNext()) { + next = next.next(); + Iterator
iterator = record.headers().headers(next.getHeadKey()).iterator(); + if (iterator.hasNext()) { + next.setHeadValue(new String(iterator.next().value())); + } + } + ContextManager.extract(contextCarrier); + } + } + + ContextManager.stopSpan(); + return ret; + } + + @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + ContextManager.activeSpan().errorOccurred().log(t); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/KafkaProducerInterceptor.java b/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/KafkaProducerInterceptor.java new file mode 100644 index 000000000..929d071cb --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/KafkaProducerInterceptor.java @@ -0,0 +1,72 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.skywalking.apm.plugin.kafka.v11; + +import java.lang.reflect.Method; +import org.apache.kafka.clients.producer.ProducerRecord; +import org.apache.skywalking.apm.agent.core.context.CarrierItem; +import org.apache.skywalking.apm.agent.core.context.ContextCarrier; +import org.apache.skywalking.apm.agent.core.context.ContextManager; +import org.apache.skywalking.apm.agent.core.context.tag.Tags; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; + +/** + * @author zhang xin + */ +public class KafkaProducerInterceptor implements InstanceMethodsAroundInterceptor { + @Override + public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + MethodInterceptResult result) throws Throwable { + + ContextCarrier contextCarrier = new ContextCarrier(); + AbstractSpan activeSpan = ContextManager.createExitSpan("Kafka/Producer/send", contextCarrier, (String)objInst.getSkyWalkingDynamicField()); + + //set tags + ProducerRecord record = (ProducerRecord)allArguments[0]; + Tags.MQ_BROKER.set(activeSpan, (String)objInst.getSkyWalkingDynamicField()); + Tags.MQ_TOPIC.set(activeSpan, (String)((EnhancedInstance)record).getSkyWalkingDynamicField()); + + // set headers + CarrierItem next = contextCarrier.items(); + while (next.hasNext()) { + next = next.next(); + record.headers().add(next.getHeadKey(), next.getHeadValue().getBytes()); + } + + EnhancedInstance callbackInstance = (EnhancedInstance)allArguments[1]; + if (callbackInstance != null) { + callbackInstance.setSkyWalkingDynamicField(ContextManager.capture()); + } + } + + @Override + public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + Object ret) throws Throwable { + ContextManager.stopSpan(); + return ret; + } + + @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + + } +} diff --git a/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/ProducerConstructorInterceptor.java b/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/ProducerConstructorInterceptor.java new file mode 100644 index 000000000..ed267df21 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/ProducerConstructorInterceptor.java @@ -0,0 +1,33 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.skywalking.apm.plugin.kafka.v11; + +import org.apache.kafka.clients.producer.ProducerConfig; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor; +import org.apache.skywalking.apm.util.StringUtil; + +public class ProducerConstructorInterceptor implements InstanceConstructorInterceptor { + + @Override public void onConstruct(EnhancedInstance objInst, Object[] allArguments) { + ProducerConfig config = (ProducerConfig)allArguments[0]; + // set the bootstrap server address + objInst.setSkyWalkingDynamicField(StringUtil.join(',', config.getList("bootstrap.servers").toArray(new String[0]))); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/ProducerRecordConstructorInterceptor.java b/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/ProducerRecordConstructorInterceptor.java new file mode 100644 index 000000000..0cb723a43 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/ProducerRecordConstructorInterceptor.java @@ -0,0 +1,30 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.skywalking.apm.plugin.kafka.v11; + +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor; + +public class ProducerRecordConstructorInterceptor implements InstanceConstructorInterceptor { + @Override public void onConstruct(EnhancedInstance objInst, Object[] allArguments) { + String topic = (String)allArguments[0]; + // set the topic + objInst.setSkyWalkingDynamicField(topic); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/SubscribeMethodInterceptor.java b/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/SubscribeMethodInterceptor.java new file mode 100644 index 000000000..657684a9f --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/SubscribeMethodInterceptor.java @@ -0,0 +1,48 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.skywalking.apm.plugin.kafka.v11; + +import java.lang.reflect.Method; +import java.util.Collection; +import org.apache.skywalking.apm.agent.core.context.ContextManager; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; + +public class SubscribeMethodInterceptor implements InstanceMethodsAroundInterceptor { + @Override + public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + MethodInterceptResult result) throws Throwable { + ConsumerEnhanceRequiredInfo requiredInfo = (ConsumerEnhanceRequiredInfo)objInst.getSkyWalkingDynamicField(); + requiredInfo.setTopics((Collection)allArguments[0]); + + objInst.setSkyWalkingDynamicField(requiredInfo); + } + + @Override + public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + Object ret) throws Throwable { + return ret; + } + + @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + ContextManager.activeSpan().errorOccurred().log(t); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/define/CallbackInstrumentation.java b/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/define/CallbackInstrumentation.java new file mode 100644 index 000000000..715166888 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/define/CallbackInstrumentation.java @@ -0,0 +1,67 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.skywalking.apm.plugin.kafka.v11.define; + +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; + +import static net.bytebuddy.matcher.ElementMatchers.named; +import static org.apache.skywalking.apm.agent.core.plugin.match.HierarchyMatch.byHierarchyMatch; + +/** + * {@link CallbackInstrumentation} intercept the method onCompletion in the class org.apache.kafka.clients.producer.Callback. + * + * @author zhangxin + */ +public class CallbackInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { + + public static final String ENHANCE_CLASS = "org.apache.kafka.clients.producer.Callback"; + public static final String ENHANCE_METHOD = "onCompletion"; + public static final String INTERCEPTOR_CLASS = "org.apache.skywalking.apm.plugin.kafka.v11.CallbackInterceptor"; + + @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[0]; + } + + @Override protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + new InstanceMethodsInterceptPoint() { + @Override public ElementMatcher getMethodsMatcher() { + return named(ENHANCE_METHOD); + } + + @Override public String getMethodsInterceptor() { + return INTERCEPTOR_CLASS; + } + + @Override public boolean isOverrideArgs() { + return false; + } + } + }; + } + + @Override protected ClassMatch enhanceClass() { + return byHierarchyMatch(new String[] {ENHANCE_CLASS}); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/define/KafkaConsumerInstrumentation.java b/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/define/KafkaConsumerInstrumentation.java new file mode 100644 index 000000000..81b9bbe87 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/define/KafkaConsumerInstrumentation.java @@ -0,0 +1,104 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.skywalking.apm.plugin.kafka.v11.define; + +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; + +import static net.bytebuddy.matcher.ElementMatchers.named; +import static org.apache.skywalking.apm.agent.core.plugin.bytebuddy.ArgumentTypeNameMatch.takesArgumentWithType; +import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName; + +/** + * {@link KafkaProducerInstrumentation} intercept the method send in the class + * org.apache.kafka.clients.producer.KafkaProducer. Here is the intercept process steps. + * + * + *
+ *  1. Record the topic when the client call subscribed
+ *  3. Create the entry span when the client call the method pollOnce.
+ *  4. Inject all the Trace Context by iterate all ConsumerRecord
+ *  5. Stop the entry span when end the pollOnce method.
+ * 
+ * + * @author zhang xin + */ +public class KafkaConsumerInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { + + public static final String CONSTRUCTOR_INTERCEPT_FLAG = "org.apache.kafka.clients.consumer.ConsumerConfig"; + public static final String CONSTRUCTOR_INTERCEPTOR_CLASS = "org.apache.skywalking.apm.plugin.kafka.v11.ConsumerConstructorInterceptor"; + public static final String INTERCEPTOR_CLASS = "org.apache.skywalking.apm.plugin.kafka.v11.KafkaConsumerInterceptor"; + public static final String ENHANCE_METHOD = "pollOnce"; + public static final String ENHANCE_CLASS = "org.apache.kafka.clients.consumer.KafkaConsumer"; + public static final String SUBSCRIBE_METHOD = "subscribe"; + public static final String SUBSCRIBE_INTERCEPT_FLAG = "org.apache.kafka.clients.consumer.ConsumerRebalanceListener"; + + @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[] { + new ConstructorInterceptPoint() { + @Override public ElementMatcher getConstructorMatcher() { + return takesArgumentWithType(0, CONSTRUCTOR_INTERCEPT_FLAG); + } + + @Override public String getConstructorInterceptor() { + return CONSTRUCTOR_INTERCEPTOR_CLASS; + } + } + }; + } + + @Override protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + new InstanceMethodsInterceptPoint() { + @Override public ElementMatcher getMethodsMatcher() { + return named(ENHANCE_METHOD); + } + + @Override public String getMethodsInterceptor() { + return INTERCEPTOR_CLASS; + } + + @Override public boolean isOverrideArgs() { + return false; + } + }, + new InstanceMethodsInterceptPoint() { + @Override public ElementMatcher getMethodsMatcher() { + return named(SUBSCRIBE_METHOD).and(takesArgumentWithType(1, SUBSCRIBE_INTERCEPT_FLAG)); + } + + @Override public String getMethodsInterceptor() { + return "org.apache.skywalking.apm.plugin.kafka.v11.SubscribeMethodInterceptor"; + } + + @Override public boolean isOverrideArgs() { + return false; + } + } + }; + } + + @Override protected ClassMatch enhanceClass() { + return byName(ENHANCE_CLASS); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/define/KafkaProducerInstrumentation.java b/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/define/KafkaProducerInstrumentation.java new file mode 100644 index 000000000..cd3ff6041 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/define/KafkaProducerInstrumentation.java @@ -0,0 +1,91 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.skywalking.apm.plugin.kafka.v11.define; + +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; + +import static net.bytebuddy.matcher.ElementMatchers.named; +import static org.apache.skywalking.apm.agent.core.plugin.bytebuddy.ArgumentTypeNameMatch.takesArgumentWithType; +import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName; + +/** + * {@link KafkaProducerInstrumentation} intercept the method send in the class + * org.apache.kafka.clients.producer.KafkaProducer. Here is the intercept process steps. + * + * + *
+ *  1. Record the broker address when the client create the org.apache.kafka.clients.producer.KafkaProducer
+ * instance
+ *  2. Fetch the topic name from org.apache.kafka.clients.producer.ProducerRecord when the client call
+ * send method.
+ *  3. Create the exit span when the client call send method
+ *  4. Set the Context into the org.apache.kafka.clients.producer.ProducerRecord#headers
+ *  5. Stop the exit span when end the send method.
+ * 
+ * + * @author zhang xin + */ +public class KafkaProducerInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { + + public static final String INTERCEPTOR_CLASS = "org.apache.skywalking.apm.plugin.kafka.v11.KafkaProducerInterceptor"; + public static final String ENHANCE_CLASS = "org.apache.kafka.clients.producer.KafkaProducer"; + public static final String CONSTRUCTOR_INTERCEPTOR_CLASS = "org.apache.skywalking.apm.plugin.kafka.v11.ProducerConstructorInterceptor"; + public static final String CONSTRUCTOR_INTERCEPTOR_FLAG = "org.apache.kafka.clients.producer.ProducerConfig"; + + @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[] { + new ConstructorInterceptPoint() { + @Override public ElementMatcher getConstructorMatcher() { + return takesArgumentWithType(0, CONSTRUCTOR_INTERCEPTOR_FLAG); + } + + @Override public String getConstructorInterceptor() { + return CONSTRUCTOR_INTERCEPTOR_CLASS; + } + } + }; + } + + @Override protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + new InstanceMethodsInterceptPoint() { + @Override public ElementMatcher getMethodsMatcher() { + return named("doSend"); + } + + @Override public String getMethodsInterceptor() { + return INTERCEPTOR_CLASS; + } + + @Override public boolean isOverrideArgs() { + return false; + } + } + }; + } + + @Override protected ClassMatch enhanceClass() { + return byName(ENHANCE_CLASS); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/define/ProducerRecordInstrumentation.java b/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/define/ProducerRecordInstrumentation.java new file mode 100644 index 000000000..abcee1a0a --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/define/ProducerRecordInstrumentation.java @@ -0,0 +1,64 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.skywalking.apm.plugin.kafka.v11.define; + +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; + +import static net.bytebuddy.matcher.ElementMatchers.takesArguments; +import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName; + +/** + * {@link ProducerRecordInstrumentation} intercept the constructor in the class org.apache.kafka.clients.producer.ProducerRecord + * for record the topic name and propagate the Context of trace. + * + * @author zhang xin + * @see org.apache.skywalking.apm.plugin.kafka.v11.define.KafkaProducerInstrumentation + */ +public class ProducerRecordInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { + + public static final String CONSTRUCTOR_INTERCEPTOR_CLASS = "org.apache.skywalking.apm.plugin.kafka.v11.ProducerRecordConstructorInterceptor"; + public static final String ENHANCE_CLASS = "org.apache.kafka.clients.producer.ProducerRecord"; + + @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[] { + new ConstructorInterceptPoint() { + @Override public ElementMatcher getConstructorMatcher() { + return takesArguments(6); + } + + @Override public String getConstructorInterceptor() { + return CONSTRUCTOR_INTERCEPTOR_CLASS; + } + } + }; + } + + @Override protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[0]; + } + + @Override protected ClassMatch enhanceClass() { + return byName(ENHANCE_CLASS); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/resources/skywalking-plugin.def b/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/resources/skywalking-plugin.def new file mode 100644 index 000000000..5f3439cbf --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/resources/skywalking-plugin.def @@ -0,0 +1,4 @@ +kafka-0.11.x=org.apache.skywalking.apm.plugin.kafka.v11.define.CallbackInstrumentation +kafka-0.11.x=org.apache.skywalking.apm.plugin.kafka.v11.define.KafkaConsumerInstrumentation +kafka-0.11.x=org.apache.skywalking.apm.plugin.kafka.v11.define.KafkaProducerInstrumentation +kafka-0.11.x=org.apache.skywalking.apm.plugin.kafka.v11.define.ProducerRecordInstrumentation diff --git a/apm-sniffer/apm-sdk-plugin/pom.xml b/apm-sniffer/apm-sdk-plugin/pom.xml index 4b81d1d8c..fa8d0b0ae 100644 --- a/apm-sniffer/apm-sdk-plugin/pom.xml +++ b/apm-sniffer/apm-sdk-plugin/pom.xml @@ -53,6 +53,7 @@ elastic-job-2.x-plugin mongodb-2.x-plugin httpasyncclient-4.x-plugin + kafka-0.11.x-plugin pom From 5fab1fada01326b1935b678ede7137b371aa8090 Mon Sep 17 00:00:00 2001 From: ascrutae Date: Mon, 22 Jan 2018 23:09:31 +0800 Subject: [PATCH 02/26] add spanlayer and component for kafka span --- .../apm/plugin/kafka/v11/KafkaProducerInterceptor.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/KafkaProducerInterceptor.java b/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/KafkaProducerInterceptor.java index 929d071cb..70d98744b 100644 --- a/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/KafkaProducerInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/KafkaProducerInterceptor.java @@ -25,9 +25,11 @@ import org.apache.skywalking.apm.agent.core.context.ContextCarrier; import org.apache.skywalking.apm.agent.core.context.ContextManager; import org.apache.skywalking.apm.agent.core.context.tag.Tags; import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; +import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; +import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; /** * @author zhang xin @@ -44,6 +46,8 @@ public class KafkaProducerInterceptor implements InstanceMethodsAroundIntercepto ProducerRecord record = (ProducerRecord)allArguments[0]; Tags.MQ_BROKER.set(activeSpan, (String)objInst.getSkyWalkingDynamicField()); Tags.MQ_TOPIC.set(activeSpan, (String)((EnhancedInstance)record).getSkyWalkingDynamicField()); + SpanLayer.asMQ(activeSpan); + activeSpan.setComponent(ComponentsDefine.KAFKA); // set headers CarrierItem next = contextCarrier.items(); From 906a2c4d05755112a94e494b68a0de4b716f3dea Mon Sep 17 00:00:00 2001 From: ascrutae Date: Tue, 23 Jan 2018 20:03:50 +0800 Subject: [PATCH 03/26] add testcase --- .../core/context/trace/AbstractSpan.java | 2 + .../context/trace/AbstractTracingSpan.java | 6 + .../agent/core/context/trace/NoopSpan.java | 4 + .../kafka-0.11.x-plugin/README.md | 5 + .../v11/ConsumerEnhanceRequiredInfo.java | 13 +- .../kafka/v11/KafkaConsumerInterceptor.java | 47 +++--- .../kafka/v11/KafkaProducerInterceptor.java | 13 +- .../v11/ProducerConstructorInterceptor.java | 2 +- .../kafka/v11/CallbackInterceptorTest.java | 147 ++++++++++++++++++ .../ConsumerConstructorInterceptorTest.java | 73 +++++++++ .../v11/KafkaConsumerInterceptorTest.java | 140 +++++++++++++++++ .../v11/KafkaProducerInterceptorTest.java | 115 ++++++++++++++ .../ProducerConstructorInterceptorTest.java | 69 ++++++++ ...ducerRecordConstructorInterceptorTest.java | 59 +++++++ .../v11/SubscribeMethodInterceptorTest.java | 67 ++++++++ .../core/context/MockContextSnapshot.java | 47 ++++++ 16 files changed, 785 insertions(+), 24 deletions(-) create mode 100644 apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/README.md create mode 100644 apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/kafka/v11/CallbackInterceptorTest.java create mode 100644 apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/kafka/v11/ConsumerConstructorInterceptorTest.java create mode 100644 apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/kafka/v11/KafkaConsumerInterceptorTest.java create mode 100644 apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/kafka/v11/KafkaProducerInterceptorTest.java create mode 100644 apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/kafka/v11/ProducerConstructorInterceptorTest.java create mode 100644 apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/kafka/v11/ProducerRecordConstructorInterceptorTest.java create mode 100644 apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/kafka/v11/SubscribeMethodInterceptorTest.java create mode 100644 apm-sniffer/apm-test-tools/src/main/java/org/apache/skywalking/apm/agent/core/context/MockContextSnapshot.java diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/trace/AbstractSpan.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/trace/AbstractSpan.java index ada06d3d0..3ce6518d3 100644 --- a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/trace/AbstractSpan.java +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/trace/AbstractSpan.java @@ -116,4 +116,6 @@ public interface AbstractSpan { * @param ref segment ref */ void ref(TraceSegmentRef ref); + + AbstractSpan start(long starttime); } diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/trace/AbstractTracingSpan.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/trace/AbstractTracingSpan.java index 90d174d02..2028215ae 100644 --- a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/trace/AbstractTracingSpan.java +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/trace/AbstractTracingSpan.java @@ -239,6 +239,12 @@ public abstract class AbstractTracingSpan implements AbstractSpan { return this; } + @Override + public AbstractSpan start(long startTime) { + this.startTime = startTime; + return this; + } + public SpanObject.Builder transform() { SpanObject.Builder spanBuilder = SpanObject.newBuilder(); diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/trace/NoopSpan.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/trace/NoopSpan.java index 4be30d1b7..df64b9015 100644 --- a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/trace/NoopSpan.java +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/trace/NoopSpan.java @@ -102,4 +102,8 @@ public class NoopSpan implements AbstractSpan { @Override public void ref(TraceSegmentRef ref) { } + + @Override public AbstractSpan start(long startTime) { + return this; + } } diff --git a/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/README.md b/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/README.md new file mode 100644 index 000000000..bcc6c3b46 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/README.md @@ -0,0 +1,5 @@ +# Kafka Plugin + +## +## Buired Point + diff --git a/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/ConsumerEnhanceRequiredInfo.java b/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/ConsumerEnhanceRequiredInfo.java index 2eb660137..97e44c57a 100644 --- a/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/ConsumerEnhanceRequiredInfo.java +++ b/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/ConsumerEnhanceRequiredInfo.java @@ -25,13 +25,14 @@ import org.apache.skywalking.apm.util.StringUtil; public class ConsumerEnhanceRequiredInfo { private String brokerServers; private String topics; + private long startTime; public void setBrokerServers(List brokerServers) { - this.brokerServers = StringUtil.join(',', brokerServers.toArray(new String[0])); + this.brokerServers = StringUtil.join(';', brokerServers.toArray(new String[0])); } public void setTopics(Collection topics) { - this.topics = StringUtil.join(',', topics.toArray(new String[0])); + this.topics = StringUtil.join(';', topics.toArray(new String[0])); } public String getBrokerServers() { @@ -41,4 +42,12 @@ public class ConsumerEnhanceRequiredInfo { public String getTopics() { return topics; } + + public void setStartTime(long startTime) { + this.startTime = startTime; + } + + public long getStartTime() { + return startTime; + } } diff --git a/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/KafkaConsumerInterceptor.java b/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/KafkaConsumerInterceptor.java index f6804cc2f..f0098e43d 100644 --- a/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/KafkaConsumerInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/KafkaConsumerInterceptor.java @@ -40,39 +40,50 @@ import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; * @autor zhang xin */ public class KafkaConsumerInterceptor implements InstanceMethodsAroundInterceptor { + + public static final String OPERATE_NAME_PREFIX = "Kafka/"; + public static final String CONSUMER_OPERATE_NAME_SUFFIX = "/Consumer"; + @Override public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, MethodInterceptResult result) throws Throwable { - AbstractSpan activeSpan = ContextManager.createEntrySpan("Kafka/Consumer/Poll", null); ConsumerEnhanceRequiredInfo requiredInfo = (ConsumerEnhanceRequiredInfo)objInst.getSkyWalkingDynamicField(); - - activeSpan.setComponent(ComponentsDefine.KAFKA); - SpanLayer.asMQ(activeSpan); - Tags.MQ_BROKER.set(activeSpan, requiredInfo.getBrokerServers()); - Tags.MQ_TOPIC.set(activeSpan, requiredInfo.getTopics()); + requiredInfo.setStartTime(System.currentTimeMillis()); } @Override public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, Object ret) throws Throwable { Map>> records = (Map>>)ret; - for (List> consumerRecords : records.values()) { - for (ConsumerRecord record : consumerRecords) { - ContextCarrier contextCarrier = new ContextCarrier(); + // + // The entry span will create when the consumer fetch anyone message from kafka cluster, or the span will not create. + // + if (records.size() > 0) { + ConsumerEnhanceRequiredInfo requiredInfo = (ConsumerEnhanceRequiredInfo)objInst.getSkyWalkingDynamicField(); + AbstractSpan activeSpan = ContextManager.createEntrySpan(OPERATE_NAME_PREFIX + requiredInfo.getTopics() + CONSUMER_OPERATE_NAME_SUFFIX, null).start(requiredInfo.getStartTime()); - CarrierItem next = contextCarrier.items(); - while (next.hasNext()) { - next = next.next(); - Iterator
iterator = record.headers().headers(next.getHeadKey()).iterator(); - if (iterator.hasNext()) { - next.setHeadValue(new String(iterator.next().value())); + activeSpan.setComponent(ComponentsDefine.KAFKA); + SpanLayer.asMQ(activeSpan); + Tags.MQ_BROKER.set(activeSpan, requiredInfo.getBrokerServers()); + Tags.MQ_TOPIC.set(activeSpan, requiredInfo.getTopics()); + + for (List> consumerRecords : records.values()) { + for (ConsumerRecord record : consumerRecords) { + ContextCarrier contextCarrier = new ContextCarrier(); + + CarrierItem next = contextCarrier.items(); + while (next.hasNext()) { + next = next.next(); + Iterator
iterator = record.headers().headers(next.getHeadKey()).iterator(); + if (iterator.hasNext()) { + next.setHeadValue(new String(iterator.next().value())); + } } + ContextManager.extract(contextCarrier); } - ContextManager.extract(contextCarrier); } + ContextManager.stopSpan(); } - - ContextManager.stopSpan(); return ret; } diff --git a/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/KafkaProducerInterceptor.java b/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/KafkaProducerInterceptor.java index 70d98744b..19d883b70 100644 --- a/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/KafkaProducerInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/KafkaProducerInterceptor.java @@ -35,17 +35,24 @@ import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; * @author zhang xin */ public class KafkaProducerInterceptor implements InstanceMethodsAroundInterceptor { + + public static final String OPERATE_NAME_PREFIX = "Kafka/"; + public static final String PRODUCER_OPERATE_NAME_SUFFIX = "/Producer"; + @Override public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, MethodInterceptResult result) throws Throwable { ContextCarrier contextCarrier = new ContextCarrier(); - AbstractSpan activeSpan = ContextManager.createExitSpan("Kafka/Producer/send", contextCarrier, (String)objInst.getSkyWalkingDynamicField()); + + ProducerRecord record = (ProducerRecord)allArguments[0]; + String topicName = (String)((EnhancedInstance)record).getSkyWalkingDynamicField(); + + AbstractSpan activeSpan = ContextManager.createExitSpan(OPERATE_NAME_PREFIX + topicName + PRODUCER_OPERATE_NAME_SUFFIX, contextCarrier, (String)objInst.getSkyWalkingDynamicField()); //set tags - ProducerRecord record = (ProducerRecord)allArguments[0]; Tags.MQ_BROKER.set(activeSpan, (String)objInst.getSkyWalkingDynamicField()); - Tags.MQ_TOPIC.set(activeSpan, (String)((EnhancedInstance)record).getSkyWalkingDynamicField()); + Tags.MQ_TOPIC.set(activeSpan, topicName); SpanLayer.asMQ(activeSpan); activeSpan.setComponent(ComponentsDefine.KAFKA); diff --git a/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/ProducerConstructorInterceptor.java b/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/ProducerConstructorInterceptor.java index ed267df21..9849d48ff 100644 --- a/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/ProducerConstructorInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/ProducerConstructorInterceptor.java @@ -28,6 +28,6 @@ public class ProducerConstructorInterceptor implements InstanceConstructorInterc @Override public void onConstruct(EnhancedInstance objInst, Object[] allArguments) { ProducerConfig config = (ProducerConfig)allArguments[0]; // set the bootstrap server address - objInst.setSkyWalkingDynamicField(StringUtil.join(',', config.getList("bootstrap.servers").toArray(new String[0]))); + objInst.setSkyWalkingDynamicField(StringUtil.join(';', config.getList("bootstrap.servers").toArray(new String[0]))); } } diff --git a/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/kafka/v11/CallbackInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/kafka/v11/CallbackInterceptorTest.java new file mode 100644 index 000000000..78991cfe2 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/kafka/v11/CallbackInterceptorTest.java @@ -0,0 +1,147 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.skywalking.apm.plugin.kafka.v11; + +import java.util.List; +import org.apache.kafka.clients.producer.RecordMetadata; +import org.apache.skywalking.apm.agent.core.context.MockContextSnapshot; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan; +import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment; +import org.apache.skywalking.apm.agent.core.context.trace.TraceSegmentRef; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.test.helper.SegmentHelper; +import org.apache.skywalking.apm.agent.test.helper.SpanHelper; +import org.apache.skywalking.apm.agent.test.tools.AgentServiceRule; +import org.apache.skywalking.apm.agent.test.tools.SegmentRefAssert; +import org.apache.skywalking.apm.agent.test.tools.SegmentStorage; +import org.apache.skywalking.apm.agent.test.tools.SegmentStoragePoint; +import org.apache.skywalking.apm.agent.test.tools.SpanAssert; +import org.apache.skywalking.apm.agent.test.tools.TracingSegmentRunner; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; +import org.powermock.modules.junit4.PowerMockRunnerDelegate; + +import static org.hamcrest.core.Is.is; +import static org.junit.Assert.assertThat; + +@RunWith(PowerMockRunner.class) +@PowerMockRunnerDelegate(TracingSegmentRunner.class) +@PrepareForTest({RecordMetadata.class}) +public class CallbackInterceptorTest { + + @SegmentStoragePoint + private SegmentStorage segmentStorage; + + @Rule + public AgentServiceRule serviceRule = new AgentServiceRule(); + + @Mock + private RecordMetadata recordMetadata; + + private CallbackInterceptor callbackInterceptor; + + private Object[] arguments; + private Object[] argumentsWithException; + private Class[] argumentTypes; + + private EnhancedInstance callBackInstance = new EnhancedInstance() { + @Override public Object getSkyWalkingDynamicField() { + return MockContextSnapshot.INSTANCE.mockContextSnapshot(); + } + + @Override public void setSkyWalkingDynamicField(Object value) { + + } + }; + + @Before + public void setUp() { + callbackInterceptor = new CallbackInterceptor(); + + arguments = new Object[] { + recordMetadata, null + }; + argumentsWithException = new Object[] { + recordMetadata, new RuntimeException() + }; + + argumentTypes = new Class[] { + RecordMetadata.class, Exception.class + }; + + } + + @Test + public void testCallbackWithoutException() throws Throwable { + callbackInterceptor.beforeMethod(callBackInstance, null, arguments, argumentTypes, null); + callbackInterceptor.afterMethod(callBackInstance, null, arguments, argumentTypes, null); + + List traceSegments = segmentStorage.getTraceSegments(); + assertThat(traceSegments.size(), is(1)); + TraceSegment traceSegment = traceSegments.get(0); + + List abstractSpans = SegmentHelper.getSpans(traceSegment); + assertThat(abstractSpans.size(), is(1)); + + assertCallbackSpan(abstractSpans.get(0)); + + assertCallbackSegmentRef(traceSegment.getRefs()); + } + + @Test + public void testCallbackWithException() throws Throwable { + callbackInterceptor.beforeMethod(callBackInstance, null, argumentsWithException, argumentTypes, null); + callbackInterceptor.afterMethod(callBackInstance, null, argumentsWithException, argumentTypes, null); + + List traceSegments = segmentStorage.getTraceSegments(); + assertThat(traceSegments.size(), is(1)); + TraceSegment traceSegment = traceSegments.get(0); + + List abstractSpans = SegmentHelper.getSpans(traceSegment); + assertThat(abstractSpans.size(), is(1)); + + assertCallbackSpanWithException(abstractSpans.get(0)); + + assertCallbackSegmentRef(traceSegment.getRefs()); + } + + private void assertCallbackSpanWithException(AbstractTracingSpan span) { + assertCallbackSpan(span); + + SpanAssert.assertException(SpanHelper.getLogs(span).get(0), RuntimeException.class); + assertThat(SpanHelper.getErrorOccurred(span), is(true)); + } + + private void assertCallbackSegmentRef(List refs) { + assertThat(refs.size(), is(1)); + + TraceSegmentRef segmentRef = refs.get(0); + SegmentRefAssert.assertSpanId(segmentRef, 1); + assertThat(segmentRef.getEntryOperationName(), is("/for-test-entryOperationName")); + } + + private void assertCallbackSpan(AbstractTracingSpan span) { + assertThat(span.getOperationName(), is("Producer/Callback")); + } +} \ No newline at end of file diff --git a/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/kafka/v11/ConsumerConstructorInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/kafka/v11/ConsumerConstructorInterceptorTest.java new file mode 100644 index 000000000..1379203d6 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/kafka/v11/ConsumerConstructorInterceptorTest.java @@ -0,0 +1,73 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.skywalking.apm.plugin.kafka.v11; + +import java.util.ArrayList; +import java.util.List; +import org.apache.kafka.clients.consumer.ConsumerConfig; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.core.Is.is; +import static org.mockito.Mockito.when; + +@RunWith(MockitoJUnitRunner.class) +public class ConsumerConstructorInterceptorTest { + + @Mock + private ConsumerConfig consumerConfig; + + @Mock + private ConsumerConstructorInterceptor constructorInterceptor; + + private EnhancedInstance enhancedInstance = new EnhancedInstance() { + private ConsumerEnhanceRequiredInfo consumerEnhanceRequiredInfo; + + @Override public Object getSkyWalkingDynamicField() { + return consumerEnhanceRequiredInfo; + } + + @Override public void setSkyWalkingDynamicField(Object value) { + consumerEnhanceRequiredInfo = (ConsumerEnhanceRequiredInfo)value; + } + }; + + @Before + public void setUp() { + List mockBootstrapServers = new ArrayList(); + mockBootstrapServers.add("localhost:9092"); + mockBootstrapServers.add("localhost:19092"); + when(consumerConfig.getList("bootstrap.servers")).thenReturn(mockBootstrapServers); + + constructorInterceptor = new ConsumerConstructorInterceptor(); + } + + @Test + public void testOnConsumer() { + constructorInterceptor.onConstruct(enhancedInstance, new Object[] {consumerConfig}); + ConsumerEnhanceRequiredInfo consumerEnhanceRequiredInfo = (ConsumerEnhanceRequiredInfo)enhancedInstance.getSkyWalkingDynamicField(); + assertThat(consumerEnhanceRequiredInfo.getBrokerServers(), is("localhost:9092;localhost:19092")); + } + +} \ No newline at end of file diff --git a/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/kafka/v11/KafkaConsumerInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/kafka/v11/KafkaConsumerInterceptorTest.java new file mode 100644 index 000000000..847b9ea87 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/kafka/v11/KafkaConsumerInterceptorTest.java @@ -0,0 +1,140 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.skywalking.apm.plugin.kafka.v11; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.apache.kafka.clients.consumer.ConsumerRecord; +import org.apache.kafka.common.TopicPartition; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan; +import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer; +import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment; +import org.apache.skywalking.apm.agent.core.context.trace.TraceSegmentRef; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.test.helper.SegmentHelper; +import org.apache.skywalking.apm.agent.test.helper.SegmentRefHelper; +import org.apache.skywalking.apm.agent.test.tools.AgentServiceRule; +import org.apache.skywalking.apm.agent.test.tools.SegmentStorage; +import org.apache.skywalking.apm.agent.test.tools.SegmentStoragePoint; +import org.apache.skywalking.apm.agent.test.tools.SpanAssert; +import org.apache.skywalking.apm.agent.test.tools.TracingSegmentRunner; +import org.hamcrest.MatcherAssert; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.powermock.modules.junit4.PowerMockRunner; +import org.powermock.modules.junit4.PowerMockRunnerDelegate; + +import static org.apache.skywalking.apm.network.trace.component.ComponentsDefine.KAFKA; +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +@RunWith(PowerMockRunner.class) +@PowerMockRunnerDelegate(TracingSegmentRunner.class) +public class KafkaConsumerInterceptorTest { + + @SegmentStoragePoint + private SegmentStorage segmentStorage; + + @Rule + public AgentServiceRule serviceRule = new AgentServiceRule(); + + private ConsumerEnhanceRequiredInfo consumerEnhanceRequiredInfo; + + private KafkaConsumerInterceptor consumerInterceptor; + + private EnhancedInstance consumerInstance = new EnhancedInstance() { + @Override public Object getSkyWalkingDynamicField() { + return consumerEnhanceRequiredInfo; + } + + @Override public void setSkyWalkingDynamicField(Object value) { + consumerEnhanceRequiredInfo = (ConsumerEnhanceRequiredInfo)value; + } + }; + + private Map> messages; + + @Before + public void setUp() { + consumerInterceptor = new KafkaConsumerInterceptor(); + consumerEnhanceRequiredInfo = new ConsumerEnhanceRequiredInfo(); + + List topics = new ArrayList(); + topics.add("test"); + topics.add("test-1"); + consumerEnhanceRequiredInfo.setTopics(topics); + List brokers = new ArrayList(); + brokers.add("localhost:9092"); + brokers.add("localhost:19092"); + consumerEnhanceRequiredInfo.setBrokerServers(brokers); + + messages = new HashMap>(); + TopicPartition topicPartition = new TopicPartition("test", 1); + List records = new ArrayList(); + ConsumerRecord consumerRecord = new ConsumerRecord("test", 1, 0, "1", "1"); + consumerRecord.headers().add("sw3", "1.234.111|3|1|1|#192.168.1.8:18002|#/portal/|#testEntrySpan|#AQA*#AQA*Et0We0tQNQA*".getBytes()); + records.add(consumerRecord); + messages.put(topicPartition, records); + } + + @Test + public void testConsumerWithoutMessage() throws Throwable { + consumerInterceptor.beforeMethod(consumerInstance, null, new Object[0], new Class[0], null); + consumerInterceptor.afterMethod(consumerInstance, null, new Object[0], new Class[0], new HashMap>()); + + List traceSegments = segmentStorage.getTraceSegments(); + assertThat(traceSegments.size(), is(0)); + } + + @Test + public void testConsumerWithMessage() throws Throwable { + consumerInterceptor.beforeMethod(consumerInstance, null, new Object[0], new Class[0], null); + consumerInterceptor.afterMethod(consumerInstance, null, new Object[0], new Class[0], messages); + + List traceSegments = segmentStorage.getTraceSegments(); + assertThat(traceSegments.size(), is(1)); + + TraceSegment traceSegment = traceSegments.get(0); + List refs = traceSegment.getRefs(); + assertThat(refs.size(), is(1)); + assertTraceSegmentRef(refs.get(0)); + + List spans = SegmentHelper.getSpans(traceSegment); + assertThat(spans.size(), is(1)); + assertConsumerSpan(spans.get(0)); + } + + private void assertConsumerSpan(AbstractTracingSpan span) { + SpanAssert.assertLayer(span, SpanLayer.MQ); + SpanAssert.assertComponent(span, KAFKA); + SpanAssert.assertTagSize(span, 2); + SpanAssert.assertTag(span, 0, "localhost:9092;localhost:19092"); + SpanAssert.assertTag(span, 1, "test;test-1"); + } + + private void assertTraceSegmentRef(TraceSegmentRef ref) { + MatcherAssert.assertThat(SegmentRefHelper.getEntryApplicationInstanceId(ref), is(1)); + MatcherAssert.assertThat(SegmentRefHelper.getSpanId(ref), is(3)); + MatcherAssert.assertThat(SegmentRefHelper.getTraceSegmentId(ref).toString(), is("1.234.111")); + } +} \ No newline at end of file diff --git a/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/kafka/v11/KafkaProducerInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/kafka/v11/KafkaProducerInterceptorTest.java new file mode 100644 index 000000000..3c7644112 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/kafka/v11/KafkaProducerInterceptorTest.java @@ -0,0 +1,115 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.skywalking.apm.plugin.kafka.v11; + +import java.util.List; +import org.apache.kafka.clients.producer.ProducerRecord; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan; +import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer; +import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.test.helper.SegmentHelper; +import org.apache.skywalking.apm.agent.test.tools.AgentServiceRule; +import org.apache.skywalking.apm.agent.test.tools.SegmentStorage; +import org.apache.skywalking.apm.agent.test.tools.SegmentStoragePoint; +import org.apache.skywalking.apm.agent.test.tools.SpanAssert; +import org.apache.skywalking.apm.agent.test.tools.TracingSegmentRunner; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.powermock.modules.junit4.PowerMockRunner; +import org.powermock.modules.junit4.PowerMockRunnerDelegate; + +import static org.apache.skywalking.apm.network.trace.component.ComponentsDefine.KAFKA; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; + +@RunWith(PowerMockRunner.class) +@PowerMockRunnerDelegate(TracingSegmentRunner.class) +public class KafkaProducerInterceptorTest { + @SegmentStoragePoint + private SegmentStorage segmentStorage; + + @Rule + public AgentServiceRule serviceRule = new AgentServiceRule(); + + private KafkaProducerInterceptor producerInterceptor; + + private Object[] arguments; + private Class[] argumentType; + + private EnhancedInstance kafkaProducerInstance = new EnhancedInstance() { + @Override public Object getSkyWalkingDynamicField() { + return "localhost:9092"; + } + + @Override public void setSkyWalkingDynamicField(Object value) { + + } + }; + + private EnhancedInstance messageInstance = new MockProducerMessage(); + + private class MockProducerMessage extends ProducerRecord implements EnhancedInstance { + + public MockProducerMessage() { + super("test", ""); + } + + @Override public Object getSkyWalkingDynamicField() { + return "test"; + } + + @Override public void setSkyWalkingDynamicField(Object value) { + + } + } + + @Before + public void setUp() { + producerInterceptor = new KafkaProducerInterceptor(); + + arguments = new Object[] {messageInstance, null}; + argumentType = new Class[] {ProducerRecord.class}; + } + + @Test + public void testSendMessage() throws Throwable { + producerInterceptor.beforeMethod(kafkaProducerInstance, null, arguments, argumentType, null); + producerInterceptor.afterMethod(kafkaProducerInstance, null, arguments, argumentType, null); + + List traceSegmentList = segmentStorage.getTraceSegments(); + assertThat(traceSegmentList.size(), is(1)); + + TraceSegment segment = traceSegmentList.get(0); + List spans = SegmentHelper.getSpans(segment); + assertThat(spans.size(), is(1)); + + assertMessageSpan(spans.get(0)); + } + + private void assertMessageSpan(AbstractTracingSpan span) { + SpanAssert.assertTag(span, 0, "localhost:9092"); + SpanAssert.assertTag(span, 1, "test"); + SpanAssert.assertComponent(span, KAFKA); + SpanAssert.assertLayer(span, SpanLayer.MQ); + assertThat(span.getOperationName(), is("Kafka/test/Producer")); + } +} \ No newline at end of file diff --git a/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/kafka/v11/ProducerConstructorInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/kafka/v11/ProducerConstructorInterceptorTest.java new file mode 100644 index 000000000..23f1a6ae3 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/kafka/v11/ProducerConstructorInterceptorTest.java @@ -0,0 +1,69 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.skywalking.apm.plugin.kafka.v11; + +import java.util.ArrayList; +import java.util.List; +import org.apache.kafka.clients.producer.ProducerConfig; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.core.Is.is; +import static org.mockito.Mockito.when; + +@RunWith(MockitoJUnitRunner.class) +public class ProducerConstructorInterceptorTest { + @Mock + private ProducerConfig producerConfig; + + @Mock + private ProducerConstructorInterceptor constructorInterceptor; + + private EnhancedInstance enhancedInstance = new EnhancedInstance() { + private String brokerServers; + + @Override public Object getSkyWalkingDynamicField() { + return brokerServers; + } + + @Override public void setSkyWalkingDynamicField(Object value) { + brokerServers = (String)value; + } + }; + + @Before + public void setUp() { + List mockBootstrapServers = new ArrayList(); + mockBootstrapServers.add("localhost:9092"); + mockBootstrapServers.add("localhost:19092"); + when(producerConfig.getList("bootstrap.servers")).thenReturn(mockBootstrapServers); + constructorInterceptor = new ProducerConstructorInterceptor(); + } + + @Test + public void testOnConsumer() { + constructorInterceptor.onConstruct(enhancedInstance, new Object[] {producerConfig}); + assertThat(enhancedInstance.getSkyWalkingDynamicField().toString(), is("localhost:9092;localhost:19092")); + } +} \ No newline at end of file diff --git a/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/kafka/v11/ProducerRecordConstructorInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/kafka/v11/ProducerRecordConstructorInterceptorTest.java new file mode 100644 index 000000000..568d3644b --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/kafka/v11/ProducerRecordConstructorInterceptorTest.java @@ -0,0 +1,59 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.skywalking.apm.plugin.kafka.v11; + +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.core.Is.is; + +@RunWith(MockitoJUnitRunner.class) +public class ProducerRecordConstructorInterceptorTest { + + @Mock + private ProducerRecordConstructorInterceptor constructorInterceptor; + + private EnhancedInstance enhancedInstance = new EnhancedInstance() { + private String brokerServers; + + @Override public Object getSkyWalkingDynamicField() { + return brokerServers; + } + + @Override public void setSkyWalkingDynamicField(Object value) { + brokerServers = (String)value; + } + }; + + @Before + public void setUp() { + constructorInterceptor = new ProducerRecordConstructorInterceptor(); + } + + @Test + public void testOnConsumer() { + constructorInterceptor.onConstruct(enhancedInstance, new Object[] {"test"}); + assertThat(enhancedInstance.getSkyWalkingDynamicField().toString(), is("test")); + } +} \ No newline at end of file diff --git a/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/kafka/v11/SubscribeMethodInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/kafka/v11/SubscribeMethodInterceptorTest.java new file mode 100644 index 000000000..b6d7190b7 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/kafka/v11/SubscribeMethodInterceptorTest.java @@ -0,0 +1,67 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.skywalking.apm.plugin.kafka.v11; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.core.Is.is; + +@RunWith(MockitoJUnitRunner.class) +public class SubscribeMethodInterceptorTest { + + @Mock + private SubscribeMethodInterceptor constructorInterceptor; + + private List mockTopics = new ArrayList(); + + private EnhancedInstance enhancedInstance = new EnhancedInstance() { + ConsumerEnhanceRequiredInfo consumerEnhanceRequiredInfo = new ConsumerEnhanceRequiredInfo(); + + @Override public Object getSkyWalkingDynamicField() { + return consumerEnhanceRequiredInfo; + } + + @Override public void setSkyWalkingDynamicField(Object value) { + this.consumerEnhanceRequiredInfo = (ConsumerEnhanceRequiredInfo)value; + } + }; + + @Before + public void setUp() { + mockTopics.add("test"); + mockTopics.add("test-1"); + constructorInterceptor = new SubscribeMethodInterceptor(); + } + + @Test + public void testOnConsumer() throws Throwable { + constructorInterceptor.beforeMethod(enhancedInstance, null, new Object[] {mockTopics}, new Class[] {Collection.class}, null); + ConsumerEnhanceRequiredInfo requiredInfo = (ConsumerEnhanceRequiredInfo)enhancedInstance.getSkyWalkingDynamicField(); + assertThat(requiredInfo.getTopics(), is("test;test-1")); + } +} \ No newline at end of file diff --git a/apm-sniffer/apm-test-tools/src/main/java/org/apache/skywalking/apm/agent/core/context/MockContextSnapshot.java b/apm-sniffer/apm-test-tools/src/main/java/org/apache/skywalking/apm/agent/core/context/MockContextSnapshot.java new file mode 100644 index 000000000..afc4f8a51 --- /dev/null +++ b/apm-sniffer/apm-test-tools/src/main/java/org/apache/skywalking/apm/agent/core/context/MockContextSnapshot.java @@ -0,0 +1,47 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.skywalking.apm.agent.core.context; + +import java.util.ArrayList; +import java.util.List; +import org.apache.skywalking.apm.agent.core.context.ids.DistributedTraceId; +import org.apache.skywalking.apm.agent.core.context.ids.ID; +import org.apache.skywalking.apm.agent.core.context.ids.NewDistributedTraceId; + +public enum MockContextSnapshot { + INSTANCE; + + private ContextSnapshot contextSnapshot; + + MockContextSnapshot() { + List distributedTraceIds = new ArrayList(); + distributedTraceIds.add(new NewDistributedTraceId()); + + contextSnapshot = new ContextSnapshot(new ID(1, 2, 3), 1, distributedTraceIds); + contextSnapshot.setEntryApplicationInstanceId(1); + contextSnapshot.setEntryOperationId(0); + contextSnapshot.setEntryOperationName("/for-test-entryOperationName"); + contextSnapshot.setParentOperationId(0); + contextSnapshot.setParentOperationName("/for-test-parentOperationName"); + } + + public ContextSnapshot mockContextSnapshot() { + return contextSnapshot; + } +} From f377c3350e971d21173db8dcd60cbc0ee527fa09 Mon Sep 17 00:00:00 2001 From: ascrutae Date: Thu, 25 Jan 2018 21:58:57 +0800 Subject: [PATCH 04/26] [Agent] support spring bean plugin --- apm-sniffer/apm-sdk-plugin/pom.xml | 7 ++- .../apm-sdk-plugin/spring-plugins/pom.xml | 1 + .../spring-annotation-plugin/README.md | 18 +++++++ .../spring-annotation-plugin/pom.xml | 44 +++++++++++++++ .../AbstractSpringBeanInstrumentation.java | 53 +++++++++++++++++++ .../SpringAnnotationInterceptor.java | 46 ++++++++++++++++ .../bean/SpringBeanInstrumentation.java | 34 ++++++++++++ .../SpringComponentInstrumentation.java | 31 +++++++++++ .../SpringRepositoryInstrumentation.java | 30 +++++++++++ .../SpringServicesInstrumentation.java | 31 +++++++++++ .../src/main/resources/skywalking-plugin.def | 4 ++ 11 files changed, 297 insertions(+), 2 deletions(-) create mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/spring-annotation-plugin/README.md create mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/spring-annotation-plugin/pom.xml create mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/spring-annotation-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/annotations/AbstractSpringBeanInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/spring-annotation-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/annotations/SpringAnnotationInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/spring-annotation-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/annotations/bean/SpringBeanInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/spring-annotation-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/annotations/component/SpringComponentInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/spring-annotation-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/annotations/repository/SpringRepositoryInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/spring-annotation-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/annotations/services/SpringServicesInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/spring-annotation-plugin/src/main/resources/skywalking-plugin.def diff --git a/apm-sniffer/apm-sdk-plugin/pom.xml b/apm-sniffer/apm-sdk-plugin/pom.xml index 4b81d1d8c..dba83ca90 100644 --- a/apm-sniffer/apm-sdk-plugin/pom.xml +++ b/apm-sniffer/apm-sdk-plugin/pom.xml @@ -64,6 +64,9 @@ net.bytebuddy ${shade.package}.${shade.net.bytebuddy.source} + + ${project.build.directory}${sdk.plugin.related.dir}/../../../../packages/skywalking-agent + ${agent.package.dest.dir}/plugins @@ -167,10 +170,10 @@ + dir="${plugin.dest.dir}"/> diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/pom.xml b/apm-sniffer/apm-sdk-plugin/spring-plugins/pom.xml index 0aa9d4512..71764b541 100644 --- a/apm-sniffer/apm-sdk-plugin/spring-plugins/pom.xml +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/pom.xml @@ -36,6 +36,7 @@ mvc-annotation-3.x-plugin core-patch mvc-annotation-commons + spring-annotation-plugin pom diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/spring-annotation-plugin/README.md b/apm-sniffer/apm-sdk-plugin/spring-plugins/spring-annotation-plugin/README.md new file mode 100644 index 000000000..6cf0c4c1f --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/spring-annotation-plugin/README.md @@ -0,0 +1,18 @@ +# Spring Annotation Plugin (Optional) + +Date: 2018/01/24 + +## Purpose +Because of multiple project are used + +Spring annotation plugin is an Optional plugin, the plugin +and if you want to active the plugin, you should move the plugin jar to the plugins folder. +The plugin will intercept all public method in the classs annotation with the following annotation. +1. `@Bean` +2. `@Service` +3. `@Componet` +4. `@Repository` + +## Purpose + + diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/spring-annotation-plugin/pom.xml b/apm-sniffer/apm-sdk-plugin/spring-plugins/spring-annotation-plugin/pom.xml new file mode 100644 index 000000000..df46249b9 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/spring-annotation-plugin/pom.xml @@ -0,0 +1,44 @@ + + + + + + spring-plugins + org.apache.skywalking + 5.0.0-alpha + + 4.0.0 + + apm-spring-annotation-plugin + + + ${agent.package.dest.dir}/optional-plugins + + + + + org.springframework + spring-context + 3.2.0.RELEASE + provided + + + \ No newline at end of file diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/spring-annotation-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/annotations/AbstractSpringBeanInstrumentation.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/spring-annotation-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/annotations/AbstractSpringBeanInstrumentation.java new file mode 100644 index 000000000..1bee08a51 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/spring-annotation-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/annotations/AbstractSpringBeanInstrumentation.java @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.skywalking.apm.plugin.spring.annotations; + +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; + +import static net.bytebuddy.matcher.ElementMatchers.isPublic; + +public abstract class AbstractSpringBeanInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { + private static final String INTERCEPTOR_CLASS = "org.apache.skywalking.apm.plugin.spring.annotations.SpringAnnotationInterceptor"; + + @Override protected final ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[0]; + } + + @Override protected final InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + new InstanceMethodsInterceptPoint() { + @Override public ElementMatcher getMethodsMatcher() { + return isPublic(); + } + + @Override public String getMethodsInterceptor() { + return INTERCEPTOR_CLASS; + } + + @Override public boolean isOverrideArgs() { + return false; + } + } + }; + } +} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/spring-annotation-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/annotations/SpringAnnotationInterceptor.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/spring-annotation-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/annotations/SpringAnnotationInterceptor.java new file mode 100644 index 000000000..ad66e1d21 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/spring-annotation-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/annotations/SpringAnnotationInterceptor.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.skywalking.apm.plugin.spring.annotations; + +import java.lang.reflect.Method; +import org.apache.skywalking.apm.agent.core.context.ContextManager; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; + +public class SpringAnnotationInterceptor implements InstanceMethodsAroundInterceptor { + @Override + public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + MethodInterceptResult result) throws Throwable { + String operationName = objInst.getClass().getName() + "." + method.getName(); + ContextManager.createLocalSpan(operationName); + } + + @Override + public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + Object ret) throws Throwable { + ContextManager.stopSpan(); + return ret; + } + + @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + ContextManager.activeSpan().errorOccurred().log(t); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/spring-annotation-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/annotations/bean/SpringBeanInstrumentation.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/spring-annotation-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/annotations/bean/SpringBeanInstrumentation.java new file mode 100644 index 000000000..366e3c55e --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/spring-annotation-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/annotations/bean/SpringBeanInstrumentation.java @@ -0,0 +1,34 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.skywalking.apm.plugin.spring.annotations.bean; + +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; +import org.apache.skywalking.apm.plugin.spring.annotations.AbstractSpringBeanInstrumentation; + +import static org.apache.skywalking.apm.agent.core.plugin.match.ClassAnnotationMatch.byClassAnnotationMatch; + +/** + * + */ +public class SpringBeanInstrumentation extends AbstractSpringBeanInstrumentation { + + @Override protected ClassMatch enhanceClass() { + return byClassAnnotationMatch(new String[] {"org.springframework.context.annotation.Bean"}); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/spring-annotation-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/annotations/component/SpringComponentInstrumentation.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/spring-annotation-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/annotations/component/SpringComponentInstrumentation.java new file mode 100644 index 000000000..e65a98d25 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/spring-annotation-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/annotations/component/SpringComponentInstrumentation.java @@ -0,0 +1,31 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.skywalking.apm.plugin.spring.annotations.component; + +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; +import org.apache.skywalking.apm.plugin.spring.annotations.AbstractSpringBeanInstrumentation; + +import static org.apache.skywalking.apm.agent.core.plugin.match.ClassAnnotationMatch.byClassAnnotationMatch; + +public class SpringComponentInstrumentation extends AbstractSpringBeanInstrumentation { + + @Override protected ClassMatch enhanceClass() { + return byClassAnnotationMatch(new String[] {"org.springframework.stereotype.Component"}); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/spring-annotation-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/annotations/repository/SpringRepositoryInstrumentation.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/spring-annotation-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/annotations/repository/SpringRepositoryInstrumentation.java new file mode 100644 index 000000000..c97c32656 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/spring-annotation-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/annotations/repository/SpringRepositoryInstrumentation.java @@ -0,0 +1,30 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.skywalking.apm.plugin.spring.annotations.repository; + +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; +import org.apache.skywalking.apm.plugin.spring.annotations.AbstractSpringBeanInstrumentation; + +import static org.apache.skywalking.apm.agent.core.plugin.match.ClassAnnotationMatch.byClassAnnotationMatch; + +public class SpringRepositoryInstrumentation extends AbstractSpringBeanInstrumentation { + @Override protected ClassMatch enhanceClass() { + return byClassAnnotationMatch(new String[] {"org.springframework.stereotype.Repository"}); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/spring-annotation-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/annotations/services/SpringServicesInstrumentation.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/spring-annotation-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/annotations/services/SpringServicesInstrumentation.java new file mode 100644 index 000000000..b38bfcb50 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/spring-annotation-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/annotations/services/SpringServicesInstrumentation.java @@ -0,0 +1,31 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.skywalking.apm.plugin.spring.annotations.services; + +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; +import org.apache.skywalking.apm.plugin.spring.annotations.AbstractSpringBeanInstrumentation; + +import static org.apache.skywalking.apm.agent.core.plugin.match.ClassAnnotationMatch.byClassAnnotationMatch; + +public class SpringServicesInstrumentation extends AbstractSpringBeanInstrumentation { + + @Override protected ClassMatch enhanceClass() { + return byClassAnnotationMatch(new String[] {"org.springframework.stereotype.Service"}); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/spring-annotation-plugin/src/main/resources/skywalking-plugin.def b/apm-sniffer/apm-sdk-plugin/spring-plugins/spring-annotation-plugin/src/main/resources/skywalking-plugin.def new file mode 100644 index 000000000..e69e32aa2 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/spring-annotation-plugin/src/main/resources/skywalking-plugin.def @@ -0,0 +1,4 @@ +spring-annotation=org.apache.skywalking.apm.plugin.spring.annotations.bean.SpringBeanInstrumentation +spring-annotation=org.apache.skywalking.apm.plugin.spring.annotations.component.SpringComponentInstrumentation +spring-annotation=org.apache.skywalking.apm.plugin.spring.annotations.repository.SpringRepositoryInstrumentation +spring-annotation=org.apache.skywalking.apm.plugin.spring.annotations.services.SpringServicesInstrumentation From 44e966526219bf88f8f4176b7cc9061e1adf252b Mon Sep 17 00:00:00 2001 From: ascrutae Date: Fri, 26 Jan 2018 18:55:19 +0800 Subject: [PATCH 05/26] [Agent] modify the method matcher of spring bean --- .../spring-annotation-plugin/README.md | 18 ------------------ .../AbstractSpringBeanInstrumentation.java | 5 ++++- 2 files changed, 4 insertions(+), 19 deletions(-) delete mode 100644 apm-sniffer/apm-sdk-plugin/spring-plugins/spring-annotation-plugin/README.md diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/spring-annotation-plugin/README.md b/apm-sniffer/apm-sdk-plugin/spring-plugins/spring-annotation-plugin/README.md deleted file mode 100644 index 6cf0c4c1f..000000000 --- a/apm-sniffer/apm-sdk-plugin/spring-plugins/spring-annotation-plugin/README.md +++ /dev/null @@ -1,18 +0,0 @@ -# Spring Annotation Plugin (Optional) - -Date: 2018/01/24 - -## Purpose -Because of multiple project are used - -Spring annotation plugin is an Optional plugin, the plugin -and if you want to active the plugin, you should move the plugin jar to the plugins folder. -The plugin will intercept all public method in the classs annotation with the following annotation. -1. `@Bean` -2. `@Service` -3. `@Componet` -4. `@Repository` - -## Purpose - - diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/spring-annotation-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/annotations/AbstractSpringBeanInstrumentation.java b/apm-sniffer/apm-sdk-plugin/spring-plugins/spring-annotation-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/annotations/AbstractSpringBeanInstrumentation.java index 1bee08a51..fd769f8fd 100644 --- a/apm-sniffer/apm-sdk-plugin/spring-plugins/spring-annotation-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/annotations/AbstractSpringBeanInstrumentation.java +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/spring-annotation-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/annotations/AbstractSpringBeanInstrumentation.java @@ -24,7 +24,10 @@ import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterc import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; +import static net.bytebuddy.matcher.ElementMatchers.isDeclaredBy; import static net.bytebuddy.matcher.ElementMatchers.isPublic; +import static net.bytebuddy.matcher.ElementMatchers.named; +import static net.bytebuddy.matcher.ElementMatchers.not; public abstract class AbstractSpringBeanInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { private static final String INTERCEPTOR_CLASS = "org.apache.skywalking.apm.plugin.spring.annotations.SpringAnnotationInterceptor"; @@ -37,7 +40,7 @@ public abstract class AbstractSpringBeanInstrumentation extends ClassInstanceMet return new InstanceMethodsInterceptPoint[] { new InstanceMethodsInterceptPoint() { @Override public ElementMatcher getMethodsMatcher() { - return isPublic(); + return isPublic().and(not(isDeclaredBy(Object.class)).and(not(named("getSkyWalkingDynamicField"))).and(not(named("setSkyWalkingDynamicField")))); } @Override public String getMethodsInterceptor() { From c300e85d9cff885782eb05eabd7b74278f49649f Mon Sep 17 00:00:00 2001 From: ascrutae Date: Sat, 27 Jan 2018 12:05:01 +0800 Subject: [PATCH 06/26] Change the file structure of spring bean plugin --- .../apm-sdk-plugin/spring-plugins/pom.xml | 1 - .../optional-spring-plugins/pom.xml | 40 ++++++ .../spring-annotation-plugin/pom.xml | 7 +- .../AbstractSpringBeanInstrumentation.java | 0 .../SpringAnnotationInterceptor.java | 0 .../bean/SpringBeanInstrumentation.java | 0 .../SpringComponentInstrumentation.java | 0 .../SpringRepositoryInstrumentation.java | 0 .../SpringServicesInstrumentation.java | 0 .../src/main/resources/skywalking-plugin.def | 0 apm-sniffer/optional-plugins/pom.xml | 114 ++++++++++++++++++ apm-sniffer/pom.xml | 1 + 12 files changed, 157 insertions(+), 6 deletions(-) create mode 100644 apm-sniffer/optional-plugins/optional-spring-plugins/pom.xml rename apm-sniffer/{apm-sdk-plugin/spring-plugins => optional-plugins/optional-spring-plugins}/spring-annotation-plugin/pom.xml (89%) rename apm-sniffer/{apm-sdk-plugin/spring-plugins => optional-plugins/optional-spring-plugins}/spring-annotation-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/annotations/AbstractSpringBeanInstrumentation.java (100%) rename apm-sniffer/{apm-sdk-plugin/spring-plugins => optional-plugins/optional-spring-plugins}/spring-annotation-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/annotations/SpringAnnotationInterceptor.java (100%) rename apm-sniffer/{apm-sdk-plugin/spring-plugins => optional-plugins/optional-spring-plugins}/spring-annotation-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/annotations/bean/SpringBeanInstrumentation.java (100%) rename apm-sniffer/{apm-sdk-plugin/spring-plugins => optional-plugins/optional-spring-plugins}/spring-annotation-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/annotations/component/SpringComponentInstrumentation.java (100%) rename apm-sniffer/{apm-sdk-plugin/spring-plugins => optional-plugins/optional-spring-plugins}/spring-annotation-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/annotations/repository/SpringRepositoryInstrumentation.java (100%) rename apm-sniffer/{apm-sdk-plugin/spring-plugins => optional-plugins/optional-spring-plugins}/spring-annotation-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/annotations/services/SpringServicesInstrumentation.java (100%) rename apm-sniffer/{apm-sdk-plugin/spring-plugins => optional-plugins/optional-spring-plugins}/spring-annotation-plugin/src/main/resources/skywalking-plugin.def (100%) create mode 100644 apm-sniffer/optional-plugins/pom.xml diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/pom.xml b/apm-sniffer/apm-sdk-plugin/spring-plugins/pom.xml index 71764b541..0aa9d4512 100644 --- a/apm-sniffer/apm-sdk-plugin/spring-plugins/pom.xml +++ b/apm-sniffer/apm-sdk-plugin/spring-plugins/pom.xml @@ -36,7 +36,6 @@ mvc-annotation-3.x-plugin core-patch mvc-annotation-commons - spring-annotation-plugin pom diff --git a/apm-sniffer/optional-plugins/optional-spring-plugins/pom.xml b/apm-sniffer/optional-plugins/optional-spring-plugins/pom.xml new file mode 100644 index 000000000..e3b38f27c --- /dev/null +++ b/apm-sniffer/optional-plugins/optional-spring-plugins/pom.xml @@ -0,0 +1,40 @@ + + + + + + optional-plugins + org.apache.skywalking + 5.0.0-alpha + + 4.0.0 + pom + + optional-spring-plugins + + ${project.build.directory}/../../../../../packages/skywalking-agent/optional-plugins + + + + spring-annotation-plugin + + + \ No newline at end of file diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/spring-annotation-plugin/pom.xml b/apm-sniffer/optional-plugins/optional-spring-plugins/spring-annotation-plugin/pom.xml similarity index 89% rename from apm-sniffer/apm-sdk-plugin/spring-plugins/spring-annotation-plugin/pom.xml rename to apm-sniffer/optional-plugins/optional-spring-plugins/spring-annotation-plugin/pom.xml index df46249b9..03413fc0b 100644 --- a/apm-sniffer/apm-sdk-plugin/spring-plugins/spring-annotation-plugin/pom.xml +++ b/apm-sniffer/optional-plugins/optional-spring-plugins/spring-annotation-plugin/pom.xml @@ -21,18 +21,15 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - spring-plugins + optional-spring-plugins org.apache.skywalking 5.0.0-alpha 4.0.0 + jar apm-spring-annotation-plugin - - ${agent.package.dest.dir}/optional-plugins - - org.springframework diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/spring-annotation-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/annotations/AbstractSpringBeanInstrumentation.java b/apm-sniffer/optional-plugins/optional-spring-plugins/spring-annotation-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/annotations/AbstractSpringBeanInstrumentation.java similarity index 100% rename from apm-sniffer/apm-sdk-plugin/spring-plugins/spring-annotation-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/annotations/AbstractSpringBeanInstrumentation.java rename to apm-sniffer/optional-plugins/optional-spring-plugins/spring-annotation-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/annotations/AbstractSpringBeanInstrumentation.java diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/spring-annotation-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/annotations/SpringAnnotationInterceptor.java b/apm-sniffer/optional-plugins/optional-spring-plugins/spring-annotation-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/annotations/SpringAnnotationInterceptor.java similarity index 100% rename from apm-sniffer/apm-sdk-plugin/spring-plugins/spring-annotation-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/annotations/SpringAnnotationInterceptor.java rename to apm-sniffer/optional-plugins/optional-spring-plugins/spring-annotation-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/annotations/SpringAnnotationInterceptor.java diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/spring-annotation-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/annotations/bean/SpringBeanInstrumentation.java b/apm-sniffer/optional-plugins/optional-spring-plugins/spring-annotation-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/annotations/bean/SpringBeanInstrumentation.java similarity index 100% rename from apm-sniffer/apm-sdk-plugin/spring-plugins/spring-annotation-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/annotations/bean/SpringBeanInstrumentation.java rename to apm-sniffer/optional-plugins/optional-spring-plugins/spring-annotation-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/annotations/bean/SpringBeanInstrumentation.java diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/spring-annotation-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/annotations/component/SpringComponentInstrumentation.java b/apm-sniffer/optional-plugins/optional-spring-plugins/spring-annotation-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/annotations/component/SpringComponentInstrumentation.java similarity index 100% rename from apm-sniffer/apm-sdk-plugin/spring-plugins/spring-annotation-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/annotations/component/SpringComponentInstrumentation.java rename to apm-sniffer/optional-plugins/optional-spring-plugins/spring-annotation-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/annotations/component/SpringComponentInstrumentation.java diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/spring-annotation-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/annotations/repository/SpringRepositoryInstrumentation.java b/apm-sniffer/optional-plugins/optional-spring-plugins/spring-annotation-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/annotations/repository/SpringRepositoryInstrumentation.java similarity index 100% rename from apm-sniffer/apm-sdk-plugin/spring-plugins/spring-annotation-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/annotations/repository/SpringRepositoryInstrumentation.java rename to apm-sniffer/optional-plugins/optional-spring-plugins/spring-annotation-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/annotations/repository/SpringRepositoryInstrumentation.java diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/spring-annotation-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/annotations/services/SpringServicesInstrumentation.java b/apm-sniffer/optional-plugins/optional-spring-plugins/spring-annotation-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/annotations/services/SpringServicesInstrumentation.java similarity index 100% rename from apm-sniffer/apm-sdk-plugin/spring-plugins/spring-annotation-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/annotations/services/SpringServicesInstrumentation.java rename to apm-sniffer/optional-plugins/optional-spring-plugins/spring-annotation-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/annotations/services/SpringServicesInstrumentation.java diff --git a/apm-sniffer/apm-sdk-plugin/spring-plugins/spring-annotation-plugin/src/main/resources/skywalking-plugin.def b/apm-sniffer/optional-plugins/optional-spring-plugins/spring-annotation-plugin/src/main/resources/skywalking-plugin.def similarity index 100% rename from apm-sniffer/apm-sdk-plugin/spring-plugins/spring-annotation-plugin/src/main/resources/skywalking-plugin.def rename to apm-sniffer/optional-plugins/optional-spring-plugins/spring-annotation-plugin/src/main/resources/skywalking-plugin.def diff --git a/apm-sniffer/optional-plugins/pom.xml b/apm-sniffer/optional-plugins/pom.xml new file mode 100644 index 000000000..07061b9d6 --- /dev/null +++ b/apm-sniffer/optional-plugins/pom.xml @@ -0,0 +1,114 @@ + + + + + + apm-sniffer + org.apache.skywalking + 5.0.0-alpha + + 4.0.0 + + optional-plugins + pom + + ${project.build.directory}/../../../../packages/skywalking-agent/optional-plugins + + + + optional-spring-plugins + + + + + org.apache.skywalking + apm-agent-core + ${project.version} + provided + + + org.apache.skywalking + apm-util + ${project.version} + provided + + + org.apache.skywalking + apm-test-tools + ${project.version} + test + + + + + + + org.apache.maven.plugins + maven-antrun-plugin + + + package + + run + + + + + + + + + + + + + + + + + + + ant-contrib + ant-contrib + 1.0b3 + + + ant + ant + + + + + org.apache.ant + ant-nodeps + 1.8.1 + + + + + + + \ No newline at end of file diff --git a/apm-sniffer/pom.xml b/apm-sniffer/pom.xml index 509de67ce..c5a7607c0 100644 --- a/apm-sniffer/pom.xml +++ b/apm-sniffer/pom.xml @@ -36,6 +36,7 @@ apm-sdk-plugin apm-toolkit-activation apm-test-tools + optional-plugins From 14a61d75fdcc8918b7f154dab5b75db081c510c4 Mon Sep 17 00:00:00 2001 From: ascrutae Date: Tue, 23 Jan 2018 20:13:12 +0800 Subject: [PATCH 07/26] remove readme.md --- .../kafka-0.11.x-plugin/README.md | 5 ----- .../kafka/v11/KafkaConsumerInterceptor.java | 2 +- .../kafka/v11/KafkaProducerInterceptor.java | 2 -- .../v11/ProducerConstructorInterceptor.java | 1 - .../ProducerRecordConstructorInterceptor.java | 1 - .../v11/define/CallbackInstrumentation.java | 3 ++- .../define/KafkaConsumerInstrumentation.java | 21 ++++++++++--------- .../define/KafkaProducerInstrumentation.java | 13 ++++++------ .../define/ProducerRecordInstrumentation.java | 5 +++-- 9 files changed, 23 insertions(+), 30 deletions(-) delete mode 100644 apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/README.md diff --git a/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/README.md b/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/README.md deleted file mode 100644 index bcc6c3b46..000000000 --- a/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/README.md +++ /dev/null @@ -1,5 +0,0 @@ -# Kafka Plugin - -## -## Buired Point - diff --git a/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/KafkaConsumerInterceptor.java b/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/KafkaConsumerInterceptor.java index f0098e43d..b7bf23b53 100644 --- a/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/KafkaConsumerInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/KafkaConsumerInterceptor.java @@ -56,7 +56,7 @@ public class KafkaConsumerInterceptor implements InstanceMethodsAroundIntercepto Object ret) throws Throwable { Map>> records = (Map>>)ret; // - // The entry span will create when the consumer fetch anyone message from kafka cluster, or the span will not create. + // The entry span will only be created when the consumer received at least one message. // if (records.size() > 0) { ConsumerEnhanceRequiredInfo requiredInfo = (ConsumerEnhanceRequiredInfo)objInst.getSkyWalkingDynamicField(); diff --git a/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/KafkaProducerInterceptor.java b/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/KafkaProducerInterceptor.java index 19d883b70..2e32d4f08 100644 --- a/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/KafkaProducerInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/KafkaProducerInterceptor.java @@ -50,13 +50,11 @@ public class KafkaProducerInterceptor implements InstanceMethodsAroundIntercepto AbstractSpan activeSpan = ContextManager.createExitSpan(OPERATE_NAME_PREFIX + topicName + PRODUCER_OPERATE_NAME_SUFFIX, contextCarrier, (String)objInst.getSkyWalkingDynamicField()); - //set tags Tags.MQ_BROKER.set(activeSpan, (String)objInst.getSkyWalkingDynamicField()); Tags.MQ_TOPIC.set(activeSpan, topicName); SpanLayer.asMQ(activeSpan); activeSpan.setComponent(ComponentsDefine.KAFKA); - // set headers CarrierItem next = contextCarrier.items(); while (next.hasNext()) { next = next.next(); diff --git a/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/ProducerConstructorInterceptor.java b/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/ProducerConstructorInterceptor.java index 9849d48ff..9dbeba457 100644 --- a/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/ProducerConstructorInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/ProducerConstructorInterceptor.java @@ -27,7 +27,6 @@ public class ProducerConstructorInterceptor implements InstanceConstructorInterc @Override public void onConstruct(EnhancedInstance objInst, Object[] allArguments) { ProducerConfig config = (ProducerConfig)allArguments[0]; - // set the bootstrap server address objInst.setSkyWalkingDynamicField(StringUtil.join(';', config.getList("bootstrap.servers").toArray(new String[0]))); } } diff --git a/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/ProducerRecordConstructorInterceptor.java b/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/ProducerRecordConstructorInterceptor.java index 0cb723a43..8a7fbac87 100644 --- a/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/ProducerRecordConstructorInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/ProducerRecordConstructorInterceptor.java @@ -24,7 +24,6 @@ import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceC public class ProducerRecordConstructorInterceptor implements InstanceConstructorInterceptor { @Override public void onConstruct(EnhancedInstance objInst, Object[] allArguments) { String topic = (String)allArguments[0]; - // set the topic objInst.setSkyWalkingDynamicField(topic); } } diff --git a/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/define/CallbackInstrumentation.java b/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/define/CallbackInstrumentation.java index 715166888..f3f22e44a 100644 --- a/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/define/CallbackInstrumentation.java +++ b/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/define/CallbackInstrumentation.java @@ -29,7 +29,8 @@ import static net.bytebuddy.matcher.ElementMatchers.named; import static org.apache.skywalking.apm.agent.core.plugin.match.HierarchyMatch.byHierarchyMatch; /** - * {@link CallbackInstrumentation} intercept the method onCompletion in the class org.apache.kafka.clients.producer.Callback. + * {@link CallbackInstrumentation} defined that {@link org.apache.skywalking.apm.plugin.kafka.v11.CallbackInterceptor} + * intercept the method onCompletion in the class org.apache.kafka.clients.producer.Callback. * * @author zhangxin */ diff --git a/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/define/KafkaConsumerInstrumentation.java b/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/define/KafkaConsumerInstrumentation.java index 81b9bbe87..f14befb7f 100644 --- a/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/define/KafkaConsumerInstrumentation.java +++ b/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/define/KafkaConsumerInstrumentation.java @@ -30,34 +30,35 @@ import static org.apache.skywalking.apm.agent.core.plugin.bytebuddy.ArgumentType import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName; /** - * {@link KafkaProducerInstrumentation} intercept the method send in the class - * org.apache.kafka.clients.producer.KafkaProducer. Here is the intercept process steps. + * {@link KafkaProducerInstrumentation} define that {@link org.apache.skywalking.apm.plugin.kafka.v11.KafkaConsumerInterceptor} + * intercept the method send in the class org.apache.kafka.clients.producer.KafkaProducer. + * Here is the intercept process steps. * * *
- *  1. Record the topic when the client call subscribed
- *  3. Create the entry span when the client call the method pollOnce.
- *  4. Inject all the Trace Context by iterate all ConsumerRecord
- *  5. Stop the entry span when end the pollOnce method.
+ *  1. Record the topic when the client invoke subscribed method
+ *  2. Create the entry span when the client invoke the method pollOnce.
+ *  3. Extract all the Trace Context by iterate all ConsumerRecord
+ *  4. Stop the entry span when pollOnce method finished.
  * 
* * @author zhang xin */ public class KafkaConsumerInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { - public static final String CONSTRUCTOR_INTERCEPT_FLAG = "org.apache.kafka.clients.consumer.ConsumerConfig"; + public static final String CONSTRUCTOR_INTERCEPT_TYPE = "org.apache.kafka.clients.consumer.ConsumerConfig"; public static final String CONSTRUCTOR_INTERCEPTOR_CLASS = "org.apache.skywalking.apm.plugin.kafka.v11.ConsumerConstructorInterceptor"; public static final String INTERCEPTOR_CLASS = "org.apache.skywalking.apm.plugin.kafka.v11.KafkaConsumerInterceptor"; public static final String ENHANCE_METHOD = "pollOnce"; public static final String ENHANCE_CLASS = "org.apache.kafka.clients.consumer.KafkaConsumer"; public static final String SUBSCRIBE_METHOD = "subscribe"; - public static final String SUBSCRIBE_INTERCEPT_FLAG = "org.apache.kafka.clients.consumer.ConsumerRebalanceListener"; + public static final String SUBSCRIBE_INTERCEPT_TYPE = "org.apache.kafka.clients.consumer.ConsumerRebalanceListener"; @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { return new ConstructorInterceptPoint[] { new ConstructorInterceptPoint() { @Override public ElementMatcher getConstructorMatcher() { - return takesArgumentWithType(0, CONSTRUCTOR_INTERCEPT_FLAG); + return takesArgumentWithType(0, CONSTRUCTOR_INTERCEPT_TYPE); } @Override public String getConstructorInterceptor() { @@ -84,7 +85,7 @@ public class KafkaConsumerInstrumentation extends ClassInstanceMethodsEnhancePlu }, new InstanceMethodsInterceptPoint() { @Override public ElementMatcher getMethodsMatcher() { - return named(SUBSCRIBE_METHOD).and(takesArgumentWithType(1, SUBSCRIBE_INTERCEPT_FLAG)); + return named(SUBSCRIBE_METHOD).and(takesArgumentWithType(1, SUBSCRIBE_INTERCEPT_TYPE)); } @Override public String getMethodsInterceptor() { diff --git a/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/define/KafkaProducerInstrumentation.java b/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/define/KafkaProducerInstrumentation.java index cd3ff6041..1cca62467 100644 --- a/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/define/KafkaProducerInstrumentation.java +++ b/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/define/KafkaProducerInstrumentation.java @@ -30,18 +30,17 @@ import static org.apache.skywalking.apm.agent.core.plugin.bytebuddy.ArgumentType import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName; /** - * {@link KafkaProducerInstrumentation} intercept the method send in the class - * org.apache.kafka.clients.producer.KafkaProducer. Here is the intercept process steps. + * {@link KafkaProducerInstrumentation} define that {@link org.apache.skywalking.apm.plugin.kafka.v11.KafkaProducerInterceptor} + * intercept the method send in the class org.apache.kafka.clients.producer.KafkaProducer. + * Here is the intercept process steps. * * *
  *  1. Record the broker address when the client create the org.apache.kafka.clients.producer.KafkaProducer
  * instance
- *  2. Fetch the topic name from org.apache.kafka.clients.producer.ProducerRecord when the client call
- * send method.
- *  3. Create the exit span when the client call send method
- *  4. Set the Context into the org.apache.kafka.clients.producer.ProducerRecord#headers
- *  5. Stop the exit span when end the send method.
+ *  2. Create the exit span when the client invoke send method
+ *  3. Inject the context to {@link org.apache.kafka.clients.producer.ProducerRecord#headers}
+ *  3. Stop the exit span when send method finished.
  * 
* * @author zhang xin diff --git a/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/define/ProducerRecordInstrumentation.java b/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/define/ProducerRecordInstrumentation.java index abcee1a0a..cb0a052b9 100644 --- a/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/define/ProducerRecordInstrumentation.java +++ b/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/define/ProducerRecordInstrumentation.java @@ -29,8 +29,9 @@ import static net.bytebuddy.matcher.ElementMatchers.takesArguments; import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName; /** - * {@link ProducerRecordInstrumentation} intercept the constructor in the class org.apache.kafka.clients.producer.ProducerRecord - * for record the topic name and propagate the Context of trace. + * {@link ProducerRecordInstrumentation} define that {@link org.apache.skywalking.apm.plugin.kafka.v11.ProducerRecordConstructorInterceptor} + * intercept the constructor in the class org.apache.kafka.clients.producer.ProducerRecord for record the + * topic name and propagate the Context of trace. * * @author zhang xin * @see org.apache.skywalking.apm.plugin.kafka.v11.define.KafkaProducerInstrumentation From dbf010485a0bb521630006e95faac7aff091d4a1 Mon Sep 17 00:00:00 2001 From: ascrutae Date: Sun, 28 Jan 2018 01:07:53 +0800 Subject: [PATCH 08/26] Add kafka plugin docs --- docs/Supported-list.md | 4 +++- docs/cn/FAQ/Kafka-plugin-CN.md | 7 +++++++ docs/en/FAQ/kafka-plugin.md | 8 ++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 docs/cn/FAQ/Kafka-plugin-CN.md create mode 100644 docs/en/FAQ/kafka-plugin.md diff --git a/docs/Supported-list.md b/docs/Supported-list.md index ea49a3aa1..4b918a23a 100644 --- a/docs/Supported-list.md +++ b/docs/Supported-list.md @@ -30,6 +30,7 @@ * [gRPC](https://github.com/grpc/grpc-java) 1.6+ * MQ * [RocketMQ](https://github.com/apache/rocketmq) 4.x + * [Kafka](http://kafka.apache.org) 0.11.0.0 -> 1.0 (Optional²) * NoSQL * Redis * [Jedis](https://github.com/xetorthio/jedis) 2.x @@ -47,4 +48,5 @@ * Motan * Hprose-java -¹Required dependencies for these components must be first manually downloaded before being built, due to license incompatibilities. For this reason these components are not by default included in the SkyWalking releases. \ No newline at end of file +¹Required dependencies for these components must be first manually downloaded before being built, due to license incompatibilities. For this reason these components are not by default included in the SkyWalking releases. +²These plugin would probably affect the performance because of enhancing class. Or some of them are in beta, If the above plugins are put under the plugins folder, it will cause the user experience not so good, For this reason these plugins is not load by default. \ No newline at end of file diff --git a/docs/cn/FAQ/Kafka-plugin-CN.md b/docs/cn/FAQ/Kafka-plugin-CN.md new file mode 100644 index 000000000..1f9e4c681 --- /dev/null +++ b/docs/cn/FAQ/Kafka-plugin-CN.md @@ -0,0 +1,7 @@ +**现象** +Kafka插件无法追踪应用是怎么处理消息 + +**原因**:Kafka消费端主动从Kafka Cluster获取消息,并且探针无法得知 +消费线程是否被监控. + +**解决方法**: 需要手动探针才能解决,获取消息和处理消息的方法追加@Trace,详情见[文档](https://github.com/apache/incubator-skywalking/blob/master/docs/en/Application-toolkit-trace.md) diff --git a/docs/en/FAQ/kafka-plugin.md b/docs/en/FAQ/kafka-plugin.md new file mode 100644 index 000000000..31db6423c --- /dev/null +++ b/docs/en/FAQ/kafka-plugin.md @@ -0,0 +1,8 @@ +**Problem**:
+The Kafka plug-in can't track how applications handle messages + +**Reason**: +The Kafka consumer actively takes a message from Kafka Cluster and the agent can not see if the consuming thread is being monitored. + +**Resolve**: +Add the `@Trace` annotation to the method of handle message and the method of poll message , see the [document](https://github.com/apache/incubator-skywalking/blob/master/docs/en/Application-toolkit-trace.md) \ No newline at end of file From c1d2afbc1ee819363abc2991236ac92f29f58677 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B4=E6=99=9F=20Wu=20Sheng?= Date: Sun, 28 Jan 2018 14:11:57 +0800 Subject: [PATCH 09/26] Update Supported-list.md Correct the English. --- docs/Supported-list.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/Supported-list.md b/docs/Supported-list.md index 4b918a23a..a327444ac 100644 --- a/docs/Supported-list.md +++ b/docs/Supported-list.md @@ -49,4 +49,4 @@ * Hprose-java ¹Required dependencies for these components must be first manually downloaded before being built, due to license incompatibilities. For this reason these components are not by default included in the SkyWalking releases. -²These plugin would probably affect the performance because of enhancing class. Or some of them are in beta, If the above plugins are put under the plugins folder, it will cause the user experience not so good, For this reason these plugins is not load by default. \ No newline at end of file +²These plugins affect the performance or must be used under some conditions, from experiences. So only released in `/optional-plugins`, copy to `/plugins` in order to make them work. From 1a21409c8970ad2070f41997b991438e0d810953 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B4=E6=99=9F=20Wu=20Sheng?= Date: Sun, 28 Jan 2018 14:15:49 +0800 Subject: [PATCH 10/26] Update Kafka-plugin-CN.md Make zh description more clear. --- docs/cn/FAQ/Kafka-plugin-CN.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/cn/FAQ/Kafka-plugin-CN.md b/docs/cn/FAQ/Kafka-plugin-CN.md index 1f9e4c681..02d15a9a6 100644 --- a/docs/cn/FAQ/Kafka-plugin-CN.md +++ b/docs/cn/FAQ/Kafka-plugin-CN.md @@ -1,7 +1,7 @@ -**现象** -Kafka插件无法追踪应用是怎么处理消息 +**现象** : +Kafka消息消费端链路断裂 -**原因**:Kafka消费端主动从Kafka Cluster获取消息,并且探针无法得知 -消费线程是否被监控. +**原因**: +Kafka探针只是追踪了对Kafka的拉取动作,而整个后续处理过程不是由kafka consumer发起。故,需要在消费处理的发起点,进行手动埋点。 -**解决方法**: 需要手动探针才能解决,获取消息和处理消息的方法追加@Trace,详情见[文档](https://github.com/apache/incubator-skywalking/blob/master/docs/en/Application-toolkit-trace.md) +**解决方法**: 可以通过Application Toolkit中的@Trace标注,或者OpenTracing API进行手动埋点。 From 73fd9c75e82ea9d7de250b281e5901e0c6f561c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B4=E6=99=9F=20Wu=20Sheng?= Date: Sun, 28 Jan 2018 14:19:28 +0800 Subject: [PATCH 11/26] Update kafka-plugin.md Clear the English description about how to trace kafka consumer. --- docs/en/FAQ/kafka-plugin.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/en/FAQ/kafka-plugin.md b/docs/en/FAQ/kafka-plugin.md index 31db6423c..7fea78807 100644 --- a/docs/en/FAQ/kafka-plugin.md +++ b/docs/en/FAQ/kafka-plugin.md @@ -1,8 +1,8 @@ -**Problem**:
-The Kafka plug-in can't track how applications handle messages +**Problem**: +The trace doesn't continue in kafka consumer side. **Reason**: -The Kafka consumer actively takes a message from Kafka Cluster and the agent can not see if the consuming thread is being monitored. +The kafka client is pulling message from server, the plugin also just traces the pull action. As that, you need to do the manual instrument before the pull action, and include the further data process. **Resolve**: -Add the `@Trace` annotation to the method of handle message and the method of poll message , see the [document](https://github.com/apache/incubator-skywalking/blob/master/docs/en/Application-toolkit-trace.md) \ No newline at end of file +Use Application Toolkit libraries to do manual instrumentation. such as `@Trace` annotaion or OpenTracing API. From a5e37108afc2ad8cfcf5fd79ac2f38ca070891d6 Mon Sep 17 00:00:00 2001 From: ascrutae Date: Sun, 28 Jan 2018 14:48:56 +0800 Subject: [PATCH 12/26] refactory code --- .../annotations/AbstractSpringBeanInstrumentation.java | 4 +++- .../spring/annotations/bean/SpringBeanInstrumentation.java | 4 +++- .../component/SpringComponentInstrumentation.java | 4 +++- .../repository/SpringRepositoryInstrumentation.java | 5 ++++- .../annotations/services/SpringServicesInstrumentation.java | 4 +++- 5 files changed, 16 insertions(+), 5 deletions(-) diff --git a/apm-sniffer/optional-plugins/optional-spring-plugins/spring-annotation-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/annotations/AbstractSpringBeanInstrumentation.java b/apm-sniffer/optional-plugins/optional-spring-plugins/spring-annotation-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/annotations/AbstractSpringBeanInstrumentation.java index fd769f8fd..961eab6cb 100644 --- a/apm-sniffer/optional-plugins/optional-spring-plugins/spring-annotation-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/annotations/AbstractSpringBeanInstrumentation.java +++ b/apm-sniffer/optional-plugins/optional-spring-plugins/spring-annotation-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/annotations/AbstractSpringBeanInstrumentation.java @@ -31,6 +31,8 @@ import static net.bytebuddy.matcher.ElementMatchers.not; public abstract class AbstractSpringBeanInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { private static final String INTERCEPTOR_CLASS = "org.apache.skywalking.apm.plugin.spring.annotations.SpringAnnotationInterceptor"; + public static final String INTERCEPT_GET_SKYWALKING_DYNAMIC_FIELD_METHOD = "getSkyWalkingDynamicField"; + public static final String INTERCEPT_SET_SKYWALKING_DYNAMIC_FEILD_METHOD = "setSkyWalkingDynamicField"; @Override protected final ConstructorInterceptPoint[] getConstructorsInterceptPoints() { return new ConstructorInterceptPoint[0]; @@ -40,7 +42,7 @@ public abstract class AbstractSpringBeanInstrumentation extends ClassInstanceMet return new InstanceMethodsInterceptPoint[] { new InstanceMethodsInterceptPoint() { @Override public ElementMatcher getMethodsMatcher() { - return isPublic().and(not(isDeclaredBy(Object.class)).and(not(named("getSkyWalkingDynamicField"))).and(not(named("setSkyWalkingDynamicField")))); + return isPublic().and(not(isDeclaredBy(Object.class)).and(not(named(INTERCEPT_GET_SKYWALKING_DYNAMIC_FIELD_METHOD))).and(not(named(INTERCEPT_SET_SKYWALKING_DYNAMIC_FEILD_METHOD)))); } @Override public String getMethodsInterceptor() { diff --git a/apm-sniffer/optional-plugins/optional-spring-plugins/spring-annotation-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/annotations/bean/SpringBeanInstrumentation.java b/apm-sniffer/optional-plugins/optional-spring-plugins/spring-annotation-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/annotations/bean/SpringBeanInstrumentation.java index 366e3c55e..8aa5b2277 100644 --- a/apm-sniffer/optional-plugins/optional-spring-plugins/spring-annotation-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/annotations/bean/SpringBeanInstrumentation.java +++ b/apm-sniffer/optional-plugins/optional-spring-plugins/spring-annotation-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/annotations/bean/SpringBeanInstrumentation.java @@ -28,7 +28,9 @@ import static org.apache.skywalking.apm.agent.core.plugin.match.ClassAnnotationM */ public class SpringBeanInstrumentation extends AbstractSpringBeanInstrumentation { + public static final String ENHANCE_ANNOTATION = "org.springframework.context.annotation.Bean"; + @Override protected ClassMatch enhanceClass() { - return byClassAnnotationMatch(new String[] {"org.springframework.context.annotation.Bean"}); + return byClassAnnotationMatch(new String[] {ENHANCE_ANNOTATION}); } } diff --git a/apm-sniffer/optional-plugins/optional-spring-plugins/spring-annotation-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/annotations/component/SpringComponentInstrumentation.java b/apm-sniffer/optional-plugins/optional-spring-plugins/spring-annotation-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/annotations/component/SpringComponentInstrumentation.java index e65a98d25..eac6bb0c4 100644 --- a/apm-sniffer/optional-plugins/optional-spring-plugins/spring-annotation-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/annotations/component/SpringComponentInstrumentation.java +++ b/apm-sniffer/optional-plugins/optional-spring-plugins/spring-annotation-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/annotations/component/SpringComponentInstrumentation.java @@ -25,7 +25,9 @@ import static org.apache.skywalking.apm.agent.core.plugin.match.ClassAnnotationM public class SpringComponentInstrumentation extends AbstractSpringBeanInstrumentation { + public static final String ENHANCE_ANNOTATION = "org.springframework.stereotype.Component"; + @Override protected ClassMatch enhanceClass() { - return byClassAnnotationMatch(new String[] {"org.springframework.stereotype.Component"}); + return byClassAnnotationMatch(new String[] {ENHANCE_ANNOTATION}); } } diff --git a/apm-sniffer/optional-plugins/optional-spring-plugins/spring-annotation-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/annotations/repository/SpringRepositoryInstrumentation.java b/apm-sniffer/optional-plugins/optional-spring-plugins/spring-annotation-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/annotations/repository/SpringRepositoryInstrumentation.java index c97c32656..d91637e0e 100644 --- a/apm-sniffer/optional-plugins/optional-spring-plugins/spring-annotation-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/annotations/repository/SpringRepositoryInstrumentation.java +++ b/apm-sniffer/optional-plugins/optional-spring-plugins/spring-annotation-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/annotations/repository/SpringRepositoryInstrumentation.java @@ -24,7 +24,10 @@ import org.apache.skywalking.apm.plugin.spring.annotations.AbstractSpringBeanIns import static org.apache.skywalking.apm.agent.core.plugin.match.ClassAnnotationMatch.byClassAnnotationMatch; public class SpringRepositoryInstrumentation extends AbstractSpringBeanInstrumentation { + + public static final String ENHANCE_ANNOTATION = "org.springframework.stereotype.Repository"; + @Override protected ClassMatch enhanceClass() { - return byClassAnnotationMatch(new String[] {"org.springframework.stereotype.Repository"}); + return byClassAnnotationMatch(new String[] {ENHANCE_ANNOTATION}); } } diff --git a/apm-sniffer/optional-plugins/optional-spring-plugins/spring-annotation-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/annotations/services/SpringServicesInstrumentation.java b/apm-sniffer/optional-plugins/optional-spring-plugins/spring-annotation-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/annotations/services/SpringServicesInstrumentation.java index b38bfcb50..759097ab3 100644 --- a/apm-sniffer/optional-plugins/optional-spring-plugins/spring-annotation-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/annotations/services/SpringServicesInstrumentation.java +++ b/apm-sniffer/optional-plugins/optional-spring-plugins/spring-annotation-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/annotations/services/SpringServicesInstrumentation.java @@ -25,7 +25,9 @@ import static org.apache.skywalking.apm.agent.core.plugin.match.ClassAnnotationM public class SpringServicesInstrumentation extends AbstractSpringBeanInstrumentation { + public static final String ENHANCE_ANNOTATION = "org.springframework.stereotype.Service"; + @Override protected ClassMatch enhanceClass() { - return byClassAnnotationMatch(new String[] {"org.springframework.stereotype.Service"}); + return byClassAnnotationMatch(new String[] {ENHANCE_ANNOTATION}); } } From 7670ef3d2706d9c141a8d7bd07280a8730e17fd0 Mon Sep 17 00:00:00 2001 From: ascrutae Date: Sun, 28 Jan 2018 14:51:57 +0800 Subject: [PATCH 13/26] link the kafka FAQ document --- docs/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/README.md b/docs/README.md index c38355652..bec84c947 100644 --- a/docs/README.md +++ b/docs/README.md @@ -23,4 +23,5 @@ * Protocol * [Cross Process Propagation Headers Protocol, v1.0](en/Skywalking-Cross-Process-Propagation-Headers-Protocol-v1.md) * FAQ + * [The trace doesn't continue in kafka consumer side](en/FAQ/kafka-plugin.md) From 4774b0277db8861323c509fdcbd06d1f4b9e77fd Mon Sep 17 00:00:00 2001 From: ascrutae Date: Sun, 28 Jan 2018 19:21:59 +0800 Subject: [PATCH 14/26] rename kafka plugin module --- .../{kafka-0.11.x-plugin => kafka-v1-plugin}/pom.xml | 2 +- .../skywalking/apm/plugin/kafka/v11/CallbackInterceptor.java | 0 .../apm/plugin/kafka/v11/ConsumerConstructorInterceptor.java | 0 .../apm/plugin/kafka/v11/ConsumerEnhanceRequiredInfo.java | 0 .../apm/plugin/kafka/v11/KafkaConsumerInterceptor.java | 0 .../apm/plugin/kafka/v11/KafkaProducerInterceptor.java | 0 .../apm/plugin/kafka/v11/ProducerConstructorInterceptor.java | 0 .../plugin/kafka/v11/ProducerRecordConstructorInterceptor.java | 0 .../apm/plugin/kafka/v11/SubscribeMethodInterceptor.java | 0 .../apm/plugin/kafka/v11/define/CallbackInstrumentation.java | 0 .../plugin/kafka/v11/define/KafkaConsumerInstrumentation.java | 0 .../plugin/kafka/v11/define/KafkaProducerInstrumentation.java | 0 .../plugin/kafka/v11/define/ProducerRecordInstrumentation.java | 0 .../src/main/resources/skywalking-plugin.def | 0 .../apm/plugin/kafka/v11/CallbackInterceptorTest.java | 0 .../plugin/kafka/v11/ConsumerConstructorInterceptorTest.java | 0 .../apm/plugin/kafka/v11/KafkaConsumerInterceptorTest.java | 0 .../apm/plugin/kafka/v11/KafkaProducerInterceptorTest.java | 0 .../plugin/kafka/v11/ProducerConstructorInterceptorTest.java | 0 .../kafka/v11/ProducerRecordConstructorInterceptorTest.java | 0 .../apm/plugin/kafka/v11/SubscribeMethodInterceptorTest.java | 0 apm-sniffer/apm-sdk-plugin/pom.xml | 2 +- 22 files changed, 2 insertions(+), 2 deletions(-) rename apm-sniffer/apm-sdk-plugin/{kafka-0.11.x-plugin => kafka-v1-plugin}/pom.xml (96%) rename apm-sniffer/apm-sdk-plugin/{kafka-0.11.x-plugin => kafka-v1-plugin}/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/CallbackInterceptor.java (100%) rename apm-sniffer/apm-sdk-plugin/{kafka-0.11.x-plugin => kafka-v1-plugin}/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/ConsumerConstructorInterceptor.java (100%) rename apm-sniffer/apm-sdk-plugin/{kafka-0.11.x-plugin => kafka-v1-plugin}/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/ConsumerEnhanceRequiredInfo.java (100%) rename apm-sniffer/apm-sdk-plugin/{kafka-0.11.x-plugin => kafka-v1-plugin}/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/KafkaConsumerInterceptor.java (100%) rename apm-sniffer/apm-sdk-plugin/{kafka-0.11.x-plugin => kafka-v1-plugin}/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/KafkaProducerInterceptor.java (100%) rename apm-sniffer/apm-sdk-plugin/{kafka-0.11.x-plugin => kafka-v1-plugin}/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/ProducerConstructorInterceptor.java (100%) rename apm-sniffer/apm-sdk-plugin/{kafka-0.11.x-plugin => kafka-v1-plugin}/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/ProducerRecordConstructorInterceptor.java (100%) rename apm-sniffer/apm-sdk-plugin/{kafka-0.11.x-plugin => kafka-v1-plugin}/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/SubscribeMethodInterceptor.java (100%) rename apm-sniffer/apm-sdk-plugin/{kafka-0.11.x-plugin => kafka-v1-plugin}/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/define/CallbackInstrumentation.java (100%) rename apm-sniffer/apm-sdk-plugin/{kafka-0.11.x-plugin => kafka-v1-plugin}/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/define/KafkaConsumerInstrumentation.java (100%) rename apm-sniffer/apm-sdk-plugin/{kafka-0.11.x-plugin => kafka-v1-plugin}/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/define/KafkaProducerInstrumentation.java (100%) rename apm-sniffer/apm-sdk-plugin/{kafka-0.11.x-plugin => kafka-v1-plugin}/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/define/ProducerRecordInstrumentation.java (100%) rename apm-sniffer/apm-sdk-plugin/{kafka-0.11.x-plugin => kafka-v1-plugin}/src/main/resources/skywalking-plugin.def (100%) rename apm-sniffer/apm-sdk-plugin/{kafka-0.11.x-plugin => kafka-v1-plugin}/src/test/java/org/apache/skywalking/apm/plugin/kafka/v11/CallbackInterceptorTest.java (100%) rename apm-sniffer/apm-sdk-plugin/{kafka-0.11.x-plugin => kafka-v1-plugin}/src/test/java/org/apache/skywalking/apm/plugin/kafka/v11/ConsumerConstructorInterceptorTest.java (100%) rename apm-sniffer/apm-sdk-plugin/{kafka-0.11.x-plugin => kafka-v1-plugin}/src/test/java/org/apache/skywalking/apm/plugin/kafka/v11/KafkaConsumerInterceptorTest.java (100%) rename apm-sniffer/apm-sdk-plugin/{kafka-0.11.x-plugin => kafka-v1-plugin}/src/test/java/org/apache/skywalking/apm/plugin/kafka/v11/KafkaProducerInterceptorTest.java (100%) rename apm-sniffer/apm-sdk-plugin/{kafka-0.11.x-plugin => kafka-v1-plugin}/src/test/java/org/apache/skywalking/apm/plugin/kafka/v11/ProducerConstructorInterceptorTest.java (100%) rename apm-sniffer/apm-sdk-plugin/{kafka-0.11.x-plugin => kafka-v1-plugin}/src/test/java/org/apache/skywalking/apm/plugin/kafka/v11/ProducerRecordConstructorInterceptorTest.java (100%) rename apm-sniffer/apm-sdk-plugin/{kafka-0.11.x-plugin => kafka-v1-plugin}/src/test/java/org/apache/skywalking/apm/plugin/kafka/v11/SubscribeMethodInterceptorTest.java (100%) diff --git a/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/pom.xml b/apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/pom.xml similarity index 96% rename from apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/pom.xml rename to apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/pom.xml index 37699929d..33a6c4b19 100644 --- a/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/pom.xml +++ b/apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/pom.xml @@ -27,7 +27,7 @@ 4.0.0 - apm-kafka-0.11.x-plugin + apm-kafka-v1-plugin diff --git a/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/CallbackInterceptor.java b/apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/CallbackInterceptor.java similarity index 100% rename from apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/CallbackInterceptor.java rename to apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/CallbackInterceptor.java diff --git a/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/ConsumerConstructorInterceptor.java b/apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/ConsumerConstructorInterceptor.java similarity index 100% rename from apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/ConsumerConstructorInterceptor.java rename to apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/ConsumerConstructorInterceptor.java diff --git a/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/ConsumerEnhanceRequiredInfo.java b/apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/ConsumerEnhanceRequiredInfo.java similarity index 100% rename from apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/ConsumerEnhanceRequiredInfo.java rename to apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/ConsumerEnhanceRequiredInfo.java diff --git a/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/KafkaConsumerInterceptor.java b/apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/KafkaConsumerInterceptor.java similarity index 100% rename from apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/KafkaConsumerInterceptor.java rename to apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/KafkaConsumerInterceptor.java diff --git a/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/KafkaProducerInterceptor.java b/apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/KafkaProducerInterceptor.java similarity index 100% rename from apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/KafkaProducerInterceptor.java rename to apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/KafkaProducerInterceptor.java diff --git a/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/ProducerConstructorInterceptor.java b/apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/ProducerConstructorInterceptor.java similarity index 100% rename from apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/ProducerConstructorInterceptor.java rename to apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/ProducerConstructorInterceptor.java diff --git a/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/ProducerRecordConstructorInterceptor.java b/apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/ProducerRecordConstructorInterceptor.java similarity index 100% rename from apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/ProducerRecordConstructorInterceptor.java rename to apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/ProducerRecordConstructorInterceptor.java diff --git a/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/SubscribeMethodInterceptor.java b/apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/SubscribeMethodInterceptor.java similarity index 100% rename from apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/SubscribeMethodInterceptor.java rename to apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/SubscribeMethodInterceptor.java diff --git a/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/define/CallbackInstrumentation.java b/apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/define/CallbackInstrumentation.java similarity index 100% rename from apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/define/CallbackInstrumentation.java rename to apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/define/CallbackInstrumentation.java diff --git a/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/define/KafkaConsumerInstrumentation.java b/apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/define/KafkaConsumerInstrumentation.java similarity index 100% rename from apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/define/KafkaConsumerInstrumentation.java rename to apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/define/KafkaConsumerInstrumentation.java diff --git a/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/define/KafkaProducerInstrumentation.java b/apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/define/KafkaProducerInstrumentation.java similarity index 100% rename from apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/define/KafkaProducerInstrumentation.java rename to apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/define/KafkaProducerInstrumentation.java diff --git a/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/define/ProducerRecordInstrumentation.java b/apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/define/ProducerRecordInstrumentation.java similarity index 100% rename from apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/define/ProducerRecordInstrumentation.java rename to apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/define/ProducerRecordInstrumentation.java diff --git a/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/resources/skywalking-plugin.def b/apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/resources/skywalking-plugin.def similarity index 100% rename from apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/main/resources/skywalking-plugin.def rename to apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/resources/skywalking-plugin.def diff --git a/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/kafka/v11/CallbackInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/test/java/org/apache/skywalking/apm/plugin/kafka/v11/CallbackInterceptorTest.java similarity index 100% rename from apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/kafka/v11/CallbackInterceptorTest.java rename to apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/test/java/org/apache/skywalking/apm/plugin/kafka/v11/CallbackInterceptorTest.java diff --git a/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/kafka/v11/ConsumerConstructorInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/test/java/org/apache/skywalking/apm/plugin/kafka/v11/ConsumerConstructorInterceptorTest.java similarity index 100% rename from apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/kafka/v11/ConsumerConstructorInterceptorTest.java rename to apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/test/java/org/apache/skywalking/apm/plugin/kafka/v11/ConsumerConstructorInterceptorTest.java diff --git a/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/kafka/v11/KafkaConsumerInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/test/java/org/apache/skywalking/apm/plugin/kafka/v11/KafkaConsumerInterceptorTest.java similarity index 100% rename from apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/kafka/v11/KafkaConsumerInterceptorTest.java rename to apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/test/java/org/apache/skywalking/apm/plugin/kafka/v11/KafkaConsumerInterceptorTest.java diff --git a/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/kafka/v11/KafkaProducerInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/test/java/org/apache/skywalking/apm/plugin/kafka/v11/KafkaProducerInterceptorTest.java similarity index 100% rename from apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/kafka/v11/KafkaProducerInterceptorTest.java rename to apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/test/java/org/apache/skywalking/apm/plugin/kafka/v11/KafkaProducerInterceptorTest.java diff --git a/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/kafka/v11/ProducerConstructorInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/test/java/org/apache/skywalking/apm/plugin/kafka/v11/ProducerConstructorInterceptorTest.java similarity index 100% rename from apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/kafka/v11/ProducerConstructorInterceptorTest.java rename to apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/test/java/org/apache/skywalking/apm/plugin/kafka/v11/ProducerConstructorInterceptorTest.java diff --git a/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/kafka/v11/ProducerRecordConstructorInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/test/java/org/apache/skywalking/apm/plugin/kafka/v11/ProducerRecordConstructorInterceptorTest.java similarity index 100% rename from apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/kafka/v11/ProducerRecordConstructorInterceptorTest.java rename to apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/test/java/org/apache/skywalking/apm/plugin/kafka/v11/ProducerRecordConstructorInterceptorTest.java diff --git a/apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/kafka/v11/SubscribeMethodInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/test/java/org/apache/skywalking/apm/plugin/kafka/v11/SubscribeMethodInterceptorTest.java similarity index 100% rename from apm-sniffer/apm-sdk-plugin/kafka-0.11.x-plugin/src/test/java/org/apache/skywalking/apm/plugin/kafka/v11/SubscribeMethodInterceptorTest.java rename to apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/test/java/org/apache/skywalking/apm/plugin/kafka/v11/SubscribeMethodInterceptorTest.java diff --git a/apm-sniffer/apm-sdk-plugin/pom.xml b/apm-sniffer/apm-sdk-plugin/pom.xml index fa8d0b0ae..ab3e4c669 100644 --- a/apm-sniffer/apm-sdk-plugin/pom.xml +++ b/apm-sniffer/apm-sdk-plugin/pom.xml @@ -53,7 +53,7 @@ elastic-job-2.x-plugin mongodb-2.x-plugin httpasyncclient-4.x-plugin - kafka-0.11.x-plugin + kafka-v1-plugin pom From 111f31c192604966862f4ae40cbf47679cef5132 Mon Sep 17 00:00:00 2001 From: ascrutae Date: Sun, 28 Jan 2018 21:16:18 +0800 Subject: [PATCH 15/26] change package --- .../apm/plugin/kafka/{v11 => v1}/CallbackInterceptor.java | 2 +- .../kafka/{v11 => v1}/ConsumerConstructorInterceptor.java | 2 +- .../kafka/{v11 => v1}/ConsumerEnhanceRequiredInfo.java | 2 +- .../kafka/{v11 => v1}/KafkaConsumerInterceptor.java | 2 +- .../kafka/{v11 => v1}/KafkaProducerInterceptor.java | 2 +- .../kafka/{v11 => v1}/ProducerConstructorInterceptor.java | 2 +- .../{v11 => v1}/ProducerRecordConstructorInterceptor.java | 2 +- .../kafka/{v11 => v1}/SubscribeMethodInterceptor.java | 2 +- .../kafka/{v11 => v1}/define/CallbackInstrumentation.java | 5 +++-- .../{v11 => v1}/define/KafkaConsumerInstrumentation.java | 5 +++-- .../{v11 => v1}/define/KafkaProducerInstrumentation.java | 5 +++-- .../{v11 => v1}/define/ProducerRecordInstrumentation.java | 7 ++++--- .../src/main/resources/skywalking-plugin.def | 8 ++++---- .../apm/plugin/kafka/v11/CallbackInterceptorTest.java | 1 + .../kafka/v11/ConsumerConstructorInterceptorTest.java | 2 ++ .../plugin/kafka/v11/KafkaConsumerInterceptorTest.java | 2 ++ .../plugin/kafka/v11/KafkaProducerInterceptorTest.java | 1 + .../kafka/v11/ProducerConstructorInterceptorTest.java | 1 + .../v11/ProducerRecordConstructorInterceptorTest.java | 1 + .../plugin/kafka/v11/SubscribeMethodInterceptorTest.java | 2 ++ 20 files changed, 35 insertions(+), 21 deletions(-) rename apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/{v11 => v1}/CallbackInterceptor.java (97%) rename apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/{v11 => v1}/ConsumerConstructorInterceptor.java (96%) rename apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/{v11 => v1}/ConsumerEnhanceRequiredInfo.java (96%) rename apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/{v11 => v1}/KafkaConsumerInterceptor.java (98%) rename apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/{v11 => v1}/KafkaProducerInterceptor.java (98%) rename apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/{v11 => v1}/ProducerConstructorInterceptor.java (96%) rename apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/{v11 => v1}/ProducerRecordConstructorInterceptor.java (96%) rename apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/{v11 => v1}/SubscribeMethodInterceptor.java (97%) rename apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/{v11 => v1}/define/CallbackInstrumentation.java (93%) rename apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/{v11 => v1}/define/KafkaConsumerInstrumentation.java (95%) rename apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/{v11 => v1}/define/KafkaProducerInstrumentation.java (94%) rename apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/{v11 => v1}/define/ProducerRecordInstrumentation.java (89%) diff --git a/apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/CallbackInterceptor.java b/apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v1/CallbackInterceptor.java similarity index 97% rename from apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/CallbackInterceptor.java rename to apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v1/CallbackInterceptor.java index a0f81a084..3d3f38e9a 100644 --- a/apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/CallbackInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v1/CallbackInterceptor.java @@ -16,7 +16,7 @@ * */ -package org.apache.skywalking.apm.plugin.kafka.v11; +package org.apache.skywalking.apm.plugin.kafka.v1; import java.lang.reflect.Method; import org.apache.skywalking.apm.agent.core.context.ContextManager; diff --git a/apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/ConsumerConstructorInterceptor.java b/apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v1/ConsumerConstructorInterceptor.java similarity index 96% rename from apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/ConsumerConstructorInterceptor.java rename to apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v1/ConsumerConstructorInterceptor.java index fd3bc6c9e..77880a7ce 100644 --- a/apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/ConsumerConstructorInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v1/ConsumerConstructorInterceptor.java @@ -16,7 +16,7 @@ * */ -package org.apache.skywalking.apm.plugin.kafka.v11; +package org.apache.skywalking.apm.plugin.kafka.v1; import org.apache.kafka.clients.consumer.ConsumerConfig; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; diff --git a/apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/ConsumerEnhanceRequiredInfo.java b/apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v1/ConsumerEnhanceRequiredInfo.java similarity index 96% rename from apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/ConsumerEnhanceRequiredInfo.java rename to apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v1/ConsumerEnhanceRequiredInfo.java index 97e44c57a..62018beb6 100644 --- a/apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/ConsumerEnhanceRequiredInfo.java +++ b/apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v1/ConsumerEnhanceRequiredInfo.java @@ -16,7 +16,7 @@ * */ -package org.apache.skywalking.apm.plugin.kafka.v11; +package org.apache.skywalking.apm.plugin.kafka.v1; import java.util.Collection; import java.util.List; diff --git a/apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/KafkaConsumerInterceptor.java b/apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v1/KafkaConsumerInterceptor.java similarity index 98% rename from apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/KafkaConsumerInterceptor.java rename to apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v1/KafkaConsumerInterceptor.java index b7bf23b53..db790b8b0 100644 --- a/apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/KafkaConsumerInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v1/KafkaConsumerInterceptor.java @@ -16,7 +16,7 @@ * */ -package org.apache.skywalking.apm.plugin.kafka.v11; +package org.apache.skywalking.apm.plugin.kafka.v1; import java.lang.reflect.Method; import java.util.Iterator; diff --git a/apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/KafkaProducerInterceptor.java b/apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v1/KafkaProducerInterceptor.java similarity index 98% rename from apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/KafkaProducerInterceptor.java rename to apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v1/KafkaProducerInterceptor.java index 2e32d4f08..1ec0d68ee 100644 --- a/apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/KafkaProducerInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v1/KafkaProducerInterceptor.java @@ -16,7 +16,7 @@ * */ -package org.apache.skywalking.apm.plugin.kafka.v11; +package org.apache.skywalking.apm.plugin.kafka.v1; import java.lang.reflect.Method; import org.apache.kafka.clients.producer.ProducerRecord; diff --git a/apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/ProducerConstructorInterceptor.java b/apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v1/ProducerConstructorInterceptor.java similarity index 96% rename from apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/ProducerConstructorInterceptor.java rename to apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v1/ProducerConstructorInterceptor.java index 9dbeba457..604f080c8 100644 --- a/apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/ProducerConstructorInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v1/ProducerConstructorInterceptor.java @@ -16,7 +16,7 @@ * */ -package org.apache.skywalking.apm.plugin.kafka.v11; +package org.apache.skywalking.apm.plugin.kafka.v1; import org.apache.kafka.clients.producer.ProducerConfig; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; diff --git a/apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/ProducerRecordConstructorInterceptor.java b/apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v1/ProducerRecordConstructorInterceptor.java similarity index 96% rename from apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/ProducerRecordConstructorInterceptor.java rename to apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v1/ProducerRecordConstructorInterceptor.java index 8a7fbac87..1a2d5e3ff 100644 --- a/apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/ProducerRecordConstructorInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v1/ProducerRecordConstructorInterceptor.java @@ -16,7 +16,7 @@ * */ -package org.apache.skywalking.apm.plugin.kafka.v11; +package org.apache.skywalking.apm.plugin.kafka.v1; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor; diff --git a/apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/SubscribeMethodInterceptor.java b/apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v1/SubscribeMethodInterceptor.java similarity index 97% rename from apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/SubscribeMethodInterceptor.java rename to apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v1/SubscribeMethodInterceptor.java index 657684a9f..7c4e65598 100644 --- a/apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/SubscribeMethodInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v1/SubscribeMethodInterceptor.java @@ -16,7 +16,7 @@ * */ -package org.apache.skywalking.apm.plugin.kafka.v11; +package org.apache.skywalking.apm.plugin.kafka.v1; import java.lang.reflect.Method; import java.util.Collection; diff --git a/apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/define/CallbackInstrumentation.java b/apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v1/define/CallbackInstrumentation.java similarity index 93% rename from apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/define/CallbackInstrumentation.java rename to apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v1/define/CallbackInstrumentation.java index f3f22e44a..e478d6204 100644 --- a/apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/define/CallbackInstrumentation.java +++ b/apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v1/define/CallbackInstrumentation.java @@ -16,7 +16,7 @@ * */ -package org.apache.skywalking.apm.plugin.kafka.v11.define; +package org.apache.skywalking.apm.plugin.kafka.v1.define; import net.bytebuddy.description.method.MethodDescription; import net.bytebuddy.matcher.ElementMatcher; @@ -24,12 +24,13 @@ import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterc import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; +import org.apache.skywalking.apm.plugin.kafka.v1.CallbackInterceptor; import static net.bytebuddy.matcher.ElementMatchers.named; import static org.apache.skywalking.apm.agent.core.plugin.match.HierarchyMatch.byHierarchyMatch; /** - * {@link CallbackInstrumentation} defined that {@link org.apache.skywalking.apm.plugin.kafka.v11.CallbackInterceptor} + * {@link CallbackInstrumentation} defined that {@link CallbackInterceptor} * intercept the method onCompletion in the class org.apache.kafka.clients.producer.Callback. * * @author zhangxin diff --git a/apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/define/KafkaConsumerInstrumentation.java b/apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v1/define/KafkaConsumerInstrumentation.java similarity index 95% rename from apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/define/KafkaConsumerInstrumentation.java rename to apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v1/define/KafkaConsumerInstrumentation.java index f14befb7f..e4e1445f6 100644 --- a/apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/define/KafkaConsumerInstrumentation.java +++ b/apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v1/define/KafkaConsumerInstrumentation.java @@ -16,7 +16,7 @@ * */ -package org.apache.skywalking.apm.plugin.kafka.v11.define; +package org.apache.skywalking.apm.plugin.kafka.v1.define; import net.bytebuddy.description.method.MethodDescription; import net.bytebuddy.matcher.ElementMatcher; @@ -24,13 +24,14 @@ import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterc import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; +import org.apache.skywalking.apm.plugin.kafka.v1.KafkaConsumerInterceptor; import static net.bytebuddy.matcher.ElementMatchers.named; import static org.apache.skywalking.apm.agent.core.plugin.bytebuddy.ArgumentTypeNameMatch.takesArgumentWithType; import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName; /** - * {@link KafkaProducerInstrumentation} define that {@link org.apache.skywalking.apm.plugin.kafka.v11.KafkaConsumerInterceptor} + * {@link KafkaProducerInstrumentation} define that {@link KafkaConsumerInterceptor} * intercept the method send in the class org.apache.kafka.clients.producer.KafkaProducer. * Here is the intercept process steps. * diff --git a/apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/define/KafkaProducerInstrumentation.java b/apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v1/define/KafkaProducerInstrumentation.java similarity index 94% rename from apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/define/KafkaProducerInstrumentation.java rename to apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v1/define/KafkaProducerInstrumentation.java index 1cca62467..54932a8af 100644 --- a/apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/define/KafkaProducerInstrumentation.java +++ b/apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v1/define/KafkaProducerInstrumentation.java @@ -16,7 +16,7 @@ * */ -package org.apache.skywalking.apm.plugin.kafka.v11.define; +package org.apache.skywalking.apm.plugin.kafka.v1.define; import net.bytebuddy.description.method.MethodDescription; import net.bytebuddy.matcher.ElementMatcher; @@ -24,13 +24,14 @@ import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterc import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; +import org.apache.skywalking.apm.plugin.kafka.v1.KafkaProducerInterceptor; import static net.bytebuddy.matcher.ElementMatchers.named; import static org.apache.skywalking.apm.agent.core.plugin.bytebuddy.ArgumentTypeNameMatch.takesArgumentWithType; import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName; /** - * {@link KafkaProducerInstrumentation} define that {@link org.apache.skywalking.apm.plugin.kafka.v11.KafkaProducerInterceptor} + * {@link KafkaProducerInstrumentation} define that {@link KafkaProducerInterceptor} * intercept the method send in the class org.apache.kafka.clients.producer.KafkaProducer. * Here is the intercept process steps. * diff --git a/apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/define/ProducerRecordInstrumentation.java b/apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v1/define/ProducerRecordInstrumentation.java similarity index 89% rename from apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/define/ProducerRecordInstrumentation.java rename to apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v1/define/ProducerRecordInstrumentation.java index cb0a052b9..fe4d8b203 100644 --- a/apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v11/define/ProducerRecordInstrumentation.java +++ b/apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/java/org/apache/skywalking/apm/plugin/kafka/v1/define/ProducerRecordInstrumentation.java @@ -16,7 +16,7 @@ * */ -package org.apache.skywalking.apm.plugin.kafka.v11.define; +package org.apache.skywalking.apm.plugin.kafka.v1.define; import net.bytebuddy.description.method.MethodDescription; import net.bytebuddy.matcher.ElementMatcher; @@ -24,17 +24,18 @@ import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterc import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; +import org.apache.skywalking.apm.plugin.kafka.v1.ProducerRecordConstructorInterceptor; import static net.bytebuddy.matcher.ElementMatchers.takesArguments; import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName; /** - * {@link ProducerRecordInstrumentation} define that {@link org.apache.skywalking.apm.plugin.kafka.v11.ProducerRecordConstructorInterceptor} + * {@link ProducerRecordInstrumentation} define that {@link ProducerRecordConstructorInterceptor} * intercept the constructor in the class org.apache.kafka.clients.producer.ProducerRecord for record the * topic name and propagate the Context of trace. * * @author zhang xin - * @see org.apache.skywalking.apm.plugin.kafka.v11.define.KafkaProducerInstrumentation + * @see org.apache.skywalking.apm.plugin.kafka.v1.define.KafkaProducerInstrumentation */ public class ProducerRecordInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { diff --git a/apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/resources/skywalking-plugin.def b/apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/resources/skywalking-plugin.def index 5f3439cbf..a6e5972a0 100644 --- a/apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/resources/skywalking-plugin.def +++ b/apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/main/resources/skywalking-plugin.def @@ -1,4 +1,4 @@ -kafka-0.11.x=org.apache.skywalking.apm.plugin.kafka.v11.define.CallbackInstrumentation -kafka-0.11.x=org.apache.skywalking.apm.plugin.kafka.v11.define.KafkaConsumerInstrumentation -kafka-0.11.x=org.apache.skywalking.apm.plugin.kafka.v11.define.KafkaProducerInstrumentation -kafka-0.11.x=org.apache.skywalking.apm.plugin.kafka.v11.define.ProducerRecordInstrumentation +kafka-0.11.x=org.apache.skywalking.apm.plugin.kafka.v1.define.CallbackInstrumentation +kafka-0.11.x=org.apache.skywalking.apm.plugin.kafka.v1.define.KafkaConsumerInstrumentation +kafka-0.11.x=org.apache.skywalking.apm.plugin.kafka.v1.define.KafkaProducerInstrumentation +kafka-0.11.x=org.apache.skywalking.apm.plugin.kafka.v1.define.ProducerRecordInstrumentation diff --git a/apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/test/java/org/apache/skywalking/apm/plugin/kafka/v11/CallbackInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/test/java/org/apache/skywalking/apm/plugin/kafka/v11/CallbackInterceptorTest.java index 78991cfe2..17ddaf443 100644 --- a/apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/test/java/org/apache/skywalking/apm/plugin/kafka/v11/CallbackInterceptorTest.java +++ b/apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/test/java/org/apache/skywalking/apm/plugin/kafka/v11/CallbackInterceptorTest.java @@ -33,6 +33,7 @@ import org.apache.skywalking.apm.agent.test.tools.SegmentStorage; import org.apache.skywalking.apm.agent.test.tools.SegmentStoragePoint; import org.apache.skywalking.apm.agent.test.tools.SpanAssert; import org.apache.skywalking.apm.agent.test.tools.TracingSegmentRunner; +import org.apache.skywalking.apm.plugin.kafka.v1.CallbackInterceptor; import org.junit.Before; import org.junit.Rule; import org.junit.Test; diff --git a/apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/test/java/org/apache/skywalking/apm/plugin/kafka/v11/ConsumerConstructorInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/test/java/org/apache/skywalking/apm/plugin/kafka/v11/ConsumerConstructorInterceptorTest.java index 1379203d6..e6125ba78 100644 --- a/apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/test/java/org/apache/skywalking/apm/plugin/kafka/v11/ConsumerConstructorInterceptorTest.java +++ b/apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/test/java/org/apache/skywalking/apm/plugin/kafka/v11/ConsumerConstructorInterceptorTest.java @@ -22,6 +22,8 @@ import java.util.ArrayList; import java.util.List; import org.apache.kafka.clients.consumer.ConsumerConfig; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.plugin.kafka.v1.ConsumerConstructorInterceptor; +import org.apache.skywalking.apm.plugin.kafka.v1.ConsumerEnhanceRequiredInfo; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; diff --git a/apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/test/java/org/apache/skywalking/apm/plugin/kafka/v11/KafkaConsumerInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/test/java/org/apache/skywalking/apm/plugin/kafka/v11/KafkaConsumerInterceptorTest.java index 847b9ea87..06479bcda 100644 --- a/apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/test/java/org/apache/skywalking/apm/plugin/kafka/v11/KafkaConsumerInterceptorTest.java +++ b/apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/test/java/org/apache/skywalking/apm/plugin/kafka/v11/KafkaConsumerInterceptorTest.java @@ -36,6 +36,8 @@ import org.apache.skywalking.apm.agent.test.tools.SegmentStorage; import org.apache.skywalking.apm.agent.test.tools.SegmentStoragePoint; import org.apache.skywalking.apm.agent.test.tools.SpanAssert; import org.apache.skywalking.apm.agent.test.tools.TracingSegmentRunner; +import org.apache.skywalking.apm.plugin.kafka.v1.ConsumerEnhanceRequiredInfo; +import org.apache.skywalking.apm.plugin.kafka.v1.KafkaConsumerInterceptor; import org.hamcrest.MatcherAssert; import org.junit.Before; import org.junit.Rule; diff --git a/apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/test/java/org/apache/skywalking/apm/plugin/kafka/v11/KafkaProducerInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/test/java/org/apache/skywalking/apm/plugin/kafka/v11/KafkaProducerInterceptorTest.java index 3c7644112..aff40ca32 100644 --- a/apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/test/java/org/apache/skywalking/apm/plugin/kafka/v11/KafkaProducerInterceptorTest.java +++ b/apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/test/java/org/apache/skywalking/apm/plugin/kafka/v11/KafkaProducerInterceptorTest.java @@ -30,6 +30,7 @@ import org.apache.skywalking.apm.agent.test.tools.SegmentStorage; import org.apache.skywalking.apm.agent.test.tools.SegmentStoragePoint; import org.apache.skywalking.apm.agent.test.tools.SpanAssert; import org.apache.skywalking.apm.agent.test.tools.TracingSegmentRunner; +import org.apache.skywalking.apm.plugin.kafka.v1.KafkaProducerInterceptor; import org.junit.Before; import org.junit.Rule; import org.junit.Test; diff --git a/apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/test/java/org/apache/skywalking/apm/plugin/kafka/v11/ProducerConstructorInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/test/java/org/apache/skywalking/apm/plugin/kafka/v11/ProducerConstructorInterceptorTest.java index 23f1a6ae3..6eee953f5 100644 --- a/apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/test/java/org/apache/skywalking/apm/plugin/kafka/v11/ProducerConstructorInterceptorTest.java +++ b/apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/test/java/org/apache/skywalking/apm/plugin/kafka/v11/ProducerConstructorInterceptorTest.java @@ -22,6 +22,7 @@ import java.util.ArrayList; import java.util.List; import org.apache.kafka.clients.producer.ProducerConfig; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.plugin.kafka.v1.ProducerConstructorInterceptor; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; diff --git a/apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/test/java/org/apache/skywalking/apm/plugin/kafka/v11/ProducerRecordConstructorInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/test/java/org/apache/skywalking/apm/plugin/kafka/v11/ProducerRecordConstructorInterceptorTest.java index 568d3644b..5a1a9d677 100644 --- a/apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/test/java/org/apache/skywalking/apm/plugin/kafka/v11/ProducerRecordConstructorInterceptorTest.java +++ b/apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/test/java/org/apache/skywalking/apm/plugin/kafka/v11/ProducerRecordConstructorInterceptorTest.java @@ -19,6 +19,7 @@ package org.apache.skywalking.apm.plugin.kafka.v11; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.plugin.kafka.v1.ProducerRecordConstructorInterceptor; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; diff --git a/apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/test/java/org/apache/skywalking/apm/plugin/kafka/v11/SubscribeMethodInterceptorTest.java b/apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/test/java/org/apache/skywalking/apm/plugin/kafka/v11/SubscribeMethodInterceptorTest.java index b6d7190b7..66a084293 100644 --- a/apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/test/java/org/apache/skywalking/apm/plugin/kafka/v11/SubscribeMethodInterceptorTest.java +++ b/apm-sniffer/apm-sdk-plugin/kafka-v1-plugin/src/test/java/org/apache/skywalking/apm/plugin/kafka/v11/SubscribeMethodInterceptorTest.java @@ -22,6 +22,8 @@ import java.util.ArrayList; import java.util.Collection; import java.util.List; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.plugin.kafka.v1.ConsumerEnhanceRequiredInfo; +import org.apache.skywalking.apm.plugin.kafka.v1.SubscribeMethodInterceptor; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; From 843e32a0adec2f92ac3430e49974846692063a75 Mon Sep 17 00:00:00 2001 From: ascrutae Date: Sun, 28 Jan 2018 19:32:30 +0800 Subject: [PATCH 16/26] link the page --- docs/README.md | 2 ++ docs/README_ZH.md | 1 + docs/cn/FAQ/Why-have-traces-no-others-CN.md | 2 +- docs/en/FAQ/Too-many-gRPC-logs.md | 6 ++++++ docs/en/FAQ/Why-have-traces-no-others.md | 10 ++++++++++ 5 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 docs/en/FAQ/Too-many-gRPC-logs.md create mode 100644 docs/en/FAQ/Why-have-traces-no-others.md diff --git a/docs/README.md b/docs/README.md index bec84c947..d0796a2d7 100644 --- a/docs/README.md +++ b/docs/README.md @@ -23,5 +23,7 @@ * Protocol * [Cross Process Propagation Headers Protocol, v1.0](en/Skywalking-Cross-Process-Propagation-Headers-Protocol-v1.md) * FAQ + * [No other data but UI can query trace](cn/FAQ/Why-have-traces-no-others.md) + * [Too many GRPC log in the console](cn/FAQ/Too-many-gRPC-logs.md) * [The trace doesn't continue in kafka consumer side](en/FAQ/kafka-plugin.md) diff --git a/docs/README_ZH.md b/docs/README_ZH.md index 8b612efc1..2cf5f1658 100644 --- a/docs/README_ZH.md +++ b/docs/README_ZH.md @@ -28,3 +28,4 @@ * FAQ * [Trace查询有数据,但是没有拓扑图和JVM数据?](cn/FAQ/Why-have-traces-no-others-CN.md) * [加载探针,Console被GRPC日志刷屏](cn/FAQ/Too-many-gRPC-logs-CN.md) + * [Kafka消息消费端链路断裂](cn/FAQ/Kafka-plugin-CN.md) \ No newline at end of file diff --git a/docs/cn/FAQ/Why-have-traces-no-others-CN.md b/docs/cn/FAQ/Why-have-traces-no-others-CN.md index fcab017a3..a6588f9fb 100644 --- a/docs/cn/FAQ/Why-have-traces-no-others-CN.md +++ b/docs/cn/FAQ/Why-have-traces-no-others-CN.md @@ -2,7 +2,7 @@ - Agent和Collector正常工作,没有异常日志 - 已经对系统进行过访问,Trace查询有数据 - UI除Trace查询页面外,其他页面无数据 -- **页面顶部时间轴和当前系统时间不一致** +- 页面顶部时间轴和当前系统时间不一致 原因: 被监控系统所在的操作系统,未设置为当前时区,导致统计数据汇集时间点偏差。 diff --git a/docs/en/FAQ/Too-many-gRPC-logs.md b/docs/en/FAQ/Too-many-gRPC-logs.md new file mode 100644 index 000000000..58b4b124c --- /dev/null +++ b/docs/en/FAQ/Too-many-gRPC-logs.md @@ -0,0 +1,6 @@ +**Problem**: +Too many GRPC log in the console + +**Reason**:Skywalking uses the GRPC framework to send data, and the GRPC framework reads log configuration files for log output. + +**Resolve**: Add filter to `org.apache.skywalking.apm.dependencies` package in log configuration file diff --git a/docs/en/FAQ/Why-have-traces-no-others.md b/docs/en/FAQ/Why-have-traces-no-others.md new file mode 100644 index 000000000..3daa76b60 --- /dev/null +++ b/docs/en/FAQ/Why-have-traces-no-others.md @@ -0,0 +1,10 @@ +**Problem**: +- There is no abnormal log in Agent log and Collector log, +- The page can see the trace stack, but the others cannot see any data +- The top of the page Time line is inconsistent with the current system time + +**Reason**: +The operating system where the monitored system is located is not set as the current time zone, causing statistics collection time points to deviate. + +**Resolve**: +Set the time zone \ No newline at end of file From ab6f4f3c76f9abbdb8a367ad538e618155805aa1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B4=E6=99=9F=20Wu=20Sheng?= Date: Mon, 29 Jan 2018 12:11:45 +0800 Subject: [PATCH 17/26] Update README.md --- docs/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/README.md b/docs/README.md index d0796a2d7..6b34addad 100644 --- a/docs/README.md +++ b/docs/README.md @@ -23,7 +23,7 @@ * Protocol * [Cross Process Propagation Headers Protocol, v1.0](en/Skywalking-Cross-Process-Propagation-Headers-Protocol-v1.md) * FAQ - * [No other data but UI can query trace](cn/FAQ/Why-have-traces-no-others.md) - * [Too many GRPC log in the console](cn/FAQ/Too-many-gRPC-logs.md) +    * [Why only traces in UI?](cn/FAQ/Why-have-traces-no-others.md) + * [Too many GRPC logs in the console](cn/FAQ/Too-many-gRPC-logs.md) * [The trace doesn't continue in kafka consumer side](en/FAQ/kafka-plugin.md) From a0428d1d13614aa20e546efbe6c9fa9017006d1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B4=E6=99=9F=20Wu=20Sheng?= Date: Mon, 29 Jan 2018 12:12:28 +0800 Subject: [PATCH 18/26] Update Why-have-traces-no-others-CN.md --- docs/cn/FAQ/Why-have-traces-no-others-CN.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docs/cn/FAQ/Why-have-traces-no-others-CN.md b/docs/cn/FAQ/Why-have-traces-no-others-CN.md index a6588f9fb..2c95a5ef3 100644 --- a/docs/cn/FAQ/Why-have-traces-no-others-CN.md +++ b/docs/cn/FAQ/Why-have-traces-no-others-CN.md @@ -2,10 +2,9 @@ - Agent和Collector正常工作,没有异常日志 - 已经对系统进行过访问,Trace查询有数据 - UI除Trace查询页面外,其他页面无数据 -- 页面顶部时间轴和当前系统时间不一致 原因: 被监控系统所在的操作系统,未设置为当前时区,导致统计数据汇集时间点偏差。 解决方法: -设置操作系统时间时区 \ No newline at end of file +设置操作系统时间时区 From 36cc9e5b3821722a5b3de327d779e28d68dd4aae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B4=E6=99=9F=20Wu=20Sheng?= Date: Mon, 29 Jan 2018 12:15:25 +0800 Subject: [PATCH 19/26] Update Why-have-traces-no-others.md --- docs/en/FAQ/Why-have-traces-no-others.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/docs/en/FAQ/Why-have-traces-no-others.md b/docs/en/FAQ/Why-have-traces-no-others.md index 3daa76b60..c0db2fe41 100644 --- a/docs/en/FAQ/Why-have-traces-no-others.md +++ b/docs/en/FAQ/Why-have-traces-no-others.md @@ -1,10 +1,9 @@ **Problem**: - There is no abnormal log in Agent log and Collector log, -- The page can see the trace stack, but the others cannot see any data -- The top of the page Time line is inconsistent with the current system time +- The traces show, but no other info in UI. **Reason**: The operating system where the monitored system is located is not set as the current time zone, causing statistics collection time points to deviate. **Resolve**: -Set the time zone \ No newline at end of file +Make sure the time is sync in collector servers and monitored application servers. From e9cffe3ffb504cce1543c59d223d80704ebdd25d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B4=E6=99=9F=20Wu=20Sheng?= Date: Mon, 29 Jan 2018 12:16:10 +0800 Subject: [PATCH 20/26] Update Why-have-traces-no-others-CN.md --- docs/cn/FAQ/Why-have-traces-no-others-CN.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/cn/FAQ/Why-have-traces-no-others-CN.md b/docs/cn/FAQ/Why-have-traces-no-others-CN.md index 2c95a5ef3..cf8f2a3d2 100644 --- a/docs/cn/FAQ/Why-have-traces-no-others-CN.md +++ b/docs/cn/FAQ/Why-have-traces-no-others-CN.md @@ -4,7 +4,7 @@ - UI除Trace查询页面外,其他页面无数据 原因: -被监控系统所在的操作系统,未设置为当前时区,导致统计数据汇集时间点偏差。 +Collector和被监控应用的系统主机时间,没有同步。 解决方法: -设置操作系统时间时区 +同步各主机操作系统时间。 From 0cf694804e457f3ab07d1569e91445aa090f911b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B4=E6=99=9F=20Wu=20Sheng?= Date: Mon, 29 Jan 2018 13:13:20 +0800 Subject: [PATCH 21/26] Update README.md --- docs/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/README.md b/docs/README.md index 6b34addad..8928e771a 100644 --- a/docs/README.md +++ b/docs/README.md @@ -23,7 +23,7 @@ * Protocol * [Cross Process Propagation Headers Protocol, v1.0](en/Skywalking-Cross-Process-Propagation-Headers-Protocol-v1.md) * FAQ -    * [Why only traces in UI?](cn/FAQ/Why-have-traces-no-others.md) + * [Why only traces in UI?](cn/FAQ/Why-have-traces-no-others.md) * [Too many GRPC logs in the console](cn/FAQ/Too-many-gRPC-logs.md) * [The trace doesn't continue in kafka consumer side](en/FAQ/kafka-plugin.md) From e0a4af34773ff54eb750c893e9471b08c0adccd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B4=E6=99=9F=20Wu=20Sheng?= Date: Mon, 29 Jan 2018 13:59:37 +0800 Subject: [PATCH 22/26] Update Supported-list.md --- docs/Supported-list.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/Supported-list.md b/docs/Supported-list.md index a327444ac..b1187e394 100644 --- a/docs/Supported-list.md +++ b/docs/Supported-list.md @@ -30,7 +30,7 @@ * [gRPC](https://github.com/grpc/grpc-java) 1.6+ * MQ * [RocketMQ](https://github.com/apache/rocketmq) 4.x - * [Kafka](http://kafka.apache.org) 0.11.0.0 -> 1.0 (Optional²) + * [Kafka](http://kafka.apache.org) 0.11.0.0 -> 1.0 * NoSQL * Redis * [Jedis](https://github.com/xetorthio/jedis) 2.x @@ -41,12 +41,12 @@ * Service Discovery * [Netflix Eureka](https://github.com/Netflix/eureka) * Spring Ecosystem + * Spring Bean annotations(@Bean, @Service, @Component, @Repository) 3.x and 4.x (Optional²) * Spring Core Async SuccessCallback/FailureCallback/ListenableFutureCallback 4.x * Scheduler * [Elastic Job](https://github.com/elasticjob/elastic-job) 2.x * OpenTracing community supported - * Motan - * Hprose-java ¹Required dependencies for these components must be first manually downloaded before being built, due to license incompatibilities. For this reason these components are not by default included in the SkyWalking releases. + ²These plugins affect the performance or must be used under some conditions, from experiences. So only released in `/optional-plugins`, copy to `/plugins` in order to make them work. From 98d3f0eaf3bc508ba31d81264f885e143f24d32a Mon Sep 17 00:00:00 2001 From: ascrutae Date: Tue, 30 Jan 2018 15:08:52 +0800 Subject: [PATCH 23/26] [Agent] fix optional plugin doesn't works --- apm-sniffer/optional-plugins/pom.xml | 41 ++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/apm-sniffer/optional-plugins/pom.xml b/apm-sniffer/optional-plugins/pom.xml index 07061b9d6..322fcace6 100644 --- a/apm-sniffer/optional-plugins/pom.xml +++ b/apm-sniffer/optional-plugins/pom.xml @@ -30,6 +30,9 @@ optional-plugins pom + net.bytebuddy + ${shade.package}.${shade.net.bytebuddy.source} + ${project.build.directory}/../../../../packages/skywalking-agent/optional-plugins @@ -60,6 +63,44 @@ + + org.apache.maven.plugins + maven-shade-plugin + 2.4.1 + + + package + + shade + + + false + true + true + true + + + com.lmax:* + org.apache.httpcomponents:* + commons-logging:* + commons-codec:* + *:gson + io.grpc:* + io.netty:* + com.google.*:* + com.google.guava:guava + + + + + ${shade.net.bytebuddy.source} + ${shade.net.bytebuddy.target} + + + + + + org.apache.maven.plugins maven-antrun-plugin From df04ed49436788ec6e01289ea20a6ac9297314f8 Mon Sep 17 00:00:00 2001 From: ascrutae Date: Tue, 30 Jan 2018 15:32:08 +0800 Subject: [PATCH 24/26] Remove incorrect exclude --- apm-sniffer/apm-sdk-plugin/pom.xml | 13 ------------- apm-sniffer/optional-plugins/pom.xml | 13 ------------- 2 files changed, 26 deletions(-) diff --git a/apm-sniffer/apm-sdk-plugin/pom.xml b/apm-sniffer/apm-sdk-plugin/pom.xml index 095740230..a4acaca4b 100644 --- a/apm-sniffer/apm-sdk-plugin/pom.xml +++ b/apm-sniffer/apm-sdk-plugin/pom.xml @@ -108,19 +108,6 @@ true true true - - - com.lmax:* - org.apache.httpcomponents:* - commons-logging:* - commons-codec:* - *:gson - io.grpc:* - io.netty:* - com.google.*:* - com.google.guava:guava - - ${shade.net.bytebuddy.source} diff --git a/apm-sniffer/optional-plugins/pom.xml b/apm-sniffer/optional-plugins/pom.xml index 322fcace6..4c9b3f925 100644 --- a/apm-sniffer/optional-plugins/pom.xml +++ b/apm-sniffer/optional-plugins/pom.xml @@ -78,19 +78,6 @@ true true true - - - com.lmax:* - org.apache.httpcomponents:* - commons-logging:* - commons-codec:* - *:gson - io.grpc:* - io.netty:* - com.google.*:* - com.google.guava:guava - - ${shade.net.bytebuddy.source} From 7554cfabaf75ba983549056a5830a39f7f8bd246 Mon Sep 17 00:00:00 2001 From: ascrutae Date: Tue, 30 Jan 2018 20:50:17 +0800 Subject: [PATCH 25/26] [Agent] Change the enhance way of oracle plugin --- .../apm/plugin/jdbc/oracle/Constants.java | 30 ++++++++ .../oracle/CreateCallableInterceptor.java} | 31 ++------ .../CreatePreparedStatementInterceptor.java | 47 ++++++++++++ .../oracle/CreateStatementInterceptor.java | 47 ++++++++++++ ...redStatementExecuteMethodsInterceptor.java | 74 ++++++++++++++++++ .../StatementExecuteMethodsInterceptor.java | 76 +++++++++++++++++++ .../define/ConnectionInstrumentation.java | 63 ++++----------- .../define/OracleCallableInstrumentation.java | 70 +++++++++++++++++ ...OraclePrepareStatementInstrumentation.java | 71 +++++++++++++++++ .../OracleStatementInstrumentation.java | 74 ++++++++++++++++++ .../src/main/resources/skywalking-plugin.def | 3 + 11 files changed, 513 insertions(+), 73 deletions(-) create mode 100644 apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/oracle/Constants.java rename apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/java/{oracle/jdbc/driver/JDBCPrepareStatementWithArrayInterceptor.java => org/apache/skywalking/apm/plugin/jdbc/oracle/CreateCallableInterceptor.java} (55%) create mode 100644 apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/oracle/CreatePreparedStatementInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/oracle/CreateStatementInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/oracle/PreparedStatementExecuteMethodsInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/oracle/StatementExecuteMethodsInterceptor.java create mode 100644 apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/oracle/define/OracleCallableInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/oracle/define/OraclePrepareStatementInstrumentation.java create mode 100644 apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/oracle/define/OracleStatementInstrumentation.java diff --git a/apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/oracle/Constants.java b/apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/oracle/Constants.java new file mode 100644 index 000000000..3a4e72de0 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/oracle/Constants.java @@ -0,0 +1,30 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.skywalking.apm.plugin.jdbc.oracle; + +/** + * Constants variables + * + * @author zhang xin + */ +public final class Constants { + public static final String STATEMENT_INTERCEPT_CLASS = "org.apache.skywalking.apm.plugin.jdbc.oracle.StatementExecuteMethodsInterceptor"; + + public static final String PREPARED_STATEMENT_INTERCEPT_CLASS = "org.apache.skywalking.apm.plugin.jdbc.oracle.PreparedStatementExecuteMethodsInterceptor"; +} diff --git a/apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/java/oracle/jdbc/driver/JDBCPrepareStatementWithArrayInterceptor.java b/apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/oracle/CreateCallableInterceptor.java similarity index 55% rename from apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/java/oracle/jdbc/driver/JDBCPrepareStatementWithArrayInterceptor.java rename to apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/oracle/CreateCallableInterceptor.java index 06ccae6d6..d526ac506 100644 --- a/apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/java/oracle/jdbc/driver/JDBCPrepareStatementWithArrayInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/oracle/CreateCallableInterceptor.java @@ -16,26 +16,16 @@ * */ -package oracle.jdbc.driver; +package org.apache.skywalking.apm.plugin.jdbc.oracle; import java.lang.reflect.Method; -import java.sql.Connection; -import java.sql.PreparedStatement; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; +import org.apache.skywalking.apm.plugin.jdbc.define.StatementEnhanceInfos; import org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo; -import org.apache.skywalking.apm.plugin.jdbc.trace.SWPreparedStatement; -/** - * {@link JDBCPrepareStatementWithArrayInterceptor} return {@link SWPreparedStatement} instance that wrapper the real - * preparedStatement instance when the client call oracle.jdbc.driver.PhysicalConnection#prepareStatement(String, - * int[]) method or oracle.jdbc.driver.PhysicalConnection#prepareStatement(String, String[]) - * method. - * - * @author zhangxin - */ -public class JDBCPrepareStatementWithArrayInterceptor implements InstanceMethodsAroundInterceptor { +public class CreateCallableInterceptor implements InstanceMethodsAroundInterceptor { @Override public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, MethodInterceptResult result) throws Throwable { @@ -45,19 +35,10 @@ public class JDBCPrepareStatementWithArrayInterceptor implements InstanceMethods @Override public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, Object ret) throws Throwable { - /** - * To prevent the org.postgresql.jdbc.prepareStatement(String sql) method from repeating - * interceptor, Because PGConnection call org.postgresql.jdbc.prepareStatement(String sql) method when - * the second argument is empty. - * - * @see oracle.jdbc.driver.PhysicalConnection#prepareStatement(String, int[]) - * @see oracle.jdbc.driver.PhysicalConnection#prepareStatement(String, String[]) - **/ - String sql = (String)allArguments[0]; - if (!AutoKeyInfo.isInsertSqlStmt(sql)) { - return ret; + if (ret instanceof EnhancedInstance) { + ((EnhancedInstance)ret).setSkyWalkingDynamicField(new StatementEnhanceInfos((ConnectionInfo)objInst.getSkyWalkingDynamicField(), (String)allArguments[0], "CallableStatement")); } - return new SWPreparedStatement((Connection)objInst, (PreparedStatement)ret, (ConnectionInfo)objInst.getSkyWalkingDynamicField(), (String)allArguments[0]); + return ret; } @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, diff --git a/apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/oracle/CreatePreparedStatementInterceptor.java b/apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/oracle/CreatePreparedStatementInterceptor.java new file mode 100644 index 000000000..9c8a2ba3b --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/oracle/CreatePreparedStatementInterceptor.java @@ -0,0 +1,47 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.skywalking.apm.plugin.jdbc.oracle; + +import java.lang.reflect.Method; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; +import org.apache.skywalking.apm.plugin.jdbc.define.StatementEnhanceInfos; +import org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo; + +public class CreatePreparedStatementInterceptor implements InstanceMethodsAroundInterceptor { + @Override + public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + MethodInterceptResult result) throws Throwable { + } + + @Override + public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + Object ret) throws Throwable { + if (ret instanceof EnhancedInstance) { + ((EnhancedInstance)ret).setSkyWalkingDynamicField(new StatementEnhanceInfos((ConnectionInfo)objInst.getSkyWalkingDynamicField(), (String)allArguments[0], "PreparedStatement")); + } + return ret; + } + + @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + + } +} diff --git a/apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/oracle/CreateStatementInterceptor.java b/apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/oracle/CreateStatementInterceptor.java new file mode 100644 index 000000000..ea2b95cad --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/oracle/CreateStatementInterceptor.java @@ -0,0 +1,47 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.skywalking.apm.plugin.jdbc.oracle; + +import java.lang.reflect.Method; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; +import org.apache.skywalking.apm.plugin.jdbc.define.StatementEnhanceInfos; +import org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo; + +public class CreateStatementInterceptor implements InstanceMethodsAroundInterceptor { + @Override + public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + MethodInterceptResult result) throws Throwable { + } + + @Override + public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + Object ret) throws Throwable { + if (ret instanceof EnhancedInstance) { + ((EnhancedInstance)ret).setSkyWalkingDynamicField(new StatementEnhanceInfos((ConnectionInfo)objInst.getSkyWalkingDynamicField(), "", "Statement")); + } + return ret; + } + + @Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + + } +} diff --git a/apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/oracle/PreparedStatementExecuteMethodsInterceptor.java b/apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/oracle/PreparedStatementExecuteMethodsInterceptor.java new file mode 100644 index 000000000..065333931 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/oracle/PreparedStatementExecuteMethodsInterceptor.java @@ -0,0 +1,74 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.skywalking.apm.plugin.jdbc.oracle; + +import java.lang.reflect.Method; +import org.apache.skywalking.apm.agent.core.context.ContextManager; +import org.apache.skywalking.apm.agent.core.context.tag.Tags; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; +import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; +import org.apache.skywalking.apm.plugin.jdbc.define.StatementEnhanceInfos; +import org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo; + +/** + * @author zhang xin + */ +public class PreparedStatementExecuteMethodsInterceptor implements InstanceMethodsAroundInterceptor { + + @Override + public final void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, + MethodInterceptResult result) throws Throwable { + StatementEnhanceInfos cacheObject = (StatementEnhanceInfos)objInst.getSkyWalkingDynamicField(); + ConnectionInfo connectInfo = cacheObject.getConnectionInfo(); + + AbstractSpan span = ContextManager.createExitSpan(buildOperationName(connectInfo, method.getName(), cacheObject.getStatementName()), connectInfo.getDatabasePeer()); + Tags.DB_TYPE.set(span, "sql"); + Tags.DB_INSTANCE.set(span, connectInfo.getDatabaseName()); + Tags.DB_STATEMENT.set(span, cacheObject.getSql()); + span.setComponent(connectInfo.getComponent()); + SpanLayer.asDB(span); + } + + @Override + public final Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, + Object ret) throws Throwable { + StatementEnhanceInfos cacheObject = (StatementEnhanceInfos)objInst.getSkyWalkingDynamicField(); + if (cacheObject.getConnectionInfo() != null) { + ContextManager.stopSpan(); + } + return ret; + } + + @Override public final void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + StatementEnhanceInfos cacheObject = (StatementEnhanceInfos)objInst.getSkyWalkingDynamicField(); + if (cacheObject.getConnectionInfo() != null) { + ContextManager.activeSpan().errorOccurred().log(t); + } + } + + private String buildOperationName(ConnectionInfo connectionInfo, String methodName, String statementName) { + return connectionInfo.getDBType() + "/JDBI/" + statementName + "/" + methodName; + } +} diff --git a/apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/oracle/StatementExecuteMethodsInterceptor.java b/apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/oracle/StatementExecuteMethodsInterceptor.java new file mode 100644 index 000000000..df6668e39 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/oracle/StatementExecuteMethodsInterceptor.java @@ -0,0 +1,76 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.skywalking.apm.plugin.jdbc.oracle; + +import java.lang.reflect.Method; +import org.apache.skywalking.apm.agent.core.context.ContextManager; +import org.apache.skywalking.apm.agent.core.context.tag.Tags; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; +import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; +import org.apache.skywalking.apm.plugin.jdbc.define.StatementEnhanceInfos; +import org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo; + +public class StatementExecuteMethodsInterceptor implements InstanceMethodsAroundInterceptor { + @Override + public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class[] argumentsTypes, + MethodInterceptResult result) throws Throwable { + StatementEnhanceInfos cacheObject = (StatementEnhanceInfos)objInst.getSkyWalkingDynamicField(); + ConnectionInfo connectInfo = cacheObject.getConnectionInfo(); + + AbstractSpan span = ContextManager.createExitSpan(buildOperationName(connectInfo, method.getName(), cacheObject.getStatementName()), connectInfo.getDatabasePeer()); + Tags.DB_TYPE.set(span, "sql"); + Tags.DB_INSTANCE.set(span, connectInfo.getDatabaseName()); + + String sql = ""; + if (allArguments.length > 0) { + sql = (String)allArguments[0]; + } + + Tags.DB_STATEMENT.set(span, sql); + span.setComponent(connectInfo.getComponent()); + + SpanLayer.asDB(span); + } + + @Override + public final Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, + Object ret) throws Throwable { + StatementEnhanceInfos cacheObject = (StatementEnhanceInfos)objInst.getSkyWalkingDynamicField(); + if (cacheObject.getConnectionInfo() != null) { + ContextManager.stopSpan(); + } + return ret; + } + + @Override public final void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + StatementEnhanceInfos cacheObject = (StatementEnhanceInfos)objInst.getSkyWalkingDynamicField(); + if (cacheObject.getConnectionInfo() != null) { + ContextManager.activeSpan().errorOccurred().log(t); + } + } + + private String buildOperationName(ConnectionInfo connectionInfo, String methodName, String statementName) { + return connectionInfo.getDBType() + "/JDBI/" + statementName + "/" + methodName; + } +} diff --git a/apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/oracle/define/ConnectionInstrumentation.java b/apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/oracle/define/ConnectionInstrumentation.java index 7533ae68d..f4542100f 100644 --- a/apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/oracle/define/ConnectionInstrumentation.java +++ b/apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/oracle/define/ConnectionInstrumentation.java @@ -16,12 +16,10 @@ * */ - package org.apache.skywalking.apm.plugin.jdbc.oracle.define; import net.bytebuddy.description.method.MethodDescription; import net.bytebuddy.matcher.ElementMatcher; -import org.apache.skywalking.apm.agent.core.plugin.bytebuddy.ArgumentTypeNameMatch; import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; @@ -33,28 +31,23 @@ import static net.bytebuddy.matcher.ElementMatchers.named; import static net.bytebuddy.matcher.ElementMatchers.takesArguments; /** - * {@link ConnectionInstrumentation} intercept the following methods that the class which extend {@link - * oracle.jdbc.driver.PhysicalConnection}.
- * - * 1. Enhance prepareStatement by org.apache.skywalking.apm.plugin.jdbc.define.JDBCPrepareStatementInterceptor - * 2. Enhance prepareStatement that the seconds argument type is java.lang.String[] by - * oracle.jdbc.driver.JDBCPrepareStatementWithArrayInterceptor - * 3. Enhance prepareStatement that the seconds argument type is int[] by - * oracle.jdbc.driver.JDBCPrepareStatementWithArrayInterceptor - * 4. Enhance prepareCall by - * org.apache.skywalking.apm.plugin.jdbc.define.JDBCPrepareCallInterceptor - * 5. Enhance createStatement - * by org.apache.skywalking.apm.plugin.jdbc.define.JDBCStatementInterceptor - * 6. Enhance commit, rollback, close, releaseSavepoint by org.apache.skywalking.apm.plugin.jdbc.define.ConnectionServiceMethodInterceptor + * {@link ConnectionInstrumentation} define that the oracle plugin intercept the following methods that the class which + * extend {@link oracle.jdbc.driver.PhysicalConnection}.
+ *
+ * 1. Enhance prepareStatement by org.apache.skywalking.apm.plugin.jdbc.oracle.CreatePreparedStatementInterceptor
+ * 2. Enhance prepareCall by org.apache.skywalking.apm.plugin.jdbc.oracle.CreateCallableInterceptor
+ * 3. Enhance createStatement by org.apache.skywalking.apm.plugin.jdbc.oracle.CreateStatementInterceptor
+ * 4. Enhance commit, rollback, close, releaseSavepoint by org.apache.skywalking.apm.plugin.jdbc.define.ConnectionServiceMethodInterceptor
+ * 
* * @author zhangxin */ public class ConnectionInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { - private static final String PREPARE_STATEMENT_METHOD_WITH_ARRAY_INTERCEPTOR_CLASS = "oracle.jdbc.driver.JDBCPrepareStatementWithArrayInterceptor"; public static final String ENHANCE_CLASS = "oracle.jdbc.driver.PhysicalConnection"; - public static final String STRING_ARRAY_ARGUMENT_TYPE = "java.lang.String[]"; - public static final String INT_ARRAY_ARGUMENT_TYPE = "int[]"; + public static final String PREPARED_STATEMENT_INTERCEPT_CLASS = "org.apache.skywalking.apm.plugin.jdbc.oracle.CreatePreparedStatementInterceptor"; + public static final String CALLABLE_INTERCEPT_CLASS = "org.apache.skywalking.apm.plugin.jdbc.oracle.CreateCallableInterceptor"; + public static final String CREATE_STATEMENT_INTERCEPT_CLASS = "org.apache.skywalking.apm.plugin.jdbc.oracle.CreateStatementInterceptor"; @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { return new ConstructorInterceptPoint[0]; @@ -64,37 +57,11 @@ public class ConnectionInstrumentation extends ClassInstanceMethodsEnhancePlugin return new InstanceMethodsInterceptPoint[] { new InstanceMethodsInterceptPoint() { @Override public ElementMatcher getMethodsMatcher() { - return named(Constants.PREPARE_STATEMENT_METHOD_NAME).and(takesArguments(3)); + return named(Constants.PREPARE_STATEMENT_METHOD_NAME); } @Override public String getMethodsInterceptor() { - return Constants.PREPARE_STATEMENT_INTERCEPT_CLASS; - } - - @Override public boolean isOverrideArgs() { - return false; - } - }, - new InstanceMethodsInterceptPoint() { - @Override public ElementMatcher getMethodsMatcher() { - return named(Constants.PREPARE_STATEMENT_METHOD_NAME).and(ArgumentTypeNameMatch.takesArgumentWithType(1, STRING_ARRAY_ARGUMENT_TYPE)); - } - - @Override public String getMethodsInterceptor() { - return PREPARE_STATEMENT_METHOD_WITH_ARRAY_INTERCEPTOR_CLASS; - } - - @Override public boolean isOverrideArgs() { - return false; - } - }, - new InstanceMethodsInterceptPoint() { - @Override public ElementMatcher getMethodsMatcher() { - return named(Constants.PREPARE_STATEMENT_METHOD_NAME).and(ArgumentTypeNameMatch.takesArgumentWithType(1, INT_ARRAY_ARGUMENT_TYPE)); - } - - @Override public String getMethodsInterceptor() { - return PREPARE_STATEMENT_METHOD_WITH_ARRAY_INTERCEPTOR_CLASS; + return PREPARED_STATEMENT_INTERCEPT_CLASS; } @Override public boolean isOverrideArgs() { @@ -107,7 +74,7 @@ public class ConnectionInstrumentation extends ClassInstanceMethodsEnhancePlugin } @Override public String getMethodsInterceptor() { - return Constants.PREPARE_CALL_INTERCEPT_CLASS; + return CALLABLE_INTERCEPT_CLASS; } @Override public boolean isOverrideArgs() { @@ -120,7 +87,7 @@ public class ConnectionInstrumentation extends ClassInstanceMethodsEnhancePlugin } @Override public String getMethodsInterceptor() { - return Constants.CREATE_STATEMENT_INTERCEPT_CLASS; + return CREATE_STATEMENT_INTERCEPT_CLASS; } @Override public boolean isOverrideArgs() { diff --git a/apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/oracle/define/OracleCallableInstrumentation.java b/apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/oracle/define/OracleCallableInstrumentation.java new file mode 100644 index 000000000..1d0be4a5e --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/oracle/define/OracleCallableInstrumentation.java @@ -0,0 +1,70 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.skywalking.apm.plugin.jdbc.oracle.define; + +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; + +import static net.bytebuddy.matcher.ElementMatchers.named; +import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName; +import static org.apache.skywalking.apm.plugin.jdbc.oracle.Constants.PREPARED_STATEMENT_INTERCEPT_CLASS; + +/** + * {@link OracleCallableInstrumentation} define that the oracle plugin intercept the execute, executeQuery and + * executeUpdate method in {@link oracle.jdbc.driver.OracleCallableStatement} class by ${@link + * org.apache.skywalking.apm.plugin.jdbc.oracle.StatementExecuteMethodsInterceptor} + * + * @author zhangxin + */ +public class OracleCallableInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { + + public static final String ENHANCE_CLASS = "oracle.jdbc.driver.OracleCallableStatement"; + + @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[0]; + } + + @Override protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + new InstanceMethodsInterceptPoint() { + @Override public ElementMatcher getMethodsMatcher() { + return named("execute") + .or(named("executeQuery")) + .or(named("executeUpdate")); + } + + @Override public String getMethodsInterceptor() { + return PREPARED_STATEMENT_INTERCEPT_CLASS; + } + + @Override public boolean isOverrideArgs() { + return false; + } + } + }; + } + + @Override protected ClassMatch enhanceClass() { + return byName(ENHANCE_CLASS); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/oracle/define/OraclePrepareStatementInstrumentation.java b/apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/oracle/define/OraclePrepareStatementInstrumentation.java new file mode 100644 index 000000000..093ded3eb --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/oracle/define/OraclePrepareStatementInstrumentation.java @@ -0,0 +1,71 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.skywalking.apm.plugin.jdbc.oracle.define; + +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; + +import static net.bytebuddy.matcher.ElementMatchers.named; +import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName; +import static org.apache.skywalking.apm.plugin.jdbc.oracle.Constants.PREPARED_STATEMENT_INTERCEPT_CLASS; + +/** + * {@link OraclePrepareStatementInstrumentation} define that the oracle plugin intercept the execute, + * executeQuery, executeUpdate and executeLargeUpdate method in {@link oracle.jdbc.driver.OraclePreparedStatement} + * class by ${@link org.apache.skywalking.apm.plugin.jdbc.oracle.StatementExecuteMethodsInterceptor} + * + * @author zhangxin + */ +public class OraclePrepareStatementInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { + + public static final String ENHANCE_CLASS = "oracle.jdbc.driver.OraclePreparedStatement"; + + @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[0]; + } + + @Override protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + new InstanceMethodsInterceptPoint() { + @Override public ElementMatcher getMethodsMatcher() { + return named("execute") + .or(named("executeQuery")) + .or(named("executeUpdate")) + .or(named("executeLargeUpdate")); + } + + @Override public String getMethodsInterceptor() { + return PREPARED_STATEMENT_INTERCEPT_CLASS; + } + + @Override public boolean isOverrideArgs() { + return false; + } + } + }; + } + + @Override protected ClassMatch enhanceClass() { + return byName(ENHANCE_CLASS); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/oracle/define/OracleStatementInstrumentation.java b/apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/oracle/define/OracleStatementInstrumentation.java new file mode 100644 index 000000000..94c15f2c7 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/oracle/define/OracleStatementInstrumentation.java @@ -0,0 +1,74 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.skywalking.apm.plugin.jdbc.oracle.define; + +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; + +import static net.bytebuddy.matcher.ElementMatchers.named; +import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName; +import static org.apache.skywalking.apm.plugin.jdbc.oracle.Constants.STATEMENT_INTERCEPT_CLASS; + +/** + * {@link OracleStatementInstrumentation} define that the oracle plugin intercept the execute, executeQuery, + * executeUpdate and executeLargeUpdate method in {@link oracle.jdbc.driver.OracleStatement} class by ${@link + * org.apache.skywalking.apm.plugin.jdbc.oracle.StatementExecuteMethodsInterceptor} + * + * @author zhangxin + */ +public class OracleStatementInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { + + public static final String ENHANCE_CLASS = "oracle.jdbc.driver.OracleStatement"; + + @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[0]; + } + + @Override protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + new InstanceMethodsInterceptPoint() { + @Override public ElementMatcher getMethodsMatcher() { + return named("execute") + .or(named("executeQuery")) + .or(named("executeUpdate")) + .or(named("executeLargeUpdate")) + .or(named("executeBatchInternal")) + .or(named("executeUpdateInternal")) + .or(named("executeQuery")); + } + + @Override public String getMethodsInterceptor() { + return STATEMENT_INTERCEPT_CLASS; + } + + @Override public boolean isOverrideArgs() { + return false; + } + } + }; + } + + @Override protected ClassMatch enhanceClass() { + return byName(ENHANCE_CLASS); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/resources/skywalking-plugin.def b/apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/resources/skywalking-plugin.def index 3a3b19358..8b6dd1307 100644 --- a/apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/resources/skywalking-plugin.def +++ b/apm-sniffer/apm-sdk-plugin/oracle-10.x-plugin/src/main/resources/skywalking-plugin.def @@ -1,2 +1,5 @@ oracle-10.x=org.apache.skywalking.apm.plugin.jdbc.oracle.define.DriverInstrumentation oracle-10.x=org.apache.skywalking.apm.plugin.jdbc.oracle.define.ConnectionInstrumentation +oracle-10.x=org.apache.skywalking.apm.plugin.jdbc.oracle.define.OracleCallableInstrumentation +oracle-10.x=org.apache.skywalking.apm.plugin.jdbc.oracle.define.OraclePrepareStatementInstrumentation +oracle-10.x=org.apache.skywalking.apm.plugin.jdbc.oracle.define.OracleStatementInstrumentation From 0851b5612e4c27d87976af0daf14242ccf4b7819 Mon Sep 17 00:00:00 2001 From: Gao Hongtao Date: Fri, 2 Feb 2018 17:18:45 +0800 Subject: [PATCH 26/26] Update protocol --- .../src/main/resources/ui-graphql/alarm.graphqls | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/apm-protocol/apm-ui-protocol/src/main/resources/ui-graphql/alarm.graphqls b/apm-protocol/apm-ui-protocol/src/main/resources/ui-graphql/alarm.graphqls index b60d0a126..ae1461b47 100644 --- a/apm-protocol/apm-ui-protocol/src/main/resources/ui-graphql/alarm.graphqls +++ b/apm-protocol/apm-ui-protocol/src/main/resources/ui-graphql/alarm.graphqls @@ -1,6 +1,6 @@ type Alarm { items: [AlarmItem!]! - count: Int! + total: Int! } type AlarmItem { @@ -10,7 +10,7 @@ type AlarmItem { # such as: threshold, trigger value, relation(greater or lower), last time content: String! startTime: String! - alertType: AlarmType! + alarmType: AlarmType! causeType: CauseType! } @@ -26,5 +26,5 @@ enum CauseType { } extend type Query { - loadAlertList(keyword: String, alertType: AlarmType, duration:Duration!, paging: Pagination!): Alarm -} \ No newline at end of file + loadAlarmList(keyword: String, alarmType: AlarmType, duration:Duration!, paging: Pagination!): Alarm +}