-
Notifications
You must be signed in to change notification settings - Fork 130
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
Integration tests for JMX Scraper #1480
Integration tests for JMX Scraper #1480
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a bit confused by this. Unless I'm missing something, you shouldn't have to find an ephemeral/open/unused port on the box running the tests -- just use a fixed port for JMX, use that fixed port in the jvm args for both rmi and jmx, and then docker itself should assign an ephemeral port on the outside surface of the container.
That's what the getMappedPort()
then does for you -- it lets you know what external port docker assigned to the fixed internal port. Make sense?
With that, I think you can just delete the PortSelector
class.
Here we have multiple challenges, and using a fixed port mapping is a way to work-around the JMX/RMI implementation details, this is clearly not ideal and I don't know if we have a better option to test JMX with RMI. I haven't investigated deeper but it seems that using In short:
Maybe here another option could also be to make sure that we have a network that is always accessible from the host like it does on Linux could be a simpler option. |
After failing to make things working with
I've opened a PR on this PR to simplify even further and reuse an available port implementation already in classpath: robsunday#1 |
refactor in a single method + reuse available port detect
String targetHost = target.getHost(); | ||
Integer targetPort = target.getMappedPort(JMX_PORT); | ||
logger.info( | ||
"Target system started, JMX port: {} mapped to {}:{}", JMX_PORT, targetHost, targetPort); | ||
|
||
// TODO : wait for metrics to be sent and add assertions on what is being captured | ||
// for now we just test that we can connect to remote JMX using our client. | ||
try (JMXConnector connector = JmxConnectorBuilder.createNew(targetHost, targetPort).build()) { | ||
assertThat(connector.getMBeanServerConnection()).isNotNull(); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[for reviewer] this part had to go anyway as it's now replaced by actual integration tests in #1485 , here it only checked the connection from the host as a proxy of "target JVM is working with JMX settings".
...est/java/io/opentelemetry/contrib/jmxscraper/target_systems/TargetSystemIntegrationTest.java
Outdated
Show resolved
Hide resolved
use fixed port for container-to-container
jmx-scraper/src/main/java/io/opentelemetry/contrib/jmxscraper/JmxConnectorBuilder.java
Show resolved
Hide resolved
// properties.put("com.sun.management.jmxremote.local.only", "false"); | ||
// properties.put("java.rmi.server.logCalls", "true"); | ||
// |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest either remove or include a code comment explaining why you may want to uncomment
// properties.put("com.sun.management.jmxremote.local.only", "false"); | |
// properties.put("java.rmi.server.logCalls", "true"); | |
// |
No description provided.