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

Skip getting metrics from new nodes #32213

Merged
merged 1 commit into from
Aug 21, 2024
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 @@ -17,6 +17,7 @@
import org.apache.hc.core5.concurrent.FutureCallback;

import java.io.IOException;
import java.time.Duration;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.logging.Level;
Expand Down Expand Up @@ -54,8 +55,11 @@ public CompletableFuture<MetricsResponse> fetchMetrics(ApplicationId application
NodeList applicationNodes = nodeRepository.nodes().list().owner(application).state(Node.State.active);

Optional<Node> metricsV2Container = applicationNodes.container()
.matching(node -> expectedUp(node))
.first();
.matching(this::expectedUp)
.stream()
.filter(node -> ! newNode(node)) // Skip newly added nodes, as they may not be reachable
.findFirst();

if (metricsV2Container.isEmpty()) {
return CompletableFuture.completedFuture(MetricsResponse.empty());
}
Expand All @@ -67,6 +71,13 @@ public CompletableFuture<MetricsResponse> fetchMetrics(ApplicationId application
}
}

/**
* Returns true if this a new node (oldest node history event is less than 3 minutes old)
*/
private boolean newNode(Node node) {
return node.history().age(nodeRepository.clock().instant()).compareTo(Duration.ofMinutes(3)) <= 0;
}

@Override
public void deconstruct() {
httpClient.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.yahoo.vespa.applicationmodel.HostName;
import org.junit.Test;

import java.time.Duration;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CompletableFuture;
Expand All @@ -37,6 +38,7 @@ public void testMetricsFetch() throws Exception {
MetricsV2MetricsFetcher fetcher = new MetricsV2MetricsFetcher(tester.nodeRepository(), orchestrator, httpClient);

tester.makeReadyNodes(4, resources); // Creates (in order) host-1.yahoo.com, host-2.yahoo.com, host-3.yahoo.com, host-4.yahoo.com
tester.clock().advance(Duration.ofMinutes(5)); // Make sure these are not considered new nodes (metrics will not be fetched for them)
tester.activateTenantHosts();

ApplicationId application1 = ProvisioningTester.applicationId();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public void testNodeMetricsDbMaintainer() {
ProvisioningTester tester = new ProvisioningTester.Builder().build();
tester.clock().setInstant(Instant.ofEpochMilli(1400));
tester.makeReadyNodes(2, resources);
tester.advanceTime(Duration.ofMinutes(5)); // Make sure these are not considered new nodes (metrics will not be fetched for them)
tester.activateTenantHosts();
tester.deploy(ProvisioningTester.applicationId("test"),
Capacity.from(new ClusterResources(2, 1, resources)));
Expand Down