Skip to content
Open
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 @@ -327,6 +327,13 @@ public ShardStats shardStats() {
.orElseThrow(() -> new ElasticsearchException("Unable to retrieve shard stats."));
}

@Override
public int countOfClusterManagerEligibleNodes() {
return (int) nodesInfo().values().stream()
.filter(node -> node.roles().contains("cluster_manager") || node.roles().contains("master"))
.count();
}

private Optional<ClusterHealthResponse> clusterHealth() {
try {
final ClusterHealthRequest request = new ClusterHealthRequest()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,13 @@ public ShardStats shardStats() {
.orElseThrow(() -> new ElasticsearchException("Unable to retrieve shard stats."));
}

@Override
public int countOfClusterManagerEligibleNodes() {
return (int)nodesInfo().values().stream()
.filter(node -> node.roles().contains("cluster_manager") || node.roles().contains("master"))
.count();
}

private Optional<ClusterHealthResponse> clusterHealth() {
try {
final ClusterHealthRequest request = new ClusterHealthRequest()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,13 @@ public ShardStats shardStats() {
.orElseThrow(() -> new ElasticsearchException("Unable to retrieve shard stats."));
}

@Override
public int countOfClusterManagerEligibleNodes() {
return (int)nodesInfo().values().stream()
.filter(node -> node.roles().contains("cluster_manager") || node.roles().contains("master"))
.count();
}

private Optional<HealthResponse> clusterHealth() {
final Time timeout = new Time.Builder().time(requestTimeout.toSeconds() + "s").build();
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import com.github.joschi.jadconfig.util.Duration;
import com.google.common.io.Resources;
import org.assertj.core.api.Assertions;
import org.graylog.storage.opensearch3.testing.client.mock.ServerlessOpenSearchClient;
import org.graylog2.indexer.cluster.health.ClusterShardAllocation;
import org.graylog2.indexer.cluster.health.NodeDiskUsageStats;
Expand Down Expand Up @@ -45,6 +46,7 @@ void setUp() {

final OfficialOpensearchClient client = ServerlessOpenSearchClient.builder()
.stubResponse("GET", "/_nodes/*", Resources.getResource("nodes-response-without-host-field.json"))
.stubResponse("GET", "/_nodes", Resources.getResource("nodes-response-without-host-field.json"))
.stubResponse("GET", "/_cat/nodes", Resources.getResource("cat_nodes.json"))
.stubResponse("GET", "/_cluster/settings", Resources.getResource("cluster_settings.json"))
.stubResponse("GET", "/_cat/allocation", Resources.getResource("cat_allocation.json"))
Expand Down Expand Up @@ -138,4 +140,10 @@ void testClusterShardAllocation() {
.extracting(NodeShardAllocation::shards)
.containsExactly(15, 16);
}

@Test
void testManagerEligibleNodesCount() {
Assertions.assertThat(clusterAdapter.countOfClusterManagerEligibleNodes())
.isEqualTo(3); // there are 3 nodes with role "master" in nodes-response-without-host-field.json
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,10 @@ public interface ClusterAdapter {

ShardStats shardStats();

/**
* The cluster health response has no such field, so implementations derive it from each node's roles.
*/
int countOfClusterManagerEligibleNodes();

Optional<HealthStatus> deflectorHealth(Collection<String> indices);
}
Loading