提交 bb0b3d36 编写于 作者: S stone.wlg 提交者: wu-sheng

provide cassandra java driver 3.x plugin (#3410)

* add cassandra java driver 3.x plugin
上级 919988fa
...@@ -132,4 +132,6 @@ public class ComponentsDefine { ...@@ -132,4 +132,6 @@ public class ComponentsDefine {
public static final OfficialComponent PLAY = new OfficialComponent(68, "Play"); public static final OfficialComponent PLAY = new OfficialComponent(68, "Play");
public static final OfficialComponent CASSANDRA_JAVA_DRIVER = new OfficialComponent(69, "cassandra-java-driver");
} }
<!--
~ 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">
<parent>
<artifactId>apm-sdk-plugin</artifactId>
<groupId>org.apache.skywalking</groupId>
<version>6.5.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>apm-cassandra-java-driver-3.x-plugin</artifactId>
<name>apm-cassandra-java-driver-3.x-plugin</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<cassandra.version>3.7.2</cassandra.version>
</properties>
<dependencies>
<dependency>
<groupId>com.datastax.cassandra</groupId>
<artifactId>cassandra-driver-core</artifactId>
<version>${cassandra.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
\ No newline at end of file
/*
* 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.cassandra.java.driver.v3;
import org.apache.skywalking.apm.agent.core.context.ContextManager;
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 java.lang.reflect.Method;
/**
* @author stone.wlg
*/
public class ClusterConnectInterceptor 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) {
String keyspace = allArguments.length > 0 ? (String) allArguments[0] : null;
ConnectionInfo connectionInfo = (ConnectionInfo) objInst.getSkyWalkingDynamicField();
connectionInfo.setKeyspace(keyspace);
((EnhancedInstance) ret).setSkyWalkingDynamicField(connectionInfo);
}
return ret;
}
@Override
public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, Throwable t) {
if (ContextManager.isActive()) {
AbstractSpan span = ContextManager.activeSpan();
span.errorOccurred();
span.log(t);
}
}
}
/*
* 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.cassandra.java.driver.v3;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor;
import java.net.InetSocketAddress;
import java.util.List;
/**
* @author stone.wlg
*/
public class ClusterConstructorWithStateListenerArgInterceptor implements InstanceConstructorInterceptor {
@Override
public void onConstruct(EnhancedInstance objInst, Object[] allArguments) {
List<InetSocketAddress> inetSocketAddresses = (List<InetSocketAddress>) allArguments[1];
StringBuilder hosts = new StringBuilder();
for (InetSocketAddress inetSocketAddress : inetSocketAddresses) {
hosts.append(inetSocketAddress.getHostName() + ":" + inetSocketAddress.getPort() + ",");
}
String contactPoints = hosts.toString();
if (contactPoints.length() > 0) {
contactPoints = contactPoints.substring(0, contactPoints.length() - 1);
}
objInst.setSkyWalkingDynamicField(
new ConnectionInfo(contactPoints)
);
}
}
/*
* 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.cassandra.java.driver.v3;
/**
* @author stone.wlg
*/
public class ConnectionInfo {
private final String contactPoints;
private String keyspace;
public ConnectionInfo(final String contactPoints) {
this.contactPoints = contactPoints;
}
public String getKeyspace() {
return this.keyspace;
}
public void setKeyspace(String keyspace) {
this.keyspace = keyspace;
}
public String getContactPoints() {
return this.contactPoints;
}
}
/*
* 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.cassandra.java.driver.v3;
/**
* @author stone.wlg
*/
public class Constants {
public static final String CASSANDRA_OP_PREFIX = "Cassandra/";
public static final String CASSANDRA_DB_TYPE = "cassandra";
}
/*
* 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.cassandra.java.driver.v3;
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;
import java.lang.reflect.Method;
/**
* @author stone.wlg
*/
public class DefaultResultSetFutureGetUninterruptiblyInterceptor implements InstanceMethodsAroundInterceptor {
@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable {
AbstractSpan span = ContextManager.createLocalSpan(Constants.CASSANDRA_OP_PREFIX + method.getName());
span.setComponent(ComponentsDefine.CASSANDRA_JAVA_DRIVER);
Tags.DB_TYPE.set(span, Constants.CASSANDRA_DB_TYPE);
SpanLayer.asDB(span);
}
@Override
public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, Object ret) throws Throwable {
if (ContextManager.isActive()) {
ContextManager.stopSpan();
}
return ret;
}
@Override
public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, Throwable t) {
if (ContextManager.isActive()) {
AbstractSpan span = ContextManager.activeSpan();
span.errorOccurred();
span.log(t);
}
}
}
/*
* 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.cassandra.java.driver.v3;
import com.datastax.driver.core.BoundStatement;
import com.datastax.driver.core.Statement;
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;
import java.lang.reflect.Method;
/**
* @author stone.wlg
*/
public class SessionManagerExecuteAndExecuteAsyncWithStatementArgInterceptor implements InstanceMethodsAroundInterceptor {
@Override
public final void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments,
Class<?>[] argumentsTypes,
MethodInterceptResult result) throws Throwable {
ConnectionInfo connectionInfo = (ConnectionInfo) objInst.getSkyWalkingDynamicField();
if (connectionInfo == null) {
return;
}
Statement statement = (Statement) allArguments[0];
String remotePeer = statement.getHost() == null ? connectionInfo.getContactPoints() : (statement.getHost().getSocketAddress().getHostName() + ":" + statement.getHost().getSocketAddress().getPort());
String keyspace = statement.getKeyspace() == null ? connectionInfo.getKeyspace() : statement.getKeyspace();
String query = statement.toString();
if (statement instanceof BoundStatement) {
query = ((BoundStatement) statement).preparedStatement().getQueryString();
}
AbstractSpan span = ContextManager.createExitSpan(Constants.CASSANDRA_OP_PREFIX + method.getName(), remotePeer);
span.setComponent(ComponentsDefine.CASSANDRA_JAVA_DRIVER);
Tags.DB_TYPE.set(span, Constants.CASSANDRA_DB_TYPE);
Tags.DB_INSTANCE.set(span, keyspace);
Tags.DB_STATEMENT.set(span, query);
SpanLayer.asDB(span);
}
@Override
public final Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments,
Class<?>[] argumentsTypes,
Object ret) throws Throwable {
ConnectionInfo connectionInfo = (ConnectionInfo) objInst.getSkyWalkingDynamicField();
if (connectionInfo != null && ContextManager.isActive()) {
ContextManager.stopSpan();
}
return ret;
}
@Override
public final void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments,
Class<?>[] argumentsTypes, Throwable t) {
if (ContextManager.isActive()) {
AbstractSpan span = ContextManager.activeSpan();
span.errorOccurred();
span.log(t);
}
}
}
/*
* 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.cassandra.java.driver.v3.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.match.NameMatch.byName;
/**
* @author stone.wlg
*/
public class ClusterInstrumentation extends ClassInstanceMethodsEnhancePluginDefine {
private static final String ENHANCE_CLASS = "com.datastax.driver.core.Cluster";
private static final String CONSTRUCTOR_INTERCEPT_CLASS = "org.apache.skywalking.apm.plugin.cassandra.java.driver.v3.ClusterConstructorWithStateListenerArgInterceptor";
private static final String METHODS_INTERCEPT_CLASS = "org.apache.skywalking.apm.plugin.cassandra.java.driver.v3.ClusterConnectInterceptor";
@Override
protected ClassMatch enhanceClass() {
return byName(ENHANCE_CLASS);
}
@Override
public ConstructorInterceptPoint[] getConstructorsInterceptPoints() {
return new ConstructorInterceptPoint[]{
new ConstructorInterceptPoint() {
@Override
public ElementMatcher<MethodDescription> getConstructorMatcher() {
return takesArguments(4);
}
@Override
public String getConstructorInterceptor() {
return CONSTRUCTOR_INTERCEPT_CLASS;
}
}
};
}
@Override
public InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
return new InstanceMethodsInterceptPoint[]{
new InstanceMethodsInterceptPoint() {
@Override
public ElementMatcher<MethodDescription> getMethodsMatcher() {
return named("connect");
}
@Override
public String getMethodsInterceptor() {
return METHODS_INTERCEPT_CLASS;
}
@Override
public boolean isOverrideArgs() {
return false;
}
}
};
}
}
/*
* 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.cassandra.java.driver.v3.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;
/**
* @author stone.wlg
*/
public class DefaultResultSetFutureInstrumentation extends ClassInstanceMethodsEnhancePluginDefine {
private static final String ENHANCE_CLASS = "com.datastax.driver.core.DefaultResultSetFuture";
private static final String METHODS_INTERCEPT_CLASS = "org.apache.skywalking.apm.plugin.cassandra.java.driver.v3.DefaultResultSetFutureGetUninterruptiblyInterceptor";
@Override
protected ClassMatch enhanceClass() {
return byName(ENHANCE_CLASS);
}
@Override
public ConstructorInterceptPoint[] getConstructorsInterceptPoints() {
return null;
}
@Override
public InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
return new InstanceMethodsInterceptPoint[]{
new InstanceMethodsInterceptPoint() {
@Override
public ElementMatcher<MethodDescription> getMethodsMatcher() {
return named("getUninterruptibly");
}
@Override
public String getMethodsInterceptor() {
return METHODS_INTERCEPT_CLASS;
}
@Override
public boolean isOverrideArgs() {
return false;
}
}
};
}
}
/*
* 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.cassandra.java.driver.v3.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 stone.wlg
*/
public class SessionManagerInstrumentation extends ClassInstanceMethodsEnhancePluginDefine {
private static final String ENHANCE_CLASS = "com.datastax.driver.core.SessionManager";
private static final String METHODS_INTERCEPT_CLASS = "org.apache.skywalking.apm.plugin.cassandra.java.driver.v3.SessionManagerExecuteAndExecuteAsyncWithStatementArgInterceptor";
@Override
protected ClassMatch enhanceClass() {
return byName(ENHANCE_CLASS);
}
@Override
public ConstructorInterceptPoint[] getConstructorsInterceptPoints() {
return null;
}
@Override
public InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
return new InstanceMethodsInterceptPoint[]{
new InstanceMethodsInterceptPoint() {
@Override
public ElementMatcher<MethodDescription> getMethodsMatcher() {
return named("execute").and(takesArgumentWithType(0, "com.datastax.driver.core.Statement"))
.or(named("executeAsync").and(takesArgumentWithType(0, "com.datastax.driver.core.Statement")));
}
@Override
public String getMethodsInterceptor() {
return METHODS_INTERCEPT_CLASS;
}
@Override
public boolean isOverrideArgs() {
return false;
}
}
};
}
}
# 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.
cassandra-java-driver-3.x=org.apache.skywalking.apm.plugin.cassandra.java.driver.v3.define.ClusterInstrumentation
cassandra-java-driver-3.x=org.apache.skywalking.apm.plugin.cassandra.java.driver.v3.define.SessionManagerInstrumentation
cassandra-java-driver-3.x=org.apache.skywalking.apm.plugin.cassandra.java.driver.v3.define.DefaultResultSetFutureInstrumentation
/*
* 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.cassandra.java.driver.v3;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
import org.hamcrest.core.Is;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.powermock.modules.junit4.PowerMockRunner;
import java.lang.reflect.Method;
/**
* @author stone.wlg
*/
@RunWith(PowerMockRunner.class)
public class ClusterConnectInterceptorTest {
private ClusterConnectInterceptor interceptor;
private EnhancedInstance enhancedInstance = new EnhancedInstance() {
private ConnectionInfo connectionInfo = new ConnectionInfo("localhost:9042");
@Override
public Object getSkyWalkingDynamicField() {
return connectionInfo;
}
@Override
public void setSkyWalkingDynamicField(Object value) {
this.connectionInfo = (ConnectionInfo) value;
}
};
@Mock
private Method method;
@Before
public void setUp() throws Exception {
interceptor = new ClusterConnectInterceptor();
}
@Test
public void afterMethod() throws Throwable {
EnhancedInstance ret = (EnhancedInstance) interceptor.afterMethod(enhancedInstance, method, new Object[]{"test"}, null, enhancedInstance);
ConnectionInfo connectionInfo = (ConnectionInfo) ret.getSkyWalkingDynamicField();
Assert.assertThat(connectionInfo.getKeyspace(), Is.is("test"));
}
}
\ No newline at end of file
/*
* 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.cassandra.java.driver.v3;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
import org.hamcrest.core.Is;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.powermock.modules.junit4.PowerMockRunner;
import java.net.InetSocketAddress;
import java.util.ArrayList;
import java.util.List;
/**
* @author stone.wlg
*/
@RunWith(PowerMockRunner.class)
public class ClusterConstructorWithStateListenerArgInterceptorTest {
@Mock
private ClusterConstructorWithStateListenerArgInterceptor interceptor;
@Mock
private EnhancedInstance enhancedInstance = new EnhancedInstance() {
private ConnectionInfo connectionInfo;
@Override
public Object getSkyWalkingDynamicField() {
return connectionInfo;
}
@Override
public void setSkyWalkingDynamicField(Object value) {
this.connectionInfo = (ConnectionInfo) value;
}
};
private List<InetSocketAddress> inetSocketAddresses;
@Before
public void setUp() throws Exception {
interceptor = new ClusterConstructorWithStateListenerArgInterceptor();
inetSocketAddresses = new ArrayList<InetSocketAddress>();
inetSocketAddresses.add(new InetSocketAddress("172.20.0.2", 9042));
}
@Test
public void onConstruct() {
interceptor.onConstruct(enhancedInstance, new Object[]{"cluster-name", inetSocketAddresses});
ConnectionInfo connectionInfo = (ConnectionInfo) enhancedInstance.getSkyWalkingDynamicField();
Assert.assertThat(connectionInfo.getContactPoints(), Is.is("172.20.0.2:9042"));
}
}
\ No newline at end of file
/*
* 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.cassandra.java.driver.v3;
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.*;
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.lang.reflect.Method;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.powermock.api.mockito.PowerMockito.when;
/**
* @author stone.wlg
*/
@RunWith(PowerMockRunner.class)
@PowerMockRunnerDelegate(TracingSegmentRunner.class)
public class DefaultResultSetFutureGetUninterruptiblyInterceptorTest {
@Rule
public AgentServiceRule serviceRule = new AgentServiceRule();
@SegmentStoragePoint
private SegmentStorage segmentStorage;
private DefaultResultSetFutureGetUninterruptiblyInterceptor interceptor;
@Mock
private EnhancedInstance objectInstance;
@Mock
private Method method;
@Before
public void setUp() throws Exception {
interceptor = new DefaultResultSetFutureGetUninterruptiblyInterceptor();
when(method.getName()).thenReturn("executeAsync");
}
@Test
public void testCreateLocalSpan() throws Throwable {
interceptor.beforeMethod(objectInstance, method, null, null, null);
interceptor.afterMethod(objectInstance, method, null, null, null);
assertThat(segmentStorage.getTraceSegments().size(), is(1));
TraceSegment segment = segmentStorage.getTraceSegments().get(0);
assertThat(SegmentHelper.getSpans(segment).size(), is(1));
AbstractTracingSpan span = SegmentHelper.getSpans(segment).get(0);
SpanAssert.assertLayer(span, SpanLayer.DB);
assertThat(span.getOperationName(), is(Constants.CASSANDRA_OP_PREFIX));
SpanAssert.assertTag(span, 0, Constants.CASSANDRA_DB_TYPE);
}
}
\ No newline at end of file
/*
* 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.cassandra.java.driver.v3;
import com.datastax.driver.core.SimpleStatement;
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.*;
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.lang.reflect.Method;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.powermock.api.mockito.PowerMockito.when;
/**
* @author stone.wlg
*/
@RunWith(PowerMockRunner.class)
@PowerMockRunnerDelegate(TracingSegmentRunner.class)
public class SessionManagerExecuteAndExecuteAsyncWithStatementArgInterceptorTest {
@Rule
public AgentServiceRule serviceRule = new AgentServiceRule();
@SegmentStoragePoint
private SegmentStorage segmentStorage;
private SessionManagerExecuteAndExecuteAsyncWithStatementArgInterceptor interceptor;
@Mock
private ConnectionInfo connectionInfo;
@Mock
private EnhancedInstance objectInstance;
@Mock
private Method method;
@Before
public void setUp() throws Exception {
interceptor = new SessionManagerExecuteAndExecuteAsyncWithStatementArgInterceptor();
when(objectInstance.getSkyWalkingDynamicField()).thenReturn(connectionInfo);
when(method.getName()).thenReturn("executeAsync");
when(connectionInfo.getContactPoints()).thenReturn("localhost:9042");
when(connectionInfo.getKeyspace()).thenReturn("test");
}
@Test
public void testCreateExitSpan() throws Throwable {
interceptor.beforeMethod(objectInstance, method, new Object[]{new SimpleStatement("SELECT * FROM test")}, null, null);
interceptor.afterMethod(objectInstance, method, new Object[]{new SimpleStatement("SELECT * FROM test")}, null, null);
assertThat(segmentStorage.getTraceSegments().size(), is(1));
TraceSegment segment = segmentStorage.getTraceSegments().get(0);
assertThat(SegmentHelper.getSpans(segment).size(), is(1));
AbstractTracingSpan span = SegmentHelper.getSpans(segment).get(0);
SpanAssert.assertLayer(span, SpanLayer.DB);
assertThat(span.getOperationName(), is(Constants.CASSANDRA_OP_PREFIX));
SpanAssert.assertTag(span, 0, Constants.CASSANDRA_DB_TYPE);
SpanAssert.assertTag(span, 1, "test");
SpanAssert.assertTag(span, 2, "SELECT * FROM test");
}
}
\ No newline at end of file
...@@ -74,6 +74,7 @@ ...@@ -74,6 +74,7 @@
<module>vertx-plugins</module> <module>vertx-plugins</module>
<module>resteasy-plugin</module> <module>resteasy-plugin</module>
<module>solrj-7.x-plugin</module> <module>solrj-7.x-plugin</module>
<module>cassandra-java-driver-3.x-plugin</module>
</modules> </modules>
<packaging>pom</packaging> <packaging>pom</packaging>
......
...@@ -56,6 +56,8 @@ ...@@ -56,6 +56,8 @@
* [transport-client](https://github.com/elastic/elasticsearch/tree/master/client/transport) 5.2.x-5.6.x * [transport-client](https://github.com/elastic/elasticsearch/tree/master/client/transport) 5.2.x-5.6.x
* [Solr](https://github.com/apache/lucene-solr/) * [Solr](https://github.com/apache/lucene-solr/)
* [SolrJ](https://github.com/apache/lucene-solr/tree/master/solr/solrj) 7.x * [SolrJ](https://github.com/apache/lucene-solr/tree/master/solr/solrj) 7.x
* [Cassandra](https://github.com/apache/cassandra) 3.x
* [cassandra-java-driver](https://github.com/datastax/java-driver) 3.6.0-3.7.2
* Service Discovery * Service Discovery
* [Netflix Eureka](https://github.com/Netflix/eureka) * [Netflix Eureka](https://github.com/Netflix/eureka)
......
...@@ -215,6 +215,12 @@ spring-webflux: ...@@ -215,6 +215,12 @@ spring-webflux:
Play: Play:
id: 68 id: 68
languages: Java,Scala languages: Java,Scala
cassandra-java-driver:
id: 69
languages: Java
Cassandra:
id: 70
languages: Java
# .NET/.NET Core components # .NET/.NET Core components
# [3000, 4000) for C#/.NET only # [3000, 4000) for C#/.NET only
...@@ -312,4 +318,5 @@ Component-Server-Mappings: ...@@ -312,4 +318,5 @@ Component-Server-Mappings:
Pomelo.EntityFrameworkCore.MySql: Mysql Pomelo.EntityFrameworkCore.MySql: Mysql
Npgsql.EntityFrameworkCore.PostgreSQL: PostgreSQL Npgsql.EntityFrameworkCore.PostgreSQL: PostgreSQL
transport-client: Elasticsearch transport-client: Elasticsearch
SolrJ: Solr SolrJ: Solr
\ No newline at end of file cassandra-java-driver: Cassandra
\ No newline at end of file
...@@ -233,6 +233,12 @@ spring-webflux: ...@@ -233,6 +233,12 @@ spring-webflux:
Play: Play:
id: 68 id: 68
languages: Java,Scala languages: Java,Scala
cassandra-java-driver:
id: 69
languages: Java
Cassandra:
id: 70
languages: Java
# .NET/.NET Core components # .NET/.NET Core components
...@@ -333,4 +339,5 @@ Component-Server-Mappings: ...@@ -333,4 +339,5 @@ Component-Server-Mappings:
Pomelo.EntityFrameworkCore.MySql: Mysql Pomelo.EntityFrameworkCore.MySql: Mysql
Npgsql.EntityFrameworkCore.PostgreSQL: PostgreSQL Npgsql.EntityFrameworkCore.PostgreSQL: PostgreSQL
transport-client: Elasticsearch transport-client: Elasticsearch
SolrJ: Solr SolrJ: Solr
\ No newline at end of file cassandra-java-driver: Cassandra
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册