Add kylin jdbc plugin (#45)
This commit is contained in:
parent
2ecdc18901
commit
0f6276b71c
|
|
@ -91,6 +91,7 @@ jobs:
|
|||
- druid-1.x-scenario
|
||||
- hikaricp-scenario
|
||||
- clickhouse-0.3.x-scenario
|
||||
- kylin-jdbc-2.6.x-3.x-4.x-scenario
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
with:
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ Release Notes.
|
|||
* Fix the bug that httpasyncclient-4.x-plugin does not take effect every time.
|
||||
* Add plugin to support ClickHouse JDBC driver.
|
||||
* Fix version compatibility for JsonRPC4J plugin.
|
||||
* Add plugin to support Apache Kylin-jdbc 2.6.x 3.x 4.x
|
||||
|
||||
#### Documentation
|
||||
|
||||
|
|
|
|||
|
|
@ -216,4 +216,6 @@ public class ComponentsDefine {
|
|||
public static final OfficialComponent JACKSON = new OfficialComponent(118, "Jackson");
|
||||
|
||||
public static final OfficialComponent CLICKHOUSE_JDBC_DRIVER = new OfficialComponent(119, "ClickHouse-jdbc-driver");
|
||||
|
||||
public static final OfficialComponent APACHE_KYLIN_JDBC_DRIVER = new OfficialComponent(121, "apache-kylin-jdbc-driver");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,27 @@
|
|||
/*
|
||||
* 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.connectionurl.parser;
|
||||
|
||||
import org.apache.skywalking.apm.network.trace.component.ComponentsDefine;
|
||||
|
||||
public class KylinJdbcURLParser extends MysqlURLParser {
|
||||
public KylinJdbcURLParser(String url) {
|
||||
super(url, "kylin", ComponentsDefine.APACHE_KYLIN_JDBC_DRIVER);
|
||||
}
|
||||
}
|
||||
|
|
@ -33,6 +33,7 @@ public class URLParser {
|
|||
private static final String MARIADB_JDBC_URL_PREFIX = "jdbc:mariadb";
|
||||
private static final String MSSQL_JTDS_URL_PREFIX = "jdbc:jtds:sqlserver:";
|
||||
private static final String MSSQL_JDBC_URL_PREFIX = "jdbc:sqlserver:";
|
||||
private static final String KYLIN_JDBC_URK_PREFIX = "jdbc:kylin";
|
||||
|
||||
public static ConnectionInfo parser(String url) {
|
||||
ConnectionURLParser parser = null;
|
||||
|
|
@ -51,6 +52,8 @@ public class URLParser {
|
|||
parser = new MssqlJtdsURLParser(url);
|
||||
} else if (lowerCaseUrl.startsWith(MSSQL_JDBC_URL_PREFIX)) {
|
||||
parser = new MssqlJdbcURLParser(url);
|
||||
} else if (lowerCaseUrl.startsWith(KYLIN_JDBC_URK_PREFIX)) {
|
||||
parser = new KylinJdbcURLParser(url);
|
||||
}
|
||||
return parser.parse();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,63 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ 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>8.8.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>apm-kylin-jdbc-2.6.x-3.x-4.x-plugin</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>kylin-jdbc-2.6.x-3.x-4.x-plugin</name>
|
||||
<url>http://maven.apache.org</url>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<kylin-jdbc>2.6.3</kylin-jdbc>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.kylin</groupId>
|
||||
<artifactId>kylin-jdbc</artifactId>
|
||||
<version>${kylin-jdbc}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.skywalking</groupId>
|
||||
<artifactId>apm-jdbc-commons</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-deploy-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
/*
|
||||
* 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.kylin;
|
||||
|
||||
import org.apache.skywalking.apm.agent.core.context.tag.StringTag;
|
||||
|
||||
public class Constants {
|
||||
public static final StringTag SQL_PARAMETERS = new StringTag("db.sql.parameters");
|
||||
}
|
||||
|
|
@ -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.jdbc.kylin;
|
||||
|
||||
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 CreateCallableStatementInterceptor implements InstanceMethodsAroundInterceptor {
|
||||
@Override
|
||||
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
|
||||
MethodInterceptResult result) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
|
||||
Object ret) {
|
||||
if (ret instanceof EnhancedInstance) {
|
||||
((EnhancedInstance) ret).setSkyWalkingDynamicField(new StatementEnhanceInfos((ConnectionInfo) objInst.getSkyWalkingDynamicField(), (String) allArguments[0], "CallableStatement"));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments,
|
||||
Class<?>[] argumentsTypes, Throwable t) {
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* 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.kylin;
|
||||
|
||||
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) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
|
||||
Object ret) {
|
||||
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) {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* 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.kylin;
|
||||
|
||||
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) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
|
||||
Object ret) {
|
||||
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) {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,94 @@
|
|||
/*
|
||||
* 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.kylin;
|
||||
|
||||
import static org.apache.skywalking.apm.plugin.jdbc.kylin.Constants.SQL_PARAMETERS;
|
||||
|
||||
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.JDBCPluginConfig;
|
||||
import org.apache.skywalking.apm.plugin.jdbc.PreparedStatementParameterBuilder;
|
||||
import org.apache.skywalking.apm.plugin.jdbc.SqlBodyUtil;
|
||||
import org.apache.skywalking.apm.plugin.jdbc.define.StatementEnhanceInfos;
|
||||
import org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo;
|
||||
|
||||
public class PreparedStatementExecuteMethodsInterceptor implements InstanceMethodsAroundInterceptor {
|
||||
|
||||
@Override
|
||||
public final void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments,
|
||||
Class<?>[] argumentsTypes, MethodInterceptResult result) {
|
||||
StatementEnhanceInfos cacheObject = (StatementEnhanceInfos) objInst.getSkyWalkingDynamicField();
|
||||
ConnectionInfo connectInfo = cacheObject.getConnectionInfo();
|
||||
if (connectInfo == null) {
|
||||
return;
|
||||
}
|
||||
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, SqlBodyUtil.limitSqlBodySize(cacheObject.getSql()));
|
||||
span.setComponent(connectInfo.getComponent());
|
||||
|
||||
if (JDBCPluginConfig.Plugin.JDBC.TRACE_SQL_PARAMETERS) {
|
||||
final Object[] parameters = cacheObject.getParameters();
|
||||
if (parameters != null && parameters.length > 0) {
|
||||
int maxIndex = cacheObject.getMaxIndex();
|
||||
SQL_PARAMETERS.set(span, getParameterString(parameters, maxIndex));
|
||||
}
|
||||
}
|
||||
|
||||
SpanLayer.asDB(span);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments,
|
||||
Class<?>[] argumentsTypes, Object ret) {
|
||||
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().log(t);
|
||||
}
|
||||
}
|
||||
|
||||
private String buildOperationName(ConnectionInfo connectionInfo, String methodName, String statementName) {
|
||||
return connectionInfo.getDBType() + "/JDBI/" + statementName + "/" + methodName;
|
||||
}
|
||||
|
||||
private String getParameterString(Object[] parameters, int maxIndex) {
|
||||
return new PreparedStatementParameterBuilder()
|
||||
.setParameters(parameters)
|
||||
.setMaxIndex(maxIndex)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
|
@ -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.kylin;
|
||||
|
||||
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.trace.ConnectionInfo;
|
||||
|
||||
public class SetCatalogInterceptor implements InstanceMethodsAroundInterceptor {
|
||||
@Override
|
||||
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
|
||||
MethodInterceptResult result) {
|
||||
Object dynamicField = objInst.getSkyWalkingDynamicField();
|
||||
if (dynamicField instanceof ConnectionInfo) {
|
||||
((ConnectionInfo) dynamicField).setDatabaseName(String.valueOf(allArguments[0]));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
|
||||
Object ret) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments,
|
||||
Class<?>[] argumentsTypes, Throwable t) {
|
||||
}
|
||||
}
|
||||
|
|
@ -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.kylin;
|
||||
|
||||
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.SqlBodyUtil;
|
||||
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 final void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments,
|
||||
Class<?>[] argumentsTypes, MethodInterceptResult result) {
|
||||
StatementEnhanceInfos cacheObject = (StatementEnhanceInfos) objInst.getSkyWalkingDynamicField();
|
||||
ConnectionInfo connectInfo = cacheObject.getConnectionInfo();
|
||||
if (connectInfo != null) {
|
||||
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 = allArguments.length > 0 ? (String) allArguments[0] : "";
|
||||
sql = SqlBodyUtil.limitSqlBodySize(sql);
|
||||
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) {
|
||||
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().log(t);
|
||||
}
|
||||
}
|
||||
|
||||
private String buildOperationName(ConnectionInfo connectionInfo, String methodName, String statementName) {
|
||||
return connectionInfo.getDBType() + "/JDBI/" + statementName + "/" + methodName;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,139 @@
|
|||
/*
|
||||
* 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.kylin.define;
|
||||
|
||||
import static net.bytebuddy.matcher.ElementMatchers.named;
|
||||
import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName;
|
||||
|
||||
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 org.apache.skywalking.apm.plugin.jdbc.define.Constants;
|
||||
|
||||
public class ConnectionInstrumentation extends ClassInstanceMethodsEnhancePluginDefine {
|
||||
|
||||
private static final String ENHANCE_CLASS = "org.apache.kylin.jdbc.KylinConnection";
|
||||
private static final String CREATE_STATEMENT_INTERCEPTOR_CLASS = "org.apache.skywalking.apm.plugin.jdbc.kylin.CreateStatementInterceptor";
|
||||
private static final String CREATE_PREPARED_STATEMENT_INTERCEPTOR_CLASS = "org.apache.skywalking.apm.plugin.jdbc.kylin.CreatePreparedStatementInterceptor";
|
||||
private static final String CREATE_CALLABLE_STATEMENT_INTERCEPTOR_CLASS = "org.apache.skywalking.apm.plugin.jdbc.kylin.CreateCallableStatementInterceptor";
|
||||
private static final String SET_CATALOG_INTERCEPTOR_CLASS = "org.apache.skywalking.apm.plugin.jdbc.kylin.SetCatalogInterceptor";
|
||||
|
||||
@Override
|
||||
protected ClassMatch enhanceClass() {
|
||||
return byName(ENHANCE_CLASS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConstructorInterceptPoint[] getConstructorsInterceptPoints() {
|
||||
return new ConstructorInterceptPoint[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
|
||||
return new InstanceMethodsInterceptPoint[]{
|
||||
new InstanceMethodsInterceptPoint() {
|
||||
@Override
|
||||
public ElementMatcher<MethodDescription> getMethodsMatcher() {
|
||||
return named(Constants.CREATE_STATEMENT_METHOD_NAME);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodsInterceptor() {
|
||||
return CREATE_STATEMENT_INTERCEPTOR_CLASS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOverrideArgs() {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
new InstanceMethodsInterceptPoint() {
|
||||
@Override
|
||||
public ElementMatcher<MethodDescription> getMethodsMatcher() {
|
||||
return named(Constants.PREPARE_STATEMENT_METHOD_NAME);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodsInterceptor() {
|
||||
return CREATE_PREPARED_STATEMENT_INTERCEPTOR_CLASS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOverrideArgs() {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
new InstanceMethodsInterceptPoint() {
|
||||
@Override
|
||||
public ElementMatcher<MethodDescription> getMethodsMatcher() {
|
||||
return named(Constants.PREPARE_CALL_METHOD_NAME);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodsInterceptor() {
|
||||
return CREATE_CALLABLE_STATEMENT_INTERCEPTOR_CLASS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOverrideArgs() {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
new InstanceMethodsInterceptPoint() {
|
||||
@Override
|
||||
public ElementMatcher<MethodDescription> getMethodsMatcher() {
|
||||
return named(Constants.COMMIT_METHOD_NAME)
|
||||
.or(named(Constants.ROLLBACK_METHOD_NAME))
|
||||
.or(named(Constants.CLOSE_METHOD_NAME))
|
||||
.or(named(Constants.RELEASE_SAVE_POINT_METHOD_NAME));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodsInterceptor() {
|
||||
return Constants.SERVICE_METHOD_INTERCEPT_CLASS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOverrideArgs() {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
new InstanceMethodsInterceptPoint() {
|
||||
@Override
|
||||
public ElementMatcher<MethodDescription> getMethodsMatcher() {
|
||||
return named("setCatalog");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodsInterceptor() {
|
||||
return SET_CATALOG_INTERCEPTOR_CLASS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOverrideArgs() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* 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.kylin.define;
|
||||
|
||||
import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName;
|
||||
|
||||
import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch;
|
||||
import org.apache.skywalking.apm.plugin.jdbc.define.AbstractDriverInstrumentation;
|
||||
|
||||
/**
|
||||
* {@link DriverInstrumentation} presents that skywalking intercepts {@link org.apache.kylin.jdbc.Driver}.
|
||||
*/
|
||||
public class DriverInstrumentation extends AbstractDriverInstrumentation {
|
||||
|
||||
private static final String ENHANCE_CLASS = "org.apache.kylin.jdbc.Driver";
|
||||
|
||||
@Override
|
||||
protected ClassMatch enhanceClass() {
|
||||
return byName(ENHANCE_CLASS);
|
||||
}
|
||||
}
|
||||
|
|
@ -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.jdbc.kylin.define;
|
||||
|
||||
import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint;
|
||||
import org.apache.skywalking.apm.plugin.jdbc.PSSetterDefinitionOfJDBCInstrumentation;
|
||||
|
||||
public class PreparedStatementIgnoredSetterInstrumentation extends
|
||||
org.apache.skywalking.apm.plugin.jdbc.kylin.define.PreparedStatementInstrumentation {
|
||||
|
||||
@Override
|
||||
public final InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
|
||||
return new InstanceMethodsInterceptPoint[]{
|
||||
new PSSetterDefinitionOfJDBCInstrumentation(true)
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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.jdbc.kylin.define;
|
||||
|
||||
import static net.bytebuddy.matcher.ElementMatchers.named;
|
||||
import static org.apache.skywalking.apm.agent.core.plugin.match.MultiClassNameMatch.byMultiClassMatch;
|
||||
|
||||
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;
|
||||
|
||||
public class PreparedStatementInstrumentation extends ClassInstanceMethodsEnhancePluginDefine {
|
||||
|
||||
private static final String KYLIN_PREPARED_STATEMENT_CLASS = "org.apache.kylin.jdbc.KylinPreparedStatement";
|
||||
private static final String PREPARED_STATEMENT_EXECUTE_METHODS_INTERCEPTOR_CLASS = "org.apache.skywalking.apm.plugin.jdbc.kylin.PreparedStatementExecuteMethodsInterceptor";
|
||||
|
||||
@Override
|
||||
protected ClassMatch enhanceClass() {
|
||||
return byMultiClassMatch(
|
||||
KYLIN_PREPARED_STATEMENT_CLASS
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConstructorInterceptPoint[] getConstructorsInterceptPoints() {
|
||||
return new ConstructorInterceptPoint[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
|
||||
return new InstanceMethodsInterceptPoint[]{
|
||||
new InstanceMethodsInterceptPoint() {
|
||||
@Override
|
||||
public ElementMatcher<MethodDescription> getMethodsMatcher() {
|
||||
return named("execute")
|
||||
.or(named("executeQuery"))
|
||||
.or(named("executeUpdate"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodsInterceptor() {
|
||||
return PREPARED_STATEMENT_EXECUTE_METHODS_INTERCEPTOR_CLASS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOverrideArgs() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -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.jdbc.kylin.define;
|
||||
|
||||
import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint;
|
||||
import org.apache.skywalking.apm.plugin.jdbc.JDBCPreparedStatementNullSetterInstanceMethodsInterceptPoint;
|
||||
|
||||
public class PreparedStatementNullSetterInstrumentation extends PreparedStatementInstrumentation {
|
||||
|
||||
@Override
|
||||
public final InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
|
||||
return new InstanceMethodsInterceptPoint[]{
|
||||
new JDBCPreparedStatementNullSetterInstanceMethodsInterceptPoint()
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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.jdbc.kylin.define;
|
||||
|
||||
import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint;
|
||||
import org.apache.skywalking.apm.plugin.jdbc.PSSetterDefinitionOfJDBCInstrumentation;
|
||||
|
||||
public class PreparedStatementSetterInstrumentation extends PreparedStatementInstrumentation {
|
||||
|
||||
@Override
|
||||
public final InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
|
||||
return new InstanceMethodsInterceptPoint[]{
|
||||
new PSSetterDefinitionOfJDBCInstrumentation(false)
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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.kylin.define;
|
||||
|
||||
import static net.bytebuddy.matcher.ElementMatchers.named;
|
||||
import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName;
|
||||
|
||||
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;
|
||||
|
||||
public class StatementInstrumentation extends ClassInstanceMethodsEnhancePluginDefine {
|
||||
private static final String KYLIN_STATEMENT_CLASS_NAME = "org.apache.kylin.jdbc.KylinStatement";
|
||||
private static final String STATEMENT_EXECUTE_METHODS_INTERCEPTOR = "org.apache.skywalking.apm.plugin.jdbc.kylin.StatementExecuteMethodsInterceptor";
|
||||
|
||||
@Override
|
||||
public ConstructorInterceptPoint[] getConstructorsInterceptPoints() {
|
||||
return new ConstructorInterceptPoint[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
|
||||
return new InstanceMethodsInterceptPoint[]{
|
||||
new InstanceMethodsInterceptPoint() {
|
||||
@Override
|
||||
public ElementMatcher<MethodDescription> getMethodsMatcher() {
|
||||
return named("execute")
|
||||
.or(named("executeQuery"))
|
||||
.or(named("executeUpdate"))
|
||||
.or(named("executeLargeUpdate"))
|
||||
.or(named("executeBatch"))
|
||||
.or(named("executeLargeBatch"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodsInterceptor() {
|
||||
return STATEMENT_EXECUTE_METHODS_INTERCEPTOR;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOverrideArgs() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ClassMatch enhanceClass() {
|
||||
return byName(KYLIN_STATEMENT_CLASS_NAME);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
# 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.
|
||||
|
||||
kylin-jdbc-2.6.x-3.x-4.x=org.apache.skywalking.apm.plugin.jdbc.kylin.define.DriverInstrumentation
|
||||
kylin-jdbc-2.6.x-3.x-4.x=org.apache.skywalking.apm.plugin.jdbc.kylin.define.ConnectionInstrumentation
|
||||
kylin-jdbc-2.6.x-3.x-4.x=org.apache.skywalking.apm.plugin.jdbc.kylin.define.StatementInstrumentation
|
||||
kylin-jdbc-2.6.x-3.x-4.x=org.apache.skywalking.apm.plugin.jdbc.kylin.define.PreparedStatementInstrumentation
|
||||
kylin-jdbc-2.6.x-3.x-4.x=org.apache.skywalking.apm.plugin.jdbc.kylin.define.PreparedStatementSetterInstrumentation
|
||||
kylin-jdbc-2.6.x-3.x-4.x=org.apache.skywalking.apm.plugin.jdbc.kylin.define.PreparedStatementNullSetterInstrumentation
|
||||
kylin-jdbc-2.6.x-3.x-4.x=org.apache.skywalking.apm.plugin.jdbc.kylin.define.PreparedStatementIgnoredSetterInstrumentation
|
||||
|
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
* 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.kylin;
|
||||
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.powermock.api.mockito.PowerMockito.when;
|
||||
|
||||
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
|
||||
import org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Matchers;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class CreateCallableStatementInterceptorTest {
|
||||
|
||||
private static final String SQL = "Select * from test";
|
||||
|
||||
private CreateCallableStatementInterceptor interceptor;
|
||||
|
||||
@Mock
|
||||
private EnhancedInstance ret;
|
||||
|
||||
@Mock
|
||||
private EnhancedInstance objectInstance;
|
||||
|
||||
@Mock
|
||||
private ConnectionInfo connectionInfo;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
interceptor = new CreateCallableStatementInterceptor();
|
||||
|
||||
when(objectInstance.getSkyWalkingDynamicField()).thenReturn(connectionInfo);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResultIsEnhanceInstance() {
|
||||
interceptor.afterMethod(objectInstance, null, new Object[]{SQL}, null, ret);
|
||||
verify(ret).setSkyWalkingDynamicField(Matchers.any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResultIsNotEnhanceInstance() {
|
||||
interceptor.afterMethod(objectInstance, null, new Object[]{SQL}, null, new Object());
|
||||
verify(ret, times(0)).setSkyWalkingDynamicField(Matchers.any());
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
* 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.kylin;
|
||||
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.powermock.api.mockito.PowerMockito.when;
|
||||
|
||||
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
|
||||
import org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Matchers;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class CreatePreparedStatementInterceptorTest {
|
||||
|
||||
private static final String SQL = "Select * from test";
|
||||
|
||||
private CreatePreparedStatementInterceptor interceptor;
|
||||
|
||||
@Mock
|
||||
private EnhancedInstance ret;
|
||||
|
||||
@Mock
|
||||
private EnhancedInstance objectInstance;
|
||||
|
||||
@Mock
|
||||
private ConnectionInfo connectionInfo;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
interceptor = new CreatePreparedStatementInterceptor();
|
||||
|
||||
when(objectInstance.getSkyWalkingDynamicField()).thenReturn(connectionInfo);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResultIsEnhanceInstance() {
|
||||
interceptor.afterMethod(objectInstance, null, new Object[]{SQL}, null, ret);
|
||||
verify(ret).setSkyWalkingDynamicField(Matchers.any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResultIsNotEnhanceInstance() {
|
||||
interceptor.afterMethod(objectInstance, null, new Object[]{SQL}, null, new Object());
|
||||
verify(ret, times(0)).setSkyWalkingDynamicField(Matchers.any());
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
* 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.kylin;
|
||||
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.powermock.api.mockito.PowerMockito.when;
|
||||
|
||||
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
|
||||
import org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Matchers;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class CreateStatementInterceptorTest {
|
||||
|
||||
private static final String SQL = "Select * from test";
|
||||
|
||||
private CreateStatementInterceptor interceptor;
|
||||
|
||||
@Mock
|
||||
private EnhancedInstance ret;
|
||||
|
||||
@Mock
|
||||
private EnhancedInstance objectInstance;
|
||||
|
||||
@Mock
|
||||
private ConnectionInfo connectionInfo;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
interceptor = new CreateStatementInterceptor();
|
||||
|
||||
when(objectInstance.getSkyWalkingDynamicField()).thenReturn(connectionInfo);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResultIsEnhanceInstance() {
|
||||
interceptor.afterMethod(objectInstance, null, new Object[]{SQL}, null, ret);
|
||||
verify(ret).setSkyWalkingDynamicField(Matchers.any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResultIsNotEnhanceInstance() {
|
||||
interceptor.afterMethod(objectInstance, null, new Object[]{SQL}, null, new Object());
|
||||
verify(ret, times(0)).setSkyWalkingDynamicField(Matchers.any());
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,153 @@
|
|||
/*
|
||||
* 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.kylin;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.powermock.api.mockito.PowerMockito.when;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
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.apache.skywalking.apm.network.trace.component.ComponentsDefine;
|
||||
import org.apache.skywalking.apm.plugin.jdbc.JDBCPluginConfig;
|
||||
import org.apache.skywalking.apm.plugin.jdbc.JDBCPreparedStatementSetterInterceptor;
|
||||
import org.apache.skywalking.apm.plugin.jdbc.define.StatementEnhanceInfos;
|
||||
import org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo;
|
||||
import org.junit.After;
|
||||
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;
|
||||
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PowerMockRunnerDelegate(TracingSegmentRunner.class)
|
||||
public class PreparedStatementExecuteMethodsInterceptorTest {
|
||||
|
||||
private static final String SQL = "Select * from test where id = ?";
|
||||
|
||||
@SegmentStoragePoint
|
||||
private SegmentStorage segmentStorage;
|
||||
|
||||
@Rule
|
||||
public AgentServiceRule serviceRule = new AgentServiceRule();
|
||||
|
||||
private PreparedStatementExecuteMethodsInterceptor serviceMethodInterceptor;
|
||||
|
||||
private JDBCPreparedStatementSetterInterceptor preparedStatementSetterInterceptor;
|
||||
|
||||
@Mock
|
||||
private ConnectionInfo connectionInfo;
|
||||
@Mock
|
||||
private EnhancedInstance objectInstance;
|
||||
@Mock
|
||||
private Method method;
|
||||
private StatementEnhanceInfos enhanceRequireCacheObject;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
JDBCPluginConfig.Plugin.JDBC.TRACE_SQL_PARAMETERS = true;
|
||||
preparedStatementSetterInterceptor = new JDBCPreparedStatementSetterInterceptor();
|
||||
serviceMethodInterceptor = new PreparedStatementExecuteMethodsInterceptor();
|
||||
|
||||
enhanceRequireCacheObject = new StatementEnhanceInfos(connectionInfo, SQL, "PreparedStatement");
|
||||
when(objectInstance.getSkyWalkingDynamicField()).thenReturn(enhanceRequireCacheObject);
|
||||
when(method.getName()).thenReturn("executeQuery");
|
||||
when(connectionInfo.getComponent()).thenReturn(ComponentsDefine.APACHE_KYLIN_JDBC_DRIVER);
|
||||
when(connectionInfo.getDBType()).thenReturn("kylin");
|
||||
when(connectionInfo.getDatabaseName()).thenReturn("test");
|
||||
when(connectionInfo.getDatabasePeer()).thenReturn("localhost:3306");
|
||||
}
|
||||
|
||||
@After
|
||||
public void clean() {
|
||||
JDBCPluginConfig.Plugin.JDBC.SQL_BODY_MAX_LENGTH = 2048;
|
||||
JDBCPluginConfig.Plugin.JDBC.TRACE_SQL_PARAMETERS = false;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecutePreparedStatement() throws Throwable {
|
||||
preparedStatementSetterInterceptor.beforeMethod(
|
||||
objectInstance, method, new Object[] {
|
||||
1,
|
||||
"abcd"
|
||||
}, null, null);
|
||||
preparedStatementSetterInterceptor.beforeMethod(
|
||||
objectInstance, method, new Object[] {
|
||||
2,
|
||||
"efgh"
|
||||
}, null, null);
|
||||
|
||||
serviceMethodInterceptor.beforeMethod(objectInstance, method, new Object[] {SQL}, null, null);
|
||||
serviceMethodInterceptor.afterMethod(objectInstance, method, new Object[] {SQL}, 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("kylin/JDBI/PreparedStatement/"));
|
||||
SpanAssert.assertTag(span, 0, "sql");
|
||||
SpanAssert.assertTag(span, 1, "test");
|
||||
SpanAssert.assertTag(span, 2, SQL);
|
||||
SpanAssert.assertTag(span, 3, "[abcd,efgh]");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecutePreparedStatementWithLimitSqlBody() throws Throwable {
|
||||
JDBCPluginConfig.Plugin.JDBC.SQL_BODY_MAX_LENGTH = 10;
|
||||
|
||||
preparedStatementSetterInterceptor.beforeMethod(
|
||||
objectInstance, method, new Object[] {
|
||||
1,
|
||||
"abcd"
|
||||
}, null, null);
|
||||
preparedStatementSetterInterceptor.beforeMethod(
|
||||
objectInstance, method, new Object[] {
|
||||
2,
|
||||
"efgh"
|
||||
}, null, null);
|
||||
|
||||
serviceMethodInterceptor.beforeMethod(objectInstance, method, new Object[] {SQL}, null, null);
|
||||
serviceMethodInterceptor.afterMethod(objectInstance, method, new Object[] {SQL}, 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("kylin/JDBI/PreparedStatement/"));
|
||||
SpanAssert.assertTag(span, 0, "sql");
|
||||
SpanAssert.assertTag(span, 1, "test");
|
||||
SpanAssert.assertTag(span, 2, "Select * f...");
|
||||
SpanAssert.assertTag(span, 3, "[abcd,efgh]");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,122 @@
|
|||
/*
|
||||
* 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.kylin;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.powermock.api.mockito.PowerMockito.when;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
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.apache.skywalking.apm.network.trace.component.ComponentsDefine;
|
||||
import org.apache.skywalking.apm.plugin.jdbc.JDBCPluginConfig;
|
||||
import org.apache.skywalking.apm.plugin.jdbc.define.StatementEnhanceInfos;
|
||||
import org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo;
|
||||
import org.junit.After;
|
||||
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;
|
||||
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PowerMockRunnerDelegate(TracingSegmentRunner.class)
|
||||
public class StatementExecuteMethodsInterceptorTest {
|
||||
|
||||
private static final String SQL = "Select * from test";
|
||||
|
||||
@SegmentStoragePoint
|
||||
private SegmentStorage segmentStorage;
|
||||
|
||||
@Rule
|
||||
public AgentServiceRule serviceRule = new AgentServiceRule();
|
||||
|
||||
private StatementExecuteMethodsInterceptor serviceMethodInterceptor;
|
||||
|
||||
@Mock
|
||||
private ConnectionInfo connectionInfo;
|
||||
@Mock
|
||||
private EnhancedInstance objectInstance;
|
||||
@Mock
|
||||
private Method method;
|
||||
private StatementEnhanceInfos enhanceRequireCacheObject;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
serviceMethodInterceptor = new StatementExecuteMethodsInterceptor();
|
||||
|
||||
enhanceRequireCacheObject = new StatementEnhanceInfos(connectionInfo, SQL, "CallableStatement");
|
||||
when(objectInstance.getSkyWalkingDynamicField()).thenReturn(enhanceRequireCacheObject);
|
||||
when(method.getName()).thenReturn("executeQuery");
|
||||
when(connectionInfo.getComponent()).thenReturn(ComponentsDefine.APACHE_KYLIN_JDBC_DRIVER);
|
||||
when(connectionInfo.getDBType()).thenReturn("kylin");
|
||||
when(connectionInfo.getDatabaseName()).thenReturn("test");
|
||||
when(connectionInfo.getDatabasePeer()).thenReturn("localhost:3306");
|
||||
}
|
||||
|
||||
@After
|
||||
public void clean() {
|
||||
JDBCPluginConfig.Plugin.JDBC.SQL_BODY_MAX_LENGTH = 2048;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteStatement() {
|
||||
serviceMethodInterceptor.beforeMethod(objectInstance, method, new Object[]{SQL}, null, null);
|
||||
serviceMethodInterceptor.afterMethod(objectInstance, method, new Object[]{SQL}, 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("kylin/JDBI/CallableStatement/"));
|
||||
SpanAssert.assertTag(span, 0, "sql");
|
||||
SpanAssert.assertTag(span, 1, "test");
|
||||
SpanAssert.assertTag(span, 2, SQL);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteStatementWithLimitSqlBody() {
|
||||
JDBCPluginConfig.Plugin.JDBC.SQL_BODY_MAX_LENGTH = 10;
|
||||
serviceMethodInterceptor.beforeMethod(objectInstance, method, new Object[]{SQL}, null, null);
|
||||
serviceMethodInterceptor.afterMethod(objectInstance, method, new Object[]{SQL}, 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("kylin/JDBI/CallableStatement/"));
|
||||
SpanAssert.assertTag(span, 0, "sql");
|
||||
SpanAssert.assertTag(span, 1, "test");
|
||||
SpanAssert.assertTag(span, 2, "Select * f...");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -111,6 +111,7 @@
|
|||
<module>hikaricp-3.x-4.x-plugin</module>
|
||||
<module>httpclient-5.x-plugin</module>
|
||||
<module>clickhouse-0.3.x-plugin</module>
|
||||
<module>kylin-jdbc-2.6.x-3.x-4.x-plugin</module>
|
||||
</modules>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
|
|
|
|||
|
|
@ -125,3 +125,4 @@
|
|||
- spring-cloud-gateway-3.x
|
||||
- neo4j-4.x
|
||||
- clickhouse-0.3.x
|
||||
- kylin-jdbc-2.6.x-3.x-4.x
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ metrics based on the tracing data.
|
|||
* [Mssql-Jtds](https://github.com/milesibastos/jTDS) 1.x
|
||||
* [Mssql-jdbc](https://github.com/microsoft/mssql-jdbc) 6.x -> 8.x
|
||||
* [ClickHouse-jdbc](https://github.com/ClickHouse/clickhouse-jdbc) 0.3.x
|
||||
* [Apache-Kylin-Jdbc](https://github.com/apache/kylin.git) 2.6.x -> 3.x -> 4.x
|
||||
* RPC Frameworks
|
||||
* [Dubbo](https://github.com/alibaba/dubbo) 2.5.4 -> 2.6.0
|
||||
* [Dubbox](https://github.com/dangdangdotcom/dubbox) 2.8.4
|
||||
|
|
|
|||
|
|
@ -0,0 +1,21 @@
|
|||
#!/bin/bash
|
||||
#
|
||||
# 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.
|
||||
|
||||
home="$(cd "$(dirname $0)"; pwd)"
|
||||
|
||||
java -jar ${agent_opts} ${home}/../libs/kylin-jdbc-2.6.x-3.x-4.x-scenario.jar &
|
||||
|
|
@ -0,0 +1,82 @@
|
|||
# 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.
|
||||
segmentItems:
|
||||
- serviceName: kylin-jdbc-2.6.x-3.x-4.x-scenario
|
||||
segmentSize: ge 1
|
||||
segments:
|
||||
- segmentId: not null
|
||||
spans:
|
||||
- operationName: kylin/JDBI/Statement/execute
|
||||
parentSpanId: 0
|
||||
spanId: 1
|
||||
spanLayer: Database
|
||||
startTime: nq 0
|
||||
endTime: nq 0
|
||||
componentId: 121
|
||||
isError: false
|
||||
spanType: Exit
|
||||
peer: kylin-server:7070
|
||||
skipAnalysis: 'false'
|
||||
tags:
|
||||
- {key: db.type, value: sql}
|
||||
- {key: db.instance, value: learn_kylin}
|
||||
- key: db.statement
|
||||
value: "select * from KYLIN_ACCOUNT LIMIT 1"
|
||||
- operationName: kylin/JDBI/PreparedStatement/executeQuery
|
||||
parentSpanId: 0
|
||||
spanId: 2
|
||||
spanLayer: Database
|
||||
startTime: nq 0
|
||||
endTime: nq 0
|
||||
componentId: 121
|
||||
isError: false
|
||||
spanType: Exit
|
||||
peer: kylin-server:7070
|
||||
skipAnalysis: 'false'
|
||||
tags:
|
||||
- {key: db.type, value: sql}
|
||||
- {key: db.instance, value: learn_kylin}
|
||||
- {key: db.statement, value: "select * from KYLIN_ACCOUNT"}
|
||||
- operationName: kylin/JDBI/Connection/close
|
||||
parentSpanId: 0
|
||||
spanId: 3
|
||||
spanLayer: Database
|
||||
startTime: nq 0
|
||||
endTime: nq 0
|
||||
componentId: 121
|
||||
isError: false
|
||||
spanType: Exit
|
||||
peer: kylin-server:7070
|
||||
skipAnalysis: 'false'
|
||||
tags:
|
||||
- {key: db.type, value: sql}
|
||||
- {key: db.instance, value: learn_kylin}
|
||||
- {key: db.statement, value: ''}
|
||||
- operationName: HEAD:/kylin-jdbc-2.6.x-3.x-4.x-scenario/case/healthCheck
|
||||
parentSpanId: -1
|
||||
spanId: 0
|
||||
startTime: nq 0
|
||||
endTime: nq 0
|
||||
spanLayer: Http
|
||||
isError: false
|
||||
spanType: Entry
|
||||
peer: ''
|
||||
componentId: 1
|
||||
tags:
|
||||
- {key: url, value: 'http://localhost:8080/kylin-jdbc-2.6.x-3.x-4.x-scenario/case/healthCheck'}
|
||||
- {key: http.method, value: HEAD}
|
||||
logs: []
|
||||
skipAnalysis: 'false'
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
# 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.
|
||||
|
||||
type: jvm
|
||||
entryService: http://localhost:8080/kylin-jdbc-2.6.x-3.x-4.x-scenario/case/kylin-jdbc-2.6.x-3.x-4.x-scenario
|
||||
healthCheck: http://localhost:8080/kylin-jdbc-2.6.x-3.x-4.x-scenario/case/healthCheck
|
||||
startScript: ./bin/startup.sh
|
||||
environment:
|
||||
depends_on:
|
||||
- kylin-server
|
||||
dependencies:
|
||||
kylin-server:
|
||||
image: apachekylin/apache-kylin-standalone:4.0.0
|
||||
hostname: kylin-server
|
||||
expose:
|
||||
- "7070"
|
||||
|
|
@ -0,0 +1,120 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ 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">
|
||||
|
||||
<groupId>org.apache.skywalking.apm.testcase</groupId>
|
||||
<artifactId>kylin-jdbc-2.6.x-3.x-4.x-scenario</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<compiler.version>1.8</compiler.version>
|
||||
<test.framework.version>2.6.3</test.framework.version>
|
||||
<docker.image.version>${test.framework.version}</docker.image.version>
|
||||
<spring-boot-version>2.1.6.RELEASE</spring-boot-version>
|
||||
<log4j.version>2.6.2</log4j.version>
|
||||
<spring.version>4.3.8.RELEASE</spring.version>
|
||||
</properties>
|
||||
|
||||
<name>skywalking-kylin-jdbc-2.6.x-3.x-4.x-scenario</name>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-dependencies</artifactId>
|
||||
<version>${spring-boot-version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-logging</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-log4j2</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.kylin</groupId>
|
||||
<artifactId>kylin-jdbc</artifactId>
|
||||
<version>${test.framework.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<finalName>kylin-jdbc-2.6.x-3.x-4.x-scenario</finalName>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>repackage</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>${compiler.version}</source>
|
||||
<target>${compiler.version}</target>
|
||||
<encoding>${project.build.sourceEncoding}</encoding>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>assemble</id>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>single</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<descriptors>
|
||||
<descriptor>src/main/assembly/assembly.xml</descriptor>
|
||||
</descriptors>
|
||||
<outputDirectory>./target/</outputDirectory>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ 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.
|
||||
~
|
||||
-->
|
||||
<assembly
|
||||
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
|
||||
<formats>
|
||||
<format>zip</format>
|
||||
</formats>
|
||||
|
||||
<fileSets>
|
||||
<fileSet>
|
||||
<directory>./bin</directory>
|
||||
<fileMode>0775</fileMode>
|
||||
</fileSet>
|
||||
</fileSets>
|
||||
|
||||
<files>
|
||||
<file>
|
||||
<source>${project.build.directory}/kylin-jdbc-2.6.x-3.x-4.x-scenario.jar</source>
|
||||
<outputDirectory>./libs</outputDirectory>
|
||||
<fileMode>0775</fileMode>
|
||||
</file>
|
||||
</files>
|
||||
</assembly>
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* 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.testcase.kylinjdbc;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class Application {
|
||||
|
||||
private static final Logger LOGGER = LogManager.getLogger(Application.class);
|
||||
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
SpringApplication.run(Application.class, args);
|
||||
} catch (Exception ex) {
|
||||
LOGGER.error("Application start error", ex);
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
* 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.testcase.kylinjdbc;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Properties;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
public class KylinJdbcConfig {
|
||||
private static final Logger LOGGER = LogManager.getLogger(KylinJdbcConfig.class);
|
||||
private static String URL;
|
||||
private static String USER_NAME;
|
||||
private static String PASSWORD;
|
||||
|
||||
static {
|
||||
InputStream inputStream = KylinJdbcConfig.class.getClassLoader().getResourceAsStream("jdbc.properties");
|
||||
Properties properties = new Properties();
|
||||
try {
|
||||
properties.load(inputStream);
|
||||
} catch (IOException e) {
|
||||
LOGGER.error("Failed to load config", e);
|
||||
}
|
||||
|
||||
URL = properties.getProperty("kylin.url");
|
||||
USER_NAME = properties.getProperty("kylin.username");
|
||||
PASSWORD = properties.getProperty("kylin.password");
|
||||
}
|
||||
|
||||
public static String getUrl() {
|
||||
return URL;
|
||||
}
|
||||
|
||||
public static String getUserName() {
|
||||
return USER_NAME;
|
||||
}
|
||||
|
||||
public static String getPassword() {
|
||||
return PASSWORD;
|
||||
}
|
||||
}
|
||||
|
|
@ -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.testcase.kylinjdbc;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
public class SQLExecutor implements AutoCloseable {
|
||||
|
||||
private static final Logger LOGGER = LogManager.getLogger(SQLExecutor.class);
|
||||
private Connection connection;
|
||||
|
||||
public SQLExecutor() throws SQLException {
|
||||
try {
|
||||
Class.forName("org.apache.kylin.jdbc.Driver");
|
||||
} catch (ClassNotFoundException ex) {
|
||||
LOGGER.error(ex);
|
||||
}
|
||||
connection = DriverManager.getConnection(KylinJdbcConfig.getUrl(), KylinJdbcConfig.getUserName(),
|
||||
KylinJdbcConfig.getPassword());
|
||||
}
|
||||
|
||||
public void execute(String sql) throws SQLException {
|
||||
Statement statement = connection.createStatement();
|
||||
statement.execute(sql);
|
||||
}
|
||||
|
||||
public void queryData(String sql, Integer id) throws SQLException {
|
||||
PreparedStatement preparedStatement = connection.prepareStatement(sql);
|
||||
preparedStatement.executeQuery();
|
||||
}
|
||||
|
||||
public void closeConnection() throws SQLException {
|
||||
if (this.connection != null) {
|
||||
this.connection.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws Exception {
|
||||
closeConnection();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,84 @@
|
|||
/*
|
||||
* 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.testcase.kylinjdbc.controller;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.Socket;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.skywalking.apm.testcase.kylinjdbc.SQLExecutor;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/case")
|
||||
public class CaseController {
|
||||
|
||||
private static final Logger LOGGER = LogManager.getLogger(CaseController.class);
|
||||
|
||||
private static final String SUCCESS = "Success";
|
||||
|
||||
private static final String STATEMENT_QUERY_DATA_SQL = "select * from KYLIN_ACCOUNT LIMIT 1";
|
||||
private static final String QUERY_DATA_SQL = "select * from KYLIN_ACCOUNT";
|
||||
|
||||
@RequestMapping("/kylin-jdbc-2.6.x-3.x-4.x-scenario")
|
||||
@ResponseBody
|
||||
public String testcase() throws Exception {
|
||||
Thread.sleep(2000);
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
@RequestMapping("/healthCheck")
|
||||
@ResponseBody
|
||||
public String healthCheck() throws Exception {
|
||||
// NEED TO WAIT KYLIN SERVER READY
|
||||
if (!telnet("kylin-server", 7070, 1000)) { //
|
||||
Thread.sleep(5000); // WAIT UTIL CLIENT TIMEOUT
|
||||
} else {
|
||||
try (SQLExecutor sqlExecute = new SQLExecutor()) {
|
||||
sqlExecute.execute(STATEMENT_QUERY_DATA_SQL);
|
||||
sqlExecute.queryData(QUERY_DATA_SQL, 10);
|
||||
} catch (Exception ex) {
|
||||
LOGGER.error("Failed to execute sql.", ex);
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
private boolean telnet(String hostname, int port, int timeout) {
|
||||
Socket socket = new Socket();
|
||||
boolean isConnected = false;
|
||||
try {
|
||||
socket.connect(new InetSocketAddress(hostname, port), timeout);
|
||||
isConnected = socket.isConnected();
|
||||
} catch (IOException e) {
|
||||
LOGGER.warn("connect to kylin server failed");
|
||||
} finally {
|
||||
try {
|
||||
socket.close();
|
||||
} catch (IOException e) {
|
||||
LOGGER.warn("close failed");
|
||||
}
|
||||
}
|
||||
return isConnected;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
#
|
||||
# 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.
|
||||
#
|
||||
#
|
||||
server:
|
||||
port: 8080
|
||||
servlet:
|
||||
context-path: /kylin-jdbc-2.6.x-3.x-4.x-scenario
|
||||
logging:
|
||||
config: classpath:log4j2.xml
|
||||
|
|
@ -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.
|
||||
kylin.url=jdbc:kylin://kylin-server:7070/learn_kylin
|
||||
kylin.username=ADMIN
|
||||
kylin.password=KYLIN
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ 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.
|
||||
~
|
||||
-->
|
||||
<Configuration status="WARN">
|
||||
<Appenders>
|
||||
<Console name="Console" target="SYSTEM_ERR">
|
||||
<PatternLayout charset="UTF-8" pattern="[%d{yyyy-MM-dd HH:mm:ss:SSS}] [%p] - %l - %m%n"/>
|
||||
</Console>
|
||||
</Appenders>
|
||||
<Loggers>
|
||||
<Root level="WARN">
|
||||
<AppenderRef ref="Console"/>
|
||||
</Root>
|
||||
</Loggers>
|
||||
</Configuration>
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
# 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.
|
||||
|
||||
2.6.6
|
||||
3.0.2
|
||||
3.1.2
|
||||
4.0.0
|
||||
|
||||
Loading…
Reference in New Issue