Provide plugin for Guava Cache (#7235)

This commit is contained in:
whl12345 2021-07-08 11:58:09 +08:00 committed by GitHub
parent f9140b80fa
commit 9e022d1a73
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 835 additions and 0 deletions

View File

@ -71,6 +71,7 @@ jobs:
- gateway-2.0.x-scenario
- grpc-scenario
- gson-scenario
- guava-cache-scenario
- elasticjob-3.x-scenario
- springmvc-reactive-scenario
- springmvc-reactive-devtools-scenario

View File

@ -29,6 +29,7 @@ Release Notes.
* Fix async finish repeatedly in `spring-webflux-5.x-webclient` plugin.
* Add agent plugin to support Sentinel.
* Move `ehcache-2.x` plugin as an optional plugin.
* Support `guava-cache` plugin
#### OAP-Backend

View File

@ -204,4 +204,7 @@ public class ComponentsDefine {
public static final OfficialComponent NEO4J = new OfficialComponent(112, "Neo4j");
public static final OfficialComponent SENTINEL = new OfficialComponent(113, "Sentinel");
public static final OfficialComponent GUAVA_CACHE = new OfficialComponent(114, "GuavaCache");
}

View File

@ -0,0 +1,50 @@
<?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>
<groupId>org.apache.skywalking</groupId>
<artifactId>optional-plugins</artifactId>
<version>8.7.0-SNAPSHOT</version>
</parent>
<artifactId>apm-guava-cache-plugin</artifactId>
<name>guava-cache-plugin</name>
<packaging>jar</packaging>
<modelVersion>4.0.0</modelVersion>
<properties>
<guava-client.version>23.0</guava-client.version>
</properties>
<dependencies>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava-client.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,50 @@
/*
* 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.guava.cache;
import org.apache.skywalking.apm.agent.core.context.ContextManager;
import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan;
import org.apache.skywalking.apm.agent.core.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;
public class GuavaCacheAllInterceptor implements InstanceMethodsAroundInterceptor {
@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable {
AbstractSpan span = ContextManager.createLocalSpan("GuavaCache/" + method.getName());
span.setComponent(ComponentsDefine.GUAVA_CACHE);
SpanLayer.asCache(span);
}
@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().log(t);
}
}

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.plugin.guava.cache;
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;
public class GuavaCacheInterceptor implements InstanceMethodsAroundInterceptor {
@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable {
AbstractSpan span = ContextManager.createLocalSpan("GuavaCache/" + method.getName());
span.setComponent(ComponentsDefine.GUAVA_CACHE);
Object key = allArguments[0];
if (key != null) {
Tags.DB_STATEMENT.set(span, key.toString());
}
SpanLayer.asCache(span);
}
@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().log(t);
}
}

View File

@ -0,0 +1,99 @@
/*
* 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.guava.cache.define;
import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.matcher.ElementMatcher;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch;
import static net.bytebuddy.matcher.ElementMatchers.named;
import static org.apache.skywalking.apm.agent.core.plugin.match.MultiClassNameMatch.byMultiClassMatch;
public class GuavaCachePluginInstrumentation extends ClassInstanceMethodsEnhancePluginDefine {
public static final String INTERCEPT_LOCALMANUAL_CLASS = "com.google.common.cache.LocalCache$LocalManualCache";
public static final String INTERCEPT_LOCALLOADING_CLASS = "com.google.common.cache.LocalCache$LocalLoadingCache";
public static final String INTERCEPT_FORWARDING_CLASS = "com.google.common.cache.ForwardingCache";
public static final String GET_ALL_PRESENT_ENHANCE_METHOD = "getAllPresent";
public static final String INVALIDATE_ALL_ENHANCE_METHOD = "invalidateAll";
public static final String GET_ENHANCE_METHOD = "get";
public static final String INVALIDATE_ENHANCE_METHOD = "invalidate";
public static final String PUT_ALL_ENHANCE_METHOD = "putAll";
public static final String PUT_ENHANCE_METHOD = "put";
public static final String GET_IF_PRESENT_ENHANCE_METHOD = "getIfPresent";
public static final String GUAVA_CACHE_INTERCEPTOR_CLASS = "org.apache.skywalking.apm.plugin.guava.cache.GuavaCacheInterceptor";
public static final String GUAVA_CACHE_ALL_INTERCEPTOR_CLASS = "org.apache.skywalking.apm.plugin.guava.cache.GuavaCacheAllInterceptor";
@Override
public ConstructorInterceptPoint[] getConstructorsInterceptPoints() {
return new ConstructorInterceptPoint[0];
}
@Override
public InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
return new InstanceMethodsInterceptPoint[]{
new InstanceMethodsInterceptPoint() {
@Override
public ElementMatcher<MethodDescription> getMethodsMatcher() {
return named(GET_ENHANCE_METHOD)
.or(named(INVALIDATE_ENHANCE_METHOD))
.or(named(PUT_ENHANCE_METHOD))
.or(named(GET_IF_PRESENT_ENHANCE_METHOD));
}
@Override
public String getMethodsInterceptor() {
return GUAVA_CACHE_INTERCEPTOR_CLASS;
}
@Override
public boolean isOverrideArgs() {
return true;
}
},
new InstanceMethodsInterceptPoint() {
@Override
public ElementMatcher<MethodDescription> getMethodsMatcher() {
return named(GET_ALL_PRESENT_ENHANCE_METHOD)
.or(named(INVALIDATE_ALL_ENHANCE_METHOD))
.or(named(PUT_ALL_ENHANCE_METHOD));
}
@Override
public String getMethodsInterceptor() {
return GUAVA_CACHE_ALL_INTERCEPTOR_CLASS;
}
@Override
public boolean isOverrideArgs() {
return true;
}
}
};
}
@Override
protected ClassMatch enhanceClass() {
return byMultiClassMatch(INTERCEPT_LOCALMANUAL_CLASS, INTERCEPT_LOCALLOADING_CLASS, INTERCEPT_FORWARDING_CLASS);
}
}

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.
guava-cache=org.apache.skywalking.apm.plugin.guava.cache.define.GuavaCachePluginInstrumentation

View File

@ -0,0 +1,146 @@
/*
* 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.guava.cache;
import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment;
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.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.modules.junit4.PowerMockRunnerDelegate;
import org.powermock.reflect.Whitebox;
import java.lang.reflect.Method;
import java.util.List;
import static org.hamcrest.CoreMatchers.is;
@RunWith(PowerMockRunner.class)
@PowerMockRunnerDelegate(TracingSegmentRunner.class)
public class GuavaCacheInterceptorTest {
@SegmentStoragePoint
private SegmentStorage segmentStorage;
private GuavaCacheInterceptor guavaCacheInterceptor;
private GuavaCacheAllInterceptor guavaCacheAllInterceptor;
private Object[] operateObjectArguments;
private Exception exception;
private Method getAllPresentMethod;
private Method invalidateAllMethod;
private Method getMethod;
private Method invalidateMethod;
private Method putAllMethod;
private Method putMethod;
private Method getIfPresentMethod;
@Rule
public AgentServiceRule serviceRule = new AgentServiceRule();
@Before
public void setUp() throws Exception {
guavaCacheInterceptor = new GuavaCacheInterceptor();
guavaCacheAllInterceptor = new GuavaCacheAllInterceptor();
exception = new Exception();
operateObjectArguments = new Object[]{"dataKey"};
Class<?> cache = Class.forName("com.google.common.cache.LocalCache$LocalManualCache");
getAllPresentMethod = Whitebox.getMethods(cache, "getAllPresent")[0];
invalidateAllMethod = Whitebox.getMethods(cache, "invalidateAll")[0];
getMethod = Whitebox.getMethods(cache, "get")[0];
invalidateMethod = Whitebox.getMethods(cache, "invalidate")[0];
putAllMethod = Whitebox.getMethods(cache, "putAll")[0];
putMethod = Whitebox.getMethods(cache, "put")[0];
getIfPresentMethod = Whitebox.getMethods(cache, "getIfPresent")[0];
}
@Test
public void assertGetAllPresentSuccess() throws Throwable {
guavaCacheAllInterceptor.beforeMethod(null, getAllPresentMethod, null, null, null);
guavaCacheAllInterceptor.handleMethodException(null, getAllPresentMethod, null, null, exception);
guavaCacheAllInterceptor.afterMethod(null, getAllPresentMethod, null, null, null);
List<TraceSegment> traceSegments = segmentStorage.getTraceSegments();
Assert.assertThat(traceSegments.size(), is(1));
}
@Test
public void assertInvalidAllSuccess() throws Throwable {
guavaCacheAllInterceptor.beforeMethod(null, invalidateAllMethod, null, null, null);
guavaCacheAllInterceptor.handleMethodException(null, invalidateAllMethod, null, null, exception);
guavaCacheAllInterceptor.afterMethod(null, invalidateAllMethod, null, null, null);
List<TraceSegment> traceSegments = segmentStorage.getTraceSegments();
Assert.assertThat(traceSegments.size(), is(1));
}
@Test
public void assertGetSuccess() throws Throwable {
guavaCacheInterceptor.beforeMethod(null, getMethod, operateObjectArguments, null, null);
guavaCacheInterceptor.handleMethodException(null, getMethod, operateObjectArguments, null, exception);
guavaCacheInterceptor.afterMethod(null, getMethod, operateObjectArguments, null, null);
List<TraceSegment> traceSegments = segmentStorage.getTraceSegments();
Assert.assertThat(traceSegments.size(), is(1));
}
@Test
public void assertInvalidateSuccess() throws Throwable {
guavaCacheInterceptor.beforeMethod(null, invalidateMethod, operateObjectArguments, null, null);
guavaCacheInterceptor.handleMethodException(null, invalidateMethod, operateObjectArguments, null, exception);
guavaCacheInterceptor.afterMethod(null, invalidateMethod, operateObjectArguments, null, null);
List<TraceSegment> traceSegments = segmentStorage.getTraceSegments();
Assert.assertThat(traceSegments.size(), is(1));
}
@Test
public void assertPutAllMethodSuccess() throws Throwable {
guavaCacheAllInterceptor.beforeMethod(null, putAllMethod, null, null, null);
guavaCacheAllInterceptor.handleMethodException(null, putAllMethod, null, null, exception);
guavaCacheAllInterceptor.afterMethod(null, putAllMethod, null, null, null);
List<TraceSegment> traceSegments = segmentStorage.getTraceSegments();
Assert.assertThat(traceSegments.size(), is(1));
}
@Test
public void assertPutMethodSuccess() throws Throwable {
guavaCacheInterceptor.beforeMethod(null, putMethod, operateObjectArguments, null, null);
guavaCacheInterceptor.handleMethodException(null, putMethod, operateObjectArguments, null, exception);
guavaCacheInterceptor.afterMethod(null, putMethod, operateObjectArguments, null, null);
List<TraceSegment> traceSegments = segmentStorage.getTraceSegments();
Assert.assertThat(traceSegments.size(), is(1));
}
@Test
public void assertGetIfPresentMethodSuccess() throws Throwable {
guavaCacheInterceptor.beforeMethod(null, getIfPresentMethod, operateObjectArguments, null, null);
guavaCacheInterceptor.handleMethodException(null, getIfPresentMethod, operateObjectArguments, null, exception);
guavaCacheInterceptor.afterMethod(null, getIfPresentMethod, operateObjectArguments, null, null);
List<TraceSegment> traceSegments = segmentStorage.getTraceSegments();
Assert.assertThat(traceSegments.size(), is(1));
}
}

View File

@ -52,6 +52,7 @@
<module>mybatis-3.x-plugin</module>
<module>sentinel-1.x-plugin</module>
<module>ehcache-2.x-plugin</module>
<module>guava-cache-plugin</module>
</modules>
<dependencies>

View File

@ -23,6 +23,7 @@
- graphql
- grpc-1.x
- gson-2.8.x
- guava-cache
- h2-1.x
- hbase-1.x/2.x
- httpasyncclient-4.x

View File

@ -195,6 +195,7 @@ Now, we have the following known optional plugins.
* Plugin of mybatis-3.x in optional plugin folder. The reason of being optional plugin is, many local span are generated, which also spend more CPU, memory and network.
* Plugin of sentinel-1.x in the optional plugin folder. The reason for being an optional plugin is, the sentinel plugin generates a large number of local spans, which have a potential performance impact.
* Plugin of ehcache-2.x in the optional plugin folder. The reason for being an optional plugin is, this plugin enhanced cache framework, generates large number of local spans, which have a potential performance impact.
* Plugin of guava-cache in the optional plugin folder. The reason for being an optional plugin is, this plugin enhanced cache framework, generates large number of local spans, which have a potential performance impact.
## Bootstrap class plugins
All bootstrap plugins are optional, due to unexpected risk. Bootstrap plugins are provided in `bootstrap-plugins` folder.

View File

@ -116,6 +116,7 @@ metrics based on the tracing data.
* JRE Callable and Runnable (Optional²)
* Cache
* [Ehcache](https://www.ehcache.org/) 2.x
* [GuavaCache](https://github.com/google/guava) 18.x -> 23.x (Optional²)
* Kotlin
* [Coroutine](https://kotlinlang.org/docs/reference/coroutines-overview.html) 1.0.1 -> 1.3.x (Optional²)
* GraphQL

View File

@ -371,6 +371,9 @@ Neo4j:
Sentinel:
id: 113
languages: Java
GuavaCache:
id: 114
languages: Java
# .NET/.NET Core components
# [3000, 4000) for C#/.NET only

View File

@ -0,0 +1,101 @@
# 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: guava-cache-scenario
segmentSize: ge 1
segments:
- segmentId: not null
spans:
- operationName: GuavaCache/put
operationId: 0
parentSpanId: 0
spanId: 1
spanLayer: Cache
startTime: nq 0
endTime: nq 0
componentId: 114
isError: false
spanType: Local
peer: ''
tags:
- {key: db.statement, value: testKey1}
skipAnalysis: 'false'
- operationName: GuavaCache/invalidate
operationId: 0
parentSpanId: 0
spanId: 2
spanLayer: Cache
startTime: nq 0
endTime: nq 0
componentId: 114
isError: false
spanType: Local
peer: ''
tags:
- {key: db.statement, value: testKey1}
skipAnalysis: 'false'
- operationName: GuavaCache/get
operationId: 0
parentSpanId: 0
spanId: 3
spanLayer: Cache
startTime: nq 0
endTime: nq 0
componentId: 114
isError: false
spanType: Local
peer: ''
tags:
- {key: db.statement, value: testKey1}
skipAnalysis: 'false'
- operationName: GuavaCache/getIfPresent
operationId: 0
parentSpanId: 0
spanId: 4
spanLayer: Cache
startTime: nq 0
endTime: nq 0
componentId: 114
isError: false
spanType: Local
peer: ''
tags:
- {key: db.statement, value: testKey1}
skipAnalysis: 'false'
- {operationName: GuavaCache/putAll, operationId: 0, parentSpanId: 0, spanId: 5, spanLayer: Cache,
startTime: nq 0, endTime: nq 0, componentId: 114, isError: false,
spanType: Local, peer: '', skipAnalysis: false}
- {operationName: GuavaCache/getAllPresent, operationId: 0, parentSpanId: 0, spanId: 6,
spanLayer: Cache, startTime: nq 0, endTime: nq 0, componentId: 114,
isError: false, spanType: Local, peer: '', skipAnalysis: false}
- {operationName: GuavaCache/invalidateAll, operationId: 0, parentSpanId: 0, spanId: 7,
spanLayer: Cache, startTime: nq 0, endTime: nq 0, componentId: 114,
isError: false, spanType: Local, peer: '', skipAnalysis: false}
- operationName: /guava-cache-scenario/case/guava
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/guava-cache-scenario/case/guava'}
- {key: http.method, value: GET}
skipAnalysis: 'false'

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.
type: tomcat
entryService: http://localhost:8080/guava-cache-scenario/case/guava
healthCheck: http://localhost:8080/guava-cache-scenario/healthCheck
runningMode: with_optional
withPlugins: apm-guava-cache-plugin-*.jar

View File

@ -0,0 +1,77 @@
<?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">
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.skywalking</groupId>
<artifactId>guava-cache-scenario</artifactId>
<version>5.0.0</version>
<packaging>war</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<compiler.version>1.8</compiler.version>
<test.framework>guava</test.framework>
<test.framework.version>23.0</test.framework.version>
</properties>
<name>skywalking-guava-cache-scenario</name>
<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.8.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.8.1</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${test.framework.version}</version>
</dependency>
</dependencies>
<build>
<finalName>guava-cache-scenario</finalName>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${compiler.version}</source>
<target>${compiler.version}</target>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,71 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.skywalking.apm.testcase.guava.cache;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutionException;
public class CaseServlet extends HttpServlet {
Cache<String, Object> cache = CacheBuilder.newBuilder().softValues().build();
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String key1 = "testKey1";
String value1 = "testValue1";
cache.put(key1, value1);
cache.invalidate(key1);
try {
cache.get(key1, () -> value1);
} catch (ExecutionException e) {
e.printStackTrace();
}
cache.getIfPresent(key1);
Map<String, String> kvs = Maps.newHashMap();
String key2 = "testKey2";
String value2 = "testValue2";
kvs.put(key2, value2);
cache.putAll(kvs);
List<String> testKeys = Lists.newArrayList(key1, key2);
cache.getAllPresent(testKeys);
cache.invalidateAll();
PrintWriter printWriter = resp.getWriter();
printWriter.write("success");
printWriter.flush();
printWriter.close();
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
doGet(req, resp);
}
}

View File

@ -0,0 +1,40 @@
/*
* 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.guava.cache;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
public class HealthCheckServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
PrintWriter writer = resp.getWriter();
writer.write("Success");
writer.flush();
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
doGet(req, resp);
}
}

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="info">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d [%traceId] %-5p %c{1}:%L - %m%n"/>
</Console>
</Appenders>
<Loggers>
<Root level="OFF">
<AppenderRef ref="Console"/>
</Root>
</Loggers>
</Configuration>

View File

@ -0,0 +1,44 @@
<!--
~ 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.
~
-->
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<display-name>skywalking-guava-cache-scenario</display-name>
<servlet>
<servlet-name>caseServlet</servlet-name>
<servlet-class>org.apache.skywalking.apm.testcase.guava.cache.CaseServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>caseServlet</servlet-name>
<url-pattern>/case/guava</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>healthCheck</servlet-name>
<servlet-class>org.apache.skywalking.apm.testcase.guava.cache.HealthCheckServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>healthCheck</servlet-name>
<url-pattern>/healthCheck</url-pattern>
</servlet-mapping>
</web-app>

View File

@ -0,0 +1,22 @@
# 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.
18.0
19.0
20.0
21.0
22.0
23.0