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

Fix handling of Windows paths in -javaagent config arguments (#312) #371

Merged
merged 1 commit into from
Apr 9, 2019
Merged

Fix handling of Windows paths in -javaagent config arguments (#312) #371

merged 1 commit into from
Apr 9, 2019

Conversation

mvdobrinin
Copy link
Contributor

This fixes Windows path handling.

@mvdobrinin
Copy link
Contributor Author

@brian-brazil


private static Pattern pattern = Pattern.compile(
"^(([\\w.]+):)?" + // optional host portion (not ipv6)
"(\\d{1,5})" + // port
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ports can be letters.

I'd suggest counting the colons, and if there's > 2, parsing them from left to right and what's left is the filename.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm? Can you clarify when a port can be letters? I'm not familiar with this concept.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

http is the same as 80, per /etc/services.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes, I see. However I'm not sure that's possible in this code base since we are in Java. Java does not have an API to find ports by name. All the APIs that are used in this code base require a port to be an integer. For example all constructor calls to InetSocketAddress. Maybe that part can be added as a new feature down the road?

Copy link
Contributor

@brian-brazil brian-brazil Apr 3, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So it is.

This code still isn't quite right. Someone can do [ipv6]:host:1234:path

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you are talking about ipv6 addresses, I believe that functionality is captured. I left a Github comment on the unit test where this is demonstrated. That functionality was introduced by a previous pull request, and I left that logic as-is. That logic remains at the top of the parseConfig method. I tried to make these changes non-invasive.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm talking specifically about the invalid input [ipv6]:host:1234:path, which should be rejected.

I tried to make these changes non-invasive.

It's more important that it works, and the end code is clean.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having [ipv6]:host:1234:path as accepted input was an existing issue in the codebase, but I did go ahead and fix it 😁. I also cleaned up the solution to use a single regex, instead of having separate logic for the ipv6 address.

}

private static Pattern pattern = Pattern.compile(
"^(?:((?:[\\w.]+)|(?:\\[.+])):)" + // host name, or ipv4, or ipv6 address in brackets
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Escape the ] too

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is considered a redundant escape in Java.


Config(String host, int port, String file, InetSocketAddress socket) {
this.host = host;
this.port = port;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Port and host aren't used.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are used for the unit tests.

Signed-off-by: Mikhail Dobrinin <mikhail.dobrinin@jda.com>
@brian-brazil brian-brazil merged commit 485f684 into prometheus:master Apr 9, 2019
@brian-brazil
Copy link
Contributor

Thanks!

@brian-brazil
Copy link
Contributor

Hmm, this change is making mvn verify fail.

@mvdobrinin
Copy link
Contributor Author

It is passing for me locally. Can you share the error?

@mvdobrinin mvdobrinin deleted the windows-paths branch May 3, 2019 21:00
@brian-brazil
Copy link
Contributor

qinghui-xu pushed a commit to qinghui-xu/jmx_exporter that referenced this pull request Sep 18, 2020
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

Successfully merging this pull request may close these issues.

2 participants