Search in sources :

Example 16 with ExtensionClassAndMethodMatcher

use of com.newrelic.agent.instrumentation.custom.ExtensionClassAndMethodMatcher in project newrelic-java-agent by newrelic.

the class ExtensionConversionUtilityTest method testExtensionConversionUtilityValid.

@Test
public void testExtensionConversionUtilityValid() throws Exception {
    File file = getFile(FILE_PATH_VALID);
    Extension extension = ExtensionDomParser.readFileCatchException(file);
    Assert.assertNotNull(extension);
    List<ExtensionClassAndMethodMatcher> pcs = ExtensionConversionUtility.convertToEnabledPointCuts(toList(extension), true, InstrumentationType.LocalCustomXml);
    Assert.assertNotNull(pcs);
    Assert.assertEquals(1, pcs.size());
    ExtensionClassAndMethodMatcher actual = pcs.get(0);
    // test method matching
    Assert.assertTrue(actual.getMethodMatcher().matches(MethodMatcher.UNSPECIFIED_ACCESS, "run", "([[Ljava/util/List;DI)V", com.google.common.collect.ImmutableSet.<String>of()));
    Assert.assertFalse(actual.getMethodMatcher().matches(MethodMatcher.UNSPECIFIED_ACCESS, "timer", "([[Ljava/util/List;DI)V", com.google.common.collect.ImmutableSet.<String>of()));
    Assert.assertTrue(actual.getMethodMatcher().matches(MethodMatcher.UNSPECIFIED_ACCESS, "timer", "(Ljava/util/List;)Ljava/lang/String", com.google.common.collect.ImmutableSet.<String>of()));
    Assert.assertFalse(actual.getMethodMatcher().matches(MethodMatcher.UNSPECIFIED_ACCESS, "run", "(F)V", com.google.common.collect.ImmutableSet.<String>of()));
    Assert.assertTrue(actual.getMethodMatcher().matches(MethodMatcher.UNSPECIFIED_ACCESS, "noParamMethod", "()V", com.google.common.collect.ImmutableSet.<String>of()));
    // test class matching
    Assert.assertEquals(1, actual.getClassMatcher().getClassNames().size());
    Collection<String> classes = actual.getClassMatcher().getClassNames();
    Assert.assertTrue(classes.contains("test/network/TestViewer"));
}
Also used : Extension(com.newrelic.agent.extension.beans.Extension) ExtensionClassAndMethodMatcher(com.newrelic.agent.instrumentation.custom.ExtensionClassAndMethodMatcher) AgentHelper.getFile(com.newrelic.agent.AgentHelper.getFile) File(java.io.File) Test(org.junit.Test)

Example 17 with ExtensionClassAndMethodMatcher

use of com.newrelic.agent.instrumentation.custom.ExtensionClassAndMethodMatcher in project newrelic-java-agent by newrelic.

the class ExtensionConversionUtilityTest method testExtensionConversionUtilityTest1.

@Test
public void testExtensionConversionUtilityTest1() throws Exception {
    File file = getFile(FILE_PATH_1);
    Extension extension = ExtensionDomParser.readFile(file);
    Assert.assertNotNull(extension);
    List<ExtensionClassAndMethodMatcher> pcs = ExtensionConversionUtility.convertToEnabledPointCuts(toList(extension), true, InstrumentationType.LocalCustomXml);
    Assert.assertNotNull(pcs);
    Assert.assertEquals(1, pcs.size());
    ExtensionClassAndMethodMatcher actual = pcs.get(0);
    // test method matching
    Assert.assertTrue(actual.getMethodMatcher().matches(MethodMatcher.UNSPECIFIED_ACCESS, "run", "(Ljava/lang/String;Ljava/lang/String;)V", com.google.common.collect.ImmutableSet.<String>of()));
    Assert.assertFalse(actual.getMethodMatcher().matches(MethodMatcher.UNSPECIFIED_ACCESS, "finish", "(Ljava/lang/String;Ljava/lang/String;)V", com.google.common.collect.ImmutableSet.<String>of()));
    Assert.assertTrue(actual.getMethodMatcher().matches(MethodMatcher.UNSPECIFIED_ACCESS, "finish", "(F)V", com.google.common.collect.ImmutableSet.<String>of()));
    Assert.assertFalse(actual.getMethodMatcher().matches(MethodMatcher.UNSPECIFIED_ACCESS, "run", "(F)V", com.google.common.collect.ImmutableSet.<String>of()));
    Assert.assertFalse(actual.getMethodMatcher().matches(MethodMatcher.UNSPECIFIED_ACCESS, "finish", "(B)V", com.google.common.collect.ImmutableSet.<String>of()));
    // test class matching
    Assert.assertEquals(1, actual.getClassMatcher().getClassNames().size());
    Assert.assertEquals("test/CustomExampleTest", actual.getClassMatcher().getClassNames().toArray()[0]);
}
Also used : Extension(com.newrelic.agent.extension.beans.Extension) ExtensionClassAndMethodMatcher(com.newrelic.agent.instrumentation.custom.ExtensionClassAndMethodMatcher) AgentHelper.getFile(com.newrelic.agent.AgentHelper.getFile) File(java.io.File) Test(org.junit.Test)

Example 18 with ExtensionClassAndMethodMatcher

use of com.newrelic.agent.instrumentation.custom.ExtensionClassAndMethodMatcher in project newrelic-java-agent by newrelic.

the class PointCutConfigTest method childClassMatcher.

