Add plugin to support Aerospike Java client (#565)

This commit is contained in:
dd1k 2023-06-29 23:32:05 +08:00 committed by GitHub
parent e464f18ad9
commit d42e24583d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 924 additions and 0 deletions

View File

@ -52,6 +52,7 @@ jobs:
strategy:
matrix:
case:
- aerospike-scenario
- mysql-scenario
- undertow-scenario
- webflux-scenario

View File

@ -138,6 +138,7 @@ Callable {
* Fix the thread safety bug of finishing operation for the span named "SpringCloudGateway/sendRequest"
* Fix NPE in guava-eventbus-plugin.
* Add WebSphere Liberty 23.x plugin
* Add Plugin to support aerospike Java client
#### Documentation

View File

@ -238,4 +238,7 @@ public class ComponentsDefine {
public static final OfficialComponent GRIZZLY = new OfficialComponent(147, "Grizzly");
public static final OfficialComponent WEBSPHERE = new OfficialComponent(148, "WebSphere");
public static final OfficialComponent AEROSPIKE = new OfficialComponent(149, "Aerospike");
}

View File

@ -0,0 +1,48 @@
<?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>9.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>apm-aerospike-plugin</artifactId>
<packaging>jar</packaging>
<name>aerospike-plugin</name>
<dependencies>
<dependency>
<groupId>com.aerospike</groupId>
<artifactId>aerospike-client</artifactId>
<version>6.0.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
</project>

View File

@ -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.aerospike;
import com.aerospike.client.Host;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor;
import org.apache.skywalking.apm.util.StringUtil;
import java.util.ArrayList;
public class AerospikeClientConstructorInterceptor implements InstanceConstructorInterceptor {
@Override
public void onConstruct(EnhancedInstance objInst, Object[] allArguments) {
String peer = "";
if (allArguments.length >= 1 && allArguments[0] instanceof String) {
peer = allArguments[0] + ":" + allArguments[1];
} else if (allArguments.length >= 2 && allArguments[1] instanceof String) {
peer = allArguments[1] + ":" + allArguments[2];
} else if (allArguments.length >= 2 && allArguments[1] instanceof Host) {
Host host = (Host) allArguments[1];
peer = host.name + ":" + host.port;
} else if (allArguments.length >= 2 && allArguments[1] instanceof Host[]) {
Host[] hosts = (Host[]) allArguments[1];
ArrayList<String> names = new ArrayList<String>(hosts.length);
for (Host host: hosts) {
names.add(host.name + ":" + host.port);
}
peer = StringUtil.join(';', names.toArray(new String[0]));
}
objInst.setSkyWalkingDynamicField(peer);
}
}

View File

@ -0,0 +1,104 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.skywalking.apm.plugin.aerospike;
import org.apache.skywalking.apm.agent.core.context.ContextManager;
import org.apache.skywalking.apm.agent.core.context.tag.Tags;
import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan;
import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult;
import org.apache.skywalking.apm.network.trace.component.ComponentsDefine;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Optional;
import java.util.Set;
public class AerospikeClientMethodInterceptor implements InstanceMethodsAroundInterceptor {
private static final Set<String> OPERATION_MAPPING_READ = new HashSet<>(Arrays.asList(
"get",
"prepend",
"exists",
"getHeader",
"scanAll",
"scanNode",
"scanPartitions",
"getLargeList",
"getLargeMap",
"getLargeSet",
"getLargeStack",
"query",
"queryNode",
"queryPartitions",
"queryAggregate",
"queryAggregateNode",
"info"
));
private static final Set<String> OPERATION_MAPPING_WRITE = new HashSet<>(Arrays.asList(
"append",
"put",
"add",
"delete",
"touch",
"operate",
"register",
"registerUdfString",
"removeUdf",
"execute"
));
@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
MethodInterceptResult result) throws Throwable {
String peer = String.valueOf(objInst.getSkyWalkingDynamicField());
String methodName = method.getName();
AbstractSpan span = ContextManager.createExitSpan("Aerospike/" + methodName, peer);
span.setComponent(ComponentsDefine.AEROSPIKE);
Tags.CACHE_TYPE.set(span, "Aerospike");
SpanLayer.asCache(span);
parseOperation(methodName).ifPresent(op -> Tags.CACHE_OP.set(span, op));
}
@Override
public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
Object ret) throws Throwable {
ContextManager.stopSpan();
return ret;
}
@Override
public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments,
Class<?>[] argumentsTypes, Throwable t) {
AbstractSpan span = ContextManager.activeSpan();
span.log(t);
}
private Optional<String> parseOperation(String cmd) {
if (OPERATION_MAPPING_READ.contains(cmd)) {
return Optional.of("read");
}
if (OPERATION_MAPPING_WRITE.contains(cmd)) {
return Optional.of("write");
}
return Optional.empty();
}
}

