From d839205135774841bdad8a6604264e0256684830 Mon Sep 17 00:00:00 2001 From: Dan Rubinstein Date: Wed, 11 Dec 2024 10:47:46 -0500 Subject: [PATCH] Removing index alias creation for deprecated transforms notification index (#117583) * Removing index alias creation for deprecated transforms notification index * Update docs/changelog/117583.yaml * Updating changelog * Updating deprecation area to Transform --------- Co-authored-by: Elastic Machine --- docs/changelog/117583.yaml | 17 +++++ .../TransformInternalIndexConstants.java | 1 - .../integration/TransformAuditorIT.java | 27 -------- .../TransformClusterStateListener.java | 63 ------------------- 4 files changed, 17 insertions(+), 91 deletions(-) create mode 100644 docs/changelog/117583.yaml diff --git a/docs/changelog/117583.yaml b/docs/changelog/117583.yaml new file mode 100644 index 0000000000000..e0c482b8d9f72 --- /dev/null +++ b/docs/changelog/117583.yaml @@ -0,0 +1,17 @@ +pr: 117583 +summary: Removing index alias creation for deprecated transforms notification index +area: Machine Learning +type: deprecation +issues: [] +deprecation: + title: Removing index alias creation for deprecated transforms notification index + area: Transform + details: >- + As part of the migration from 7.x to 8.x, the `.data-frame-notifications-1` index + was deprecated and replaced with the `.transform-notifications-000002` index. + The index is no longer created by default, all writes are directed to the new index, + and any clusters with the deprecated index will have an alias created to ensure that + reads are still retrieving data that was written to the index before the migration to 8.x. + This change removes the alias from the deprecated index in 9.x. Any clusters with the alias present + will retain it, but it will not be created on new clusters. + impact: No known end user impact. diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/transform/transforms/persistence/TransformInternalIndexConstants.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/transform/transforms/persistence/TransformInternalIndexConstants.java index 0d54583b89976..8439c9cd76fad 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/transform/transforms/persistence/TransformInternalIndexConstants.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/transform/transforms/persistence/TransformInternalIndexConstants.java @@ -45,7 +45,6 @@ public final class TransformInternalIndexConstants { public static final String AUDIT_TEMPLATE_VERSION = "000002"; public static final String AUDIT_INDEX_PREFIX = TRANSFORM_PREFIX + "notifications-"; public static final String AUDIT_INDEX_PATTERN = AUDIT_INDEX_PREFIX + "*"; - public static final String AUDIT_INDEX_DEPRECATED = TRANSFORM_PREFIX_DEPRECATED + "notifications-1"; public static final String AUDIT_INDEX_PATTERN_DEPRECATED = TRANSFORM_PREFIX_DEPRECATED + "notifications-*"; public static final String AUDIT_INDEX_READ_ALIAS = TRANSFORM_PREFIX + "notifications-read"; diff --git a/x-pack/plugin/transform/qa/single-node-tests/src/javaRestTest/java/org/elasticsearch/xpack/transform/integration/TransformAuditorIT.java b/x-pack/plugin/transform/qa/single-node-tests/src/javaRestTest/java/org/elasticsearch/xpack/transform/integration/TransformAuditorIT.java index 7e31b7ec0c5e4..97851f79322b3 100644 --- a/x-pack/plugin/transform/qa/single-node-tests/src/javaRestTest/java/org/elasticsearch/xpack/transform/integration/TransformAuditorIT.java +++ b/x-pack/plugin/transform/qa/single-node-tests/src/javaRestTest/java/org/elasticsearch/xpack/transform/integration/TransformAuditorIT.java @@ -8,9 +8,6 @@ package org.elasticsearch.xpack.transform.integration; import org.elasticsearch.client.Request; -import org.elasticsearch.client.RequestOptions; -import org.elasticsearch.common.Strings; -import org.elasticsearch.common.settings.Settings; import org.elasticsearch.xpack.core.transform.transforms.persistence.TransformInternalIndexConstants; import org.junit.Before; @@ -92,28 +89,4 @@ public void testAuditorWritesAudits() throws Exception { }); } - - public void testAliasCreatedforBWCIndexes() throws Exception { - Settings.Builder settings = indexSettings(1, 0); - - // These indices should only exist if created in previous versions, ignore the deprecation warning for this test - RequestOptions options = expectWarnings( - "index name [" - + TransformInternalIndexConstants.AUDIT_INDEX_DEPRECATED - + "] starts " - + "with a dot '.', in the next major version, index names starting with a dot are reserved for hidden indices " - + "and system indices" - ).toBuilder().addHeader("X-elastic-product-origin", "elastic").build(); - Request request = new Request("PUT", "/" + TransformInternalIndexConstants.AUDIT_INDEX_DEPRECATED); - String entity = "{\"settings\": " + Strings.toString(settings.build()) + "}"; - request.setJsonEntity(entity); - request.setOptions(options); - client().performRequest(request); - - assertBusy( - () -> assertTrue( - aliasExists(TransformInternalIndexConstants.AUDIT_INDEX_DEPRECATED, TransformInternalIndexConstants.AUDIT_INDEX_READ_ALIAS) - ) - ); - } } diff --git a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/TransformClusterStateListener.java b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/TransformClusterStateListener.java index 4c867616e9be0..e49beb9d57f4d 100644 --- a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/TransformClusterStateListener.java +++ b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/TransformClusterStateListener.java @@ -9,26 +9,18 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.elasticsearch.action.ActionListener; -import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest; -import org.elasticsearch.action.admin.indices.alias.IndicesAliasesResponse; import org.elasticsearch.client.internal.Client; import org.elasticsearch.cluster.ClusterChangedEvent; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.ClusterStateListener; -import org.elasticsearch.cluster.metadata.Metadata; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.gateway.GatewayService; -import org.elasticsearch.xpack.core.transform.transforms.persistence.TransformInternalIndexConstants; import java.util.Optional; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference; import java.util.function.Supplier; -import static org.elasticsearch.xpack.core.ClientHelper.TRANSFORM_ORIGIN; -import static org.elasticsearch.xpack.core.ClientHelper.executeAsyncWithOrigin; - class TransformClusterStateListener implements ClusterStateListener, Supplier> { private static final Logger logger = LogManager.getLogger(TransformClusterStateListener.class); @@ -51,61 +43,6 @@ public void clusterChanged(ClusterChangedEvent event) { } clusterState.set(event.state()); - - // The atomic flag prevents multiple simultaneous attempts to run alias creation - // if there is a flurry of cluster state updates in quick succession - if (event.localNodeMaster() && isIndexCreationInProgress.compareAndSet(false, true)) { - createAuditAliasForDataFrameBWC(event.state(), client, ActionListener.wrap(r -> { - isIndexCreationInProgress.set(false); - if (r) { - logger.info("Created alias for deprecated data frame notifications index"); - } else { - logger.debug("Skipped creating alias for deprecated data frame notifications index"); - } - }, e -> { - isIndexCreationInProgress.set(false); - logger.error("Error creating alias for deprecated data frame notifications index", e); - })); - } - } - - private static void createAuditAliasForDataFrameBWC(ClusterState state, Client client, final ActionListener finalListener) { - - // check if old audit index exists, no need to create the alias if it does not - if (state.getMetadata().hasIndexAbstraction(TransformInternalIndexConstants.AUDIT_INDEX_DEPRECATED) == false) { - finalListener.onResponse(false); - return; - } - - Metadata metadata = state.metadata(); - if (state.getMetadata() - .getIndicesLookup() - .get(TransformInternalIndexConstants.AUDIT_INDEX_DEPRECATED) - .getIndices() - .stream() - .anyMatch(name -> metadata.index(name).getAliases().containsKey(TransformInternalIndexConstants.AUDIT_INDEX_READ_ALIAS))) { - finalListener.onResponse(false); - return; - } - - final IndicesAliasesRequest request = client.admin() - .indices() - .prepareAliases() - .addAliasAction( - IndicesAliasesRequest.AliasActions.add() - .index(TransformInternalIndexConstants.AUDIT_INDEX_DEPRECATED) - .alias(TransformInternalIndexConstants.AUDIT_INDEX_READ_ALIAS) - .isHidden(true) - ) - .request(); - - executeAsyncWithOrigin( - client.threadPool().getThreadContext(), - TRANSFORM_ORIGIN, - request, - ActionListener.wrap(r -> finalListener.onResponse(r.isAcknowledged()), finalListener::onFailure), - client.admin().indices()::aliases - ); } /**