From 4f1ca596f6ff5dee1e145d137b79c1d2c26c9339 Mon Sep 17 00:00:00 2001 From: jaehong-kim Date: Wed, 19 Oct 2016 17:35:07 +0900 Subject: [PATCH] add ant-style path pattern. --- .../src/main/resources-local/pinpoint.config | 1 + .../main/resources-release/pinpoint.config | 1 + ...inpoint-real-env-lowoverhead-sample.config | 1 + .../pinpoint-disabled-plugin-test.config | 1 + .../pinpoint-spring-bean-test.config | 1 + .../spring/beans/SpringBeansTarget.java | 8 +++---- .../spring/beans/SpringBeansTargetTest.java | 8 +++---- .../interceptor/TargetBeanFilterTest.java | 22 ++++++++++++++----- .../agent/src/main/resources/pinpoint.config | 1 + quickstart/conf/pinpoint.config | 1 + 10 files changed, 31 insertions(+), 14 deletions(-) diff --git a/agent/src/main/resources-local/pinpoint.config b/agent/src/main/resources-local/pinpoint.config index 421b87c195c2..265767ad7530 100644 --- a/agent/src/main/resources-local/pinpoint.config +++ b/agent/src/main/resources-local/pinpoint.config @@ -444,6 +444,7 @@ profiler.spring.beans=true # ANT Style pattern rules: # ? - matches on character # * - matches zero or more characters +# ** - matches zero or more 'directories' in a path # Examples # profiler.spring.beans.1.name.scope=component-scan diff --git a/agent/src/main/resources-release/pinpoint.config b/agent/src/main/resources-release/pinpoint.config index b3eef9d1a4a8..4ebec25be7f5 100644 --- a/agent/src/main/resources-release/pinpoint.config +++ b/agent/src/main/resources-release/pinpoint.config @@ -441,6 +441,7 @@ profiler.spring.beans=true # ANT Style pattern rules: # ? - matches on character # * - matches zero or more characters +# ** - matches zero or more 'directories' in a path # Examples # profiler.spring.beans.1.name.scope=component-scan diff --git a/agent/src/main/resources/pinpoint-real-env-lowoverhead-sample.config b/agent/src/main/resources/pinpoint-real-env-lowoverhead-sample.config index b51268cf80c5..44faab44b9b5 100644 --- a/agent/src/main/resources/pinpoint-real-env-lowoverhead-sample.config +++ b/agent/src/main/resources/pinpoint-real-env-lowoverhead-sample.config @@ -398,6 +398,7 @@ profiler.spring.beans=true # ANT Style pattern rules: # ? - matches on character # * - matches zero or more characters +# ** - matches zero or more 'directories' in a path # Examples # profiler.spring.beans.1.name.scope=component-scan diff --git a/agent/src/test/resources/pinpoint-disabled-plugin-test.config b/agent/src/test/resources/pinpoint-disabled-plugin-test.config index ff7759806559..bfebde28776e 100644 --- a/agent/src/test/resources/pinpoint-disabled-plugin-test.config +++ b/agent/src/test/resources/pinpoint-disabled-plugin-test.config @@ -269,6 +269,7 @@ profiler.spring.beans=true # ANT Style pattern rules: # ? - matches on character # * - matches zero or more characters +# ** - matches zero or more 'directories' in a path # Examples # profiler.spring.beans.1.name.scope=component-scan diff --git a/agent/src/test/resources/pinpoint-spring-bean-test.config b/agent/src/test/resources/pinpoint-spring-bean-test.config index 11d28da44a26..570e16c0b06f 100644 --- a/agent/src/test/resources/pinpoint-spring-bean-test.config +++ b/agent/src/test/resources/pinpoint-spring-bean-test.config @@ -268,6 +268,7 @@ profiler.spring.beans=true # ANT Style pattern rules: # ? - matches on character # * - matches zero or more characters +# ** - matches zero or more 'directories' in a path # Examples: # profiler.spring.beans.1.name.scope=component-scan diff --git a/plugins/spring/src/main/java/com/navercorp/pinpoint/plugin/spring/beans/SpringBeansTarget.java b/plugins/spring/src/main/java/com/navercorp/pinpoint/plugin/spring/beans/SpringBeansTarget.java index ecf962eff796..cfc9f0675da0 100644 --- a/plugins/spring/src/main/java/com/navercorp/pinpoint/plugin/spring/beans/SpringBeansTarget.java +++ b/plugins/spring/src/main/java/com/navercorp/pinpoint/plugin/spring/beans/SpringBeansTarget.java @@ -73,7 +73,7 @@ public List getBasePackages() { } public void setNamePatterns(final String namePatternRegex) { - this.namePatterns = compilePattern(split(namePatternRegex)); + this.namePatterns = compilePattern(split(namePatternRegex), "/"); } public List getNamePatterns() { @@ -81,7 +81,7 @@ public List getNamePatterns() { } public void setClassPatterns(final String classPatternRegex) { - this.classPatterns = compilePattern(split(classPatternRegex)); + this.classPatterns = compilePattern(split(classPatternRegex), "."); } public List getClassPatterns() { @@ -114,7 +114,7 @@ List split(final String values) { return result; } - List compilePattern(List patternStrings) { + List compilePattern(List patternStrings, final String separator) { if (patternStrings == null || patternStrings.isEmpty()) { return null; } @@ -127,7 +127,7 @@ List compilePattern(List patternStrings) { if (prefix.equals(ANT_STYLE_PATTERN_PREFIX)) { final String trimmed = patternString.substring(prefixEnd + 1).trim(); if (!trimmed.isEmpty()) { - pathMatchers.add(new AntPathMatcher(trimmed)); + pathMatchers.add(new AntPathMatcher(trimmed, separator)); } continue; } else if (prefix.equals(REGEX_PATTERN_PREFIX)) { diff --git a/plugins/spring/src/test/java/com/navercorp/pinpoint/plugin/spring/beans/SpringBeansTargetTest.java b/plugins/spring/src/test/java/com/navercorp/pinpoint/plugin/spring/beans/SpringBeansTargetTest.java index 73069160b195..fa8102bb5a24 100644 --- a/plugins/spring/src/test/java/com/navercorp/pinpoint/plugin/spring/beans/SpringBeansTargetTest.java +++ b/plugins/spring/src/test/java/com/navercorp/pinpoint/plugin/spring/beans/SpringBeansTargetTest.java @@ -39,13 +39,13 @@ public void split() { @Test public void compilePattern() { SpringBeansTarget target = new SpringBeansTarget(); - List list = target.compilePattern(Arrays.asList("1", "regex:2", "antstyle:3")); + List list = target.compilePattern(Arrays.asList("1", "regex:2", "antstyle:3"), "."); assertEquals(3, list.size()); - list = target.compilePattern(Arrays.asList("1", "regex: 2", "antstyle: 3")); + list = target.compilePattern(Arrays.asList("1", "regex: 2", "antstyle: 3"), "."); assertEquals(3, list.size()); - list = target.compilePattern(Arrays.asList("1", "regex:", "antstyle:")); + list = target.compilePattern(Arrays.asList("1", "regex:", "antstyle:"), "."); assertEquals(1, list.size()); - list = target.compilePattern(Arrays.asList("1", "regex: 1", "antstyle: 2")); + list = target.compilePattern(Arrays.asList("1", "regex: 1", "antstyle: 2"), "."); assertEquals(3, list.size()); } } \ No newline at end of file diff --git a/plugins/spring/src/test/java/com/navercorp/pinpoint/plugin/spring/beans/interceptor/TargetBeanFilterTest.java b/plugins/spring/src/test/java/com/navercorp/pinpoint/plugin/spring/beans/interceptor/TargetBeanFilterTest.java index 86886cc9138b..fb16c52f5054 100644 --- a/plugins/spring/src/test/java/com/navercorp/pinpoint/plugin/spring/beans/interceptor/TargetBeanFilterTest.java +++ b/plugins/spring/src/test/java/com/navercorp/pinpoint/plugin/spring/beans/interceptor/TargetBeanFilterTest.java @@ -111,19 +111,29 @@ public void beansNamePattern() { @Test public void classNamePattern() { + assertClassNamePattern("antstyle:**"); + assertClassNamePattern("antstyle:java.*.String"); + assertClassNamePattern("antstyle:java.**.String"); + assertClassNamePattern("antstyle:java.*.*"); + assertClassNamePattern("antstyle:java.**"); + assertClassNamePattern("antstyle:**.String"); + assertClassNamePattern("antstyle:java.lang.S*"); + assertClassNamePattern("antstyle:java.lang.*"); + assertClassNamePattern("antstyle:java.lang.Strin?"); + assertClassNamePattern("java.*"); + assertClassNamePattern("regex:java.*"); + assertClassNamePattern("regex:java.*.String"); + } + + private void assertClassNamePattern(final String pattern) { Properties properties = new Properties(); - properties.put(SpringBeansConfig.SPRING_BEANS_PREFIX + 1 + SpringBeansConfig.SPRING_BEANS_CLASS_PATTERN_POSTFIX, "antstyle:*"); + properties.put(SpringBeansConfig.SPRING_BEANS_PREFIX + 1 + SpringBeansConfig.SPRING_BEANS_CLASS_PATTERN_POSTFIX, pattern); ProfilerConfig config = new DefaultProfilerConfig(properties); TargetBeanFilter filter = TargetBeanFilter.of(config); filter.clear(); BeanDefinition beanDefinition = new RootBeanDefinition(String.class); assertTrue(filter.isTarget(SpringBeansTargetScope.COMPONENT_SCAN, "Target0", beanDefinition)); - - filter.addTransformed(String.class.getName()); - - assertFalse(filter.isTarget(SpringBeansTargetScope.COMPONENT_SCAN, "Target0", beanDefinition)); - assertFalse(filter.isTarget(SpringBeansTargetScope.COMPONENT_SCAN, "Target1", beanDefinition)); } @Test diff --git a/quickstart/agent/src/main/resources/pinpoint.config b/quickstart/agent/src/main/resources/pinpoint.config index c292facff0e9..e08a6947c0b5 100644 --- a/quickstart/agent/src/main/resources/pinpoint.config +++ b/quickstart/agent/src/main/resources/pinpoint.config @@ -277,6 +277,7 @@ profiler.spring.beans=true # ANT Style pattern rules: # ? - matches on character # * - matches zero or more characters +# ** - matches zero or more 'directories' in a path # Examples # profiler.spring.beans.1.name.scope=component-scan diff --git a/quickstart/conf/pinpoint.config b/quickstart/conf/pinpoint.config index ce3ee3ad4c96..bb3ec20b4973 100644 --- a/quickstart/conf/pinpoint.config +++ b/quickstart/conf/pinpoint.config @@ -291,6 +291,7 @@ profiler.spring.beans=true # ANT Style pattern rules: # ? - matches on character # * - matches zero or more characters +# ** - matches zero or more 'directories' in a path # Examples # profiler.spring.beans.1.name.scope=component-scan