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

Deprecate returning 408 for a server timeout on _cluster/health #78180

Merged
merged 52 commits into from
Oct 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
817c5d6
Return correct HTTP code for a server timeout on `_cluster/health`
arteam Sep 22, 2021
17e6f94
Check that we return 200 even in a case of a timeout
arteam Sep 22, 2021
b3e8d6b
Update Rest API tests
arteam Sep 22, 2021
3a572d4
Update client tests for server cluster health timeouts
arteam Sep 22, 2021
4e8031d
Don't catch the request timeout in a security test
arteam Sep 22, 2021
97499e7
Temporarily disable backward compatibility tests for 78180
arteam Sep 22, 2021
28539e6
Return 408 REQUEST_TIMEOUT for ES7
arteam Sep 23, 2021
bd30be7
Mutes cluster health tests
arteam Sep 23, 2021
642205b
cluster-health tests don't belong in x-pack
arteam Sep 23, 2021
79a9687
Fix the name of the ignored compatibility tests
arteam Sep 23, 2021
14d92a9
Disable BWC for #78180
arteam Sep 23, 2021
e1ad212
Merge branch 'master' into return-200-for-cluster-health-timeout
elasticmachine Sep 23, 2021
0a55e0a
Merge branch 'master' into return-200-for-cluster-health-timeout
elasticmachine Sep 27, 2021
231c884
Revert "Disable BWC for #78180"
arteam Sep 27, 2021
8563df0
Merge branch 'master' into return-200-for-cluster-health-timeout
elasticmachine Sep 30, 2021
21862d9
Skip bwc tests for the request timeout
arteam Sep 30, 2021
dcac23e
Add deprecation warning for a cluster health timeout
arteam Sep 30, 2021
360cd87
Update deprecation message
arteam Sep 30, 2021
e455588
Return REQUEST_TIMEOUT for v7
arteam Sep 30, 2021
caaa3e3
Add a system property to opt out from returning 200 on cluster health…
arteam Sep 30, 2021
6fecb02
Merge remote-tracking branch 'origin/master' into return-200-for-clus…
arteam Oct 1, 2021
112a389
Ignore cluster health tests for rest compatibility
arteam Oct 1, 2021
703f187
Skip security tests for cluster timeout
arteam Oct 1, 2021
a9cd29d
Make the ClusterHealthResponse change backward-compatible
arteam Oct 3, 2021
0ce07db
The parameter should provide a way for a user to opt OUT from the new…
arteam Oct 3, 2021
fb7bee2
Remove rest api version check
arteam Oct 4, 2021
68a0af7
Rollback 408 to 200 change
arteam Oct 4, 2021
2744de5
Fix the deprecation message to use the opt in patameter
arteam Oct 4, 2021
f0a57e9
Add tests for deprecation messages
arteam Oct 4, 2021
bdf418c
Revert "Update client tests for server cluster health timeouts"
arteam Oct 4, 2021
8554dc5
Fix checkstyle warning
arteam Oct 4, 2021
fec172e
Merge branch 'master' into return-200-for-cluster-health-timeout
elasticmachine Oct 5, 2021
b21cb5c
Accept only true for esClusterHealthRequestTimeout200
arteam Oct 5, 2021
1a49a76
Satisfy checkstyle
arteam Oct 5, 2021
09c4706
Update the variable holding the deprecation message
arteam Oct 5, 2021
5578517
Add warning assertion
arteam Oct 5, 2021
b8d0986
Add a test for opting in for the 200 status code
arteam Oct 5, 2021
4a8a733
Rename to readEsClusterHealthRequestTimeout200FromProperty
arteam Oct 5, 2021
9bfea43
Update client/rest-high-level/src/test/java/org/elasticsearch/client/…
arteam Oct 6, 2021
1805434
Extract the property name to a constant
arteam Oct 6, 2021
7ec21b2
Reformat error message
arteam Oct 6, 2021
fcee4c5
Adapt the warning message with square brackets
arteam Oct 6, 2021
f3e9f26
Add the key prefix to the constant
arteam Oct 6, 2021
721b396
Revert "Adapt the warning message with square brackets"
arteam Oct 6, 2021
e2ddfb2
Use brackets
arteam Oct 6, 2021
b005feb
Update the error message in ClusterHealthResponse
arteam Oct 6, 2021
690f905
Merge branch 'master' into return-200-for-cluster-health-timeout
elasticmachine Oct 6, 2021
6070668
Merge branch 'master' into return-200-for-cluster-health-timeout
arteam Oct 11, 2021
8bcdab1
Add DeprecationLogger import
arteam Oct 11, 2021
27dabc4
Update server/src/main/java/org/elasticsearch/action/admin/cluster/he…
arteam Oct 11, 2021
5bb0135
Update the error message for ClusterClientIT
arteam Oct 11, 2021
0208c54
Merge branch 'master' into return-200-for-cluster-health-timeout
elasticmachine Oct 11, 2021
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 @@ -303,6 +303,9 @@ public void testClusterHealthNotFoundIndex() throws IOException {
assertThat(response.status(), equalTo(RestStatus.REQUEST_TIMEOUT));
assertThat(response.getStatus(), equalTo(ClusterHealthStatus.RED));
assertNoIndices(response);
assertWarnings("The HTTP status code for a cluster health timeout will be changed from 408 to 200 in a " +
"future version. Set the [es.cluster_health.request_timeout_200] system property to [true] to suppress this message and " +
"opt in to the future behaviour now.");
}

