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

Cleanup monitorType JMX #611

Merged
merged 1 commit into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ public class ClusterStatsJmxMonitor
private static final JsonResponseHandler<JsonNode> JMX_JSON_RESPONSE_HANDLER = createJsonResponseHandler(jsonCodec(JsonNode.class));
private static final String JMX_PATH = "/v1/jmx/mbean";

private final HttpClient client;
private final String username;
private final String password;
private final HttpClient client;

public ClusterStatsJmxMonitor(HttpClient client, BackendStateConfiguration backendStateConfiguration)
{
Expand Down Expand Up @@ -88,7 +88,7 @@ private static void updateClusterStatsFromQueryManagerResponse(JmxResponse respo
int runningQueryCount = stats.getOrDefault("RunningQueries", 0);
clusterStats.runningQueryCount(runningQueryCount);

log.debug(String.format("Processed QueryManager: QueuedQueries = %d, RunningQueries = %d", queuedQueryCount, runningQueryCount));
log.debug("Processed QueryManager: QueuedQueries = %d, RunningQueries = %d", queuedQueryCount, runningQueryCount);
}
catch (Exception e) {
log.error(e, "Error parsing QueryManager stats");
Expand Down Expand Up @@ -144,7 +144,7 @@ private Optional<JmxResponse> queryJmx(ProxyBackendConfiguration backend, String

try {
JsonNode response = client.execute(preparedRequest, JMX_JSON_RESPONSE_HANDLER);
return Optional.ofNullable(response).map(JmxResponse::fromJson);
return Optional.of(response).map(JmxResponse::fromJson);
}
catch (UnexpectedResponseException e) {
log.error(e, "Failed to fetch JMX data for %s, response code: %d", mbeanName, e.getStatusCode());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ void testJmxMonitor()
@Test
void testJmxMonitorWithBadRequest()
{
HttpClient client = new TestingHttpClient(ignored -> TestingResponse
HttpClient client = new TestingHttpClient(_ -> TestingResponse
.mockResponse(HttpStatus.BAD_REQUEST, MediaType.PLAIN_TEXT_UTF_8, "Bad Request"));

testClusterStatsMonitorWithClient(client);
Expand All @@ -89,7 +89,7 @@ void testJmxMonitorWithBadRequest()
@Test
void testJmxMonitorWithServerError()
{
HttpClient client = new TestingHttpClient(ignored -> TestingResponse
HttpClient client = new TestingHttpClient(_ -> TestingResponse
.mockResponse(HttpStatus.INTERNAL_SERVER_ERROR, MediaType.PLAIN_TEXT_UTF_8, "Internal Server Error"));

testClusterStatsMonitorWithClient(client);
Expand All @@ -98,7 +98,7 @@ void testJmxMonitorWithServerError()
@Test
void testJmxMonitorWithInvalidJson()
{
HttpClient client = new TestingHttpClient(ignored -> TestingResponse
HttpClient client = new TestingHttpClient(_ -> TestingResponse
.mockResponse(HttpStatus.OK, MediaType.JSON_UTF_8, "{invalid:json}"));

testClusterStatsMonitorWithClient(client);
Expand All @@ -107,7 +107,7 @@ void testJmxMonitorWithInvalidJson()
@Test
void testJmxMonitorWithNetworkError()
{
HttpClient client = new TestingHttpClient(ignored -> {
HttpClient client = new TestingHttpClient(_ -> {
throw new RuntimeException("Network error");
});

Expand All @@ -133,8 +133,8 @@ void testInfoApiMonitor()
{
MonitorConfiguration monitorConfigurationWithRetries = new MonitorConfiguration();
monitorConfigurationWithRetries.setRetries(10);
testClusterStatsMonitor(ignored -> new ClusterStatsInfoApiMonitor(new JettyHttpClient(new HttpClientConfig()), new MonitorConfiguration()));
testClusterStatsMonitor(ignored -> new ClusterStatsInfoApiMonitor(new JettyHttpClient(new HttpClientConfig()), monitorConfigurationWithRetries));
testClusterStatsMonitor(_ -> new ClusterStatsInfoApiMonitor(new JettyHttpClient(new HttpClientConfig()), new MonitorConfiguration()));
testClusterStatsMonitor(_ -> new ClusterStatsInfoApiMonitor(new JettyHttpClient(new HttpClientConfig()), monitorConfigurationWithRetries));
}

private void testClusterStatsMonitor(Function<BackendStateConfiguration, ClusterStatsMonitor> monitorFactory)
Expand Down