View File

@ -0,0 +1,113 @@
/*
* 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.aerospike.define;
import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.matcher.ElementMatcher;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch;
import static net.bytebuddy.matcher.ElementMatchers.named;
import static org.apache.skywalking.apm.agent.core.plugin.bytebuddy.ArgumentTypeNameMatch.takesArgumentWithType;
import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName;
public class AerospikeClientInstrumentation extends ClassInstanceMethodsEnhancePluginDefine {
private static final String ENHANCE_CLASS = "com.aerospike.client.AerospikeClient";
private static final String HOST_ARG_TYPE_NAME = "com.aerospike.client.policy.ClientPolicy";
private static final String AEROSPIKE_CLIENT_CONSTRUCTOR_INTERCEPTOR = "org.apache.skywalking.apm.plugin.aerospike.AerospikeClientConstructorInterceptor";
private static final String AEROSPIKE_CLIENT_METHOD_INTERCEPTOR = "org.apache.skywalking.apm.plugin.aerospike.AerospikeClientMethodInterceptor";
private static final String[] ENHANCE_METHODS = new String[] {
"append",
"put",
"prepend",
"add",
"delete",
"touch",
"exists",
"get",
"getHeader",
"operate",
"scanAll",
"scanNode",
"scanPartitions",
"getLargeList",
"getLargeMap",
"getLargeSet",
"getLargeStack",
"register",
"registerUdfString",
"removeUdf",
"execute",
"query",
"queryNode",
"queryPartitions",
"queryAggregate",
"queryAggregateNode",
"info"
};
@Override
public ClassMatch enhanceClass() {
return byName(ENHANCE_CLASS);
}
@Override
public ConstructorInterceptPoint[] getConstructorsInterceptPoints() {
return new ConstructorInterceptPoint[] {
new ConstructorInterceptPoint() {
@Override
public ElementMatcher<MethodDescription> getConstructorMatcher() {
return takesArgumentWithType(0, HOST_ARG_TYPE_NAME);
}
@Override
public String getConstructorInterceptor() {
return AEROSPIKE_CLIENT_CONSTRUCTOR_INTERCEPTOR;
}
}
};
}
@Override
public InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
final InstanceMethodsInterceptPoint[] points = new InstanceMethodsInterceptPoint[ENHANCE_METHODS.length];
for (int i = 0; i < ENHANCE_METHODS.length; i++) {
final String method = ENHANCE_METHODS[i];
final InstanceMethodsInterceptPoint point = new InstanceMethodsInterceptPoint() {
@Override
public ElementMatcher<MethodDescription> getMethodsMatcher() {
return named(method);
}
@Override
public String getMethodsInterceptor() {
return AEROSPIKE_CLIENT_METHOD_INTERCEPTOR;
}
@Override
public boolean isOverrideArgs() {
return false;
}
};
points[i] = point;
}
return points;
}
}

View File

@ -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.
aerospike=org.apache.skywalking.apm.plugin.aerospike.define.AerospikeClientInstrumentation

View File

@ -133,6 +133,7 @@
<module>grizzly-2.3.x-4.x-work-threadpool-plugin</module>
<module>rocketMQ-5.x-plugin</module>
<module>websphere-liberty-23.x-plugin</module>
<module>aerospike-plugin</module>
</modules>
<packaging>pom</packaging>

View File

@ -1,4 +1,5 @@
# Skywalking Agent List
- aerospike
- activemq-5.x
- armeria-063-084
- armeria-085

View File

@ -79,6 +79,7 @@ metrics based on the tracing data.
* [NATS](https://github.com/nats-io/nats.java) 2.14.x -> 2.15.x
* Aliyun ONS 1.x (Optional¹)
* NoSQL
* [aerospike](https://github.com/aerospike/aerospike-client-java) 3.x -> 6.x
* Redis
* [Jedis](https://github.com/xetorthio/jedis) 2.x-4.x
* [Redisson](https://github.com/redisson/redisson) Easy Java Redis client 3.5.2+

View File

@ -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} -Daerospike.host=${AEROSPIKE_HOST} -Daerospike.port=${AEROSPIKE_PORT} ${home}/../libs/aerospike-scenario.jar &

View File

@ -0,0 +1,121 @@
# 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: aerospike-scenario
segmentSize: ge 1
segments:
- segmentId: not null
spans:
- operationName: Aerospike/put
parentSpanId: 0
spanId: 1
spanLayer: Cache
startTime: gt 0
endTime: gt 0
componentId: 149
isError: false
spanType: Exit
peer: aerospike-server:3000
skipAnalysis: false
tags:
- { key: cache.type, value: Aerospike}
- { key: cache.op, value: write }
- operationName: Aerospike/exists
parentSpanId: 0
spanId: 2
spanLayer: Cache
startTime: gt 0
endTime: gt 0
componentId: 149
isError: false
spanType: Exit
peer: aerospike-server:3000
skipAnalysis: false
tags:
- { key: cache.type, value: Aerospike }
- { key: cache.op, value: read }
- operationName: Aerospike/get
parentSpanId: 0
spanId: 3
spanLayer: Cache
startTime: gt 0
endTime: gt 0
componentId: 149
isError: false
spanType: Exit
peer: aerospike-server:3000
skipAnalysis: false
tags:
- { key: cache.type, value: Aerospike }
- { key: cache.op, value: read }
- operationName: Aerospike/append
parentSpanId: 0
spanId: 4
spanLayer: Cache
startTime: gt 0
endTime: gt 0
componentId: 149
isError: false
spanType: Exit
peer: aerospike-server:3000
skipAnalysis: false
tags:
- { key: cache.type, value: Aerospike }
- { key: cache.op, value: write }
- operationName: Aerospike/operate
parentSpanId: 0
spanId: 5
spanLayer: Cache
startTime: gt 0
endTime: gt 0
componentId: 149
isError: false
spanType: Exit
peer: aerospike-server:3000
skipAnalysis: false
tags:
- { key: cache.type, value: Aerospike }
- { key: cache.op, value: write }
- operationName: Aerospike/delete
parentSpanId: 0
spanId: 6
spanLayer: Cache
startTime: gt 0
endTime: gt 0
componentId: 149
isError: false
spanType: Exit
peer: aerospike-server:3000
skipAnalysis: false
tags:
- { key: cache.type, value: Aerospike }
- { key: cache.op, value: write }
- operationName: GET:/aerospike-scenario/case/aerospike-scenario
parentSpanId: -1
spanId: 0
spanLayer: Http
startTime: gt 0
endTime: gt 0
componentId: 1
isError: false
spanType: Entry
peer: ''
skipAnalysis: false
tags:
- { key: url, value: 'http://localhost:8080/aerospike-scenario/case/aerospike-scenario' }
- { key: http.method, value: GET }
- { key: http.status_code, value: '200' }

View File

@ -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/aerospike-scenario/case/aerospike-scenario
healthCheck: http://localhost:8080/aerospike-scenario/case/healthCheck
startScript: ./bin/startup.sh
environment:
- AEROSPIKE_HOST=aerospike-server
- AEROSPIKE_PORT=3000
dependencies:
aerospike-server:
image: aerospike:ce-6.0.0.0
hostname: aerospike-server

View File

@ -0,0 +1,126 @@
<?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>aerospike-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>
<maven-compiler-plugin.version>3.8.1</maven-compiler-plugin.version>
<test.framework.version>YOUR VERSION</test.framework.version>
<spring.boot.version>2.1.6.RELEASE</spring.boot.version>
<lombok.version>1.18.20</lombok.version>
</properties>
<name>skywalking-aerospike-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>com.aerospike</groupId>
<artifactId>aerospike-client</artifactId>
<version>6.0.0</version>
</dependency>
<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.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<finalName>aerospike-scenario</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring.boot.version}</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<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>

View File

@ -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}/aerospike-scenario.jar</source>
<outputDirectory>./libs</outputDirectory>
<fileMode>0775</fileMode>
</file>
</files>
</assembly>

View File

@ -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.aerospike;
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
}
}
}

View File

@ -0,0 +1,80 @@
/*
* 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.aerospike.controller;
import com.aerospike.client.AerospikeClient;
import com.aerospike.client.Bin;
import com.aerospike.client.Key;
import com.aerospike.client.Operation;
import com.aerospike.client.policy.WritePolicy;
public class AerospikeCommandExecutor implements AutoCloseable {
private final AerospikeClient client;
private final WritePolicy defaultWritePolicy = new WritePolicy();
private final WritePolicy defaultReadPolicy = new WritePolicy();
private static final String VALUENAME = "DATA";
private static final String NAMESPACE = "test";
private static final String SETNAME = "skywalking";
public AerospikeCommandExecutor(String host, Integer port) {
client = new AerospikeClient(host, port);
}
public void set(String key, String value) {
final Key k = new Key(NAMESPACE, SETNAME, key);
final Bin bin = new Bin(VALUENAME, value);
client.put(defaultWritePolicy, k, bin);
}
public void exists(String key) {
final Key k = new Key(NAMESPACE, SETNAME, key);
client.exists(null, k);
}
public void get(String key) {
final Key k = new Key(NAMESPACE, SETNAME, key);
client.get(defaultReadPolicy, k);
}
public void append(String key, String value) {
final Key k = new Key(NAMESPACE, SETNAME, key);
final Bin bin = new Bin(VALUENAME, value);
client.append(defaultWritePolicy, k, bin);
}
public void operate(String key, long by) {
final Key k = new Key(NAMESPACE, SETNAME, key);
client.operate(defaultWritePolicy, k, Operation.add(new Bin(VALUENAME, by)), Operation.get(VALUENAME));
}
public void delete(String key) {
final Key k = new Key(NAMESPACE, SETNAME, key);
client.delete(null, k);
}
public void close() throws Exception {
client.close();
}
}

View File

@ -0,0 +1,62 @@
/*
* 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.aerospike.controller;
import lombok.extern.log4j.Log4j2;
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;
@RestController
@RequestMapping("/case")
@Log4j2
public class CaseController {
private static final String SUCCESS = "Success";
@Value("${aerospike.host:127.0.0.1}")
private String aerospikeHost;
@Value("${aerospike.port:3000}")
private Integer aerospikePort;
@RequestMapping("/aerospike-scenario")
@ResponseBody
public String testcase() throws Exception {
try (AerospikeCommandExecutor command = new AerospikeCommandExecutor(aerospikeHost, aerospikePort)) {
command.set("a", "a");
command.exists("a");
command.get("a");
command.append("a", "a");
command.operate("b", 1);
command.delete("a");
}
return SUCCESS;
}
@RequestMapping("/healthCheck")
@ResponseBody
public String healthCheck() {
// your codes
return SUCCESS;
}
}

View File

@ -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: /aerospike-scenario
logging:
config: classpath:log4j2.xml

View File

@ -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>

View File

@ -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.
# lists your version here (Contains only the last version number of each minor version.)
6.0.0
5.0.0
4.0.0
3.0.0