Skip to content

ENG-27785: allow port-only for -m, require host for -b#21

Merged
benjaminballard merged 4 commits intomasterfrom
ENG-27785-fix
Jun 16, 2025
Merged

ENG-27785: allow port-only for -m, require host for -b#21
benjaminballard merged 4 commits intomasterfrom
ENG-27785-fix

Conversation

@benjaminballard
Copy link
Contributor

@benjaminballard benjaminballard commented Jun 11, 2025

The previous ENG-27785 change setting the default value to "12223" for the -m metrics bind address caused meshmonitor to crash with a port already in use exception, unless you provided -m "0.0.0.0:12223" which I've used successfully as a workaround to get data to Prometheus. Now I'm circling back to fix this.

PicoCLI handles the CLI argument parsing, but in the case of the -b and -m options, and the parameter (optional list of hostnames), since these are mapped to InetSocketAddress attributes, PicoCLI does not provide a built-in converter to this type. This project has used a custom converter class to handle parsing these inputs to InetSocketAddress output, but it treated the absence of ":" as a hostname-only address, not a port-only address. So for -m 12223, rather than getting that port with the wildcard host, it converted the integer 12223 to the IP address "0.0.47.191" and tacked on the default port 12222 (which should only be used for -b, not for -m). Hence the metrics http server came up trying to use port 12222 which was already in use by meshmonitor.

I've created a new separate converter for -m, which allows port-only, and handles IPv4 and IPv6 hosts if provided.

I could have left the existing converter alone for -b and the parameter list, but it only works if the FQDN or ip address is provided, so setting -b and providing a hostname should be required.

private boolean portInValidRange(int port) {
return port >=1 && port <= 65535;
}
}

Choose a reason for hiding this comment

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

wow!


@Override
protected boolean requiresHostname() {
return true;

Choose a reason for hiding this comment

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

Does this mean you only listen on a single interface?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

requiresHostname = true means the user must provide some sort of hostname. It could be [:::] or 0.0.0.0, or locahost, but it can't be empty.

@benjaminballard benjaminballard merged commit d862e9b into master Jun 16, 2025
2 checks passed
@benjaminballard benjaminballard deleted the ENG-27785-fix branch June 16, 2025 14:28
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