use of com.newrelic.agent.instrumentation.methodmatchers.MethodMatcher in project newrelic-java-agent by newrelic.
the class PointCutConfigTest method nestedStaticMethodMatcher.
@Test
public void nestedStaticMethodMatcher() throws Exception {
final String yaml = "oder:\n class_matcher: java/lang/String\n method_matcher: [ !static_method_matcher [ concat(Ljava/lang/String;)Ljava/lang/String; ], go()V ]";
PointCutConfig config = new PointCutConfig(new ByteArrayInputStream(yaml.getBytes(StandardCharsets.UTF_8)));
Assert.assertEquals(1, config.getPointCuts().size());
Assert.assertNotNull(config.getPointCuts().get(0));
MethodMatcher methodMatcher = config.getPointCuts().get(0).getMethodMatcher();
Assert.assertTrue(methodMatcher.matches(MethodMatcher.UNSPECIFIED_ACCESS, "concat", "(Ljava/lang/String;)Ljava/lang/String;", com.google.common.collect.ImmutableSet.<String>of()));
Assert.assertTrue(methodMatcher.matches(MethodMatcher.UNSPECIFIED_ACCESS, "go", "()V", com.google.common.collect.ImmutableSet.<String>of()));
Assert.assertFalse(methodMatcher.matches(MethodMatcher.UNSPECIFIED_ACCESS, "dude", "(Ljava/lang/String;)Ljava/lang/String;", com.google.common.collect.ImmutableSet.<String>of()));
}
use of com.newrelic.agent.instrumentation.methodmatchers.MethodMatcher in project newrelic-java-agent by newrelic.
the class InstrumentationConstructorTest method orMethodMatchers.
@Test
public void orMethodMatchers() throws Exception {
String methods = "[ !exact_method_matcher [ 'getTracerFactoryClassName', '()Ljava/lang/String;' ], !exact_method_matcher [ 'getDude', '()V' ] ]";
MethodMatcher[] matchers = new MethodMatcher[] { new ExactMethodMatcher("getTracerFactoryClassName", "()Ljava/lang/String;"), new ExactMethodMatcher("getDude", "()V") };
MethodMatcher methodMatcher = load("!or_method_matcher " + methods);
Assert.assertEquals(OrMethodMatcher.getMethodMatcher(matchers), methodMatcher);
}
use of com.newrelic.agent.instrumentation.methodmatchers.MethodMatcher in project newrelic-java-agent by newrelic.
the class YmlExtensionPointCutConverter method createExtensionPointCut.
public static ExtensionClassAndMethodMatcher createExtensionPointCut(Map attrs, String defaultMetricPrefix, ClassLoader classLoader, String extName) {
ClassMatcher classMatcher = getClassMatcher(attrs);
MethodMatcher methodMatcher = getMethodMatcher(attrs);
boolean dispatcher = getDispatcher(attrs);
Config newConfig = new BaseConfig(attrs);
boolean skipTransTrace = newConfig.getProperty(SKIP_TRANS_KEY, Boolean.FALSE);
boolean ignoreTrans = newConfig.getProperty(IGNORE_TRANS_KEY, Boolean.FALSE);
String metricPrefix = defaultMetricPrefix;
String metricName;
Object format = attrs.get(METRIC_NAME_FORMAT_KEY);
if (format instanceof String) {
metricName = format.toString();
} else if (null == format) {
metricName = null;
} else if (format instanceof MetricNameFormatFactory) {
// sorry - not supported anymore
Agent.LOG.log(Level.WARNING, MessageFormat.format("The object property {0} is no longer supported in the agent. The default naming mechanism will be used.", METRIC_NAME_FORMAT_KEY));
metricName = null;
} else {
throw new RuntimeException(MessageFormat.format("Unsupported {0} value", METRIC_NAME_FORMAT_KEY));
}
String tracerFactoryNameString = getTracerFactoryName(attrs, defaultMetricPrefix, dispatcher, format, classLoader);
String nameOfExtension = (extName == null) ? "Unknown" : extName;
return new ExtensionClassAndMethodMatcher(nameOfExtension, metricName, metricPrefix, classMatcher, methodMatcher, dispatcher, skipTransTrace, false, ignoreTrans, tracerFactoryNameString);
}
use of com.newrelic.agent.instrumentation.methodmatchers.MethodMatcher in project newrelic-java-agent by newrelic.
the class ExtensionServiceTest method testXMLExtensionOneFile.
/**
* Tests reading in the xml extensions for one file.
*/
@Test
public void testXMLExtensionOneFile() throws Exception {
setupFiles(true, XML_FILE_PATH_1);
List<ExtensionClassAndMethodMatcher> pcs = extensionService.getEnabledPointCuts();
assertNotNull(pcs);
assertEquals(3, pcs.size());
List<String> classNames = new ArrayList<>();
List<MethodMatcher> mms = new ArrayList<>();
for (ExtensionClassAndMethodMatcher pc : pcs) {
classNames.addAll(pc.getClassMatcher().getClassNames());
mms.add(pc.getMethodMatcher());
}
// verify that classes
assertEquals(3, classNames.size());
assertTrue(classNames.contains("test/CustomExtensionTest$1"));
assertTrue(classNames.contains("test/AbstractCustomExtensionTest"));
assertTrue(classNames.contains("test/CustomExtensionTest"));
// verify the methods
assertEquals(3, mms.size());
verifyMatch("run", "()V", mms);
verifyMatch("abstractTest1", "()V", mms);
verifyMatch("abstractTest2", "()V", mms);
verifyMatch("test2", "(Ljava/lang/String;J)V", mms);
}
use of com.newrelic.agent.instrumentation.methodmatchers.MethodMatcher in project newrelic-java-agent by newrelic.
the class PointCutConfigTest method invalidMethodDescriptor.
@Test
public void invalidMethodDescriptor() 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', '(java/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);
MethodMatcher methodMatcher = pc.getMethodMatcher();
Assert.assertTrue(methodMatcher instanceof NoMethodsMatcher);
}
Aggregations