parent
b86426c9a2
commit
0929ff3453
|
|
@ -112,6 +112,8 @@ public class ComponentsDefine {
|
|||
|
||||
public static final OfficialComponent LETTUCE = new OfficialComponent(57, "Lettuce");
|
||||
|
||||
public static final OfficialComponent ZOOKEEPER = new OfficialComponent(58, "Zookeeper");
|
||||
|
||||
private static ComponentsDefine INSTANCE = new ComponentsDefine();
|
||||
|
||||
private String[] components;
|
||||
|
|
@ -121,7 +123,7 @@ public class ComponentsDefine {
|
|||
}
|
||||
|
||||
public ComponentsDefine() {
|
||||
components = new String[58];
|
||||
components = new String[59];
|
||||
addComponent(TOMCAT);
|
||||
addComponent(HTTPCLIENT);
|
||||
addComponent(DUBBO);
|
||||
|
|
@ -164,6 +166,7 @@ public class ComponentsDefine {
|
|||
addComponent(GSON);
|
||||
addComponent(REDISSON);
|
||||
addComponent(LETTUCE);
|
||||
addComponent(ZOOKEEPER);
|
||||
}
|
||||
|
||||
private void addComponent(OfficialComponent component) {
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@
|
|||
<module>trace-ignore-plugin</module>
|
||||
<module>gson-2.8.x-plugin</module>
|
||||
<module>lettuce-5.x-plugin</module>
|
||||
<module>zookeeper-3.4.x-plugin</module>
|
||||
</modules>
|
||||
|
||||
<dependencies>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,45 @@
|
|||
<?xml version="1.0"?>
|
||||
<!--
|
||||
~ 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.
|
||||
~
|
||||
-->
|
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" 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">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.apache.skywalking</groupId>
|
||||
<artifactId>optional-plugins</artifactId>
|
||||
<version>6.1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>apm-zookeeper-3.4.x-plugin</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>zookeeper-3.4.x-plugin</name>
|
||||
<url>http://maven.apache.org</url>
|
||||
<properties>
|
||||
<zookeeper.version>3.4.13</zookeeper.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.zookeeper</groupId>
|
||||
<artifactId>zookeeper</artifactId>
|
||||
<version>${zookeeper.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
@ -0,0 +1,96 @@
|
|||
/*
|
||||
* 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.zookeeper;
|
||||
|
||||
import org.apache.jute.Record;
|
||||
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.logging.api.ILog;
|
||||
import org.apache.skywalking.apm.agent.core.logging.api.LogManager;
|
||||
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.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;
|
||||
import org.apache.zookeeper.client.StaticHostProvider;
|
||||
import org.apache.zookeeper.proto.RequestHeader;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author zhaoyuguang
|
||||
*/
|
||||
public class ClientCnxnInterceptor implements InstanceMethodsAroundInterceptor, InstanceConstructorInterceptor {
|
||||
|
||||
private static final ILog logger = LogManager.getLogger(ClientCnxnInterceptor.class);
|
||||
|
||||
@Override
|
||||
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
|
||||
MethodInterceptResult result) throws Throwable {
|
||||
String peer = (String) objInst.getSkyWalkingDynamicField();
|
||||
RequestHeader header = (RequestHeader) allArguments[0];
|
||||
String operationName = ZooOpt.getOperationName(header.getType());
|
||||
AbstractSpan span = ContextManager.createExitSpan("Zookeeper/" + operationName, peer);
|
||||
span.setComponent(ComponentsDefine.ZOOKEEPER);
|
||||
Tags.DB_TYPE.set(span, "Zookeeper");
|
||||
ZooOpt.setTags(span, (Record) allArguments[2]);
|
||||
SpanLayer.asCache(span);
|
||||
}
|
||||
|
||||
@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) {
|
||||
AbstractSpan span = ContextManager.activeSpan();
|
||||
span.errorOccurred();
|
||||
span.log(t);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConstruct(EnhancedInstance objInst, Object[] allArguments) {
|
||||
StaticHostProvider hostProvider = (StaticHostProvider) allArguments[1];
|
||||
try {
|
||||
Field field = StaticHostProvider.class.getDeclaredField("serverAddresses");
|
||||
field.setAccessible(true);
|
||||
@SuppressWarnings("unchecked")
|
||||
List<InetSocketAddress> serverAddresses = (List<InetSocketAddress>) field.get(hostProvider);
|
||||
StringBuilder peer = new StringBuilder();
|
||||
for (InetSocketAddress address : serverAddresses) {
|
||||
peer.append(address.getHostName()).append(":").append(address.getPort()).append(";");
|
||||
}
|
||||
objInst.setSkyWalkingDynamicField(peer.toString());
|
||||
} catch (NoSuchFieldException e) {
|
||||
logger.warn("NoSuchFieldException, not be compatible with this version of zookeeper", e);
|
||||
} catch (IllegalAccessException e) {
|
||||
logger.warn("IllegalAccessException, not be compatible with this version of zookeeper", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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.zookeeper;
|
||||
|
||||
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;
|
||||
import org.apache.skywalking.apm.network.trace.component.ComponentsDefine;
|
||||
import org.apache.zookeeper.WatchedEvent;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
* @author zhaoyuguang
|
||||
*/
|
||||
public class EventThreadMethodInterceptor implements InstanceMethodsAroundInterceptor {
|
||||
|
||||
@Override
|
||||
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
|
||||
MethodInterceptResult result) throws Throwable {
|
||||
if (isWatchedEvent(allArguments[0])) {
|
||||
Field field = allArguments[0].getClass().getDeclaredField("event");
|
||||
field.setAccessible(true);
|
||||
WatchedEvent event = (WatchedEvent) field.get(allArguments[0]);
|
||||
AbstractSpan span = ContextManager.createEntrySpan("Zookeeper/WatchedEvent/" + event.getType().name(), null);
|
||||
ZooOpt.setTags(span, event);
|
||||
span.setComponent(ComponentsDefine.ZOOKEEPER);
|
||||
Tags.DB_TYPE.set(span, "Zookeeper");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments,
|
||||
Class<?>[] argumentsTypes, Object ret) throws Throwable {
|
||||
if (isWatchedEvent(allArguments[0])) {
|
||||
ContextManager.stopSpan();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments,
|
||||
Class<?>[] argumentsTypes, Throwable t) {
|
||||
if (isWatchedEvent(allArguments[0])) {
|
||||
ContextManager.activeSpan().errorOccurred().log(t);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isWatchedEvent(Object event) {
|
||||
return event != null && "org.apache.zookeeper.ClientCnxn$WatcherSetEventPair".equals(event.getClass().getName());
|
||||
}
|
||||
}
|
||||
|
|
@ -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.zookeeper;
|
||||
|
||||
import org.apache.jute.Record;
|
||||
import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan;
|
||||
import org.apache.zookeeper.WatchedEvent;
|
||||
import org.apache.zookeeper.ZooDefs;
|
||||
import org.apache.zookeeper.proto.*;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author zhaoyuguang
|
||||
*/
|
||||
class ZooOpt {
|
||||
|
||||
private static final Map<Integer, String> OPTS = new HashMap<Integer, String>();
|
||||
private static final String PATH = "path";
|
||||
private static final String VERSION = "version";
|
||||
private static final String WATCH = "watch";
|
||||
private static final String MAX_CHILDREN = "max";
|
||||
private static final String KEEPER_STATE = "state";
|
||||
|
||||
static {
|
||||
OPTS.put(ZooDefs.OpCode.notification, "notification");
|
||||
OPTS.put(ZooDefs.OpCode.create, "create");
|
||||
OPTS.put(ZooDefs.OpCode.delete, "delete");
|
||||
OPTS.put(ZooDefs.OpCode.exists, "exists");
|
||||
OPTS.put(ZooDefs.OpCode.getData, "getData");
|
||||
OPTS.put(ZooDefs.OpCode.setData, "setData");
|
||||
OPTS.put(ZooDefs.OpCode.getACL, "getACL");
|
||||
OPTS.put(ZooDefs.OpCode.setACL, "setACL");
|
||||
OPTS.put(ZooDefs.OpCode.getChildren, "getChildren");
|
||||
OPTS.put(ZooDefs.OpCode.sync, "sync");
|
||||
OPTS.put(ZooDefs.OpCode.ping, "ping");
|
||||
OPTS.put(ZooDefs.OpCode.getChildren2, "getChildren2");
|
||||
OPTS.put(ZooDefs.OpCode.check, "check");
|
||||
OPTS.put(ZooDefs.OpCode.multi, "multi");
|
||||
OPTS.put(ZooDefs.OpCode.auth, "auth");
|
||||
OPTS.put(ZooDefs.OpCode.setWatches, "setWatches");
|
||||
OPTS.put(ZooDefs.OpCode.sasl, "sasl");
|
||||
OPTS.put(ZooDefs.OpCode.createSession, "createSession");
|
||||
OPTS.put(ZooDefs.OpCode.closeSession, "closeSession");
|
||||
OPTS.put(ZooDefs.OpCode.error, "error");
|
||||
}
|
||||
|
||||
static String getOperationName(Integer opCode) {
|
||||
String operationName = OPTS.get(opCode);
|
||||
return operationName == null ? "unknown" : operationName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the tag attribute only for the implementation of the Request suffix
|
||||
* except ConnectRequest.class because no very important attributes
|
||||
* except GetSASLRequest.class because no very important attributes
|
||||
* except SetSASLRequest.class because no very important attributes
|
||||
*
|
||||
* @param span SkyWalking AbstractSpan.class
|
||||
* @param record Zookeeper Record.class
|
||||
*/
|
||||
static void setTags(AbstractSpan span, Record record) {
|
||||
if (record instanceof CheckVersionRequest) {
|
||||
CheckVersionRequest recordImpl = (CheckVersionRequest) record;
|
||||
span.tag(PATH, recordImpl.getPath());
|
||||
} else if (record instanceof CreateRequest) {
|
||||
CreateRequest recordImpl = (CreateRequest) record;
|
||||
span.tag(PATH, recordImpl.getPath());
|
||||
} else if (record instanceof DeleteRequest) {
|
||||
DeleteRequest recordImpl = (DeleteRequest) record;
|
||||
span.tag(PATH, recordImpl.getPath());
|
||||
span.tag(VERSION, String.valueOf(recordImpl.getVersion()));
|
||||
} else if (record instanceof ExistsRequest) {
|
||||
ExistsRequest recordImpl = (ExistsRequest) record;
|
||||
span.tag(PATH, recordImpl.getPath());
|
||||
span.tag(WATCH, String.valueOf(recordImpl.getWatch()));
|
||||
} else if (record instanceof GetACLRequest) {
|
||||
GetACLRequest recordImpl = (GetACLRequest) record;
|
||||
span.tag(PATH, recordImpl.getPath());
|
||||
} else if (record instanceof GetChildren2Request) {
|
||||
GetChildren2Request recordImpl = (GetChildren2Request) record;
|
||||
span.tag(PATH, recordImpl.getPath());
|
||||
span.tag(WATCH, String.valueOf(recordImpl.getWatch()));
|
||||
} else if (record instanceof GetChildrenRequest) {
|
||||
GetChildrenRequest recordImpl = (GetChildrenRequest) record;
|
||||
span.tag(PATH, recordImpl.getPath());
|
||||
span.tag(WATCH, String.valueOf(recordImpl.getWatch()));
|
||||
} else if (record instanceof GetDataRequest) {
|
||||
GetDataRequest recordImpl = (GetDataRequest) record;
|
||||
span.tag(PATH, recordImpl.getPath());
|
||||
span.tag(WATCH, String.valueOf(recordImpl.getWatch()));
|
||||
} else if (record instanceof GetMaxChildrenRequest) {
|
||||
GetMaxChildrenRequest recordImpl = (GetMaxChildrenRequest) record;
|
||||
span.tag(PATH, recordImpl.getPath());
|
||||
} else if (record instanceof SetACLRequest) {
|
||||
SetACLRequest recordImpl = (SetACLRequest) record;
|
||||
span.tag(PATH, recordImpl.getPath());
|
||||
span.tag(VERSION, String.valueOf(recordImpl.getVersion()));
|
||||
} else if (record instanceof SetDataRequest) {
|
||||
SetDataRequest recordImpl = (SetDataRequest) record;
|
||||
span.tag(PATH, recordImpl.getPath());
|
||||
span.tag(VERSION, String.valueOf(recordImpl.getVersion()));
|
||||
} else if (record instanceof SetMaxChildrenRequest) {
|
||||
SetMaxChildrenRequest recordImpl = (SetMaxChildrenRequest) record;
|
||||
span.tag(PATH, recordImpl.getPath());
|
||||
span.tag(MAX_CHILDREN, String.valueOf(recordImpl.getMax()));
|
||||
} else if (record instanceof SyncRequest) {
|
||||
SyncRequest recordImpl = (SyncRequest) record;
|
||||
span.tag(PATH, recordImpl.getPath());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the necessary tags for the WatchedEvent
|
||||
*
|
||||
* @param span SkyWalking AbstractSpan.class
|
||||
* @param event Zookeeper WatchedEvent.class
|
||||
*/
|
||||
static void setTags(AbstractSpan span, WatchedEvent event) {
|
||||
span.tag(PATH, event.getPath());
|
||||
span.tag(KEEPER_STATE, event.getState().name());
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,88 @@
|
|||
/*
|
||||
* 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.zookeeper.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 net.bytebuddy.matcher.ElementMatchers.takesArguments;
|
||||
import static org.apache.skywalking.apm.agent.core.plugin.bytebuddy.ArgumentTypeNameMatch.takesArgumentWithType;
|
||||
import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName;
|
||||
|
||||
/**
|
||||
* @author zhaoyuguang
|
||||
*/
|
||||
public class ClientCnxnInstrumentation extends ClassInstanceMethodsEnhancePluginDefine {
|
||||
|
||||
private static final String ENHANCE_CLASS = "org.apache.zookeeper.ClientCnxn";
|
||||
|
||||
private static final String CLIENT_CNXN_INTERCEPTOR = "org.apache.skywalking.apm.plugin.zookeeper.ClientCnxnInterceptor";
|
||||
|
||||
@Override
|
||||
protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() {
|
||||
return new ConstructorInterceptPoint[] {
|
||||
new ConstructorInterceptPoint() {
|
||||
@Override
|
||||
public ElementMatcher<MethodDescription> getConstructorMatcher() {
|
||||
return takesArguments(9);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getConstructorInterceptor() {
|
||||
return CLIENT_CNXN_INTERCEPTOR;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
|
||||
return new InstanceMethodsInterceptPoint[]{
|
||||
new InstanceMethodsInterceptPoint() {
|
||||
@Override
|
||||
public ElementMatcher<MethodDescription> getMethodsMatcher() {
|
||||
return named("queuePacket")
|
||||
.and(takesArgumentWithType(0,"org.apache.zookeeper.proto.RequestHeader"))
|
||||
.and(takesArgumentWithType(2,"org.apache.jute.Record"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodsInterceptor() {
|
||||
return CLIENT_CNXN_INTERCEPTOR;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOverrideArgs() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClassMatch enhanceClass() {
|
||||
return byName(ENHANCE_CLASS);
|
||||
}
|
||||
}
|
||||
|
|
@ -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.zookeeper.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;
|
||||
|
||||
/**
|
||||
* @author zhaoyuguang
|
||||
*/
|
||||
public class EventThreadInstrumentation extends ClassInstanceMethodsEnhancePluginDefine {
|
||||
|
||||
private static final String ENHANCE_CLASS = "org.apache.zookeeper.ClientCnxn$EventThread";
|
||||
|
||||
private static final String EVENT_THREAD_METHOD_INTERCEPTOR = "org.apache.skywalking.apm.plugin.zookeeper.EventThreadMethodInterceptor";
|
||||
|
||||
@Override
|
||||
protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() {
|
||||
return new ConstructorInterceptPoint[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
|
||||
return new InstanceMethodsInterceptPoint[]{
|
||||
new InstanceMethodsInterceptPoint() {
|
||||
@Override
|
||||
public ElementMatcher<MethodDescription> getMethodsMatcher() {
|
||||
return named("processEvent").and(takesArgumentWithType(0,"java.lang.Object"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodsInterceptor() {
|
||||
return EVENT_THREAD_METHOD_INTERCEPTOR;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOverrideArgs() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClassMatch enhanceClass() {
|
||||
return byName(ENHANCE_CLASS);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
# 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.
|
||||
|
||||
zookeeper-3.4.x=org.apache.skywalking.apm.plugin.zookeeper.define.ClientCnxnInstrumentation
|
||||
zookeeper-3.4.x=org.apache.skywalking.apm.plugin.zookeeper.define.EventThreadInstrumentation
|
||||
|
|
@ -0,0 +1,114 @@
|
|||
/*
|
||||
* 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.zookeeper;
|
||||
|
||||
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.util.TagValuePair;
|
||||
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.SegmentStorage;
|
||||
import org.apache.skywalking.apm.agent.test.tools.SegmentStoragePoint;
|
||||
import org.apache.skywalking.apm.agent.test.tools.TracingSegmentRunner;
|
||||
import org.apache.zookeeper.client.StaticHostProvider;
|
||||
import org.apache.zookeeper.proto.CreateRequest;
|
||||
import org.apache.zookeeper.proto.RequestHeader;
|
||||
import org.hamcrest.CoreMatchers;
|
||||
import org.hamcrest.MatcherAssert;
|
||||
import org.hamcrest.core.Is;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
import org.powermock.modules.junit4.PowerMockRunnerDelegate;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
/**
|
||||
* @author zhaoyuguang
|
||||
*/
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PowerMockRunnerDelegate(TracingSegmentRunner.class)
|
||||
public class ClientCnxnInterceptorTest {
|
||||
|
||||
@SegmentStoragePoint
|
||||
private SegmentStorage segmentStorage;
|
||||
|
||||
@Rule
|
||||
public AgentServiceRule serviceRule = new AgentServiceRule();
|
||||
|
||||
@Mock
|
||||
private MockInstance instance;
|
||||
|
||||
private ClientCnxnInterceptor interceptor;
|
||||
|
||||
private class MockInstance implements EnhancedInstance {
|
||||
private Object object;
|
||||
|
||||
@Override
|
||||
public Object getSkyWalkingDynamicField() {
|
||||
return object;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSkyWalkingDynamicField(Object value) {
|
||||
this.object = value;
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
instance = new MockInstance();
|
||||
interceptor = new ClientCnxnInterceptor();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInterceptor() throws Throwable {
|
||||
InetSocketAddress address = new InetSocketAddress("localhost", 2800);
|
||||
List<InetSocketAddress> serverAddresses = new ArrayList<InetSocketAddress>();
|
||||
serverAddresses.add(address);
|
||||
StaticHostProvider provider = new StaticHostProvider(serverAddresses);
|
||||
interceptor.onConstruct(instance, new Object[]{null, provider});
|
||||
RequestHeader header = new RequestHeader(1, 1);
|
||||
CreateRequest createRequest = new CreateRequest("/path", null, null, 0);
|
||||
interceptor.beforeMethod(instance, null, new Object[]{header, null, createRequest}, null, null);
|
||||
interceptor.afterMethod(instance, null, null, null, null);
|
||||
MatcherAssert.assertThat((String) instance.getSkyWalkingDynamicField(), Is.is("localhost:2800;"));
|
||||
TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
|
||||
List<AbstractTracingSpan> spans = SegmentHelper.getSpans(traceSegment);
|
||||
assertThat(spans.size(), is(1));
|
||||
assertThat(spans.get(0).getOperationName(), is("Zookeeper/create"));
|
||||
assertThat(spans.get(0).isExit(), is(true));
|
||||
assertThat(SpanHelper.getComponentId(spans.get(0)), is(58));
|
||||
List<TagValuePair> tags = SpanHelper.getTags(spans.get(0));
|
||||
assertThat(tags.get(0).getValue(), is("Zookeeper"));
|
||||
assertThat(SpanHelper.getLayer(spans.get(0)), CoreMatchers.is(SpanLayer.CACHE));
|
||||
}
|
||||
}
|
||||
|
|
@ -201,6 +201,9 @@ Redisson:
|
|||
Lettuce:
|
||||
id: 57
|
||||
languages: Java
|
||||
Zookeeper:
|
||||
id: 58
|
||||
languages: Java
|
||||
|
||||
|
||||
# .NET/.NET Core components
|
||||
|
|
@ -287,6 +290,7 @@ Component-Server-Mappings:
|
|||
Jedis: Redis
|
||||
Redisson: Redis
|
||||
Lettuce: Redis
|
||||
Zookeeper: Zookeeper
|
||||
StackExchange.Redis: Redis
|
||||
SqlClient: SqlServer
|
||||
Npgsql: PostgreSQL
|
||||
|
|
|
|||
|
|
@ -57,6 +57,7 @@ Component-Server-Mappings:
|
|||
StackExchange.Redis: Redis
|
||||
Redisson: Redis
|
||||
Lettuce: Redis
|
||||
Zookeeper: Zookeeper
|
||||
SqlClient: SqlServer
|
||||
Npgsql: PostgreSQL
|
||||
MySqlConnector: Mysql
|
||||
|
|
|
|||
|
|
@ -88,6 +88,7 @@ Now, we have the following known optional plugins.
|
|||
* [Filter traces through specified endpoint name patterns](agent-optional-plugins/trace-ignore-plugin.md)
|
||||
* Gson serialization lib in optional plugin folder
|
||||
* Lettuce 5.x(JRE1.8+) in optional plugin folder
|
||||
* Zookeeper 3.4.x in optional plugin folder. The reason of being optional plugin is, many business irrelevant traces are generated, which cause extra payload to agents and backends. At the same time, those traces may be just heartbeat(s).
|
||||
|
||||
## Advanced Features
|
||||
* Set the settings through system properties for config file override. Read [setting override](Setting-override.md).
|
||||
|
|
|
|||
|
|
@ -50,6 +50,8 @@
|
|||
* [transport-client](https://github.com/elastic/elasticsearch/tree/master/client/transport) 5.2.x-5.6.x
|
||||
* Service Discovery
|
||||
* [Netflix Eureka](https://github.com/Netflix/eureka)
|
||||
* Distributed Coordination
|
||||
* [Zookeeper](https://github.com/apache/zookeeper) 3.4.x (Optional² & Except 3.4.4)
|
||||
* Spring Ecosystem
|
||||
* Spring Bean annotations(@Bean, @Service, @Component, @Repository) 3.x and 4.x (Optional²)
|
||||
* Spring Core Async SuccessCallback/FailureCallback/ListenableFutureCallback 4.x
|
||||
|
|
|
|||
|
|
@ -57,6 +57,7 @@ Component-Server-Mappings:
|
|||
StackExchange.Redis: Redis
|
||||
Redisson: Redis
|
||||
Lettuce: Redis
|
||||
Zookeeper: Zookeeper
|
||||
SqlClient: SqlServer
|
||||
Npgsql: PostgreSQL
|
||||
MySqlConnector: Mysql
|
||||
|
|
|
|||
|
|
@ -183,6 +183,9 @@ Redisson:
|
|||
Lettuce:
|
||||
id: 57
|
||||
languages: Java
|
||||
Zookeeper:
|
||||
id: 58
|
||||
languages: Java
|
||||
|
||||
# .NET/.NET Core components
|
||||
# [3000, 4000) for C#/.NET only
|
||||
|
|
@ -266,6 +269,7 @@ Component-Server-Mappings:
|
|||
Jedis: Redis
|
||||
Redisson: Redis
|
||||
Lettuce: Redis
|
||||
Zookeeper: Zookeeper
|
||||
StackExchange.Redis: Redis
|
||||
SqlClient: SqlServer
|
||||
Npgsql: PostgreSQL
|
||||
|
|
|
|||
|
|
@ -201,6 +201,9 @@ Redisson:
|
|||
Lettuce:
|
||||
id: 57
|
||||
languages: Java
|
||||
Zookeeper:
|
||||
id: 58
|
||||
languages: Java
|
||||
|
||||
|
||||
# .NET/.NET Core components
|
||||
|
|
@ -288,6 +291,7 @@ Component-Server-Mappings:
|
|||
StackExchange.Redis: Redis
|
||||
Redisson: Redis
|
||||
Lettuce: Redis
|
||||
Zookeeper: Zookeeper
|
||||
SqlClient: SqlServer
|
||||
Npgsql: PostgreSQL
|
||||
MySqlConnector: Mysql
|
||||
|
|
|
|||
Loading…
Reference in New Issue