Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Agent fails to load configuration from opaque classpath resource #80

Closed
tcrossland opened this issue May 25, 2016 · 11 comments
Closed

Agent fails to load configuration from opaque classpath resource #80

tcrossland opened this issue May 25, 2016 · 11 comments
Assignees

Comments

@tcrossland
Copy link

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 cyrille-leclerc self-assigned this May 25, 2016
@cyrille-leclerc
Copy link
Member

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

@cyrille-leclerc
Copy link
Member

@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
Copy link
Author

tcrossland commented May 25, 2016

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
Copy link
Member

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
Copy link
Author

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
Copy link
Member

@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
Copy link
Member

@kerlandsson good catch! I'm fixing

cyrille-leclerc added a commit to cyrille-leclerc/jmxtrans-agent that referenced this issue May 26, 2016
@cyrille-leclerc
Copy link
Member

@tcrossland I am working on a fix on my fork cyrille-leclerc@8d853c8

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
Copy link
Author

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

@tcrossland
Copy link
Author

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

@tcrossland
Copy link
Author

tcrossland commented Jun 6, 2016

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants