From f7759227adf2e65c5f380829ca917f7edcb570b1 Mon Sep 17 00:00:00 2001 From: Jim Ferenczi Date: Fri, 5 May 2023 16:38:07 +0100 Subject: [PATCH] Disable auto-creation of indices in the AnalyticsEventEmitter (#95880) The analytics event emitter delegates the posted events to a bulk processor. When deleting the analytics collection, there's no guarantee that some events are still in flight. This change ensures that these events cannot re-create the underlying index after its deletion. Closes #95629 Closes #95657 Closes #95686 Closes #95717 --- .../test/entsearch/60_behavioral_analytics_list.yml | 9 ++++----- .../test/entsearch/70_behavioral_analytics_put.yml | 1 - .../entsearch/90_behavioral_analytics_event_post.yml | 5 ----- .../analytics/ingest/AnalyticsEventEmitter.java | 2 ++ 4 files changed, 6 insertions(+), 11 deletions(-) diff --git a/x-pack/plugin/ent-search/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/entsearch/60_behavioral_analytics_list.yml b/x-pack/plugin/ent-search/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/entsearch/60_behavioral_analytics_list.yml index 2deccda1edf43..387348cf4064f 100644 --- a/x-pack/plugin/ent-search/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/entsearch/60_behavioral_analytics_list.yml +++ b/x-pack/plugin/ent-search/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/entsearch/60_behavioral_analytics_list.yml @@ -1,8 +1,4 @@ setup: - - skip: - version: "all" - reason: "@AwaitsFix https://github.com/elastic/elasticsearch/issues/95717" - - do: search_application.put_behavioral_analytics: name: my-test-analytics-collection @@ -16,7 +12,10 @@ teardown: - do: search_application.delete_behavioral_analytics: name: my-test-analytics-collection - ignore: 404 + + - do: + search_application.delete_behavioral_analytics: + name: my-test-analytics-collection2 --- "Get Analytics Collection for a particular collection": diff --git a/x-pack/plugin/ent-search/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/entsearch/70_behavioral_analytics_put.yml b/x-pack/plugin/ent-search/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/entsearch/70_behavioral_analytics_put.yml index a9b15c983f492..7252de0b3b792 100644 --- a/x-pack/plugin/ent-search/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/entsearch/70_behavioral_analytics_put.yml +++ b/x-pack/plugin/ent-search/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/entsearch/70_behavioral_analytics_put.yml @@ -2,7 +2,6 @@ teardown: - do: search_application.delete_behavioral_analytics: name: test-analytics-collection - ignore: 404 --- "Create Analytics Collection": diff --git a/x-pack/plugin/ent-search/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/entsearch/90_behavioral_analytics_event_post.yml b/x-pack/plugin/ent-search/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/entsearch/90_behavioral_analytics_event_post.yml index 8460857769398..cb8bcbb7a8bdb 100644 --- a/x-pack/plugin/ent-search/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/entsearch/90_behavioral_analytics_event_post.yml +++ b/x-pack/plugin/ent-search/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/entsearch/90_behavioral_analytics_event_post.yml @@ -1,8 +1,4 @@ setup: - - skip: - version: "all" - reason: "@AwaitsFix https://github.com/elastic/elasticsearch/issues/95686" - - do: search_application.put_behavioral_analytics: name: my-test-analytics-collection @@ -12,7 +8,6 @@ teardown: - do: search_application.delete_behavioral_analytics: name: my-test-analytics-collection - ignore: 404 # Page view event tests ######################################### diff --git a/x-pack/plugin/ent-search/src/main/java/org/elasticsearch/xpack/application/analytics/ingest/AnalyticsEventEmitter.java b/x-pack/plugin/ent-search/src/main/java/org/elasticsearch/xpack/application/analytics/ingest/AnalyticsEventEmitter.java index aa22dfbe2e3cb..d2aab53b558a2 100644 --- a/x-pack/plugin/ent-search/src/main/java/org/elasticsearch/xpack/application/analytics/ingest/AnalyticsEventEmitter.java +++ b/x-pack/plugin/ent-search/src/main/java/org/elasticsearch/xpack/application/analytics/ingest/AnalyticsEventEmitter.java @@ -108,6 +108,8 @@ private IndexRequest createIndexRequest(AnalyticsEvent event) throws IOException try (XContentBuilder builder = JsonXContent.contentBuilder()) { return client.prepareIndex(collection.getEventDataStream()) + // disable auto-creation of the underlying index + .setRequireAlias(true) .setCreate(true) .setSource(event.toXContent(builder, ToXContent.EMPTY_PARAMS)) .request();