@Test
public void childClassMatcher() throws Exception {
    final String yaml = "kiddie:\n  class_matcher: !or_class_matcher [ !child_class_matcher 'com/newrelic/agent/instrumentation/DefaultPointCut', !exact_class_matcher 'com/newrelic/agent/instrumentation/DefaultPointCut' ]\n  method_matcher: !exact_method_matcher [ 'getTracerFactoryClassName', '()Ljava/lang/String;' ]";
    PointCutConfig config = new PointCutConfig(new ByteArrayInputStream(yaml.getBytes(StandardCharsets.UTF_8)));
    Assert.assertEquals(1, config.getPointCuts().size());
    Assert.assertNotNull(config.getPointCuts().get(0));
    ExtensionClassAndMethodMatcher pointCut = config.getPointCuts().get(0);
    MethodMatcher methodMatcher = pointCut.getMethodMatcher();
    Assert.assertTrue(methodMatcher.matches(MethodMatcher.UNSPECIFIED_ACCESS, "getTracerFactoryClassName", "()Ljava/lang/String;", com.google.common.collect.ImmutableSet.<String>of()));
    Assert.assertFalse(methodMatcher.matches(MethodMatcher.UNSPECIFIED_ACCESS, "getTracerFactoryClassName", "()V", com.google.common.collect.ImmutableSet.<String>of()));
}
Also used : ExtensionClassAndMethodMatcher(com.newrelic.agent.instrumentation.custom.ExtensionClassAndMethodMatcher) ByteArrayInputStream(java.io.ByteArrayInputStream) ExtensionClassAndMethodMatcher(com.newrelic.agent.instrumentation.custom.ExtensionClassAndMethodMatcher) MethodMatcher(com.newrelic.agent.instrumentation.methodmatchers.MethodMatcher) ExactMethodMatcher(com.newrelic.agent.instrumentation.methodmatchers.ExactMethodMatcher) Test(org.junit.Test)

Example 19 with ExtensionClassAndMethodMatcher

use of com.newrelic.agent.instrumentation.custom.ExtensionClassAndMethodMatcher in project newrelic-java-agent by newrelic.

the class PointCutConfigTest method metricPrefix.

@Test
public void metricPrefix() throws Exception {
    PointCutConfig config = new PointCutConfig(new ByteArrayInputStream("pre:\n  class_matcher: !exact_class_matcher 'java/lang/String'\n  method_matcher: !exact_method_matcher [ 'concat', '(Ljava/lang/String;)Ljava/lang/String;' ]\n  metric_name_format: !class_method_metric_name_format 'ImportantMetricCategory'".getBytes(StandardCharsets.UTF_8)));
    List<ExtensionClassAndMethodMatcher> pcs = config.getPointCuts();
    Assert.assertEquals(1, pcs.size());
    Assert.assertNotNull(config.getPointCuts().get(0));
}
Also used : ExtensionClassAndMethodMatcher(com.newrelic.agent.instrumentation.custom.ExtensionClassAndMethodMatcher) ByteArrayInputStream(java.io.ByteArrayInputStream) Test(org.junit.Test)

Example 20 with ExtensionClassAndMethodMatcher

use of com.newrelic.agent.instrumentation.custom.ExtensionClassAndMethodMatcher in project newrelic-java-agent by newrelic.

the class PointCutConfigTest method defaultMetricPrefix.

@Test
public void defaultMetricPrefix() throws Exception {
    PointCutConfig config = new PointCutConfig(new ByteArrayInputStream("pre:\n  class_matcher: !exact_class_matcher 'java/lang/String'\n  method_matcher: !exact_method_matcher [ 'concat', '(Ljava/lang/String;)Ljava/lang/String;' ]\n".getBytes(StandardCharsets.UTF_8)));
    List<ExtensionClassAndMethodMatcher> pcs = config.getPointCuts();
    Assert.assertEquals(1, pcs.size());
    ExtensionClassAndMethodMatcher pc = config.getPointCuts().get(0);
    Assert.assertNotNull(pc);
// metric name prefix should be "Custom"
}
Also used : ExtensionClassAndMethodMatcher(com.newrelic.agent.instrumentation.custom.ExtensionClassAndMethodMatcher) ByteArrayInputStream(java.io.ByteArrayInputStream) Test(org.junit.Test)

Aggregations

ExtensionClassAndMethodMatcher (com.newrelic.agent.instrumentation.custom.ExtensionClassAndMethodMatcher)36 Test (org.junit.Test)26 Extension (com.newrelic.agent.extension.beans.Extension)11 MethodMatcher (com.newrelic.agent.instrumentation.methodmatchers.MethodMatcher)10 ArrayList (java.util.ArrayList)10 Pointcut (com.newrelic.agent.extension.beans.Extension.Instrumentation.Pointcut)9 Instrumentation (com.newrelic.agent.extension.beans.Extension.Instrumentation)8 File (java.io.File)6 AgentHelper.getFile (com.newrelic.agent.AgentHelper.getFile)5 ByteArrayInputStream (java.io.ByteArrayInputStream)5 LinkedList (java.util.LinkedList)5 Method (com.newrelic.agent.extension.beans.Extension.Instrumentation.Pointcut.Method)4 ExactClassMatcher (com.newrelic.agent.instrumentation.classmatchers.ExactClassMatcher)3 ExactMethodMatcher (com.newrelic.agent.instrumentation.methodmatchers.ExactMethodMatcher)3 ParameterAttributeName (com.newrelic.agent.instrumentation.tracing.ParameterAttributeName)3 ChildClassMatcher (com.newrelic.agent.instrumentation.classmatchers.ChildClassMatcher)2 ClassMatcher (com.newrelic.agent.instrumentation.classmatchers.ClassMatcher)2 BaseConfig (com.newrelic.agent.config.BaseConfig)1 Config (com.newrelic.agent.config.Config)1 AllClassesMatcher (com.newrelic.agent.instrumentation.classmatchers.AllClassesMatcher)1