fix jedis can not get host info when use jedis 3.3.x+ (#526)

This commit is contained in:
xu1009 2023-05-08 22:50:17 +08:00 committed by GitHub
parent 04603b2027
commit 6e6aafe310
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
21 changed files with 831 additions and 152 deletions

View File

@ -66,6 +66,7 @@ jobs:
- jedis-2.x-scenario
- jedis-3.1.x-plus-scenario
- jedis-4.x-scenario
- jedis-3.3.x-plus-scenario
- jetty-scenario
- kafka-scenario
- kotlin-coroutine-scenario

View File

@ -13,6 +13,7 @@ Release Notes.
* Fix ClassCastException when SQLServer inserts data
* [Chore] Exclude org.checkerframework:checker-qual and com.google.j2objc:j2objc-annotations
* [Chore] Exclude proto files in the generated jar
* Fix Jedis-2.x plugin can not get host info in jedis 3.3.x+
#### Documentation

View File

@ -19,13 +19,14 @@ package org.apache.skywalking.apm.plugin.jedis.v3;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor;
import redis.clients.jedis.HostAndPort;
public class JedisClusterConstructorWithHostAndPortArgInterceptor implements InstanceConstructorInterceptor {
import redis.clients.jedis.Client;
import redis.clients.jedis.Jedis;
public class JedisConstructorInterceptor implements InstanceConstructorInterceptor {
@Override
public void onConstruct(EnhancedInstance objInst, Object[] allArguments) {
HostAndPort hostAndPort = (HostAndPort) allArguments[0];
objInst.setSkyWalkingDynamicField(hostAndPort.getHost() + ":" + hostAndPort.getPort());
public void onConstruct(EnhancedInstance objInst, Object[] allArguments) throws Throwable {
Client client = ((Jedis) objInst).getClient();
objInst.setSkyWalkingDynamicField(client.getHost() + ":" + client.getPort());
}
}

View File

@ -1,33 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.skywalking.apm.plugin.jedis.v3;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor;
import redis.clients.jedis.JedisShardInfo;
public class JedisConstructorWithShardInfoArgInterceptor implements InstanceConstructorInterceptor {
@Override
public void onConstruct(EnhancedInstance objInst, Object[] allArguments) {
String redisConnInfo;
JedisShardInfo shardInfo = (JedisShardInfo) allArguments[0];
redisConnInfo = shardInfo.getHost() + ":" + shardInfo.getPort();
objInst.setSkyWalkingDynamicField(redisConnInfo);
}
}

View File

@ -1,35 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.skywalking.apm.plugin.jedis.v3;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor;
public class JedisConstructorWithStringArgInterceptor implements InstanceConstructorInterceptor {
@Override
public void onConstruct(EnhancedInstance objInst, Object[] allArguments) {
String host = (String) allArguments[0];
String port = "6379";
if (allArguments.length > 1) {
port = String.valueOf(allArguments[1]);
}
objInst.setSkyWalkingDynamicField(host + ":" + port);
}
}

View File

@ -1,31 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.skywalking.apm.plugin.jedis.v3;
import java.net.URI;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor;
public class JedisConstructorWithUriArgInterceptor implements InstanceConstructorInterceptor {
@Override
public void onConstruct(EnhancedInstance objInst, Object[] allArguments) {
URI uri = (URI) allArguments[0];
objInst.setSkyWalkingDynamicField(uri.getHost() + ":" + uri.getPort());
}
}

View File

@ -24,22 +24,14 @@ import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsIn
import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch;
import org.apache.skywalking.apm.plugin.jedis.v3.RedisMethodMatch;
import java.net.URI;
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
import static org.apache.skywalking.apm.agent.core.plugin.bytebuddy.ArgumentTypeNameMatch.takesArgumentWithType;
import static net.bytebuddy.matcher.ElementMatchers.any;
import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName;
public class JedisInstrumentation extends AbstractWitnessInstrumentation {
private static final String HOST_AND_PORT_ARG_TYPE_NAME = "redis.clients.jedis.HostAndPort";
private static final String JEDIS_SHARD_INFO_ARG_TYPE_NAME = "redis.clients.jedis.JedisShardInfo";
private static final String ENHANCE_CLASS = "redis.clients.jedis.Jedis";
private static final String CONSTRUCTOR_WITH_STRING_ARG_INTERCEPT_CLASS = "org.apache.skywalking.apm.plugin.jedis.v3.JedisConstructorWithStringArgInterceptor";
private static final String CONSTRUCTOR_WITH_SHARD_INFO_ARG_INTERCEPT_CLASS = "org.apache.skywalking.apm.plugin.jedis.v3.JedisConstructorWithShardInfoArgInterceptor";
private static final String CONSTRUCTOR_WITH_HOST_AND_PORT_INTERCEPT_CLASS = "org.apache.skywalking.apm.plugin.jedis.v3.JedisClusterConstructorWithHostAndPortArgInterceptor";
private static final String CONSTRUCTOR_WITH_URI_ARG_INTERCEPT_CLASS = "org.apache.skywalking.apm.plugin.jedis.v3.JedisConstructorWithUriArgInterceptor";
private static final String JEDIS_METHOD_INTERCET_CLASS = "org.apache.skywalking.apm.plugin.jedis.v3.JedisMethodInterceptor";
private static final String JEDIS_METHOD_INTERCEPT_CLASS = "org.apache.skywalking.apm.plugin.jedis.v3.JedisMethodInterceptor";
private static final String JEDIS_CONSTRUCTOR_INTERCEPT_CLASS = "org.apache.skywalking.apm.plugin.jedis.v3.JedisConstructorInterceptor";
@Override
public ClassMatch enhanceClass() {
@ -52,45 +44,12 @@ public class JedisInstrumentation extends AbstractWitnessInstrumentation {
new ConstructorInterceptPoint() {
@Override
public ElementMatcher<MethodDescription> getConstructorMatcher() {
return takesArgument(0, String.class);
return any();
}
@Override
public String getConstructorInterceptor() {
return CONSTRUCTOR_WITH_STRING_ARG_INTERCEPT_CLASS;
}
},
new ConstructorInterceptPoint() {
@Override
public ElementMatcher<MethodDescription> getConstructorMatcher() {
return takesArgumentWithType(0, HOST_AND_PORT_ARG_TYPE_NAME);
}
@Override
public String getConstructorInterceptor() {
return CONSTRUCTOR_WITH_HOST_AND_PORT_INTERCEPT_CLASS;
}
},
new ConstructorInterceptPoint() {
@Override
public ElementMatcher<MethodDescription> getConstructorMatcher() {
return takesArgumentWithType(0, JEDIS_SHARD_INFO_ARG_TYPE_NAME);
}
@Override
public String getConstructorInterceptor() {
return CONSTRUCTOR_WITH_SHARD_INFO_ARG_INTERCEPT_CLASS;
}
},
new ConstructorInterceptPoint() {
@Override
public ElementMatcher<MethodDescription> getConstructorMatcher() {
return takesArgument(0, URI.class);
}
@Override
public String getConstructorInterceptor() {
return CONSTRUCTOR_WITH_URI_ARG_INTERCEPT_CLASS;
return JEDIS_CONSTRUCTOR_INTERCEPT_CLASS;
}
}
};
@ -107,7 +66,7 @@ public class JedisInstrumentation extends AbstractWitnessInstrumentation {
@Override
public String getMethodsInterceptor() {
return JEDIS_METHOD_INTERCET_CLASS;
return JEDIS_METHOD_INTERCEPT_CLASS;
}
@Override

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} -Dredis.host=${REDIS_HOST} -Dredis.port=${REDIS_PORT} -Dskywalking.plugin.jedis.trace_redis_parameters=true ${home}/../libs/jedis-3.3.x-plus-scenario.jar &

View File

@ -0,0 +1,214 @@
# 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: jedis-3.3.x-plus-scenario
segmentSize: ge 1
segments:
- segmentId: not null
spans:
- operationName: Jedis/echo
operationId: 0
parentSpanId: 0
spanId: 1
spanLayer: Cache
startTime: gt 0
endTime: gt 0
componentId: 30
isError: false
spanType: Exit
peer: redis-server:6379
skipAnalysis: false
tags:
- {key: cache.type, value: Redis}
- {key: cache.cmd, value: echo}
- {key: cache.key, value: Test}
- operationName: Jedis/set
operationId: 0
parentSpanId: 0
spanId: 2
spanLayer: Cache
startTime: gt 0
endTime: gt 0
componentId: 30
isError: false
spanType: Exit
peer: redis-server:6379
skipAnalysis: false
tags:
- {key: cache.type, value: Redis}
- {key: cache.cmd, value: set}
- {key: cache.key, value: a}
- {key: cache.op, value: write}
- operationName: Jedis/get
operationId: 0
parentSpanId: 0
spanId: 3
spanLayer: Cache
startTime: gt 0
endTime: gt 0
componentId: 30
isError: false
spanType: Exit
peer: redis-server:6379
skipAnalysis: false
tags:
- {key: cache.type, value: Redis}
- {key: cache.cmd, value: get}
- {key: cache.key, value: a}
- {key: cache.op, value: read}
- operationName: Jedis/del
operationId: 0
parentSpanId: 0
spanId: 4
spanLayer: Cache
startTime: gt 0
endTime: gt 0
componentId: 30
isError: false
spanType: Exit
peer: redis-server:6379
skipAnalysis: false
tags:
- {key: cache.type, value: Redis}
- {key: cache.cmd, value: del}
- {key: cache.key, value: a}
- {key: cache.op, value: write}
- operationName: Jedis/syncAndReturnAll
operationId: 0
parentSpanId: 0
spanId: 5
spanLayer: Cache
startTime: gt 0
endTime: gt 0
componentId: 30
isError: false
spanType: Exit
peer: redis-server:6379
skipAnalysis: false
tags:
- {key: cache.type, value: Redis}
- {key: cache.cmd, value: BATCH_EXECUTE}
- operationName: Jedis/discard
operationId: 0
parentSpanId: 0
spanId: 6
spanLayer: Cache
startTime: gt 0
endTime: gt 0
componentId: 30
isError: false
spanType: Exit
peer: redis-server:6379
skipAnalysis: false
tags:
- { key: cache.type, value: Redis }
- { key: cache.cmd, value: BATCH_EXECUTE }
- operationName: Jedis/exec
operationId: 0
parentSpanId: 0
spanId: 7
spanLayer: Cache
startTime: gt 0
endTime: gt 0
componentId: 30
isError: false
spanType: Exit
peer: redis-server:6379
skipAnalysis: false
tags:
- {key: cache.type, value: Redis}
- {key: cache.cmd, value: BATCH_EXECUTE}
- operationName: Jedis/discard
operationId: 0
parentSpanId: 0
spanId: 8
spanLayer: Cache
startTime: gt 0
endTime: gt 0
componentId: 30
isError: false
spanType: Exit
peer: redis-server:6379
skipAnalysis: false
tags:
- { key: cache.type, value: Redis }
- { key: cache.cmd, value: BATCH_EXECUTE }
- operationName: Jedis/xadd
operationId: 0
parentSpanId: 0
spanId: 9
spanLayer: Cache
startTime: gt 0
endTime: gt 0
componentId: 30
isError: false
spanType: Exit
peer: redis-server:6379
skipAnalysis: false
tags:
- {key: cache.type, value: Redis}
- {key: cache.cmd, value: xadd}
- {key: cache.key, value: abc}
- {key: cache.op, value: write}
- operationName: Jedis/xread
operationId: 0
parentSpanId: 0
spanId: 10
spanLayer: Cache
startTime: gt 0
endTime: gt 0
componentId: 30
isError: false
spanType: Exit
peer: redis-server:6379
skipAnalysis: false
tags:
- {key: cache.type, value: Redis}
- {key: cache.cmd, value: xread}
- {key: cache.op, value: read}
- operationName: Jedis/xdel
operationId: 0
parentSpanId: 0
spanId: 11
spanLayer: Cache
startTime: gt 0
endTime: gt 0
componentId: 30
isError: false
spanType: Exit
peer: redis-server:6379
skipAnalysis: false
tags:
- {key: cache.type, value: Redis}
- {key: cache.cmd, value: xdel}
- {key: cache.key, value: abc}
- {key: cache.op, value: write}
- operationName: GET:/jedis-3.3.x-plus-scenario/case/jedis-3.3.x-plus-scenario
operationId: 0
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/jedis-3.3.x-plus-scenario/case/jedis-3.3.x-plus-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/jedis-3.3.x-plus-scenario/case/jedis-3.3.x-plus-scenario
healthCheck: http://localhost:8080/jedis-3.3.x-plus-scenario/case/healthCheck
startScript: ./bin/startup.sh
environment:
- REDIS_HOST=redis-server
- REDIS_PORT=6379
dependencies:
redis-server:
image: redis:6.2.7
hostname: redis-server

View File

@ -0,0 +1,109 @@
<?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>jedis-3.3.x-plus-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>3.8.0</test.framework.version>
<spring.boot.version>2.1.6.RELEASE</spring.boot.version>
<lombok.version>1.18.20</lombok.version>
</properties>
<name>skywalking-jedis-3.3.x-plus-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>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>${test.framework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<build>
<finalName>jedis-3.3.x-plus-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>

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}/jedis-3.3.x-plus-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.jedis;
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,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.jedis.controller;
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")
public class CaseController {
private static final String SUCCESS = "Success";
@Value("${redis.host:127.0.0.1}")
private String redisHost;
@Value("${redis.port:6379}")
private Integer redisPort;
@RequestMapping("/jedis-3.3.x-plus-scenario")
@ResponseBody
public String testcase() throws Exception {
try (RedisCommandExecutor command = new RedisCommandExecutor(redisHost, redisPort)) {
command.set("a", "a");
command.get("a");
command.del("a");
}
try (RedisPipelineCommandExecutor command = new RedisPipelineCommandExecutor(redisHost, redisPort)) {
command.pipelineExecute();
command.pipelineDiscard();
}
try (RedisTransactionCommandExecutor command = new RedisTransactionCommandExecutor(redisHost, redisPort)) {
command.multiExecute();
command.multiDiscard();
}
try (RedisStreamCommandExecutor c = new RedisStreamCommandExecutor(redisHost, redisPort)) {
c.exec();
}
return SUCCESS;
}
@RequestMapping("/healthCheck")
@ResponseBody
public String healthCheck() throws Exception {
return SUCCESS;
}
}

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.testcase.jedis.controller;
import redis.clients.jedis.StreamEntryID;
import java.lang.reflect.Method;
import java.util.Map;
public class JedisXreadparamAdaptor {
// The stream apis have changed from 3.6.0
public static Object callXReadMethod(Object target, int count, Map<String, StreamEntryID> map) {
try {
Class<?> xReadParamsCls = Class.forName("redis.clients.jedis.params.XReadParams");
Object xReadParams = xReadParamsCls.getConstructor().newInstance();
xReadParamsCls.getDeclaredMethod("count", Integer.TYPE).invoke(xReadParams, count);
Method xread = target.getClass().getDeclaredMethod("xread", xReadParamsCls, Map.class);
return xread.invoke(target, xReadParams, map);
} catch (Exception e) {
Map.Entry<String, StreamEntryID>[] entries = new Map.Entry[map.size()];
int i = 0;
for (Map.Entry<String, StreamEntryID> stringStreamEntryIDEntry : map.entrySet()) {
entries[i++] = stringStreamEntryIDEntry;
}
try {
return target.getClass().getDeclaredMethod("xread", Integer.TYPE, Long.TYPE, Map.Entry[].class).invoke(target, count, 0, entries);
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
}
}

View File

@ -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.testcase.jedis.controller;
import redis.clients.jedis.DefaultJedisSocketFactory;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisSocketFactory;
public class RedisCommandExecutor implements AutoCloseable {
private Jedis jedis;
public RedisCommandExecutor(String host, Integer port) {
JedisSocketFactory jedisSocketFactory = new DefaultJedisSocketFactory(host, port, 1000, 1000, false, null, null, null);
jedis = new Jedis(jedisSocketFactory);
jedis.echo("Test");
}
public void set(String key, String value) {
jedis.set(key, value);
}
public void get(String key) {
jedis.get(key);
}
public void del(String key) {
jedis.del(key);
}
public void close() throws Exception {
jedis.close();
}
}

View File

@ -0,0 +1,54 @@
/*
* 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.jedis.controller;
import redis.clients.jedis.DefaultJedisSocketFactory;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisSocketFactory;
import redis.clients.jedis.Pipeline;
public class RedisPipelineCommandExecutor implements AutoCloseable {
private Jedis jedis;
public RedisPipelineCommandExecutor(String host, Integer port) {
JedisSocketFactory jedisSocketFactory = new DefaultJedisSocketFactory(host, port, 1000, 1000, false, null, null, null);
jedis = new Jedis(jedisSocketFactory);
}
public void pipelineExecute() {
Pipeline pipeline = jedis.pipelined();
pipeline.hset("a", "a", "a");
pipeline.hget("a", "a");
pipeline.hdel("a", "a");
pipeline.syncAndReturnAll();
}
public void pipelineDiscard() {
Pipeline pipeline = jedis.pipelined();
pipeline.multi();
pipeline.hset("a", "a", "a");
pipeline.hget("a", "a");
pipeline.hdel("a", "a");
pipeline.discard();
}
public void close() throws Exception {
jedis.close();
}
}

View File

@ -0,0 +1,55 @@
/*
* 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.jedis.controller;
import redis.clients.jedis.DefaultJedisSocketFactory;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisSocketFactory;
import redis.clients.jedis.StreamEntryID;
import java.util.HashMap;
import java.util.Map;
public class RedisStreamCommandExecutor implements AutoCloseable {
private final Jedis jedis;
public RedisStreamCommandExecutor(String host, Integer port) {
JedisSocketFactory jedisSocketFactory = new DefaultJedisSocketFactory(host, port, 1000, 1000, false, null, null, null);
jedis = new Jedis(jedisSocketFactory);
}
public void exec() {
HashMap<String, String> hash = new HashMap<>();
hash.put("a", "1");
StreamEntryID streamEntryID = new StreamEntryID("0-1");
jedis.xadd("abc", streamEntryID, hash);
Map<String, StreamEntryID> hashMap = new HashMap<>();
hashMap.put("abc", new StreamEntryID("0-1"));
// adapt jedis 3.6.0 jedis.xread(XReadParams param,Map<<String, StreamEntryID>> stream);
// and jedis.3.5.2 xread(final int count, final long block, final Entry<String, StreamEntryID>... streams)
JedisXreadparamAdaptor.callXReadMethod(jedis, 1, hashMap);
jedis.xdel("abc", streamEntryID);
}
public void close() throws Exception {
jedis.close();
}
}

View File

@ -0,0 +1,51 @@
/*
* 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.jedis.controller;
import redis.clients.jedis.DefaultJedisSocketFactory;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisSocketFactory;
import redis.clients.jedis.Transaction;
public class RedisTransactionCommandExecutor implements AutoCloseable {
private Jedis jedis;
public RedisTransactionCommandExecutor(String host, Integer port) {
JedisSocketFactory jedisSocketFactory = new DefaultJedisSocketFactory(host, port, 1000, 1000, false, null, null, null);
jedis = new Jedis(jedisSocketFactory);
}
public void multiExecute() {
Transaction pipeline = jedis.multi();
pipeline.set("key", "a");
pipeline.expire("key", 5);
pipeline.exec();
}
public void multiDiscard() {
Transaction pipeline = jedis.multi();
pipeline.set("key", "a");
pipeline.expire("key", 5);
pipeline.discard();
}
public void close() throws Exception {
jedis.close();
}
}

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.
#
#
server:
port: 8080
servlet:
context-path: /jedis-3.3.x-plus-scenario

View File

@ -0,0 +1,24 @@
# 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.
3.9.0
3.8.0
3.7.1
3.6.3
3.5.2
3.4.1
3.3.0
# jedis socket factory from 3.3.0