diff options
author | jonmv <venstad@gmail.com> | 2022-10-28 09:36:39 +0200 |
---|---|---|
committer | jonmv <venstad@gmail.com> | 2022-10-28 09:36:39 +0200 |
commit | 1c361cb32c0c79cd25fbcc61da9e14e8d2fce184 (patch) | |
tree | e2b1251af977593d3b85f2472e63e653ab8576b5 /metrics-proxy | |
parent | 752f290e434989d2bc49b707c7418c858e3953dc (diff) |
Remove unnecessary return type
Diffstat (limited to 'metrics-proxy')
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<Node, Future<Boolean>> futures = new HashMap<>(); + Map<Node, Future<?>> 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<Node, Future<Boolean>> entry : futures.entrySet()) { + for (Map.Entry<Node, Future<?>> 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<Future<Boolean>> startSnapshotUpdate(ConsumerId consumer, Duration ttl) { + Optional<Future<?>> 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<Boolean> retrieveMetrics(ConsumerId consumer) { + private Future<?> retrieveMetrics(ConsumerId consumer) { String metricsUri = node.metricsUri(consumer).toString(); log.log(FINE, () -> "Retrieving metrics from host " + metricsUri); - CompletableFuture<Boolean> 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); + } }); } + } |