|
@@ -17,6 +17,7 @@ import org.apache.http.entity.StringEntity;
|
|
|
import org.elasticsearch.client.Request;
|
|
|
import org.elasticsearch.client.RequestOptions;
|
|
|
import org.elasticsearch.client.Response;
|
|
|
+import org.elasticsearch.client.ResponseException;
|
|
|
import org.elasticsearch.client.RestClient;
|
|
|
import org.elasticsearch.client.RestClientBuilder;
|
|
|
import org.elasticsearch.common.Strings;
|
|
@@ -29,6 +30,8 @@ import org.elasticsearch.test.rest.ESRestTestCase;
|
|
|
import org.elasticsearch.xcontent.XContentBuilder;
|
|
|
import org.elasticsearch.xcontent.json.JsonXContent;
|
|
|
import org.hamcrest.Matcher;
|
|
|
+import org.junit.After;
|
|
|
+import org.junit.Before;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
import java.util.ArrayList;
|
|
@@ -62,66 +65,139 @@ public class DeprecationHttpIT extends ESRestTestCase {
|
|
|
*/
|
|
|
private static final String DATA_STREAM_NAME = ".logs-deprecation.elasticsearch-default";
|
|
|
|
|
|
+ @Before
|
|
|
+ public void assertIndexingIsEnabled() throws Exception {
|
|
|
+ configureWriteDeprecationLogsToIndex(true);
|
|
|
+
|
|
|
+ // make sure the deprecation logs indexing is enabled
|
|
|
+ Response response = client().performRequest(new Request("GET", "/_cluster/settings?include_defaults=true&flat_settings=true"));
|
|
|
+ assertOK(response);
|
|
|
+ ObjectMapper mapper = new ObjectMapper();
|
|
|
+ final JsonNode jsonNode = mapper.readTree(response.getEntity().getContent());
|
|
|
+
|
|
|
+ final boolean transientValue = jsonNode.at("/transient/cluster.deprecation_indexing.enabled").asBoolean();
|
|
|
+ assertTrue(transientValue);
|
|
|
+
|
|
|
+ // assert index does not exist, which will prevent previous tests to interfere
|
|
|
+ assertBusy(() -> {
|
|
|
+ try {
|
|
|
+ client().performRequest(new Request("GET", "/_data_stream/" + DATA_STREAM_NAME));
|
|
|
+ } catch (ResponseException e) {
|
|
|
+ if (e.getResponse().getStatusLine().getStatusCode() == 404) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<Map<String, Object>> documents = getIndexedDeprecations();
|
|
|
+ logger.warn(documents);
|
|
|
+ fail("Index should be removed on startup");
|
|
|
+ }, 30, TimeUnit.SECONDS);
|
|
|
+ }
|
|
|
+
|
|
|
+ @After
|
|
|
+ public void cleanUp() throws Exception {
|
|
|
+ // making sure the deprecation indexing cache is reset and index is deleted
|
|
|
+ assertBusy(() -> {
|
|
|
+ try {
|
|
|
+ client().performRequest(new Request("DELETE", "_logging/deprecation_cache"));
|
|
|
+ client().performRequest(new Request("DELETE", "/_data_stream/" + DATA_STREAM_NAME));
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new AssertionError(e);
|
|
|
+ }
|
|
|
+
|
|
|
+ }, 30, TimeUnit.SECONDS);
|
|
|
+
|
|
|
+ // switch logging setting to default
|
|
|
+ configureWriteDeprecationLogsToIndex(null);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Check that configuring deprecation settings causes a warning to be added to the
|
|
|
* response headers.
|
|
|
*/
|
|
|
- public void testDeprecatedSettingsReturnWarnings() throws IOException {
|
|
|
+ public void testDeprecatedSettingsReturnWarnings() throws Exception {
|
|
|
+ try {
|
|
|
+ XContentBuilder builder = JsonXContent.contentBuilder()
|
|
|
+ .startObject()
|
|
|
+ .startObject("persistent")
|
|
|
+ .field(
|
|
|
+ TestDeprecationHeaderRestAction.TEST_DEPRECATED_SETTING_TRUE1.getKey(),
|
|
|
+ TestDeprecationHeaderRestAction.TEST_DEPRECATED_SETTING_TRUE1.getDefault(Settings.EMPTY) == false
|
|
|
+ )
|
|
|
+ .field(
|
|
|
+ TestDeprecationHeaderRestAction.TEST_DEPRECATED_SETTING_TRUE2.getKey(),
|
|
|
+ TestDeprecationHeaderRestAction.TEST_DEPRECATED_SETTING_TRUE2.getDefault(Settings.EMPTY) == false
|
|
|
+ )
|
|
|
+ // There should be no warning for this field
|
|
|
+ .field(
|
|
|
+ TestDeprecationHeaderRestAction.TEST_NOT_DEPRECATED_SETTING.getKey(),
|
|
|
+ TestDeprecationHeaderRestAction.TEST_NOT_DEPRECATED_SETTING.getDefault(Settings.EMPTY) == false
|
|
|
+ )
|
|
|
+ .endObject()
|
|
|
+ .endObject();
|
|
|
+
|
|
|
+ final Request request = new Request("PUT", "_cluster/settings");
|
|
|
+ ///
|
|
|
+ request.setJsonEntity(Strings.toString(builder));
|
|
|
+ final Response response = client().performRequest(request);
|
|
|
+
|
|
|
+ final List<String> deprecatedWarnings = getWarningHeaders(response.getHeaders());
|
|
|
+ final List<Matcher<String>> headerMatchers = new ArrayList<>(2);
|
|
|
+
|
|
|
+ for (Setting<Boolean> setting : List.of(
|
|
|
+ TestDeprecationHeaderRestAction.TEST_DEPRECATED_SETTING_TRUE1,
|
|
|
+ TestDeprecationHeaderRestAction.TEST_DEPRECATED_SETTING_TRUE2
|
|
|
+ )) {
|
|
|
+ headerMatchers.add(
|
|
|
+ equalTo(
|
|
|
+ "["
|
|
|
+ + setting.getKey()
|
|
|
+ + "] setting was deprecated in Elasticsearch and will be removed in a future release! "
|
|
|
+ + "See the breaking changes documentation for the next major version."
|
|
|
+ )
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ assertThat(deprecatedWarnings, hasSize(headerMatchers.size()));
|
|
|
+ for (final String deprecatedWarning : deprecatedWarnings) {
|
|
|
+ assertThat(
|
|
|
+ "Header does not conform to expected pattern",
|
|
|
+ deprecatedWarning,
|
|
|
+ matches(HeaderWarning.WARNING_HEADER_PATTERN.pattern())
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ final List<String> actualWarningValues = deprecatedWarnings.stream()
|
|
|
+ .map(s -> HeaderWarning.extractWarningValueFromWarningHeader(s, true))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ for (Matcher<String> headerMatcher : headerMatchers) {
|
|
|
+ assertThat(actualWarningValues, hasItem(headerMatcher));
|
|
|
+ }
|
|
|
+
|
|
|
+ assertBusy(() -> {
|
|
|
+ List<Map<String, Object>> documents = getIndexedDeprecations();
|
|
|
+ logger.warn(documents);
|
|
|
+ assertThat(documents, hasSize(2));
|
|
|
+ });
|
|
|
+
|
|
|
+ } finally {
|
|
|
+ cleanupSettings();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void cleanupSettings() throws IOException {
|
|
|
XContentBuilder builder = JsonXContent.contentBuilder()
|
|
|
.startObject()
|
|
|
- .startObject("transient")
|
|
|
- .field(
|
|
|
- TestDeprecationHeaderRestAction.TEST_DEPRECATED_SETTING_TRUE1.getKey(),
|
|
|
- TestDeprecationHeaderRestAction.TEST_DEPRECATED_SETTING_TRUE1.getDefault(Settings.EMPTY) == false
|
|
|
- )
|
|
|
- .field(
|
|
|
- TestDeprecationHeaderRestAction.TEST_DEPRECATED_SETTING_TRUE2.getKey(),
|
|
|
- TestDeprecationHeaderRestAction.TEST_DEPRECATED_SETTING_TRUE2.getDefault(Settings.EMPTY) == false
|
|
|
- )
|
|
|
+ .startObject("persistent")
|
|
|
+ .field(TestDeprecationHeaderRestAction.TEST_DEPRECATED_SETTING_TRUE1.getKey(), (Boolean) null)
|
|
|
+ .field(TestDeprecationHeaderRestAction.TEST_DEPRECATED_SETTING_TRUE2.getKey(), (Boolean) null)
|
|
|
// There should be no warning for this field
|
|
|
- .field(
|
|
|
- TestDeprecationHeaderRestAction.TEST_NOT_DEPRECATED_SETTING.getKey(),
|
|
|
- TestDeprecationHeaderRestAction.TEST_NOT_DEPRECATED_SETTING.getDefault(Settings.EMPTY) == false
|
|
|
- )
|
|
|
+ .field(TestDeprecationHeaderRestAction.TEST_NOT_DEPRECATED_SETTING.getKey(), (Boolean) null)
|
|
|
.endObject()
|
|
|
.endObject();
|
|
|
|
|
|
final Request request = new Request("PUT", "_cluster/settings");
|
|
|
request.setJsonEntity(Strings.toString(builder));
|
|
|
- final Response response = client().performRequest(request);
|
|
|
-
|
|
|
- final List<String> deprecatedWarnings = getWarningHeaders(response.getHeaders());
|
|
|
- final List<Matcher<String>> headerMatchers = new ArrayList<>(2);
|
|
|
-
|
|
|
- for (Setting<Boolean> setting : List.of(
|
|
|
- TestDeprecationHeaderRestAction.TEST_DEPRECATED_SETTING_TRUE1,
|
|
|
- TestDeprecationHeaderRestAction.TEST_DEPRECATED_SETTING_TRUE2
|
|
|
- )) {
|
|
|
- headerMatchers.add(
|
|
|
- equalTo(
|
|
|
- "["
|
|
|
- + setting.getKey()
|
|
|
- + "] setting was deprecated in Elasticsearch and will be removed in a future release! "
|
|
|
- + "See the breaking changes documentation for the next major version."
|
|
|
- )
|
|
|
- );
|
|
|
- }
|
|
|
-
|
|
|
- assertThat(deprecatedWarnings, hasSize(headerMatchers.size()));
|
|
|
- for (final String deprecatedWarning : deprecatedWarnings) {
|
|
|
- assertThat(
|
|
|
- "Header does not conform to expected pattern",
|
|
|
- deprecatedWarning,
|
|
|
- matches(HeaderWarning.WARNING_HEADER_PATTERN.pattern())
|
|
|
- );
|
|
|
- }
|
|
|
-
|
|
|
- final List<String> actualWarningValues = deprecatedWarnings.stream()
|
|
|
- .map(s -> HeaderWarning.extractWarningValueFromWarningHeader(s, true))
|
|
|
- .collect(Collectors.toList());
|
|
|
- for (Matcher<String> headerMatcher : headerMatchers) {
|
|
|
- assertThat(actualWarningValues, hasItem(headerMatcher));
|
|
|
- }
|
|
|
+ client().performRequest(request);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -208,6 +284,11 @@ public class DeprecationHttpIT extends ESRestTestCase {
|
|
|
// trigger all deprecations
|
|
|
Request request = new Request("GET", "/_test_cluster/deprecated_settings");
|
|
|
request.setEntity(buildSettingsRequest(settings, useDeprecatedField ? "deprecated_settings" : "settings"));
|
|
|
+ final RequestOptions options = request.getOptions()
|
|
|
+ .toBuilder()
|
|
|
+ .addHeader("X-Opaque-Id", "XOpaqueId-doTestDeprecationWarningsAppearInHeaders")
|
|
|
+ .build();
|
|
|
+ request.setOptions(options);
|
|
|
Response response = client().performRequest(request);
|
|
|
assertOK(response);
|
|
|
|
|
@@ -232,77 +313,79 @@ public class DeprecationHttpIT extends ESRestTestCase {
|
|
|
}
|
|
|
|
|
|
public void testDeprecationRouteThrottling() throws Exception {
|
|
|
- try {
|
|
|
- configureWriteDeprecationLogsToIndex(true);
|
|
|
|
|
|
- final Request getRequest = createTestRequest("GET");
|
|
|
- assertOK(client().performRequest(getRequest));
|
|
|
+ final Request deprecatedRequest = deprecatedRequest("GET", "xOpaqueId-testDeprecationRouteThrottling");
|
|
|
+ assertOK(client().performRequest(deprecatedRequest));
|
|
|
|
|
|
- assertOK(client().performRequest(getRequest));
|
|
|
+ assertOK(client().performRequest(deprecatedRequest));
|
|
|
|
|
|
- final Request postRequest = createTestRequest("POST");
|
|
|
- assertOK(client().performRequest(postRequest));
|
|
|
+ final Request postRequest = deprecatedRequest("POST", "xOpaqueId-testDeprecationRouteThrottling");
|
|
|
+ assertOK(client().performRequest(postRequest));
|
|
|
|
|
|
- assertBusy(() -> {
|
|
|
- Response response;
|
|
|
- try {
|
|
|
- client().performRequest(new Request("POST", "/" + DATA_STREAM_NAME + "/_refresh?ignore_unavailable=true"));
|
|
|
- response = client().performRequest(new Request("GET", "/" + DATA_STREAM_NAME + "/_search"));
|
|
|
- } catch (Exception e) {
|
|
|
- // It can take a moment for the index to be created. If it doesn't exist then the client
|
|
|
- // throws an exception. Translate it into an assertion error so that assertBusy() will
|
|
|
- // continue trying.
|
|
|
- throw new AssertionError(e);
|
|
|
- }
|
|
|
- assertOK(response);
|
|
|
+ assertBusy(() -> {
|
|
|
+ List<Map<String, Object>> documents = getIndexedDeprecations();
|
|
|
|
|
|
- ObjectMapper mapper = new ObjectMapper();
|
|
|
- final JsonNode jsonNode = mapper.readTree(response.getEntity().getContent());
|
|
|
+ logger.warn(documents);
|
|
|
+ assertThat(documents, hasSize(3));
|
|
|
|
|
|
- final int hits = jsonNode.at("/hits/total/value").intValue();
|
|
|
- assertThat(hits, greaterThan(0));
|
|
|
+ assertThat(
|
|
|
+ documents,
|
|
|
+ containsInAnyOrder(
|
|
|
+ allOf(
|
|
|
+ hasEntry(KEY_FIELD_NAME, "deprecated_route_POST_/_test_cluster/deprecated_settings"),
|
|
|
+ hasEntry("message", "[/_test_cluster/deprecated_settings] exists for deprecated tests")
|
|
|
+ ),
|
|
|
+ allOf(
|
|
|
+ hasEntry(KEY_FIELD_NAME, "deprecated_route_GET_/_test_cluster/deprecated_settings"),
|
|
|
+ hasEntry("message", "[/_test_cluster/deprecated_settings] exists for deprecated tests")
|
|
|
+ ),
|
|
|
+ allOf(
|
|
|
+ hasEntry(KEY_FIELD_NAME, "deprecated_settings"),
|
|
|
+ hasEntry("message", "[deprecated_settings] usage is deprecated. use [settings] instead")
|
|
|
+ )
|
|
|
+ )
|
|
|
+ );
|
|
|
+ }, 30, TimeUnit.SECONDS);
|
|
|
|
|
|
- List<Map<String, Object>> documents = new ArrayList<>();
|
|
|
+ }
|
|
|
|
|
|
- for (int i = 0; i < hits; i++) {
|
|
|
- final JsonNode hit = jsonNode.at("/hits/hits/" + i + "/_source");
|
|
|
+ public void testDisableDeprecationLogIndexing() throws Exception {
|
|
|
|
|
|
- final Map<String, Object> document = new HashMap<>();
|
|
|
- hit.fields().forEachRemaining(entry -> document.put(entry.getKey(), entry.getValue().textValue()));
|
|
|
+ configureWriteDeprecationLogsToIndex(true);
|
|
|
+ final Request deprecatedRequest = deprecatedRequest("GET", "xOpaqueId-testDisableDeprecationLogIndexing");
|
|
|
+ assertOK(client().performRequest(deprecatedRequest));
|
|
|
+ configureWriteDeprecationLogsToIndex(false);
|
|
|
|
|
|
- documents.add(document);
|
|
|
- }
|
|
|
+ final Request postRequest = deprecatedRequest("POST", "xOpaqueId-testDisableDeprecationLogIndexing");
|
|
|
+ assertOK(client().performRequest(postRequest));
|
|
|
|
|
|
- logger.warn(documents);
|
|
|
- assertThat(documents, hasSize(3));
|
|
|
+ assertBusy(() -> {
|
|
|
+ List<Map<String, Object>> documents = getIndexedDeprecations();
|
|
|
|
|
|
- assertThat(
|
|
|
- documents,
|
|
|
- containsInAnyOrder(
|
|
|
- allOf(
|
|
|
- hasEntry(KEY_FIELD_NAME, "deprecated_route_POST_/_test_cluster/deprecated_settings"),
|
|
|
- hasEntry("message", "[/_test_cluster/deprecated_settings] exists for deprecated tests")
|
|
|
- ),
|
|
|
- allOf(
|
|
|
- hasEntry(KEY_FIELD_NAME, "deprecated_route_GET_/_test_cluster/deprecated_settings"),
|
|
|
- hasEntry("message", "[/_test_cluster/deprecated_settings] exists for deprecated tests")
|
|
|
- ),
|
|
|
- allOf(
|
|
|
- hasEntry(KEY_FIELD_NAME, "deprecated_settings"),
|
|
|
- hasEntry("message", "[deprecated_settings] usage is deprecated. use [settings] instead")
|
|
|
- )
|
|
|
+ logger.warn(documents);
|
|
|
+ assertThat(documents, hasSize(2));
|
|
|
+
|
|
|
+ assertThat(
|
|
|
+ documents,
|
|
|
+ containsInAnyOrder(
|
|
|
+ allOf(
|
|
|
+ hasEntry(KEY_FIELD_NAME, "deprecated_route_GET_/_test_cluster/deprecated_settings"),
|
|
|
+ hasEntry("message", "[/_test_cluster/deprecated_settings] exists for deprecated tests")
|
|
|
+ ),
|
|
|
+ allOf(
|
|
|
+ hasEntry(KEY_FIELD_NAME, "deprecated_settings"),
|
|
|
+ hasEntry("message", "[deprecated_settings] usage is deprecated. use [settings] instead")
|
|
|
)
|
|
|
- );
|
|
|
- }, 30, TimeUnit.SECONDS);
|
|
|
- } finally {
|
|
|
- configureWriteDeprecationLogsToIndex(null);
|
|
|
- client().performRequest(new Request("DELETE", "_data_stream/" + DATA_STREAM_NAME));
|
|
|
- }
|
|
|
+ )
|
|
|
+ );
|
|
|
+ }, 30, TimeUnit.SECONDS);
|
|
|
+
|
|
|
}
|
|
|
|
|
|
- private Request createTestRequest(String method) throws IOException {
|
|
|
+ // triggers two deprecations - endpoint and setting
|
|
|
+ private Request deprecatedRequest(String method, String xOpaqueId) throws IOException {
|
|
|
final Request getRequest = new Request(method, "/_test_cluster/deprecated_settings");
|
|
|
- final RequestOptions options = getRequest.getOptions().toBuilder().addHeader("X-Opaque-Id", "some xid").build();
|
|
|
+ final RequestOptions options = getRequest.getOptions().toBuilder().addHeader("X-Opaque-Id", xOpaqueId).build();
|
|
|
getRequest.setOptions(options);
|
|
|
getRequest.setEntity(
|
|
|
buildSettingsRequest(
|
|
@@ -317,390 +400,254 @@ public class DeprecationHttpIT extends ESRestTestCase {
|
|
|
* Check that deprecation messages can be recorded to an index
|
|
|
*/
|
|
|
public void testDeprecationMessagesCanBeIndexed() throws Exception {
|
|
|
- try {
|
|
|
- configureWriteDeprecationLogsToIndex(true);
|
|
|
-
|
|
|
- final Request request = new Request("GET", "/_test_cluster/deprecated_settings");
|
|
|
- final RequestOptions options = request.getOptions().toBuilder().addHeader("X-Opaque-Id", "some xid").build();
|
|
|
- request.setOptions(options);
|
|
|
- request.setEntity(
|
|
|
- buildSettingsRequest(
|
|
|
- Collections.singletonList(TestDeprecationHeaderRestAction.TEST_DEPRECATED_SETTING_TRUE1),
|
|
|
- "deprecated_settings"
|
|
|
- )
|
|
|
- );
|
|
|
- assertOK(client().performRequest(request));
|
|
|
-
|
|
|
- assertBusy(() -> {
|
|
|
- Response response;
|
|
|
- try {
|
|
|
- client().performRequest(new Request("POST", "/" + DATA_STREAM_NAME + "/_refresh?ignore_unavailable=true"));
|
|
|
- response = client().performRequest(new Request("GET", "/" + DATA_STREAM_NAME + "/_search"));
|
|
|
- } catch (Exception e) {
|
|
|
- // It can take a moment for the index to be created. If it doesn't exist then the client
|
|
|
- // throws an exception. Translate it into an assertion error so that assertBusy() will
|
|
|
- // continue trying.
|
|
|
- throw new AssertionError(e);
|
|
|
- }
|
|
|
- assertOK(response);
|
|
|
-
|
|
|
- ObjectMapper mapper = new ObjectMapper();
|
|
|
- final JsonNode jsonNode = mapper.readTree(response.getEntity().getContent());
|
|
|
-
|
|
|
- final int hits = jsonNode.at("/hits/total/value").intValue();
|
|
|
- assertThat(hits, greaterThan(0));
|
|
|
|
|
|
- List<Map<String, Object>> documents = new ArrayList<>();
|
|
|
+ final Request request = deprecatedRequest("GET", "xOpaqueId-testDeprecationMessagesCanBeIndexed");
|
|
|
+ assertOK(client().performRequest(request));
|
|
|
|
|
|
- for (int i = 0; i < hits; i++) {
|
|
|
- final JsonNode hit = jsonNode.at("/hits/hits/" + i + "/_source");
|
|
|
+ assertBusy(() -> {
|
|
|
+ List<Map<String, Object>> documents = getIndexedDeprecations();
|
|
|
|
|
|
- final Map<String, Object> document = new HashMap<>();
|
|
|
- hit.fields().forEachRemaining(entry -> document.put(entry.getKey(), entry.getValue().textValue()));
|
|
|
+ logger.warn(documents);
|
|
|
+ assertThat(documents, hasSize(2));
|
|
|
|
|
|
- documents.add(document);
|
|
|
- }
|
|
|
-
|
|
|
- logger.warn(documents);
|
|
|
- assertThat(documents, hasSize(2));
|
|
|
-
|
|
|
- assertThat(
|
|
|
- documents,
|
|
|
- containsInAnyOrder(
|
|
|
- allOf(
|
|
|
- hasKey("@timestamp"),
|
|
|
- hasKey("elasticsearch.cluster.name"),
|
|
|
- hasKey("elasticsearch.cluster.uuid"),
|
|
|
- hasEntry(X_OPAQUE_ID_FIELD_NAME, "some xid"),
|
|
|
- hasEntry("elasticsearch.event.category", "settings"),
|
|
|
- hasKey("elasticsearch.node.id"),
|
|
|
- hasKey("elasticsearch.node.name"),
|
|
|
- hasEntry("data_stream.dataset", "deprecation.elasticsearch"),
|
|
|
- hasEntry("data_stream.namespace", "default"),
|
|
|
- hasEntry("data_stream.type", "logs"),
|
|
|
- hasEntry("ecs.version", "1.7"),
|
|
|
- hasEntry(KEY_FIELD_NAME, "deprecated_settings"),
|
|
|
- hasEntry("event.dataset", "deprecation.elasticsearch"),
|
|
|
- hasEntry("log.level", "CRITICAL"),
|
|
|
- hasKey("log.logger"),
|
|
|
- hasEntry("message", "[deprecated_settings] usage is deprecated. use [settings] instead")
|
|
|
- ),
|
|
|
- allOf(
|
|
|
- hasKey("@timestamp"),
|
|
|
- hasKey("elasticsearch.cluster.name"),
|
|
|
- hasKey("elasticsearch.cluster.uuid"),
|
|
|
- hasEntry(X_OPAQUE_ID_FIELD_NAME, "some xid"),
|
|
|
- hasEntry("elasticsearch.event.category", "api"),
|
|
|
- hasKey("elasticsearch.node.id"),
|
|
|
- hasKey("elasticsearch.node.name"),
|
|
|
- hasEntry("data_stream.dataset", "deprecation.elasticsearch"),
|
|
|
- hasEntry("data_stream.namespace", "default"),
|
|
|
- hasEntry("data_stream.type", "logs"),
|
|
|
- hasEntry("ecs.version", "1.7"),
|
|
|
- hasEntry(KEY_FIELD_NAME, "deprecated_route_GET_/_test_cluster/deprecated_settings"),
|
|
|
- hasEntry("event.dataset", "deprecation.elasticsearch"),
|
|
|
- hasEntry("log.level", "CRITICAL"),
|
|
|
- hasKey("log.logger"),
|
|
|
- hasEntry("message", "[/_test_cluster/deprecated_settings] exists for deprecated tests")
|
|
|
- )
|
|
|
+ assertThat(
|
|
|
+ documents,
|
|
|
+ containsInAnyOrder(
|
|
|
+ allOf(
|
|
|
+ hasKey("@timestamp"),
|
|
|
+ hasKey("elasticsearch.cluster.name"),
|
|
|
+ hasKey("elasticsearch.cluster.uuid"),
|
|
|
+ hasEntry(X_OPAQUE_ID_FIELD_NAME, "xOpaqueId-testDeprecationMessagesCanBeIndexed"),
|
|
|
+ hasEntry("elasticsearch.event.category", "settings"),
|
|
|
+ hasKey("elasticsearch.node.id"),
|
|
|
+ hasKey("elasticsearch.node.name"),
|
|
|
+ hasEntry("data_stream.dataset", "deprecation.elasticsearch"),
|
|
|
+ hasEntry("data_stream.namespace", "default"),
|
|
|
+ hasEntry("data_stream.type", "logs"),
|
|
|
+ hasEntry("ecs.version", "1.7"),
|
|
|
+ hasEntry(KEY_FIELD_NAME, "deprecated_settings"),
|
|
|
+ hasEntry("event.dataset", "deprecation.elasticsearch"),
|
|
|
+ hasEntry("log.level", "CRITICAL"),
|
|
|
+ hasKey("log.logger"),
|
|
|
+ hasEntry("message", "[deprecated_settings] usage is deprecated. use [settings] instead")
|
|
|
+ ),
|
|
|
+ allOf(
|
|
|
+ hasKey("@timestamp"),
|
|
|
+ hasKey("elasticsearch.cluster.name"),
|
|
|
+ hasKey("elasticsearch.cluster.uuid"),
|
|
|
+ hasEntry(X_OPAQUE_ID_FIELD_NAME, "xOpaqueId-testDeprecationMessagesCanBeIndexed"),
|
|
|
+ hasEntry("elasticsearch.event.category", "api"),
|
|
|
+ hasKey("elasticsearch.node.id"),
|
|
|
+ hasKey("elasticsearch.node.name"),
|
|
|
+ hasEntry("data_stream.dataset", "deprecation.elasticsearch"),
|
|
|
+ hasEntry("data_stream.namespace", "default"),
|
|
|
+ hasEntry("data_stream.type", "logs"),
|
|
|
+ hasEntry("ecs.version", "1.7"),
|
|
|
+ hasEntry(KEY_FIELD_NAME, "deprecated_route_GET_/_test_cluster/deprecated_settings"),
|
|
|
+ hasEntry("event.dataset", "deprecation.elasticsearch"),
|
|
|
+ hasEntry("log.level", "CRITICAL"),
|
|
|
+ hasKey("log.logger"),
|
|
|
+ hasEntry("message", "[/_test_cluster/deprecated_settings] exists for deprecated tests")
|
|
|
)
|
|
|
- );
|
|
|
- }, 30, TimeUnit.SECONDS);
|
|
|
- } finally {
|
|
|
- configureWriteDeprecationLogsToIndex(null);
|
|
|
- client().performRequest(new Request("DELETE", "_data_stream/" + DATA_STREAM_NAME));
|
|
|
- }
|
|
|
+ )
|
|
|
+ );
|
|
|
+ }, 30, TimeUnit.SECONDS);
|
|
|
+
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Check that deprecation messages with WARN level can be recorded to an index
|
|
|
*/
|
|
|
public void testDeprecationWarnMessagesCanBeIndexed() throws Exception {
|
|
|
- try {
|
|
|
- configureWriteDeprecationLogsToIndex(true);
|
|
|
-
|
|
|
- final Request request = new Request("GET", "/_test_cluster/deprecated_settings");
|
|
|
- final RequestOptions options = request.getOptions().toBuilder().addHeader("X-Opaque-Id", "some xid").build();
|
|
|
- request.setOptions(options);
|
|
|
- request.setEntity(
|
|
|
- buildSettingsRequest(
|
|
|
- Collections.singletonList(TestDeprecationHeaderRestAction.TEST_DEPRECATED_SETTING_TRUE1),
|
|
|
- "deprecation_warning"
|
|
|
- )
|
|
|
- );
|
|
|
- assertOK(client().performRequest(request));
|
|
|
|
|
|
- assertBusy(() -> {
|
|
|
- Response response;
|
|
|
- try {
|
|
|
- client().performRequest(new Request("POST", "/" + DATA_STREAM_NAME + "/_refresh?ignore_unavailable=true"));
|
|
|
- response = client().performRequest(new Request("GET", "/" + DATA_STREAM_NAME + "/_search"));
|
|
|
- } catch (Exception e) {
|
|
|
- // It can take a moment for the index to be created. If it doesn't exist then the client
|
|
|
- // throws an exception. Translate it into an assertion error so that assertBusy() will
|
|
|
- // continue trying.
|
|
|
- throw new AssertionError(e);
|
|
|
- }
|
|
|
- assertOK(response);
|
|
|
-
|
|
|
- ObjectMapper mapper = new ObjectMapper();
|
|
|
- final JsonNode jsonNode = mapper.readTree(response.getEntity().getContent());
|
|
|
-
|
|
|
- final int hits = jsonNode.at("/hits/total/value").intValue();
|
|
|
- assertThat(hits, greaterThan(0));
|
|
|
-
|
|
|
- List<Map<String, Object>> documents = new ArrayList<>();
|
|
|
-
|
|
|
- for (int i = 0; i < hits; i++) {
|
|
|
- final JsonNode hit = jsonNode.at("/hits/hits/" + i + "/_source");
|
|
|
-
|
|
|
- final Map<String, Object> document = new HashMap<>();
|
|
|
- hit.fields().forEachRemaining(entry -> document.put(entry.getKey(), entry.getValue().textValue()));
|
|
|
+ final Request request = new Request("GET", "/_test_cluster/deprecated_settings");
|
|
|
+ final RequestOptions options = request.getOptions()
|
|
|
+ .toBuilder()
|
|
|
+ .addHeader("X-Opaque-Id", "xOpaqueId-testDeprecationWarnMessagesCanBeIndexed")
|
|
|
+ .build();
|
|
|
+ request.setOptions(options);
|
|
|
+ request.setEntity(
|
|
|
+ buildSettingsRequest(
|
|
|
+ Collections.singletonList(TestDeprecationHeaderRestAction.TEST_DEPRECATED_SETTING_TRUE1),
|
|
|
+ "deprecation_warning"
|
|
|
+ )
|
|
|
+ );
|
|
|
+ assertOK(client().performRequest(request));
|
|
|
|
|
|
- documents.add(document);
|
|
|
- }
|
|
|
+ assertBusy(() -> {
|
|
|
+ List<Map<String, Object>> documents = getIndexedDeprecations();
|
|
|
|
|
|
- logger.warn(documents);
|
|
|
- assertThat(documents, hasSize(2));
|
|
|
+ logger.warn(documents);
|
|
|
+ assertThat(documents, hasSize(2));
|
|
|
|
|
|
- assertThat(
|
|
|
- documents,
|
|
|
- containsInAnyOrder(
|
|
|
- allOf(
|
|
|
- hasKey("@timestamp"),
|
|
|
- hasKey("elasticsearch.cluster.name"),
|
|
|
- hasKey("elasticsearch.cluster.uuid"),
|
|
|
- hasEntry(X_OPAQUE_ID_FIELD_NAME, "some xid"),
|
|
|
- hasEntry("elasticsearch.event.category", "settings"),
|
|
|
- hasKey("elasticsearch.node.id"),
|
|
|
- hasKey("elasticsearch.node.name"),
|
|
|
- hasEntry("data_stream.dataset", "deprecation.elasticsearch"),
|
|
|
- hasEntry("data_stream.namespace", "default"),
|
|
|
- hasEntry("data_stream.type", "logs"),
|
|
|
- hasEntry("ecs.version", "1.7"),
|
|
|
- hasEntry(KEY_FIELD_NAME, "deprecated_warn_settings"),
|
|
|
- hasEntry("event.dataset", "deprecation.elasticsearch"),
|
|
|
- hasEntry("log.level", "WARN"),
|
|
|
- hasKey("log.logger"),
|
|
|
- hasEntry("message", "[deprecated_warn_settings] usage is deprecated but won't be breaking in next version")
|
|
|
- ),
|
|
|
- allOf(
|
|
|
- hasKey("@timestamp"),
|
|
|
- hasKey("elasticsearch.cluster.name"),
|
|
|
- hasKey("elasticsearch.cluster.uuid"),
|
|
|
- hasEntry(X_OPAQUE_ID_FIELD_NAME, "some xid"),
|
|
|
- hasEntry("elasticsearch.event.category", "api"),
|
|
|
- hasKey("elasticsearch.node.id"),
|
|
|
- hasKey("elasticsearch.node.name"),
|
|
|
- hasEntry("data_stream.dataset", "deprecation.elasticsearch"),
|
|
|
- hasEntry("data_stream.namespace", "default"),
|
|
|
- hasEntry("data_stream.type", "logs"),
|
|
|
- hasEntry("ecs.version", "1.7"),
|
|
|
- hasEntry(KEY_FIELD_NAME, "deprecated_route_GET_/_test_cluster/deprecated_settings"),
|
|
|
- hasEntry("event.dataset", "deprecation.elasticsearch"),
|
|
|
- hasEntry("log.level", "CRITICAL"),
|
|
|
- hasKey("log.logger"),
|
|
|
- hasEntry("message", "[/_test_cluster/deprecated_settings] exists for deprecated tests")
|
|
|
- )
|
|
|
+ assertThat(
|
|
|
+ documents,
|
|
|
+ containsInAnyOrder(
|
|
|
+ allOf(
|
|
|
+ hasKey("@timestamp"),
|
|
|
+ hasKey("elasticsearch.cluster.name"),
|
|
|
+ hasKey("elasticsearch.cluster.uuid"),
|
|
|
+ hasEntry(X_OPAQUE_ID_FIELD_NAME, "xOpaqueId-testDeprecationWarnMessagesCanBeIndexed"),
|
|
|
+ hasEntry("elasticsearch.event.category", "settings"),
|
|
|
+ hasKey("elasticsearch.node.id"),
|
|
|
+ hasKey("elasticsearch.node.name"),
|
|
|
+ hasEntry("data_stream.dataset", "deprecation.elasticsearch"),
|
|
|
+ hasEntry("data_stream.namespace", "default"),
|
|
|
+ hasEntry("data_stream.type", "logs"),
|
|
|
+ hasEntry("ecs.version", "1.7"),
|
|
|
+ hasEntry(KEY_FIELD_NAME, "deprecated_warn_settings"),
|
|
|
+ hasEntry("event.dataset", "deprecation.elasticsearch"),
|
|
|
+ hasEntry("log.level", "WARN"),
|
|
|
+ hasKey("log.logger"),
|
|
|
+ hasEntry("message", "[deprecated_warn_settings] usage is deprecated but won't be breaking in next version")
|
|
|
+ ),
|
|
|
+ allOf(
|
|
|
+ hasKey("@timestamp"),
|
|
|
+ hasKey("elasticsearch.cluster.name"),
|
|
|
+ hasKey("elasticsearch.cluster.uuid"),
|
|
|
+ hasEntry(X_OPAQUE_ID_FIELD_NAME, "xOpaqueId-testDeprecationWarnMessagesCanBeIndexed"),
|
|
|
+ hasEntry("elasticsearch.event.category", "api"),
|
|
|
+ hasKey("elasticsearch.node.id"),
|
|
|
+ hasKey("elasticsearch.node.name"),
|
|
|
+ hasEntry("data_stream.dataset", "deprecation.elasticsearch"),
|
|
|
+ hasEntry("data_stream.namespace", "default"),
|
|
|
+ hasEntry("data_stream.type", "logs"),
|
|
|
+ hasEntry("ecs.version", "1.7"),
|
|
|
+ hasEntry(KEY_FIELD_NAME, "deprecated_route_GET_/_test_cluster/deprecated_settings"),
|
|
|
+ hasEntry("event.dataset", "deprecation.elasticsearch"),
|
|
|
+ hasEntry("log.level", "CRITICAL"),
|
|
|
+ hasKey("log.logger"),
|
|
|
+ hasEntry("message", "[/_test_cluster/deprecated_settings] exists for deprecated tests")
|
|
|
)
|
|
|
- );
|
|
|
- }, 30, TimeUnit.SECONDS);
|
|
|
- } finally {
|
|
|
- configureWriteDeprecationLogsToIndex(null);
|
|
|
- client().performRequest(new Request("DELETE", "_data_stream/" + DATA_STREAM_NAME));
|
|
|
- }
|
|
|
+ )
|
|
|
+ );
|
|
|
+ }, 30, TimeUnit.SECONDS);
|
|
|
+
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Check that log messages about REST API compatibility are recorded to an index
|
|
|
*/
|
|
|
public void testCompatibleMessagesCanBeIndexed() throws Exception {
|
|
|
- try {
|
|
|
- configureWriteDeprecationLogsToIndex(true);
|
|
|
-
|
|
|
- final Request compatibleRequest = new Request("GET", "/_test_cluster/deprecated_settings");
|
|
|
- final RequestOptions compatibleOptions = compatibleRequest.getOptions()
|
|
|
- .toBuilder()
|
|
|
- .addHeader("X-Opaque-Id", "some xid")
|
|
|
- .addHeader("Accept", "application/vnd.elasticsearch+json;compatible-with=" + RestApiVersion.minimumSupported().major)
|
|
|
- .addHeader("Content-Type", "application/vnd.elasticsearch+json;compatible-with=" + RestApiVersion.minimumSupported().major)
|
|
|
- .build();
|
|
|
- compatibleRequest.setOptions(compatibleOptions);
|
|
|
- compatibleRequest.setEntity(
|
|
|
- buildSettingsRequest(
|
|
|
- Collections.singletonList(TestDeprecationHeaderRestAction.TEST_DEPRECATED_SETTING_TRUE1),
|
|
|
- "deprecated_settings"
|
|
|
- )
|
|
|
- );
|
|
|
- Response deprecatedApiResponse = client().performRequest(compatibleRequest);
|
|
|
- assertOK(deprecatedApiResponse);
|
|
|
-
|
|
|
- final List<String> deprecatedWarnings = getWarningHeaders(deprecatedApiResponse.getHeaders());
|
|
|
- final List<String> actualWarningValues = deprecatedWarnings.stream()
|
|
|
- .map(s -> HeaderWarning.extractWarningValueFromWarningHeader(s, true))
|
|
|
- .collect(Collectors.toList());
|
|
|
- assertThat(
|
|
|
- actualWarningValues,
|
|
|
- containsInAnyOrder(
|
|
|
- TestDeprecationHeaderRestAction.DEPRECATED_ENDPOINT,
|
|
|
- TestDeprecationHeaderRestAction.COMPATIBLE_API_USAGE
|
|
|
- )
|
|
|
- );
|
|
|
-
|
|
|
- assertBusy(() -> {
|
|
|
- Response response;
|
|
|
- try {
|
|
|
- client().performRequest(new Request("POST", "/" + DATA_STREAM_NAME + "/_refresh?ignore_unavailable=true"));
|
|
|
- response = client().performRequest(new Request("GET", "/" + DATA_STREAM_NAME + "/_search"));
|
|
|
- } catch (Exception e) {
|
|
|
- // It can take a moment for the index to be created. If it doesn't exist then the client
|
|
|
- // throws an exception. Translate it into an assertion error so that assertBusy() will
|
|
|
- // continue trying.
|
|
|
- throw new AssertionError(e);
|
|
|
- }
|
|
|
- assertOK(response);
|
|
|
-
|
|
|
- ObjectMapper mapper = new ObjectMapper();
|
|
|
- final JsonNode jsonNode = mapper.readTree(response.getEntity().getContent());
|
|
|
|
|
|
- final int hits = jsonNode.at("/hits/total/value").intValue();
|
|
|
- assertThat(hits, greaterThan(0));
|
|
|
-
|
|
|
- List<Map<String, Object>> documents = new ArrayList<>();
|
|
|
-
|
|
|
- for (int i = 0; i < hits; i++) {
|
|
|
- final JsonNode hit = jsonNode.at("/hits/hits/" + i + "/_source");
|
|
|
+ final Request compatibleRequest = new Request("GET", "/_test_cluster/deprecated_settings");
|
|
|
+ final RequestOptions compatibleOptions = compatibleRequest.getOptions()
|
|
|
+ .toBuilder()
|
|
|
+ .addHeader("X-Opaque-Id", "xOpaqueId-testCompatibleMessagesCanBeIndexed")
|
|
|
+ .addHeader("Accept", "application/vnd.elasticsearch+json;compatible-with=" + RestApiVersion.minimumSupported().major)
|
|
|
+ .addHeader("Content-Type", "application/vnd.elasticsearch+json;compatible-with=" + RestApiVersion.minimumSupported().major)
|
|
|
+ .build();
|
|
|
+ compatibleRequest.setOptions(compatibleOptions);
|
|
|
+ compatibleRequest.setEntity(
|
|
|
+ buildSettingsRequest(
|
|
|
+ Collections.singletonList(TestDeprecationHeaderRestAction.TEST_DEPRECATED_SETTING_TRUE1),
|
|
|
+ "deprecated_settings"
|
|
|
+ )
|
|
|
+ );
|
|
|
+ Response deprecatedApiResponse = client().performRequest(compatibleRequest);
|
|
|
+ assertOK(deprecatedApiResponse);
|
|
|
|
|
|
- final Map<String, Object> document = new HashMap<>();
|
|
|
- hit.fields().forEachRemaining(entry -> document.put(entry.getKey(), entry.getValue().textValue()));
|
|
|
+ final List<String> deprecatedWarnings = getWarningHeaders(deprecatedApiResponse.getHeaders());
|
|
|
+ final List<String> actualWarningValues = deprecatedWarnings.stream()
|
|
|
+ .map(s -> HeaderWarning.extractWarningValueFromWarningHeader(s, true))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ assertThat(
|
|
|
+ actualWarningValues,
|
|
|
+ containsInAnyOrder(TestDeprecationHeaderRestAction.DEPRECATED_ENDPOINT, TestDeprecationHeaderRestAction.COMPATIBLE_API_USAGE)
|
|
|
+ );
|
|
|
|
|
|
- documents.add(document);
|
|
|
- }
|
|
|
+ assertBusy(() -> {
|
|
|
+ List<Map<String, Object>> documents = getIndexedDeprecations();
|
|
|
|
|
|
- logger.warn(documents);
|
|
|
- assertThat(documents, hasSize(2));
|
|
|
+ logger.warn(documents);
|
|
|
+ assertThat(documents, hasSize(2));
|
|
|
|
|
|
- assertThat(
|
|
|
- documents,
|
|
|
- containsInAnyOrder(
|
|
|
- allOf(
|
|
|
- hasKey("@timestamp"),
|
|
|
- hasKey("elasticsearch.cluster.name"),
|
|
|
- hasKey("elasticsearch.cluster.uuid"),
|
|
|
- hasEntry(X_OPAQUE_ID_FIELD_NAME, "some xid"),
|
|
|
- hasEntry("elasticsearch.event.category", "compatible_api"),
|
|
|
- hasKey("elasticsearch.node.id"),
|
|
|
- hasKey("elasticsearch.node.name"),
|
|
|
- hasEntry("data_stream.dataset", "deprecation.elasticsearch"),
|
|
|
- hasEntry("data_stream.namespace", "default"),
|
|
|
- hasEntry("data_stream.type", "logs"),
|
|
|
- hasEntry("ecs.version", "1.7"),
|
|
|
- hasEntry(KEY_FIELD_NAME, "compatible_key"),
|
|
|
- hasEntry("event.dataset", "deprecation.elasticsearch"),
|
|
|
- hasEntry("log.level", "CRITICAL"),
|
|
|
- hasKey("log.logger"),
|
|
|
- hasEntry("message", "You are using a compatible API for this request")
|
|
|
- ),
|
|
|
- allOf(
|
|
|
- hasKey("@timestamp"),
|
|
|
- hasKey("elasticsearch.cluster.name"),
|
|
|
- hasKey("elasticsearch.cluster.uuid"),
|
|
|
- hasEntry(X_OPAQUE_ID_FIELD_NAME, "some xid"),
|
|
|
- hasEntry("elasticsearch.event.category", "api"),
|
|
|
- hasKey("elasticsearch.node.id"),
|
|
|
- hasKey("elasticsearch.node.name"),
|
|
|
- hasEntry("data_stream.dataset", "deprecation.elasticsearch"),
|
|
|
- hasEntry("data_stream.namespace", "default"),
|
|
|
- hasEntry("data_stream.type", "logs"),
|
|
|
- hasEntry("ecs.version", "1.7"),
|
|
|
- hasEntry(KEY_FIELD_NAME, "deprecated_route_GET_/_test_cluster/deprecated_settings"),
|
|
|
- hasEntry("event.dataset", "deprecation.elasticsearch"),
|
|
|
- hasEntry("log.level", "CRITICAL"),
|
|
|
- hasKey("log.logger"),
|
|
|
- hasEntry("message", "[/_test_cluster/deprecated_settings] exists for deprecated tests")
|
|
|
- )
|
|
|
+ assertThat(
|
|
|
+ documents,
|
|
|
+ containsInAnyOrder(
|
|
|
+ allOf(
|
|
|
+ hasKey("@timestamp"),
|
|
|
+ hasKey("elasticsearch.cluster.name"),
|
|
|
+ hasKey("elasticsearch.cluster.uuid"),
|
|
|
+ hasEntry(X_OPAQUE_ID_FIELD_NAME, "xOpaqueId-testCompatibleMessagesCanBeIndexed"),
|
|
|
+ hasEntry("elasticsearch.event.category", "compatible_api"),
|
|
|
+ hasKey("elasticsearch.node.id"),
|
|
|
+ hasKey("elasticsearch.node.name"),
|
|
|
+ hasEntry("data_stream.dataset", "deprecation.elasticsearch"),
|
|
|
+ hasEntry("data_stream.namespace", "default"),
|
|
|
+ hasEntry("data_stream.type", "logs"),
|
|
|
+ hasEntry("ecs.version", "1.7"),
|
|
|
+ hasEntry(KEY_FIELD_NAME, "compatible_key"),
|
|
|
+ hasEntry("event.dataset", "deprecation.elasticsearch"),
|
|
|
+ hasEntry("log.level", "CRITICAL"),
|
|
|
+ hasKey("log.logger"),
|
|
|
+ hasEntry("message", "You are using a compatible API for this request")
|
|
|
+ ),
|
|
|
+ allOf(
|
|
|
+ hasKey("@timestamp"),
|
|
|
+ hasKey("elasticsearch.cluster.name"),
|
|
|
+ hasKey("elasticsearch.cluster.uuid"),
|
|
|
+ hasEntry(X_OPAQUE_ID_FIELD_NAME, "xOpaqueId-testCompatibleMessagesCanBeIndexed"),
|
|
|
+ hasEntry("elasticsearch.event.category", "api"),
|
|
|
+ hasKey("elasticsearch.node.id"),
|
|
|
+ hasKey("elasticsearch.node.name"),
|
|
|
+ hasEntry("data_stream.dataset", "deprecation.elasticsearch"),
|
|
|
+ hasEntry("data_stream.namespace", "default"),
|
|
|
+ hasEntry("data_stream.type", "logs"),
|
|
|
+ hasEntry("ecs.version", "1.7"),
|
|
|
+ hasEntry(KEY_FIELD_NAME, "deprecated_route_GET_/_test_cluster/deprecated_settings"),
|
|
|
+ hasEntry("event.dataset", "deprecation.elasticsearch"),
|
|
|
+ hasEntry("log.level", "CRITICAL"),
|
|
|
+ hasKey("log.logger"),
|
|
|
+ hasEntry("message", "[/_test_cluster/deprecated_settings] exists for deprecated tests")
|
|
|
)
|
|
|
- );
|
|
|
- }, 30, TimeUnit.SECONDS);
|
|
|
- } finally {
|
|
|
- configureWriteDeprecationLogsToIndex(null);
|
|
|
- client().performRequest(new Request("DELETE", "_data_stream/" + DATA_STREAM_NAME));
|
|
|
- }
|
|
|
+ )
|
|
|
+ );
|
|
|
+ }, 30, TimeUnit.SECONDS);
|
|
|
+
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Check that deprecation messages can be recorded to an index
|
|
|
*/
|
|
|
public void testDeprecationIndexingCacheReset() throws Exception {
|
|
|
- try {
|
|
|
- configureWriteDeprecationLogsToIndex(true);
|
|
|
-
|
|
|
- final Request getRequest = createTestRequest("GET");
|
|
|
- assertOK(client().performRequest(getRequest));
|
|
|
|
|
|
- client().performRequest(new Request("DELETE", "/_logging/deprecation_cache"));
|
|
|
+ final Request deprecatedRequest = deprecatedRequest("GET", "xOpaqueId-testDeprecationIndexingCacheReset");
|
|
|
+ assertOK(client().performRequest(deprecatedRequest));
|
|
|
|
|
|
- assertOK(client().performRequest(getRequest));
|
|
|
+ client().performRequest(new Request("DELETE", "/_logging/deprecation_cache"));
|
|
|
|
|
|
- assertBusy(() -> {
|
|
|
- Response response;
|
|
|
- try {
|
|
|
- client().performRequest(new Request("POST", "/" + DATA_STREAM_NAME + "/_refresh?ignore_unavailable=true"));
|
|
|
- response = client().performRequest(new Request("GET", "/" + DATA_STREAM_NAME + "/_search"));
|
|
|
- } catch (Exception e) {
|
|
|
- // It can take a moment for the index to be created. If it doesn't exist then the client
|
|
|
- // throws an exception. Translate it into an assertion error so that assertBusy() will
|
|
|
- // continue trying.
|
|
|
- throw new AssertionError(e);
|
|
|
- }
|
|
|
- assertOK(response);
|
|
|
-
|
|
|
- ObjectMapper mapper = new ObjectMapper();
|
|
|
- final JsonNode jsonNode = mapper.readTree(response.getEntity().getContent());
|
|
|
+ assertOK(client().performRequest(deprecatedRequest));
|
|
|
|
|
|
- final int hits = jsonNode.at("/hits/total/value").intValue();
|
|
|
- assertThat(hits, greaterThan(0));
|
|
|
+ assertBusy(() -> {
|
|
|
+ List<Map<String, Object>> documents = getIndexedDeprecations();
|
|
|
|
|
|
- List<Map<String, Object>> documents = new ArrayList<>();
|
|
|
+ logger.warn(documents);
|
|
|
+ assertThat(documents, hasSize(4));
|
|
|
|
|
|
- for (int i = 0; i < hits; i++) {
|
|
|
- final JsonNode hit = jsonNode.at("/hits/hits/" + i + "/_source");
|
|
|
-
|
|
|
- final Map<String, Object> document = new HashMap<>();
|
|
|
- hit.fields().forEachRemaining(entry -> document.put(entry.getKey(), entry.getValue().textValue()));
|
|
|
-
|
|
|
- documents.add(document);
|
|
|
- }
|
|
|
-
|
|
|
- logger.warn(documents);
|
|
|
- assertThat(documents, hasSize(4));
|
|
|
-
|
|
|
- assertThat(
|
|
|
- documents,
|
|
|
- containsInAnyOrder(
|
|
|
- allOf(
|
|
|
- hasEntry(KEY_FIELD_NAME, "deprecated_route_GET_/_test_cluster/deprecated_settings"),
|
|
|
- hasEntry("message", "[/_test_cluster/deprecated_settings] exists for deprecated tests")
|
|
|
- ),
|
|
|
- allOf(
|
|
|
- hasEntry(KEY_FIELD_NAME, "deprecated_route_GET_/_test_cluster/deprecated_settings"),
|
|
|
- hasEntry("message", "[/_test_cluster/deprecated_settings] exists for deprecated tests")
|
|
|
- ),
|
|
|
- allOf(
|
|
|
- hasEntry(KEY_FIELD_NAME, "deprecated_settings"),
|
|
|
- hasEntry("message", "[deprecated_settings] usage is deprecated. use [settings] instead")
|
|
|
- ),
|
|
|
- allOf(
|
|
|
- hasEntry(KEY_FIELD_NAME, "deprecated_settings"),
|
|
|
- hasEntry("message", "[deprecated_settings] usage is deprecated. use [settings] instead")
|
|
|
- )
|
|
|
+ assertThat(
|
|
|
+ documents,
|
|
|
+ containsInAnyOrder(
|
|
|
+ allOf(
|
|
|
+ hasEntry(KEY_FIELD_NAME, "deprecated_route_GET_/_test_cluster/deprecated_settings"),
|
|
|
+ hasEntry("message", "[/_test_cluster/deprecated_settings] exists for deprecated tests")
|
|
|
+ ),
|
|
|
+ allOf(
|
|
|
+ hasEntry(KEY_FIELD_NAME, "deprecated_route_GET_/_test_cluster/deprecated_settings"),
|
|
|
+ hasEntry("message", "[/_test_cluster/deprecated_settings] exists for deprecated tests")
|
|
|
+ ),
|
|
|
+ allOf(
|
|
|
+ hasEntry(KEY_FIELD_NAME, "deprecated_settings"),
|
|
|
+ hasEntry("message", "[deprecated_settings] usage is deprecated. use [settings] instead")
|
|
|
+ ),
|
|
|
+ allOf(
|
|
|
+ hasEntry(KEY_FIELD_NAME, "deprecated_settings"),
|
|
|
+ hasEntry("message", "[deprecated_settings] usage is deprecated. use [settings] instead")
|
|
|
)
|
|
|
- );
|
|
|
- }, 30, TimeUnit.SECONDS);
|
|
|
- } finally {
|
|
|
- configureWriteDeprecationLogsToIndex(null);
|
|
|
- client().performRequest(new Request("DELETE", "_data_stream/" + DATA_STREAM_NAME));
|
|
|
- }
|
|
|
+ )
|
|
|
+ );
|
|
|
+ }, 30, TimeUnit.SECONDS);
|
|
|
+
|
|
|
}
|
|
|
|
|
|
private void configureWriteDeprecationLogsToIndex(Boolean value) throws IOException {
|
|
@@ -710,6 +657,38 @@ public class DeprecationHttpIT extends ESRestTestCase {
|
|
|
assertOK(response);
|
|
|
}
|
|
|
|
|
|
+ private List<Map<String, Object>> getIndexedDeprecations() throws IOException {
|
|
|
+ Response response;
|
|
|
+ try {
|
|
|
+ client().performRequest(new Request("POST", "/" + DATA_STREAM_NAME + "/_refresh?ignore_unavailable=true"));
|
|
|
+ response = client().performRequest(new Request("GET", "/" + DATA_STREAM_NAME + "/_search"));
|
|
|
+ } catch (Exception e) {
|
|
|
+ // It can take a moment for the index to be created. If it doesn't exist then the client
|
|
|
+ // throws an exception. Translate it into an assertion error so that assertBusy() will
|
|
|
+ // continue trying.
|
|
|
+ throw new AssertionError(e);
|
|
|
+ }
|
|
|
+ assertOK(response);
|
|
|
+
|
|
|
+ ObjectMapper mapper = new ObjectMapper();
|
|
|
+ final JsonNode jsonNode = mapper.readTree(response.getEntity().getContent());
|
|
|
+
|
|
|
+ final int hits = jsonNode.at("/hits/total/value").intValue();
|
|
|
+ assertThat(hits, greaterThan(0));
|
|
|
+
|
|
|
+ List<Map<String, Object>> documents = new ArrayList<>();
|
|
|
+
|
|
|
+ for (int i = 0; i < hits; i++) {
|
|
|
+ final JsonNode hit = jsonNode.at("/hits/hits/" + i + "/_source");
|
|
|
+
|
|
|
+ final Map<String, Object> document = new HashMap<>();
|
|
|
+ hit.fields().forEachRemaining(entry -> document.put(entry.getKey(), entry.getValue().textValue()));
|
|
|
+
|
|
|
+ documents.add(document);
|
|
|
+ }
|
|
|
+ return documents;
|
|
|
+ }
|
|
|
+
|
|
|
private List<String> getWarningHeaders(Header[] headers) {
|
|
|
List<String> warnings = new ArrayList<>();
|
|
|
|