New feature provided : new plugin for influxdb-java client (#4846)
This commit is contained in:
parent
8648f0d417
commit
08897ce5f8
|
|
@ -38,6 +38,7 @@ jobs:
|
||||||
- { name: 'httpclient-3.x-scenario', title: 'HttpClient 2.0-3.1 (5)' }
|
- { name: 'httpclient-3.x-scenario', title: 'HttpClient 2.0-3.1 (5)' }
|
||||||
- { name: 'httpclient-4.3.x-scenario', title: 'HttpClient 4.3.x-4.5.x (14)' }
|
- { name: 'httpclient-4.3.x-scenario', title: 'HttpClient 4.3.x-4.5.x (14)' }
|
||||||
- { name: 'hystrix-scenario', title: 'Hystrix 1.4.20-1.5.12 (20)' }
|
- { name: 'hystrix-scenario', title: 'Hystrix 1.4.20-1.5.12 (20)' }
|
||||||
|
- { name: 'influxdb-scenario', title: 'InfluxDB Java 2.5-2.17 (12)' }
|
||||||
- { name: 'jdk-http-scenario', title: 'JDK http (1)' }
|
- { name: 'jdk-http-scenario', title: 'JDK http (1)' }
|
||||||
- { name: 'jdk-threading-scenario', title: 'JDK Threading (1)' }
|
- { name: 'jdk-threading-scenario', title: 'JDK Threading (1)' }
|
||||||
- { name: 'jedis-scenario', title: 'Jedis 2.4.0-2.9.0 (18)' }
|
- { name: 'jedis-scenario', title: 'Jedis 2.4.0-2.9.0 (18)' }
|
||||||
|
|
|
||||||
|
|
@ -20,3 +20,5 @@ OALLexer.tokens
|
||||||
.externalToolBuilders
|
.externalToolBuilders
|
||||||
/test/plugin/dist
|
/test/plugin/dist
|
||||||
/test/plugin/workspace
|
/test/plugin/workspace
|
||||||
|
/test/jacoco/classes
|
||||||
|
/test/jacoco/*.exec
|
||||||
|
|
@ -160,4 +160,6 @@ public class ComponentsDefine {
|
||||||
public static final OfficialComponent MARIADB_JDBC = new OfficialComponent(87, "mariadb-jdbc");
|
public static final OfficialComponent MARIADB_JDBC = new OfficialComponent(87, "mariadb-jdbc");
|
||||||
|
|
||||||
public static final OfficialComponent QUASAR = new OfficialComponent(88, "quasar");
|
public static final OfficialComponent QUASAR = new OfficialComponent(88, "quasar");
|
||||||
|
|
||||||
|
public static final OfficialComponent INFLUXDB_JAVA = new OfficialComponent(90, "influxdb-java");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -399,6 +399,13 @@ public class Config {
|
||||||
*/
|
*/
|
||||||
public static int HTTP_PARAMS_LENGTH_THRESHOLD = 1024;
|
public static int HTTP_PARAMS_LENGTH_THRESHOLD = 1024;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class InfluxDB {
|
||||||
|
/**
|
||||||
|
* If set to true, the parameters of the InfluxQL would be collected.
|
||||||
|
*/
|
||||||
|
public static boolean TRACE_INFLUXQL = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Correlation {
|
public static class Correlation {
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,47 @@
|
||||||
|
<?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.1.0-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<artifactId>apm-influxdb-2.x-plugin</artifactId>
|
||||||
|
<description>This plugin is for use with influxdb-java client</description>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<influxdb-jave.version>2.15</influxdb-jave.version>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.influxdb</groupId>
|
||||||
|
<artifactId>influxdb-java</artifactId>
|
||||||
|
<version>${influxdb-jave.version}</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
</project>
|
||||||
|
|
@ -0,0 +1,45 @@
|
||||||
|
/*
|
||||||
|
* 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.influxdb.define;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* InfluxDB plugin Constants
|
||||||
|
*
|
||||||
|
* @since 2020/6/6
|
||||||
|
*/
|
||||||
|
public class Constants {
|
||||||
|
|
||||||
|
public static final String DB_TYPE = "InfluxDB";
|
||||||
|
|
||||||
|
public static final String PING_METHOD = "ping";
|
||||||
|
public static final String WRITE_METHOD = "write";
|
||||||
|
public static final String QUERY_METHOD = "query";
|
||||||
|
public static final String CREATE_DATABASE_METHOD = "createDatabase";
|
||||||
|
public static final String DELETE_DATABASE_METHOD = "deleteDatabase";
|
||||||
|
public static final String FLUSH_METHOD = "flush";
|
||||||
|
public static final String CREATE_RETENTION_POLICY_METHOD = "createRetentionPolicy";
|
||||||
|
public static final String DROP_RETENTION_POLICY_METHOD = "dropRetentionPolicy";
|
||||||
|
|
||||||
|
public static final Set<String> MATCHER_METHOD_NAME = new HashSet<>(Arrays.asList(PING_METHOD, WRITE_METHOD, QUERY_METHOD, CREATE_DATABASE_METHOD, DELETE_DATABASE_METHOD, FLUSH_METHOD, CREATE_RETENTION_POLICY_METHOD, DROP_RETENTION_POLICY_METHOD));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,100 @@
|
||||||
|
/*
|
||||||
|
* 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.influxdb.define;
|
||||||
|
|
||||||
|
import net.bytebuddy.description.method.MethodDescription;
|
||||||
|
import net.bytebuddy.matcher.ElementMatcher;
|
||||||
|
import net.bytebuddy.matcher.ElementMatchers;
|
||||||
|
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.agent.core.plugin.match.NameMatch;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import static net.bytebuddy.matcher.ElementMatchers.named;
|
||||||
|
import static net.bytebuddy.matcher.ElementMatchers.none;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enhance InfluxDB InfluxDBFactory
|
||||||
|
* Really impl class {@link org.influxdb.impl.InfluxDBImpl}
|
||||||
|
*
|
||||||
|
* @since 2020/05/22
|
||||||
|
*/
|
||||||
|
public class InfluxDBInstrumentation extends ClassInstanceMethodsEnhancePluginDefine {
|
||||||
|
|
||||||
|
private static final String ENHANCE_CLASS = "org.influxdb.impl.InfluxDBImpl";
|
||||||
|
private static final String INTERCEPTOR_CLASS = "org.apache.skywalking.apm.plugin.influxdb.interceptor.InfluxDBConstructorInterceptor";
|
||||||
|
private static final String INFLUXDB_METHOD_INTERCEPT_CLASS = "org.apache.skywalking.apm.plugin.influxdb.interceptor.InfluxDBMethodInterceptor";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected ClassMatch enhanceClass() {
|
||||||
|
return NameMatch.byName(ENHANCE_CLASS);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ConstructorInterceptPoint[] getConstructorsInterceptPoints() {
|
||||||
|
return new ConstructorInterceptPoint[] {
|
||||||
|
new ConstructorInterceptPoint() {
|
||||||
|
@Override
|
||||||
|
public ElementMatcher<MethodDescription> getConstructorMatcher() {
|
||||||
|
return ElementMatchers.takesArgument(0, String.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getConstructorInterceptor() {
|
||||||
|
return INTERCEPTOR_CLASS;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
|
||||||
|
return new InstanceMethodsInterceptPoint[] {
|
||||||
|
new InstanceMethodsInterceptPoint() {
|
||||||
|
@Override
|
||||||
|
public ElementMatcher<MethodDescription> getMethodsMatcher() {
|
||||||
|
ElementMatcher.Junction<MethodDescription> matcher = none();
|
||||||
|
final Set<String> setters = Constants.MATCHER_METHOD_NAME;
|
||||||
|
for (String setter : setters) {
|
||||||
|
matcher = matcher.or(named(setter));
|
||||||
|
}
|
||||||
|
return matcher;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getMethodsInterceptor() {
|
||||||
|
return getInstanceMethodsInterceptor();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isOverrideArgs() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String getInstanceMethodsInterceptor() {
|
||||||
|
return INFLUXDB_METHOD_INTERCEPT_CLASS;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,32 @@
|
||||||
|
/*
|
||||||
|
* 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.influxdb.interceptor;
|
||||||
|
|
||||||
|
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
|
||||||
|
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor;
|
||||||
|
|
||||||
|
public class InfluxDBConstructorInterceptor implements InstanceConstructorInterceptor {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onConstruct(EnhancedInstance objInst, Object[] allArguments) {
|
||||||
|
String url = (String) allArguments[0];
|
||||||
|
objInst.setSkyWalkingDynamicField(url);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,98 @@
|
||||||
|
/*
|
||||||
|
* 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.influxdb.interceptor;
|
||||||
|
|
||||||
|
import org.apache.skywalking.apm.agent.core.conf.Config;
|
||||||
|
import org.apache.skywalking.apm.agent.core.context.ContextManager;
|
||||||
|
import org.apache.skywalking.apm.agent.core.context.tag.Tags;
|
||||||
|
import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan;
|
||||||
|
import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer;
|
||||||
|
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
|
||||||
|
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor;
|
||||||
|
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult;
|
||||||
|
import org.apache.skywalking.apm.network.trace.component.ComponentsDefine;
|
||||||
|
import org.apache.skywalking.apm.plugin.influxdb.define.Constants;
|
||||||
|
import org.influxdb.dto.BatchPoints;
|
||||||
|
import org.influxdb.dto.Point;
|
||||||
|
import org.influxdb.dto.Query;
|
||||||
|
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
|
import static org.apache.skywalking.apm.plugin.influxdb.define.Constants.DB_TYPE;
|
||||||
|
|
||||||
|
public class InfluxDBMethodInterceptor implements InstanceMethodsAroundInterceptor {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
|
||||||
|
MethodInterceptResult result) throws Throwable {
|
||||||
|
String methodName = method.getName();
|
||||||
|
String peer = String.valueOf(objInst.getSkyWalkingDynamicField());
|
||||||
|
AbstractSpan span = ContextManager.createExitSpan("InfluxDB/" + methodName, peer);
|
||||||
|
span.setComponent(ComponentsDefine.INFLUXDB_JAVA);
|
||||||
|
SpanLayer.asDB(span);
|
||||||
|
Tags.DB_TYPE.set(span, DB_TYPE);
|
||||||
|
|
||||||
|
if (allArguments.length <= 0 || !Config.Plugin.InfluxDB.TRACE_INFLUXQL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (allArguments[0] instanceof Query) {
|
||||||
|
Query query = (Query) allArguments[0];
|
||||||
|
Tags.DB_INSTANCE.set(span, query.getDatabase());
|
||||||
|
Tags.DB_STATEMENT.set(span, query.getCommand());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Constants.WRITE_METHOD.equals(methodName)) {
|
||||||
|
if (allArguments[0] instanceof BatchPoints) {
|
||||||
|
BatchPoints batchPoints = (BatchPoints) allArguments[0];
|
||||||
|
Tags.DB_INSTANCE.set(span, batchPoints.getDatabase());
|
||||||
|
Tags.DB_STATEMENT.set(span, batchPoints.lineProtocol());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (allArguments.length == 5) {
|
||||||
|
if (allArguments[0] instanceof String) {
|
||||||
|
Tags.DB_INSTANCE.set(span, (String) allArguments[0]);
|
||||||
|
}
|
||||||
|
if (allArguments[4] instanceof String) {
|
||||||
|
Tags.DB_STATEMENT.set(span, (String) allArguments[4]);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (allArguments.length == 3 && allArguments[2] instanceof Point) {
|
||||||
|
Tags.DB_INSTANCE.set(span, (String) allArguments[0]);
|
||||||
|
Tags.DB_STATEMENT.set(span, ((Point) allArguments[2]).lineProtocol());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
|
||||||
|
Object ret) throws Throwable {
|
||||||
|
ContextManager.stopSpan();
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments,
|
||||||
|
Class<?>[] argumentsTypes, Throwable t) {
|
||||||
|
ContextManager.activeSpan().errorOccurred().log(t);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,17 @@
|
||||||
|
# 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.
|
||||||
|
|
||||||
|
influxdb-2.x=org.apache.skywalking.apm.plugin.influxdb.define.InfluxDBInstrumentation
|
||||||
|
|
@ -0,0 +1,65 @@
|
||||||
|
/*
|
||||||
|
* 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.influxdb;
|
||||||
|
|
||||||
|
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
|
||||||
|
import org.apache.skywalking.apm.plugin.influxdb.interceptor.InfluxDBConstructorInterceptor;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.runners.MockitoJUnitRunner;
|
||||||
|
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
|
|
||||||
|
@RunWith(MockitoJUnitRunner.class)
|
||||||
|
public class InfluxDBConstructorInterceptorTest {
|
||||||
|
|
||||||
|
private static final String INFLUXDB_URL = "http://127.0.0.1:8086";
|
||||||
|
|
||||||
|
private InfluxDBConstructorInterceptor interceptor;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private EnhancedInstance enhancedInstance;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() throws Exception {
|
||||||
|
interceptor = new InfluxDBConstructorInterceptor();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void onConstruct() throws Exception {
|
||||||
|
interceptor.onConstruct(enhancedInstance, new Object[] {INFLUXDB_URL});
|
||||||
|
|
||||||
|
verify(enhancedInstance).setSkyWalkingDynamicField(INFLUXDB_URL);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void onConstructWithUsernameAndPassword() {
|
||||||
|
interceptor.onConstruct(enhancedInstance, new Object[] {
|
||||||
|
INFLUXDB_URL,
|
||||||
|
"admin",
|
||||||
|
"123456",
|
||||||
|
null
|
||||||
|
});
|
||||||
|
|
||||||
|
verify(enhancedInstance).setSkyWalkingDynamicField(INFLUXDB_URL);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,169 @@
|
||||||
|
/*
|
||||||
|
* 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.influxdb;
|
||||||
|
|
||||||
|
import org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan;
|
||||||
|
import org.apache.skywalking.apm.agent.core.context.trace.LogDataEntity;
|
||||||
|
import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer;
|
||||||
|
import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment;
|
||||||
|
import org.apache.skywalking.apm.agent.core.context.util.TagValuePair;
|
||||||
|
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
|
||||||
|
import org.apache.skywalking.apm.agent.test.helper.SegmentHelper;
|
||||||
|
import org.apache.skywalking.apm.agent.test.helper.SpanHelper;
|
||||||
|
import org.apache.skywalking.apm.agent.test.tools.AgentServiceRule;
|
||||||
|
import org.apache.skywalking.apm.agent.test.tools.SegmentStorage;
|
||||||
|
import org.apache.skywalking.apm.agent.test.tools.SegmentStoragePoint;
|
||||||
|
import org.apache.skywalking.apm.agent.test.tools.TracingSegmentRunner;
|
||||||
|
import org.apache.skywalking.apm.network.trace.component.ComponentsDefine;
|
||||||
|
import org.apache.skywalking.apm.plugin.influxdb.define.Constants;
|
||||||
|
import org.apache.skywalking.apm.plugin.influxdb.interceptor.InfluxDBMethodInterceptor;
|
||||||
|
import org.hamcrest.CoreMatchers;
|
||||||
|
import org.influxdb.InfluxDB;
|
||||||
|
import org.influxdb.InfluxDBException;
|
||||||
|
import org.influxdb.dto.Query;
|
||||||
|
import org.influxdb.impl.InfluxDBImpl;
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Rule;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
import org.powermock.modules.junit4.PowerMockRunner;
|
||||||
|
import org.powermock.modules.junit4.PowerMockRunnerDelegate;
|
||||||
|
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import static junit.framework.TestCase.assertNotNull;
|
||||||
|
import static org.hamcrest.CoreMatchers.is;
|
||||||
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
@RunWith(PowerMockRunner.class)
|
||||||
|
@PowerMockRunnerDelegate(TracingSegmentRunner.class)
|
||||||
|
public class InfluxDBMethodInterceptorTest {
|
||||||
|
|
||||||
|
@SegmentStoragePoint
|
||||||
|
private SegmentStorage segmentStorage;
|
||||||
|
|
||||||
|
@Rule
|
||||||
|
public AgentServiceRule serviceRule = new AgentServiceRule();
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private EnhancedInstance enhancedInstance;
|
||||||
|
|
||||||
|
private InfluxDBMethodInterceptor interceptor;
|
||||||
|
|
||||||
|
private Object[] writeArguments;
|
||||||
|
|
||||||
|
private Class[] writeArgumentTypes;
|
||||||
|
|
||||||
|
private Object[] queryArguments;
|
||||||
|
|
||||||
|
private Class[] queryArgumentTypes;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() throws Exception {
|
||||||
|
// write
|
||||||
|
writeArguments = new Object[] {
|
||||||
|
"sw8", "auto_gen", InfluxDB.ConsistencyLevel.ALL, TimeUnit.SECONDS,
|
||||||
|
"weather,location=us-midwest temperature=82 1465839830100400200"
|
||||||
|
};
|
||||||
|
writeArgumentTypes = new Class[] {
|
||||||
|
String.class, String.class, InfluxDB.ConsistencyLevel.class, TimeUnit.class, String.class
|
||||||
|
};
|
||||||
|
|
||||||
|
// query
|
||||||
|
queryArguments = new Object[] {
|
||||||
|
new Query("select * from weather limit 1", "sw8")
|
||||||
|
};
|
||||||
|
queryArgumentTypes = new Class[] {
|
||||||
|
Query.class
|
||||||
|
};
|
||||||
|
|
||||||
|
interceptor = new InfluxDBMethodInterceptor();
|
||||||
|
when(enhancedInstance.getSkyWalkingDynamicField()).thenReturn("http://127.0.0.1:8086");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testIntercept() throws Throwable {
|
||||||
|
interceptor.beforeMethod(enhancedInstance, getMockWriteMethod(), writeArguments, writeArgumentTypes, null);
|
||||||
|
interceptor.afterMethod(enhancedInstance, getMockQueryMethod(), queryArguments, queryArgumentTypes, null);
|
||||||
|
|
||||||
|
TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
|
||||||
|
List<AbstractTracingSpan> spans = SegmentHelper.getSpans(traceSegment);
|
||||||
|
assertThat(spans.size(), is(1));
|
||||||
|
assertWriteInfluxDBSpan(spans.get(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testInterceptWithException() throws Throwable {
|
||||||
|
interceptor.beforeMethod(enhancedInstance, getMockWriteMethod(), writeArguments, writeArgumentTypes, null);
|
||||||
|
interceptor.handleMethodException(enhancedInstance, getMockWriteMethod(), writeArguments, writeArgumentTypes, new InfluxDBException("test exception"));
|
||||||
|
interceptor.afterMethod(enhancedInstance, getMockWriteMethod(), writeArguments, writeArgumentTypes, null);
|
||||||
|
|
||||||
|
TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
|
||||||
|
List<AbstractTracingSpan> spans = SegmentHelper.getSpans(traceSegment);
|
||||||
|
assertThat(spans.size(), is(1));
|
||||||
|
assertWriteInfluxDBSpan(spans.get(0));
|
||||||
|
|
||||||
|
assertLogData(SpanHelper.getLogs(spans.get(0)));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void assertLogData(List<LogDataEntity> logDataEntities) {
|
||||||
|
assertThat(logDataEntities.size(), is(1));
|
||||||
|
LogDataEntity logData = logDataEntities.get(0);
|
||||||
|
Assert.assertThat(logData.getLogs().size(), is(4));
|
||||||
|
Assert.assertThat(logData.getLogs().get(0).getValue(),
|
||||||
|
CoreMatchers.<Object>is("error"));
|
||||||
|
Assert.assertThat(logData.getLogs().get(1).getValue(),
|
||||||
|
CoreMatchers.<Object>is(InfluxDBException.class.getName()));
|
||||||
|
Assert.assertEquals("test exception", logData.getLogs().get(2).getValue());
|
||||||
|
assertNotNull(logData.getLogs().get(3).getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void assertWriteInfluxDBSpan(AbstractTracingSpan span) {
|
||||||
|
assertThat(span.getOperationName(), is("InfluxDB/write"));
|
||||||
|
assertThat(span.isExit(), is(true));
|
||||||
|
assertThat(SpanHelper.getComponentId(span), is(ComponentsDefine.INFLUXDB_JAVA.getId()));
|
||||||
|
List<TagValuePair> tags = SpanHelper.getTags(span);
|
||||||
|
assertThat(tags.get(0).getValue(), is(Constants.DB_TYPE));
|
||||||
|
assertThat(SpanHelper.getLayer(span), CoreMatchers.is(SpanLayer.DB));
|
||||||
|
}
|
||||||
|
|
||||||
|
private Method getMockWriteMethod() {
|
||||||
|
try {
|
||||||
|
return InfluxDBImpl.class.getMethod(Constants.WRITE_METHOD, writeArgumentTypes);
|
||||||
|
} catch (NoSuchMethodException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Method getMockQueryMethod() {
|
||||||
|
try {
|
||||||
|
return InfluxDBImpl.class.getMethod(Constants.QUERY_METHOD, queryArgumentTypes);
|
||||||
|
} catch (NoSuchMethodException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -92,6 +92,7 @@
|
||||||
<module>finagle-6.25.x-plugin</module>
|
<module>finagle-6.25.x-plugin</module>
|
||||||
<module>quasar-plugin</module>
|
<module>quasar-plugin</module>
|
||||||
<module>mariadb-2.x-plugin</module>
|
<module>mariadb-2.x-plugin</module>
|
||||||
|
<module>influxdb-2.x-plugin</module>
|
||||||
</modules>
|
</modules>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -126,6 +126,7 @@ property key | Description | Default |
|
||||||
`plugin.tomcat.collect_http_params`| This config item controls that whether the Tomcat plugin should collect the parameters of the request. Also, activate implicitly in the profiled trace. | `false` |
|
`plugin.tomcat.collect_http_params`| This config item controls that whether the Tomcat plugin should collect the parameters of the request. Also, activate implicitly in the profiled trace. | `false` |
|
||||||
`plugin.springmvc.collect_http_params`| This config item controls that whether the SpringMVC plugin should collect the parameters of the request, when your Spring application is based on Tomcat, consider only setting either `plugin.tomcat.collect_http_params` or `plugin.springmvc.collect_http_params`. Also, activate implicitly in the profiled trace. | `false` |
|
`plugin.springmvc.collect_http_params`| This config item controls that whether the SpringMVC plugin should collect the parameters of the request, when your Spring application is based on Tomcat, consider only setting either `plugin.tomcat.collect_http_params` or `plugin.springmvc.collect_http_params`. Also, activate implicitly in the profiled trace. | `false` |
|
||||||
`plugin.http.http_params_length_threshold`| When `COLLECT_HTTP_PARAMS` is enabled, how many characters to keep and send to the OAP backend, use negative values to keep and send the complete parameters, NB. this config item is added for the sake of performance. | `1024` |
|
`plugin.http.http_params_length_threshold`| When `COLLECT_HTTP_PARAMS` is enabled, how many characters to keep and send to the OAP backend, use negative values to keep and send the complete parameters, NB. this config item is added for the sake of performance. | `1024` |
|
||||||
|
`plugin.influxdb.trace_influxql`|If true, trace all the influxql(query and write) in InfluxDB access, default is true.|`true`|
|
||||||
`correlation.element_max_number`|Max element count of the correlation context.|`3`|
|
`correlation.element_max_number`|Max element count of the correlation context.|`3`|
|
||||||
`correlation.value_max_length`|Max value length of correlation context element.|`128`|
|
`correlation.value_max_length`|Max value length of correlation context element.|`128`|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,7 @@
|
||||||
* [ShardingSphere](https://github.com/apache/shardingsphere) 3.0.0, 4.0.0-RC1, 4.0.0, 4.0.1, 4.1.0, 4.1.1
|
* [ShardingSphere](https://github.com/apache/shardingsphere) 3.0.0, 4.0.0-RC1, 4.0.0, 4.0.1, 4.1.0, 4.1.1
|
||||||
* PostgreSQL Driver 8.x, 9.x, 42.x
|
* PostgreSQL Driver 8.x, 9.x, 42.x
|
||||||
* Mariadb Driver 2.x, 1.8
|
* Mariadb Driver 2.x, 1.8
|
||||||
|
* [InfluxDB](https://github.com/influxdata/influxdb-java) 2.5 -> 2.17
|
||||||
* RPC Frameworks
|
* RPC Frameworks
|
||||||
* [Dubbo](https://github.com/alibaba/dubbo) 2.5.4 -> 2.6.0
|
* [Dubbo](https://github.com/alibaba/dubbo) 2.5.4 -> 2.6.0
|
||||||
* [Dubbox](https://github.com/dangdangdotcom/dubbox) 2.8.4
|
* [Dubbox](https://github.com/dangdangdotcom/dubbox) 2.8.4
|
||||||
|
|
|
||||||
|
|
@ -296,6 +296,12 @@ mariadb-jdbc:
|
||||||
quasar:
|
quasar:
|
||||||
id: 88
|
id: 88
|
||||||
languages: Java
|
languages: Java
|
||||||
|
InfluxDB:
|
||||||
|
id: 89
|
||||||
|
languages: Java
|
||||||
|
influxdb-java:
|
||||||
|
id: 90
|
||||||
|
languages: Java
|
||||||
|
|
||||||
# .NET/.NET Core components
|
# .NET/.NET Core components
|
||||||
# [3000, 4000) for C#/.NET only
|
# [3000, 4000) for C#/.NET only
|
||||||
|
|
|
||||||
|
|
@ -260,7 +260,12 @@ mariadb-jdbc:
|
||||||
quasar:
|
quasar:
|
||||||
id: 88
|
id: 88
|
||||||
languages: Java
|
languages: Java
|
||||||
|
InfluxDB:
|
||||||
|
id: 89
|
||||||
|
languages: Java
|
||||||
|
influxdb-java:
|
||||||
|
id: 90
|
||||||
|
languages: Java
|
||||||
|
|
||||||
# .NET/.NET Core components
|
# .NET/.NET Core components
|
||||||
# [3000, 4000) for C#/.NET only
|
# [3000, 4000) for C#/.NET only
|
||||||
|
|
|
||||||
1
pom.xml
1
pom.xml
|
|
@ -486,6 +486,7 @@
|
||||||
|
|
||||||
<!-- generated file from test agent plugin scenarios -->
|
<!-- generated file from test agent plugin scenarios -->
|
||||||
<exclude>**/test/plugin/workspace/**</exclude>
|
<exclude>**/test/plugin/workspace/**</exclude>
|
||||||
|
<exclude>**/test/jacoco/**</exclude>
|
||||||
|
|
||||||
<!-- TSL relevant files for e2e test -->
|
<!-- TSL relevant files for e2e test -->
|
||||||
<exclude>**/*.crt</exclude>
|
<exclude>**/*.crt</exclude>
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,22 @@
|
||||||
|
#!/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} -Dinfluxdb.url=${INFLUXDB_URL} \
|
||||||
|
${home}/../libs/influxdb-scenario.jar &
|
||||||
|
|
@ -0,0 +1,131 @@
|
||||||
|
# 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: influxdb-scenario
|
||||||
|
segmentSize: gt 1
|
||||||
|
segments:
|
||||||
|
- segmentId: not null
|
||||||
|
spans:
|
||||||
|
- operationName: InfluxDB/ping
|
||||||
|
operationId: 0
|
||||||
|
parentSpanId: 0
|
||||||
|
spanId: 1
|
||||||
|
spanLayer: Database
|
||||||
|
startTime: nq 0
|
||||||
|
endTime: nq 0
|
||||||
|
componentId: 90
|
||||||
|
isError: false
|
||||||
|
spanType: Exit
|
||||||
|
peer: http://influxdb:8086
|
||||||
|
tags:
|
||||||
|
- {key: db.type, value: InfluxDB}
|
||||||
|
skipAnalysis: 'false'
|
||||||
|
- operationName: /influxdb-scenario/case/healthCheck
|
||||||
|
operationId: 0
|
||||||
|
parentSpanId: -1
|
||||||
|
spanId: 0
|
||||||
|
spanLayer: Http
|
||||||
|
startTime: nq 0
|
||||||
|
endTime: nq 0
|
||||||
|
componentId: 1
|
||||||
|
isError: false
|
||||||
|
spanType: Entry
|
||||||
|
peer: ''
|
||||||
|
skipAnalysis: false
|
||||||
|
tags:
|
||||||
|
- {key: url, value: 'http://localhost:8080/influxdb-scenario/case/healthCheck'}
|
||||||
|
- {key: http.method, value: HEAD}
|
||||||
|
- segmentId: not null
|
||||||
|
spans:
|
||||||
|
- operationName: InfluxDB/query
|
||||||
|
operationId: 0
|
||||||
|
parentSpanId: 0
|
||||||
|
spanId: 1
|
||||||
|
spanLayer: Database
|
||||||
|
startTime: nq 0
|
||||||
|
endTime: nq 0
|
||||||
|
componentId: 90
|
||||||
|
isError: false
|
||||||
|
spanType: Exit
|
||||||
|
peer: http://influxdb:8086
|
||||||
|
tags:
|
||||||
|
- {key: db.type, value: InfluxDB}
|
||||||
|
- {key: db.instance, value: skywalking}
|
||||||
|
- {key: db.statement, value: 'CREATE DATABASE skywalking'}
|
||||||
|
skipAnalysis: 'false'
|
||||||
|
- operationName: InfluxDB/query
|
||||||
|
operationId: 0
|
||||||
|
parentSpanId: 0
|
||||||
|
spanId: 2
|
||||||
|
spanLayer: Database
|
||||||
|
startTime: nq 0
|
||||||
|
endTime: nq 0
|
||||||
|
componentId: 90
|
||||||
|
isError: false
|
||||||
|
spanType: Exit
|
||||||
|
peer: http://influxdb:8086
|
||||||
|
tags:
|
||||||
|
- {key: db.type, value: InfluxDB}
|
||||||
|
- {key: db.instance, value: skywalking}
|
||||||
|
- {key: db.statement, value: 'CREATE RETENTION POLICY one_day ON skywalking DURATION 1d REPLICATION 1 DEFAULT'}
|
||||||
|
skipAnalysis: 'false'
|
||||||
|
- operationName: InfluxDB/write
|
||||||
|
operationId: 0
|
||||||
|
parentSpanId: 0
|
||||||
|
spanId: 3
|
||||||
|
spanLayer: Database
|
||||||
|
startTime: nq 0
|
||||||
|
endTime: nq 0
|
||||||
|
componentId: 90
|
||||||
|
isError: false
|
||||||
|
spanType: Exit
|
||||||
|
peer: http://influxdb:8086
|
||||||
|
tags:
|
||||||
|
- {key: db.type, value: InfluxDB}
|
||||||
|
- {key: db.instance, value: skywalking}
|
||||||
|
- {key: db.statement, value: not null}
|
||||||
|
skipAnalysis: 'false'
|
||||||
|
- operationName: InfluxDB/query
|
||||||
|
operationId: 0
|
||||||
|
parentSpanId: 0
|
||||||
|
spanId: 4
|
||||||
|
spanLayer: Database
|
||||||
|
startTime: nq 0
|
||||||
|
endTime: nq 0
|
||||||
|
componentId: 90
|
||||||
|
isError: false
|
||||||
|
spanType: Exit
|
||||||
|
peer: http://influxdb:8086
|
||||||
|
tags:
|
||||||
|
- {key: db.type, value: InfluxDB}
|
||||||
|
- {key: db.instance, value: skywalking}
|
||||||
|
- {key: db.statement, value: 'SELECT * FROM heartbeat'}
|
||||||
|
skipAnalysis: 'false'
|
||||||
|
- operationName: /influxdb-scenario/case/influxdb-scenario
|
||||||
|
operationId: 0
|
||||||
|
parentSpanId: -1
|
||||||
|
spanId: 0
|
||||||
|
spanLayer: Http
|
||||||
|
startTime: nq 0
|
||||||
|
endTime: nq 0
|
||||||
|
componentId: 1
|
||||||
|
isError: false
|
||||||
|
spanType: Entry
|
||||||
|
peer: ''
|
||||||
|
tags:
|
||||||
|
- {key: url, value: 'http://localhost:8080/influxdb-scenario/case/influxdb-scenario'}
|
||||||
|
- {key: http.method, value: GET}
|
||||||
|
skipAnalysis: 'false'
|
||||||
|
|
@ -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.
|
||||||
|
|
||||||
|
type: jvm
|
||||||
|
entryService: http://localhost:8080/influxdb-scenario/case/influxdb-scenario
|
||||||
|
healthCheck: http://localhost:8080/influxdb-scenario/case/healthCheck
|
||||||
|
startScript: ./bin/startup.sh
|
||||||
|
environment:
|
||||||
|
- INFLUXDB_URL=http://influxdb:8086
|
||||||
|
dependencies:
|
||||||
|
influxdb:
|
||||||
|
image: influxdb:1.7.10
|
||||||
|
hostname: influxdb
|
||||||
|
|
||||||
|
|
@ -0,0 +1,114 @@
|
||||||
|
<?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>influxdb-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>
|
||||||
|
<spring-boot-version>2.1.6.RELEASE</spring-boot-version>
|
||||||
|
<test.framework.version>2.17</test.framework.version>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<name>skywalking-influxdb-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>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.influxdb</groupId>
|
||||||
|
<artifactId>influxdb-java</artifactId>
|
||||||
|
<version>${test.framework.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>junit</groupId>
|
||||||
|
<artifactId>junit</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<finalName>influxdb-scenario</finalName>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
|
<version>1.5.9.RELEASE</version>
|
||||||
|
<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}/influxdb-scenario.jar</source>
|
||||||
|
<outputDirectory>./libs</outputDirectory>
|
||||||
|
<fileMode>0775</fileMode>
|
||||||
|
</file>
|
||||||
|
</files>
|
||||||
|
</assembly>
|
||||||
|
|
@ -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.testcase.influxdb;
|
||||||
|
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
|
||||||
|
@SpringBootApplication
|
||||||
|
public class Application {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
try {
|
||||||
|
SpringApplication.run(Application.class, args);
|
||||||
|
} catch (Exception e) {
|
||||||
|
// Never do this
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,70 @@
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership.
|
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
* (the "License"); you may not use this file except in compliance with
|
||||||
|
* the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.apache.skywalking.apm.testcase.influxdb.controller;
|
||||||
|
|
||||||
|
import org.apache.skywalking.apm.testcase.influxdb.executor.InfluxDBExecutor;
|
||||||
|
import org.influxdb.dto.Point;
|
||||||
|
import org.influxdb.dto.Pong;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.ResponseBody;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/case")
|
||||||
|
public class CaseController {
|
||||||
|
|
||||||
|
private static final String SUCCESS = "Success";
|
||||||
|
private static final String ERROR = "Error";
|
||||||
|
|
||||||
|
@Value("${influxdb.url:http://127.0.0.1:8086}")
|
||||||
|
private String serverURL;
|
||||||
|
|
||||||
|
@RequestMapping("/influxdb-scenario")
|
||||||
|
@ResponseBody
|
||||||
|
public String testcase(){
|
||||||
|
InfluxDBExecutor executor = new InfluxDBExecutor(serverURL);
|
||||||
|
// createDatabase
|
||||||
|
String db = "skywalking";
|
||||||
|
executor.createDatabase(db);
|
||||||
|
// createRetentionPolicy
|
||||||
|
String rp = "one_day";
|
||||||
|
executor.createRetentionPolicyWithOneDay(db,rp);
|
||||||
|
Point point = Point.measurement("heartbeat")
|
||||||
|
.time(System.currentTimeMillis(), TimeUnit.MILLISECONDS)
|
||||||
|
.tag("host", "127.0.0.1")
|
||||||
|
.addField("device_name", "sensor x")
|
||||||
|
.build();
|
||||||
|
// write
|
||||||
|
executor.write(db,rp,point);
|
||||||
|
// query
|
||||||
|
executor.query(db,"SELECT * FROM heartbeat");
|
||||||
|
return SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequestMapping("/healthCheck")
|
||||||
|
@ResponseBody
|
||||||
|
public String healthCheck() {
|
||||||
|
InfluxDBExecutor executor = new InfluxDBExecutor(serverURL);
|
||||||
|
Pong pong = executor.ping();
|
||||||
|
return pong.getVersion() != null ? SUCCESS : ERROR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -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.testcase.influxdb.executor;
|
||||||
|
|
||||||
|
import org.influxdb.InfluxDB;
|
||||||
|
import org.influxdb.InfluxDBFactory;
|
||||||
|
import org.influxdb.dto.Point;
|
||||||
|
import org.influxdb.dto.Pong;
|
||||||
|
import org.influxdb.dto.Query;
|
||||||
|
import org.influxdb.dto.QueryResult;
|
||||||
|
|
||||||
|
public class InfluxDBExecutor implements AutoCloseable {
|
||||||
|
|
||||||
|
private final InfluxDB influxDB;
|
||||||
|
|
||||||
|
public InfluxDBExecutor(String serverURL){
|
||||||
|
influxDB = InfluxDBFactory.connect(serverURL,"admin",null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Pong ping(){
|
||||||
|
return influxDB.ping();
|
||||||
|
}
|
||||||
|
|
||||||
|
public QueryResult createDatabase(String databaseName){
|
||||||
|
// Create a database...
|
||||||
|
return influxDB.query(new Query("CREATE DATABASE " + databaseName, databaseName));
|
||||||
|
}
|
||||||
|
|
||||||
|
public QueryResult createRetentionPolicyWithOneDay(String databaseName, String retentionPolicyName){
|
||||||
|
// influxDB.setDatabase(databaseName);
|
||||||
|
// ... and a retention policy, if necessary.
|
||||||
|
return influxDB.query(new Query("CREATE RETENTION POLICY " + retentionPolicyName + " ON " + databaseName + " DURATION 1d REPLICATION 1 DEFAULT", databaseName));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void write(String databaseName, String retentionPolicyName,Point point){
|
||||||
|
// Write points to InfluxDB.
|
||||||
|
influxDB.write(databaseName, retentionPolicyName, point);
|
||||||
|
}
|
||||||
|
|
||||||
|
public QueryResult query(String databaseName,String command){
|
||||||
|
// Query your data using InfluxQL.
|
||||||
|
return influxDB.query(new Query(command, databaseName));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close() throws Exception {
|
||||||
|
if (influxDB != null){
|
||||||
|
// Close it if your application is terminating or you are not using it anymore.
|
||||||
|
influxDB.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -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.
|
||||||
|
#
|
||||||
|
#
|
||||||
|
server:
|
||||||
|
port: 8080
|
||||||
|
servlet:
|
||||||
|
context-path: /influxdb-scenario
|
||||||
|
|
@ -0,0 +1,30 @@
|
||||||
|
# Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
# or more contributor license agreements. See the NOTICE file
|
||||||
|
# distributed with this work for additional information
|
||||||
|
# regarding copyright ownership. The ASF licenses this file
|
||||||
|
# to you under the Apache License, Version
|
||||||
|
# "License"); you may not use this file except in compliance
|
||||||
|
# with the License. You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT 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.17
|
||||||
|
2.16
|
||||||
|
2.15
|
||||||
|
2.14
|
||||||
|
2.13
|
||||||
|
2.12
|
||||||
|
2.11
|
||||||
|
2.10
|
||||||
|
2.9
|
||||||
|
2.8
|
||||||
|
2.7
|
||||||
|
2.6
|
||||||
|
2.5
|
||||||
Loading…
Reference in New Issue