Skip to content

Commit

Permalink
cleanup monitorType JMX
Browse files Browse the repository at this point in the history
  • Loading branch information
alaturqua authored and ebyhr committed Feb 6, 2025
1 parent 3a82b83 commit b16801a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
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

0 comments on commit b16801a

Please sign in to comment.