Search in sources :

Example 6 with ExtensionClassAndMethodMatcher

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

the class PointCutConfig method getExtensionPointCuts.

public static Collection<ExtensionClassAndMethodMatcher> getExtensionPointCuts(Extension extension, Map instrumentation) {
    Collection<ExtensionClassAndMethodMatcher> list = new ArrayList<>();
    if (instrumentation != null) {
        list.addAll(addInstrumentation(extension, instrumentation));
    }
    if (Agent.LOG.isLoggable(Level.FINEST)) {
        for (ExtensionClassAndMethodMatcher pc : list.toArray(new ExtensionClassAndMethodMatcher[0])) {
            String msg = MessageFormat.format("Extension instrumentation point: {0} {1}", pc.getClassMatcher(), pc.getMethodMatcher());
            Agent.LOG.finest(msg);
        }
    }
    return list;
}
Also used : ExtensionClassAndMethodMatcher(com.newrelic.agent.instrumentation.custom.ExtensionClassAndMethodMatcher) ArrayList(java.util.ArrayList)

Example 7 with ExtensionClassAndMethodMatcher

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

the class XmlInstrumentValidator method validateInstrumentation.

/**
 * Validates the instrumentation.
 *
 * @param params The command line parameters.
 * @throws ClassNotFoundException Thrown if the class is not found.
 * @throws RuntimeException Thrown if a problem when converting the xml.
 * @throws IllegalArgumentException Thrown when the method or class can not be found on the class path.
 * @throws IOException Thrown if the file can not be read.
 * @throws SAXException Thrown if a problem parsing the document.
 */
protected static void validateInstrumentation(final XmlInstrumentParams params) throws Exception {
    // read in the file - DOM Exception potentially thrown
    Extension extension = ExtensionDomParser.readFile(params.getFile());
    if (params.isDebug()) {
        System.out.println("Xml was successfully read. Starting processing.");
    }
    // attempt to convert to point cuts - RuntimeException
    // potentially thrown
    List<ExtensionClassAndMethodMatcher> convertedPcs = ExtensionConversionUtility.convertToPointCutsForValidation(extension);
    Instrumentation inst = extension.getInstrumentation();
    // this really has already been checked
    if (inst == null) {
        throw new RuntimeException("The instrumentation propery must be set for the extension.");
    }
    List<Pointcut> origPcs = inst.getPointcut();
    if (convertedPcs.size() != origPcs.size()) {
        throw new IllegalArgumentException("The processed number of point cuts does not match the" + "original number of point cuts in the xml. Remove duplicates.");
    }
    for (int i = 0; i < convertedPcs.size(); i++) {
        MethodHolder holder = sortData(origPcs.get(i), params.isDebug());
        verifyPointCut(convertedPcs.get(i), holder);
        verifyAllMethodsAccounted(holder);
    }
}
Also used : Extension(com.newrelic.agent.extension.beans.Extension) Pointcut(com.newrelic.agent.extension.beans.Extension.Instrumentation.Pointcut) ExtensionClassAndMethodMatcher(com.newrelic.agent.instrumentation.custom.ExtensionClassAndMethodMatcher) Instrumentation(com.newrelic.agent.extension.beans.Extension.Instrumentation)

Example 8 with ExtensionClassAndMethodMatcher

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

the class ExtensionServiceTest method testXMLExtensionWithDuplicates.

@Test
public void testXMLExtensionWithDuplicates() throws Exception {
    setupFiles(true, XML_DUPS);
    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 classes
    assertEquals(3, classNames.size());
    assertTrue(classNames.contains("test/TheClass"));
    assertTrue(classNames.contains("test/TheOtherClass"));
    // verify the methods
    assertEquals(3, mms.size());
    verifyMatch("run", "()Ljava/lang/String;", mms);
    verifyMatch("merge", "()Ljava/lang/String;", mms);
    verifyMatch("migrate", "()Ljava/lang/String;", mms);
    verifyMatch("run", "()Ljava/lang/String;", mms);
    verifyMatch("merge", "()Ljava/lang/String;", mms);
    verifyMatch("run", "(Ljava/lang/String;J)Ljava/lang/String;", mms);
}
Also used : ExtensionClassAndMethodMatcher(com.newrelic.agent.instrumentation.custom.ExtensionClassAndMethodMatcher) ArrayList(java.util.ArrayList) ExtensionClassAndMethodMatcher(com.newrelic.agent.instrumentation.custom.ExtensionClassAndMethodMatcher) MethodMatcher(com.newrelic.agent.instrumentation.methodmatchers.MethodMatcher) Test(org.junit.Test)

Example 9 with ExtensionClassAndMethodMatcher

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

the class ExtensionServiceTest method testXMLExtensionWithYMLSameName.

/**
 * Verifies that the xml file gets read in instead of the yml since the files have the same name.
 */
@Test
public void testXMLExtensionWithYMLSameName() throws Exception {
    setupFiles(true, XML_FILE_PATH_1, YML_FILE_PATH_1_1);
    List<ExtensionClassAndMethodMatcher> pcs = extensionService.getEnabledPointCuts();
    assertNotNull(pcs);
    assertEquals(3, pcs.size());
    List<String> classNames = new ArrayList<>();
    for (ExtensionClassAndMethodMatcher pc : pcs) {
        classNames.addAll(pc.getClassMatcher().getClassNames());
    }
    // verify that classes
    assertEquals(3, classNames.size());
    assertTrue(classNames.contains("test/CustomExtensionTest$1"));
    assertTrue(classNames.contains("test/AbstractCustomExtensionTest"));
    assertTrue(classNames.contains("test/CustomExtensionTest"));
}
Also used : ExtensionClassAndMethodMatcher(com.newrelic.agent.instrumentation.custom.ExtensionClassAndMethodMatcher) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 10 with ExtensionClassAndMethodMatcher

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

the class ExtensionServiceTest method testYMLExtensionIneFile.

@Test
public void testYMLExtensionIneFile() throws Exception {
    setupFiles(true, YML_FILE_PATH_1_1);
    List<ExtensionClassAndMethodMatcher> pcs = extensionService.getEnabledPointCuts();
    assertNotNull(pcs);
    assertEquals(1, pcs.size());
    List<String> classNames = new ArrayList<>();
    List<MethodMatcher> mms = new ArrayList<>();
    for (ExtensionClassAndMethodMatcher pc : pcs) {
        classNames.addAll(pc.getClassMatcher().getClassNames());
        assertEquals(ExactClassMatcher.class, pc.getClassMatcher().getClass());
        mms.add(pc.getMethodMatcher());
    }
    // verify that classes
    assertEquals(1, classNames.size());
    assertTrue(classNames.contains("java/lang/instrument/Instrumentation/Agent"));
    // verify method matcher
    assertEquals(1, mms.size());
    assertTrue(mms.get(0).matches(MethodMatcher.UNSPECIFIED_ACCESS, "getVersion", "()Ljava/lang/String;", com.google.common.collect.ImmutableSet.<String>of()));
}
Also used : ExtensionClassAndMethodMatcher(com.newrelic.agent.instrumentation.custom.ExtensionClassAndMethodMatcher) ArrayList(java.util.ArrayList) ExtensionClassAndMethodMatcher(com.newrelic.agent.instrumentation.custom.ExtensionClassAndMethodMatcher) MethodMatcher(com.newrelic.agent.instrumentation.methodmatchers.MethodMatcher) 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