public void testRemoteInfo() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.elasticsearch.cluster.health.ClusterHealthStatus;
import org.elasticsearch.cluster.health.ClusterIndexHealth;
import org.elasticsearch.cluster.health.ClusterStateHealth;
import org.elasticsearch.common.logging.DeprecationLogger;
import org.elasticsearch.xcontent.ParseField;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.io.stream.StreamInput;
Expand All @@ -24,6 +25,7 @@
import org.elasticsearch.xcontent.XContentBuilder;
import org.elasticsearch.xcontent.XContentParser;
import org.elasticsearch.rest.RestStatus;
import org.elasticsearch.rest.action.search.RestSearchAction;

import java.io.IOException;
import java.util.HashMap;
Expand Down Expand Up @@ -55,6 +57,7 @@ public class ClusterHealthResponse extends ActionResponse implements StatusToXCo
private static final String INITIALIZING_SHARDS = "initializing_shards";
private static final String UNASSIGNED_SHARDS = "unassigned_shards";
private static final String INDICES = "indices";
private static final DeprecationLogger deprecationLogger = DeprecationLogger.getLogger(RestSearchAction.class);

private static final ConstructingObjectParser<ClusterHealthResponse, Void> PARSER =
new ConstructingObjectParser<>("cluster_health_response", true,
Expand Down Expand Up @@ -97,7 +100,11 @@ public class ClusterHealthResponse extends ActionResponse implements StatusToXCo
});

private static final ObjectParser.NamedObjectParser<ClusterIndexHealth, Void> INDEX_PARSER =
(XContentParser parser, Void context, String index) -> ClusterIndexHealth.innerFromXContent(parser, index);
(XContentParser parser, Void context, String index) -> ClusterIndexHealth.innerFromXContent(parser, index);
private static final String ES_CLUSTER_HEALTH_REQUEST_TIMEOUT_200_KEY = "es.cluster_health.request_timeout_200";
static final String CLUSTER_HEALTH_REQUEST_TIMEOUT_DEPRECATION_MSG = "The HTTP status code for a cluster health timeout " +
"will be changed from 408 to 200 in a future version. Set the [" + ES_CLUSTER_HEALTH_REQUEST_TIMEOUT_200_KEY + "] " +
"system property to [true] to suppress this message and opt in to the future behaviour now.";

static {
// ClusterStateHealth fields
Expand Down Expand Up @@ -130,8 +137,15 @@ public class ClusterHealthResponse extends ActionResponse implements StatusToXCo
private boolean timedOut = false;
private ClusterStateHealth clusterStateHealth;
private ClusterHealthStatus clusterHealthStatus;
private boolean esClusterHealthRequestTimeout200 = readEsClusterHealthRequestTimeout200FromProperty();

public ClusterHealthResponse() {}
public ClusterHealthResponse() {
}

/** For the testing of opting in for the 200 status code without setting a system property */
ClusterHealthResponse(boolean esClusterHealthRequestTimeout200) {
this.esClusterHealthRequestTimeout200 = esClusterHealthRequestTimeout200;
}

public ClusterHealthResponse(StreamInput in) throws IOException {
super(in);
Expand Down Expand Up @@ -299,7 +313,15 @@ public String toString() {

@Override
public RestStatus status() {
return isTimedOut() ? RestStatus.REQUEST_TIMEOUT : RestStatus.OK;
if (isTimedOut() == false) {
return RestStatus.OK;
}
if (esClusterHealthRequestTimeout200) {
return RestStatus.OK;
} else {
deprecationLogger.compatibleCritical("cluster_health_request_timeout", CLUSTER_HEALTH_REQUEST_TIMEOUT_DEPRECATION_MSG);
return RestStatus.REQUEST_TIMEOUT;
}
}

@Override
Expand Down Expand Up @@ -359,4 +381,17 @@ public int hashCode() {
return Objects.hash(clusterName, numberOfPendingTasks, numberOfInFlightFetch, delayedUnassignedShards, taskMaxWaitingTime,
timedOut, clusterStateHealth, clusterHealthStatus);
}

private static boolean readEsClusterHealthRequestTimeout200FromProperty() {
String property = System.getProperty(ES_CLUSTER_HEALTH_REQUEST_TIMEOUT_200_KEY);
if (property == null) {
return false;
}
if (Boolean.parseBoolean(property)) {
return true;
} else {
throw new IllegalArgumentException(ES_CLUSTER_HEALTH_REQUEST_TIMEOUT_200_KEY + " can only be unset or [true] but was ["
+ property + "]");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,21 @@ public void testIsTimeout() {
res.setTimedOut(randomBoolean());
if (res.isTimedOut()) {
assertEquals(RestStatus.REQUEST_TIMEOUT, res.status());
assertWarnings(ClusterHealthResponse.CLUSTER_HEALTH_REQUEST_TIMEOUT_DEPRECATION_MSG);
} else {
assertEquals(RestStatus.OK, res.status());
}
}
}

public void testTimeoutReturns200IfOptedIn() {
ClusterHealthResponse res = new ClusterHealthResponse(true);
for (int i = 0; i < 5; i++) {
res.setTimedOut(randomBoolean());
assertEquals(RestStatus.OK, res.status());
}
}

public void testClusterHealth() throws IOException {
ClusterState clusterState = ClusterState.builder(ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).build();
int pendingTasks = randomIntBetween(0, 200);
Expand Down