-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
[HUDI-7763] Fix that multiple jmx reporter can exist if metadata enables #11226
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,7 @@ | |
import javax.management.MBeanServer; | ||
|
||
import java.lang.management.ManagementFactory; | ||
import java.rmi.server.ExportException; | ||
import java.util.Objects; | ||
import java.util.stream.IntStream; | ||
|
||
|
@@ -53,16 +54,13 @@ public JmxMetricsReporter(HoodieMetricsConfig config, MetricRegistry registry) { | |
host, portsConfig)); | ||
} | ||
int[] ports = getPortRangeFromString(portsConfig); | ||
boolean successfullyStartedServer = false; | ||
for (int port : ports) { | ||
jmxReporterServer = createJmxReport(host, port); | ||
LOG.info("Started JMX server on port " + port + "."); | ||
successfullyStartedServer = true; | ||
break; | ||
} | ||
initializeJmxReporterServer(host, ports); | ||
|
||
boolean successfullyStartedServer = isServerCreated(); | ||
if (!successfullyStartedServer) { | ||
throw new HoodieException( | ||
"Could not start JMX server on any configured port. Ports: " + portsConfig); | ||
"Could not start JMX server on any configured port. Ports: " + portsConfig | ||
+ ". Maybe require port range for multiple hoodie tables"); | ||
} | ||
LOG.info("Configured JMXReporter with {port:" + portsConfig + "}"); | ||
} catch (Exception e) { | ||
|
@@ -72,9 +70,29 @@ public JmxMetricsReporter(HoodieMetricsConfig config, MetricRegistry registry) { | |
} | ||
} | ||
|
||
private boolean isServerCreated() { | ||
return jmxReporterServer != null; | ||
} | ||
|
||
private void initializeJmxReporterServer(String host, int[] ports) { | ||
for (int port : ports) { | ||
try { | ||
jmxReporterServer = createJmxReport(host, port); | ||
LOG.info("Started JMX server on port " + port + "."); | ||
break; | ||
} catch (Exception e) { | ||
if (e.getCause() instanceof ExportException) { | ||
LOG.info("Skip for initializing jmx port " + port + " because of already in use"); | ||
} else { | ||
LOG.info("Failed to initialize jmx port " + port + ". " + e.getMessage()); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. emit log if all unknown error occur |
||
} | ||
} | ||
} | ||
|
||
@Override | ||
public void start() { | ||
if (jmxReporterServer != null) { | ||
if (isServerCreated()) { | ||
jmxReporterServer.start(); | ||
} else { | ||
LOG.error("Cannot start as the jmxReporter is null."); | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Should we catch specific exception type here?
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.
c7b4028
Callee function catches all exceptions, then rethrow to HoodieException.
Thus, check causes and log messages in detail.
Thanks for comment