forked from alibaba/jvm-sandbox-repeater
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
754e441
commit 13153f7
Showing
17 changed files
with
306 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<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>repeater-plugins</artifactId> | ||
<groupId>com.alibaba.jvm.sandbox</groupId> | ||
<version>1.1.0-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>spring-plugin</artifactId> | ||
<name>repeater-agent::plugins::spring</name> | ||
|
||
<dependencies> | ||
|
||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-assembly-plugin</artifactId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
61 changes: 61 additions & 0 deletions
61
...lugin/src/main/java/com/alibaba/jvm/sandbox/repeater/plugin/spring/JavaInstanceCache.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package com.alibaba.jvm.sandbox.repeater.plugin.spring; | ||
|
||
import com.google.common.collect.Maps; | ||
|
||
import java.lang.reflect.Proxy; | ||
import java.util.Map; | ||
|
||
/** | ||
* {@link JavaInstanceCache} | ||
* <p> | ||
* Java实例缓存,作用是将拦截到的JavaEntrance缓存起来,作为{@link JavaRepeater}获取java运行实例的补充 | ||
* <p> | ||
* 该方法的局限性在于,必须该实例的埋点被采样到 | ||
* </p> | ||
* | ||
* @author zhaoyb1990 | ||
*/ | ||
class JavaInstanceCache { | ||
|
||
/** | ||
* key : className | ||
* value : instance | ||
*/ | ||
private static Map<String, Object> CACHED = Maps.newConcurrentMap(); | ||
|
||
|
||
/** | ||
* 根据实例的类名缓存 | ||
* <p> | ||
* 注意问题: | ||
* 1. 多实例问题可能导致回放失败 | ||
* </p> | ||
* | ||
* @param instance 实例 | ||
*/ | ||
static void cacheInstance(Object instance) { | ||
if (instance != null) { | ||
Class<?> clazz; | ||
if (Proxy.isProxyClass(instance.getClass())) { | ||
clazz = Proxy.getInvocationHandler(instance).getClass(); | ||
} else { | ||
clazz = instance.getClass(); | ||
} | ||
CACHED.put(clazz.getCanonicalName(), instance); | ||
} | ||
} | ||
|
||
/** | ||
* 通过类找到实例 | ||
* <p> | ||
* 注意问题: | ||
* 1. 实例的缓存时机是被回放的埋点被采样到(否则sandbox无法感知到实例) | ||
* </p> | ||
* | ||
* @param className 类全名 | ||
* @return 实例 | ||
*/ | ||
static Object getInstance(String className) { | ||
return CACHED.get(className); | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
...ing-plugin/src/main/java/com/alibaba/jvm/sandbox/repeater/plugin/spring/SpringPlugin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package com.alibaba.jvm.sandbox.repeater.plugin.spring; | ||
|
||
import com.alibaba.jvm.sandbox.api.event.Event; | ||
import com.alibaba.jvm.sandbox.repeater.plugin.api.InvocationProcessor; | ||
import com.alibaba.jvm.sandbox.repeater.plugin.core.impl.AbstractInvokePluginAdapter; | ||
import com.alibaba.jvm.sandbox.repeater.plugin.core.model.EnhanceModel; | ||
import com.alibaba.jvm.sandbox.repeater.plugin.domain.InvokeType; | ||
import com.alibaba.jvm.sandbox.repeater.plugin.domain.RepeaterConfig; | ||
import com.alibaba.jvm.sandbox.repeater.plugin.exception.PluginLifeCycleException; | ||
import com.alibaba.jvm.sandbox.repeater.plugin.spi.InvokePlugin; | ||
import com.google.common.collect.Lists; | ||
import org.kohsuke.MetaInfServices; | ||
|
||
import java.util.List; | ||
|
||
@MetaInfServices(InvokePlugin.class) | ||
public class SpringPlugin extends AbstractInvokePluginAdapter { | ||
@Override | ||
protected List<EnhanceModel> getEnhanceModels() { | ||
EnhanceModel springService = EnhanceModel.builder() | ||
.classPattern("com.aos.*") | ||
.classAnnotations(new String[]{ | ||
"org.springframework.stereotype.Service" | ||
}) | ||
.methodPatterns(EnhanceModel.MethodPattern.transform("*")) | ||
.watchTypes(Event.Type.BEFORE, Event.Type.RETURN, Event.Type.THROWS) | ||
.build(); | ||
|
||
EnhanceModel springController = EnhanceModel.builder() | ||
.classPattern("com.aos.*") | ||
.classAnnotations(new String[]{ | ||
"org.springframework.stereotype.Controller" | ||
}) | ||
.methodPatterns(EnhanceModel.MethodPattern.transform("*")) | ||
.watchTypes(Event.Type.BEFORE, Event.Type.RETURN, Event.Type.THROWS) | ||
.build(); | ||
|
||
EnhanceModel springRestController = EnhanceModel.builder() | ||
.classPattern("com.aos.*") | ||
.classAnnotations(new String[]{ | ||
"org.springframework.web.bind.annotation.RestController" | ||
}) | ||
.methodPatterns(EnhanceModel.MethodPattern.transform("*")) | ||
.watchTypes(Event.Type.BEFORE, Event.Type.RETURN, Event.Type.THROWS) | ||
.build(); | ||
|
||
return Lists.newArrayList(springService, springController, springRestController); | ||
} | ||
|
||
@Override | ||
protected InvocationProcessor getInvocationProcessor() { | ||
return new SpringProcessor(getType()); | ||
} | ||
|
||
@Override | ||
public InvokeType getType() { | ||
return InvokeType.SPRING; | ||
} | ||
|
||
@Override | ||
public String identity() { | ||
return "spring"; | ||
} | ||
|
||
@Override | ||
public boolean isEntrance() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public void onConfigChange(RepeaterConfig config) throws PluginLifeCycleException { | ||
super.onConfigChange(config); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...-plugin/src/main/java/com/alibaba/jvm/sandbox/repeater/plugin/spring/SpringProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.alibaba.jvm.sandbox.repeater.plugin.spring; | ||
|
||
import com.alibaba.jvm.sandbox.api.event.BeforeEvent; | ||
import com.alibaba.jvm.sandbox.repeater.plugin.core.impl.api.DefaultInvocationProcessor; | ||
import com.alibaba.jvm.sandbox.repeater.plugin.domain.Identity; | ||
import com.alibaba.jvm.sandbox.repeater.plugin.domain.InvokeType; | ||
|
||
import java.util.Collections; | ||
|
||
public class SpringProcessor extends DefaultInvocationProcessor { | ||
public SpringProcessor(InvokeType type) { | ||
super(type); | ||
} | ||
|
||
@Override | ||
public Identity assembleIdentity(BeforeEvent event) { | ||
return new Identity(InvokeType.JAVA.name(), event.javaClassName, event.javaMethodName + "~" + event.javaMethodDesc, Collections.EMPTY_MAP); | ||
} | ||
} |
Oops, something went wrong.