Skip to content

Commit 82e0414

Browse files
authored
Add version guards around Transform hidden index settings (#54036)
This commit ensures that the hidden index settings are only applied to the Transform index templates when the cluster can support those settings. Also unmutes the tests which were failing due to the previous behavior.
1 parent 55f2e8b commit 82e0414

File tree

7 files changed

+34
-26
lines changed

7 files changed

+34
-26
lines changed

x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/Transform.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import org.apache.logging.log4j.LogManager;
1010
import org.apache.logging.log4j.Logger;
1111
import org.apache.lucene.util.SetOnce;
12+
import org.elasticsearch.Version;
1213
import org.elasticsearch.action.ActionRequest;
1314
import org.elasticsearch.action.ActionResponse;
1415
import org.elasticsearch.client.Client;
@@ -320,7 +321,10 @@ public UnaryOperator<Map<String, IndexTemplateMetaData>> getIndexTemplateMetaDat
320321
logger.error("Error creating transform index template", e);
321322
}
322323
try {
323-
templates.put(TransformInternalIndexConstants.AUDIT_INDEX, TransformInternalIndex.getAuditIndexTemplateMetaData());
324+
// Template upgraders are only ever called on the master nodes, so we can use the current node version as the compatibility
325+
// version here because we can be sure that this node, if elected master, will be compatible with itself.
326+
templates.put(TransformInternalIndexConstants.AUDIT_INDEX,
327+
TransformInternalIndex.getAuditIndexTemplateMetaData(Version.CURRENT));
324328
} catch (IOException e) {
325329
logger.warn("Error creating transform audit index", e);
326330
}

x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/TransformClusterStateListener.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
import static org.elasticsearch.xpack.core.ClientHelper.TRANSFORM_ORIGIN;
2525
import static org.elasticsearch.xpack.core.ClientHelper.executeAsyncWithOrigin;
26+
import static org.elasticsearch.xpack.transform.persistence.TransformInternalIndex.HIDDEN_INTRODUCED_VERSION;
2627

