[Monitoring] Remove 202 responses in favor of 200 responses (elastic/x-pack-elasticsearch#4213)

This changes `_xpack/monitoring/_bulk` to fundamentally behave in the same
way as `_bulk` and never return 202 when data is ignored (something
`_bulk` cannot do). Instead, anyone interested will have to inspect the
returned response for the ignored flag.

Original commit: elastic/x-pack-elasticsearch@07254a006d
This commit is contained in:
Chris Earle 2018-03-26 11:36:04 -04:00 committed by GitHub
parent 67badaadb0
commit a600350d4c
4 changed files with 8 additions and 6 deletions

View File

@ -60,14 +60,13 @@ public class MonitoringBulkResponse extends ActionResponse {
* Returns HTTP status
*
* <ul>
* <li>{@link RestStatus#OK} if monitoring bulk request was successful</li>
* <li>{@link RestStatus#ACCEPTED} if monitoring bulk request was ignored because collection is disabled</li>
* <li>{@link RestStatus#OK} if monitoring bulk request was successful (or ignored because collection is disabled)</li>
* <li>{@link RestStatus#INTERNAL_SERVER_ERROR} if monitoring bulk request was partially successful or failed completely</li>
* </ul>
*/
public RestStatus status() {
if (error == null) {
return ignored ? RestStatus.ACCEPTED : RestStatus.OK;
return RestStatus.OK;
}
return RestStatus.INTERNAL_SERVER_ERROR;

View File

@ -30,19 +30,22 @@ public class MonitoringBulkResponseTests extends ESTestCase {
assertThat(response.getTookInMillis(), equalTo(took));
assertThat(response.getError(), is(nullValue()));
assertThat(response.isIgnored(), is(false));
assertThat(response.status(), equalTo(RestStatus.OK));
response = new MonitoringBulkResponse(took, true);
assertThat(response.getTookInMillis(), equalTo(took));
assertThat(response.getError(), is(nullValue()));
assertThat(response.status(), equalTo(RestStatus.ACCEPTED));
assertThat(response.isIgnored(), is(true));
assertThat(response.status(), equalTo(RestStatus.OK));
ExportException exception = new ExportException(randomAlphaOfLength(10));
response = new MonitoringBulkResponse(took, new MonitoringBulkResponse.Error(exception));
assertThat(response.getTookInMillis(), equalTo(took));
assertThat(response.getError(), is(notNullValue()));
assertThat(response.isIgnored(), is(false));
assertThat(response.status(), equalTo(RestStatus.INTERNAL_SERVER_ERROR));
}

View File

@ -134,7 +134,7 @@ public class TransportMonitoringBulkActionTests extends ESTestCase {
final MonitoringBulkResponse response = action.execute(request).get();
assertThat(response.status(), is(RestStatus.ACCEPTED));
assertThat(response.status(), is(RestStatus.OK));
assertThat(response.isIgnored(), is(true));
assertThat(response.getTookInMillis(), is(0L));
assertThat(response.getError(), nullValue());

View File

@ -128,7 +128,7 @@ public class RestMonitoringBulkActionTests extends ESTestCase {
final FakeRestRequest request = createRestRequest(randomSystemId(), TEMPLATE_VERSION, "10s");
final RestResponse restResponse = getRestBuilderListener(request).buildResponse(response);
assertThat(restResponse.status(), is(RestStatus.ACCEPTED));
assertThat(restResponse.status(), is(RestStatus.OK));
assertThat(restResponse.content().utf8ToString(),
is("{\"took\":" + response.getTookInMillis() + ",\"ignored\":true,\"errors\":false}"));
}