From 1c361cb32c0c79cd25fbcc61da9e14e8d2fce184 Mon Sep 17 00:00:00 2001 From: jonmv Date: Fri, 28 Oct 2022 09:36:39 +0200 Subject: Remove unnecessary return type --- .../http/application/ApplicationMetricsRetriever.java | 11 +++++------ .../metricsproxy/http/application/NodeMetricsClient.java | 8 ++++---- .../metricsproxy/http/application/NodeMetricsClientTest.java | 9 ++++++--- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/metrics-proxy/src/main/java/ai/vespa/metricsproxy/http/application/ApplicationMetricsRetriever.java b/metrics-proxy/src/main/java/ai/vespa/metricsproxy/http/application/ApplicationMetricsRetriever.java index df5b0a16bee..2bdad7d1f0b 100644 --- a/metrics-proxy/src/main/java/ai/vespa/metricsproxy/http/application/ApplicationMetricsRetriever.java +++ b/metrics-proxy/src/main/java/ai/vespa/metricsproxy/http/application/ApplicationMetricsRetriever.java @@ -153,17 +153,16 @@ public class ApplicationMetricsRetriever extends AbstractComponent implements Ru } private int fetchMetricsAsync(ConsumerId consumer) { - Map> futures = new HashMap<>(); + Map> futures = new HashMap<>(); for (NodeMetricsClient client : clients) { - var optional = client.startSnapshotUpdate(consumer, METRICS_TTL); - optional.ifPresent(future -> futures.put(client.node, future)); + client.startSnapshotUpdate(consumer, METRICS_TTL).ifPresent(future -> futures.put(client.node, future)); } int numOk = 0; int numTried = futures.size(); - for (Map.Entry> entry : futures.entrySet()) { + for (Map.Entry> entry : futures.entrySet()) { try { - Boolean result = entry.getValue().get(taskTimeout.get().toMillis(), TimeUnit.MILLISECONDS); - if (result == Boolean.TRUE) numOk++; + entry.getValue().get(taskTimeout.get().toMillis(), TimeUnit.MILLISECONDS); + numOk++; } catch (InterruptedException | ExecutionException | TimeoutException e) { Throwable cause = e.getCause(); if (stopped || e instanceof ExecutionException && ((cause instanceof SocketException) || cause instanceof ConnectTimeoutException)) { diff --git a/metrics-proxy/src/main/java/ai/vespa/metricsproxy/http/application/NodeMetricsClient.java b/metrics-proxy/src/main/java/ai/vespa/metricsproxy/http/application/NodeMetricsClient.java index 927d7b67d46..e55c42f6b57 100644 --- a/metrics-proxy/src/main/java/ai/vespa/metricsproxy/http/application/NodeMetricsClient.java +++ b/metrics-proxy/src/main/java/ai/vespa/metricsproxy/http/application/NodeMetricsClient.java @@ -62,23 +62,23 @@ public class NodeMetricsClient { return (snapshot != null) ? snapshot.metrics : List.of(); } - Optional> startSnapshotUpdate(ConsumerId consumer, Duration ttl) { + Optional> startSnapshotUpdate(ConsumerId consumer, Duration ttl) { var snapshot = snapshots.get(consumer); if ((snapshot != null) && snapshot.isValid(clock.instant(), ttl)) return Optional.empty(); return Optional.of(retrieveMetrics(consumer)); } - private Future retrieveMetrics(ConsumerId consumer) { + private Future retrieveMetrics(ConsumerId consumer) { String metricsUri = node.metricsUri(consumer).toString(); log.log(FINE, () -> "Retrieving metrics from host " + metricsUri); - CompletableFuture onDone = new CompletableFuture<>(); + CompletableFuture onDone = new CompletableFuture<>(); httpClient.execute(SimpleRequestBuilder.get(metricsUri).build(), new FutureCallback<>() { @Override public void completed(SimpleHttpResponse result) { handleResponse(metricsUri, consumer, result.getBodyText()); - onDone.complete(true); + onDone.complete(null); } @Override public void failed(Exception ex) { onDone.completeExceptionally(ex); } @Override public void cancelled() { onDone.cancel(false); } diff --git a/metrics-proxy/src/test/java/ai/vespa/metricsproxy/http/application/NodeMetricsClientTest.java b/metrics-proxy/src/test/java/ai/vespa/metricsproxy/http/application/NodeMetricsClientTest.java index 0d3782a6e51..420d37fc32b 100644 --- a/metrics-proxy/src/test/java/ai/vespa/metricsproxy/http/application/NodeMetricsClientTest.java +++ b/metrics-proxy/src/test/java/ai/vespa/metricsproxy/http/application/NodeMetricsClientTest.java @@ -133,13 +133,16 @@ public class NodeMetricsClientTest { MetricsPacket replacedCpuMetric = customMetrics.get(0); assertTrue(replacedCpuMetric.metrics().containsKey(toMetricId(REPLACED_CPU_METRIC))); } - private void updateSnapshot(ConsumerId consumerId, Duration ttl) { + private void updateSnapshot(ConsumerId consumerId, Duration ttl) { var optional = nodeMetricsClient.startSnapshotUpdate(consumerId, ttl); optional.ifPresent(future -> { try { - assertTrue(future.get()); - } catch (InterruptedException | ExecutionException e) {} + future.get(); + } catch (InterruptedException | ExecutionException e) { + throw new AssertionError(e); + } }); } + } -- cgit v1.2.3