jmxtrans / jmxtrans-agent

Java Agent based JMX metrics exporter.
MIT License
178 stars 110 forks source link

Agent fails to load configuration from opaque classpath resource #80

Closed tcrossland closed 8 years ago

tcrossland commented 8 years ago

The io.resource framework introduced in jmxtrans-agent 1.2.3 causes a load-time failure if the classpath URI is not hierarchical. For example:

java -javaagent:org.jmxtrans.agent.jmxtrans-agent-1.2.3.jar=classpath:jmxtrans-config.xml ...
SEVERE [main] org.jmxtrans.agent.JmxTransAgent - Exception loading JmxTransExporter from 'classpath:jmxtrans-config.xml'
java.lang.IllegalArgumentException: URI is not hierarchical
    at java.io.File.<init>(File.java:418)
    at org.jmxtrans.agent.util.io.ClasspathResource.getFile(ClasspathResource.java:68)
    at org.jmxtrans.agent.util.io.IoUtils.getFileAsDocument(IoUtils.java:153)
    at org.jmxtrans.agent.JmxTransConfigurationXmlLoader.loadConfiguration(JmxTransConfigurationXmlLoader.java:80)
    at org.jmxtrans.agent.JmxTransExporter.loadNewConfiguration(JmxTransExporter.java:74)
    at org.jmxtrans.agent.JmxTransExporter.<init>(JmxTransExporter.java:70)
    at org.jmxtrans.agent.JmxTransAgent.initializeAgent(JmxTransAgent.java:99)
    at org.jmxtrans.agent.JmxTransAgent.premain(JmxTransAgent.java:84)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at sun.instrument.InstrumentationImpl.loadClassAndStartAgent(InstrumentationImpl.java:386)
    at sun.instrument.InstrumentationImpl.loadClassAndCallPremain(InstrumentationImpl.java:401)
cyrille-leclerc commented 8 years ago

Thanks for the detailed report @tcrossland . I'm investigating.

cyrille-leclerc commented 8 years ago

@tcrossland can you please give us one more details please: is jmxtrans-config.xml contained in a jar or is on the file system?

tcrossland commented 8 years ago

It's in one of the jars on the classpath (i.e. it's copied from src/main/resources by maven, or in this case, SBT). The same (opaque) classpath URI works with 1.2.2 of jmxtrans-agent.

I'm happy to continue using 1.2.2, just thought it would be useful to create the issue in case anyone else has the problem.

cyrille-leclerc commented 8 years ago

Thanks @tcrossland. I have just verified that the problem does not happen with a config file on the file system :-)

I suspect that you can workaround prefixing the filename with /.

Can you try to reproduce with https://oss.sonatype.org/content/repositories/snapshots/org/jmxtrans/agent/jmxtrans-agent/1.2.4-SNAPSHOT/jmxtrans-agent-1.2.4-20160525.221853-2.jar

You should have a better exception message. I'm based in France and it's late, I'll continue to investigate tomorrow.

Cyrille

tcrossland commented 8 years ago

I tried using a leading / (classpath:///jmxtrans-config.xml and classpath:/jmxtrans-config.xml) but both failed with an NPE (I've lost the stacktrace from my terminal scrollback, also a bit late here in Spain!). In any case, no hurry, 1.2.2 is working fine.

kerlandsson commented 8 years ago

@cyrille-leclerc I suspect the problem is at org.jmxtrans.agent.util.io.ClasspathResource.getFile() - AFAIK, it is not possible to create File objects for files that reside within a jar file. We probably will have to work with only the stream when reading configuration from within a jar.

cyrille-leclerc commented 8 years ago

@kerlandsson good catch! I'm fixing

cyrille-leclerc commented 8 years ago

@tcrossland I am working on a fix on my fork https://github.com/cyrille-leclerc/jmxtrans-agent/commit/8d853c872cddfd04d6928f5143df4d61f5ceb23a

I did not have the time to finish my tests but this should do the job. Would you have the time to verify?

https://oss.sonatype.org/content/repositories/snapshots/org/jmxtrans/agent/jmxtrans-agent/1.2.4-SNAPSHOT/jmxtrans-agent-1.2.4-20160526.092044-4.jar

tcrossland commented 8 years ago

I'll try tomorrow and let you know. Thanks for the quick fix!

tcrossland commented 8 years ago

Sorry, haven't found time to test it yet... will get round to it soon.

tcrossland commented 8 years ago

@cyrille-leclerc Hi, finally got round to testing the snapshot version, works correctly loading classpath resources. Many thanks!