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

Set ignore_throttled to true in ES health requests #1053

Merged
merged 1 commit into from
Aug 9, 2022
Merged
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 @@ -22,6 +22,7 @@
import java.time.temporal.ChronoUnit;
import java.util.Arrays;
import java.util.Collections;
import java.util.EnumSet;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
Expand All @@ -36,6 +37,8 @@
import org.elasticsearch.action.admin.indices.settings.get.GetSettingsRequest;
import org.elasticsearch.action.admin.indices.settings.get.GetSettingsResponse;
import org.elasticsearch.action.support.IndicesOptions;
import org.elasticsearch.action.support.IndicesOptions.Option;
import org.elasticsearch.action.support.IndicesOptions.WildcardStates;
import org.elasticsearch.cluster.health.ClusterHealthStatus;
import org.elasticsearch.rest.RestStatus;
import org.slf4j.Logger;
Expand All @@ -57,6 +60,17 @@ public abstract class EsClientBase implements EsClient {

private static final String READ_ONLY_SETTING = "index.blocks.read_only_allow_delete";

// Equivalent to org.elasticsearch.action.support.IndicesOptions.lenientExpand() with ignore_throttled set to true
private static final IndicesOptions DEFAULT_INDICES_OPTIONS = new IndicesOptions(
EnumSet.of(
Option.ALLOW_NO_INDICES,
Option.IGNORE_UNAVAILABLE,
// this has to be set to avoid deprecation warnings in the log, see org.elasticsearch.client.RequestConverters.Params.withIndicesOptions(IndicesOptions)
Option.IGNORE_THROTTLED
),
EnumSet.of(WildcardStates.OPEN, WildcardStates.CLOSED)
);

private final HttpHost host;
private final Logger log;

Expand Down Expand Up @@ -144,10 +158,7 @@ private ClusterHealthResponse checkClusterHealth(ClusterHealthResponse previousH
log.info("Checking cluster health at '{}'...", host.toURI());
ClusterHealthRequest req = new ClusterHealthRequest();
req.level(Level.INDICES);
// The default indices options (IndicesOptions.lenientExpandHidden()) returns all indices including system or hidden.
// It is not possible to determine if a hidden index is read only or not.
// This leads to the isIndexReadOnly() method waiting 60 seconds for each hidden index, eventually causing requests to be stalled.
req.indicesOptions(IndicesOptions.lenientExpand());
req.indicesOptions(DEFAULT_INDICES_OPTIONS);
return cluster().health(req);
} catch (IOException e) {
throw new IndexException("Failed to get cluster health", e);
Expand All @@ -157,7 +168,7 @@ private ClusterHealthResponse checkClusterHealth(ClusterHealthResponse previousH
private GetSettingsResponse checkIndicesSettings(GetSettingsResponse previousSettings) {
try {
log.info("Checking indices settings at '{}'...", host.toURI());
return indices().settings(new GetSettingsRequest().indicesOptions(IndicesOptions.lenientExpand()));
return indices().settings(new GetSettingsRequest().indicesOptions(DEFAULT_INDICES_OPTIONS));
} catch (IOException e) {
throw new IndexException("Failed to get indices settings", e);
}
Expand Down