2728
class TransformClusterStateListener implements ClusterStateListener {
2829

@@ -77,11 +78,16 @@ private static void createAuditAliasForDataFrameBWC(ClusterState state, Client c
7778
return;
7879
}
7980

81+
final IndicesAliasesRequest.AliasActions aliasAction = IndicesAliasesRequest.AliasActions.add()
82+
.index(TransformInternalIndexConstants.AUDIT_INDEX_DEPRECATED)
83+
.alias(TransformInternalIndexConstants.AUDIT_INDEX_READ_ALIAS);
84+
85+
if (state.nodes().getMinNodeVersion().onOrAfter(HIDDEN_INTRODUCED_VERSION)) {
86+
aliasAction.isHidden(true);
87+
}
88+
8089
final IndicesAliasesRequest request = client.admin().indices().prepareAliases()
81-
.addAliasAction(IndicesAliasesRequest.AliasActions.add()
82-
.index(TransformInternalIndexConstants.AUDIT_INDEX_DEPRECATED)
83-
.alias(TransformInternalIndexConstants.AUDIT_INDEX_READ_ALIAS)
84-
.isHidden(true))
90+
.addAliasAction(aliasAction)
8591
.request();
8692

8793
executeAsyncWithOrigin(client.threadPool().getThreadContext(), TRANSFORM_ORIGIN, request,

x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/persistence/TransformInternalIndex.java

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import java.io.IOException;
4040
import java.util.Collections;
4141

42+
import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_INDEX_HIDDEN;
4243
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
4344
import static org.elasticsearch.index.mapper.MapperService.SINGLE_MAPPING_NAME;
4445
import static org.elasticsearch.xpack.core.ClientHelper.TRANSFORM_ORIGIN;
@@ -79,6 +80,8 @@ public final class TransformInternalIndex {
7980
public static final String KEYWORD = "keyword";
8081
public static final String BOOLEAN = "boolean";
8182

83+
public static final Version HIDDEN_INTRODUCED_VERSION = Version.V_7_7_0;
84+
8285
public static IndexTemplateMetaData getIndexTemplateMetaData() throws IOException {
8386
IndexTemplateMetaData transformTemplate = IndexTemplateMetaData.builder(TransformInternalIndexConstants.LATEST_INDEX_VERSIONED_NAME)
8487
.patterns(Collections.singletonList(TransformInternalIndexConstants.LATEST_INDEX_VERSIONED_NAME))
@@ -97,19 +100,22 @@ public static IndexTemplateMetaData getIndexTemplateMetaData() throws IOExceptio
97100
return transformTemplate;
98101
}
99102

100-
public static IndexTemplateMetaData getAuditIndexTemplateMetaData() throws IOException {
103+
public static IndexTemplateMetaData getAuditIndexTemplateMetaData(Version compatibilityVersion) throws IOException {
104+
final Settings.Builder auditIndexSettings = Settings.builder()
105+
// the audits are expected to be small
106+
.put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1)
107+
.put(IndexMetaData.SETTING_AUTO_EXPAND_REPLICAS, "0-1");
108+
final AliasMetaData.Builder alias = AliasMetaData.builder(TransformInternalIndexConstants.AUDIT_INDEX_READ_ALIAS);
109+
if (compatibilityVersion.onOrAfter(HIDDEN_INTRODUCED_VERSION)) {
110+
auditIndexSettings.put(SETTING_INDEX_HIDDEN, true);
111+
alias.isHidden(true);
112+
}
101113
IndexTemplateMetaData transformTemplate = IndexTemplateMetaData.builder(TransformInternalIndexConstants.AUDIT_INDEX)
102114
.patterns(Collections.singletonList(TransformInternalIndexConstants.AUDIT_INDEX_PREFIX + "*"))
103115
.version(Version.CURRENT.id)
104-
.settings(
105-
Settings.builder()
106-
// the audits are expected to be small
107-
.put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1)
108-
.put(IndexMetaData.SETTING_AUTO_EXPAND_REPLICAS, "0-1")
109-
.put(IndexMetaData.SETTING_INDEX_HIDDEN, true)
110-
)
116+
.settings(auditIndexSettings)
111117
.putMapping(MapperService.SINGLE_MAPPING_NAME, Strings.toString(auditMappings()))
112-
.putAlias(AliasMetaData.builder(TransformInternalIndexConstants.AUDIT_INDEX_READ_ALIAS).isHidden(true))
118+
.putAlias(alias)
113119
.build();
114120
return transformTemplate;
115121
}
@@ -406,7 +412,7 @@ protected static void installLatestAuditIndexTemplateIfRequired(
406412

407413
// Installing the template involves communication with the master node, so it's more expensive but much rarer
408414
try {
409-
IndexTemplateMetaData indexTemplateMetaData = getAuditIndexTemplateMetaData();
415+
IndexTemplateMetaData indexTemplateMetaData = getAuditIndexTemplateMetaData(clusterService.state().nodes().getMinNodeVersion());
410416
BytesReference jsonMappings = new BytesArray(indexTemplateMetaData.mappings().get(SINGLE_MAPPING_NAME).uncompressed());
411417
PutIndexTemplateRequest request = new PutIndexTemplateRequest(TransformInternalIndexConstants.AUDIT_INDEX).patterns(
412418
indexTemplateMetaData.patterns()

x-pack/plugin/transform/src/test/java/org/elasticsearch/xpack/transform/persistence/TransformInternalIndexTests.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
package org.elasticsearch.xpack.transform.persistence;
88

9+
import org.elasticsearch.Version;
910
import org.elasticsearch.action.ActionListener;
1011
import org.elasticsearch.action.support.master.AcknowledgedResponse;
1112
import org.elasticsearch.client.AdminClient;
@@ -55,7 +56,8 @@ public class TransformInternalIndexTests extends ESTestCase {
5556

5657
mapBuilder = ImmutableOpenMap.builder();
5758
try {
58-
mapBuilder.put(TransformInternalIndexConstants.AUDIT_INDEX, TransformInternalIndex.getAuditIndexTemplateMetaData());
59+
mapBuilder.put(TransformInternalIndexConstants.AUDIT_INDEX,
60+
TransformInternalIndex.getAuditIndexTemplateMetaData(Version.CURRENT));
5961
} catch (IOException e) {
6062
throw new UncheckedIOException(e);
6163
}

x-pack/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/TransformSurvivesUpgradeIT.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,6 @@ protected RestClient buildClient(Settings settings, HttpHost[] hosts) throws IOE
128128
* The purpose of this test is to ensure that when a job is open through a rolling upgrade we upgrade the results
129129
* index mappings when it is assigned to an upgraded node even if no other ML endpoint is called after the upgrade
130130
*/
131-
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/53931")
132131
public void testTransformRollingUpgrade() throws Exception {
133132
assumeTrue("Continuous transform time sync not fixed until 7.4", UPGRADE_FROM_VERSION.onOrAfter(Version.V_7_4_0));
134133
Request adjustLoggingLevels = new Request("PUT", "/_cluster/settings");

x-pack/qa/rolling-upgrade/src/test/resources/rest-api-spec/test/mixed_cluster/80_transform_jobs_crud.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
setup:
2-
- skip:
3-
version: "all"
4-
reason: "AwaitsFix https://github.com/elastic/elasticsearch/issues/53931"
5-
61
---
72
"Test put batch transform on mixed cluster":
83
- skip:

x-pack/qa/rolling-upgrade/src/test/resources/rest-api-spec/test/upgraded_cluster/80_transform_jobs_crud.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
setup:
2-
- skip:
3-
version: "all"
4-
reason: "AwaitsFix https://github.com/elastic/elasticsearch/issues/53931"
5-
62
- do:
73
cluster.health:
84
wait_for_status: green

0 commit comments

Comments
 (0)