Skip to content

[main] System data streams are not being upgraded in the feature migration API #126409

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Prev Previous commit
Next Next commit
Fix compilation of tests
  • Loading branch information
alexey-ivanov-es committed Apr 7, 2025
commit 50f877f781983c94a81b352833df52ba84b6f1e2
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public void testAddBackingIndexToSystemDataStream() {
final int numBackingIndices = randomIntBetween(1, 4);
final String dataStreamName = randomAlphaOfLength(5);
IndexMetadata[] backingIndices = new IndexMetadata[numBackingIndices];
Metadata.Builder mb = Metadata.builder();
ProjectMetadata.Builder mb = ProjectMetadata.builder(randomProjectIdOrDefault());
for (int k = 0; k < numBackingIndices; k++) {
backingIndices[k] = IndexMetadata.builder(DataStream.getDefaultBackingIndexName(dataStreamName, k + 1, epochMillis))
.settings(Settings.builder().put(IndexMetadata.SETTING_VERSION_CREATED, IndexVersion.current()))
Expand All @@ -133,15 +133,15 @@ public void testAddBackingIndexToSystemDataStream() {
.build();
mb.put(indexToAdd, false);

ClusterState originalState = ClusterState.builder(new ClusterName("dummy")).metadata(mb.build()).build();
ClusterState newState = MetadataDataStreamsService.modifyDataStream(
originalState,
ProjectMetadata projectMetadata = mb.build();
ProjectMetadata newState = MetadataDataStreamsService.modifyDataStream(
projectMetadata,
List.of(DataStreamAction.addBackingIndex(dataStreamName, indexToAdd.getIndex().getName())),
this::getMapperService,
Settings.EMPTY
);

IndexAbstraction ds = newState.metadata().getIndicesLookup().get(dataStreamName);
IndexAbstraction ds = newState.getIndicesLookup().get(dataStreamName);
assertThat(ds, notNullValue());
assertThat(ds.getType(), equalTo(IndexAbstraction.Type.DATA_STREAM));
assertThat(ds.getIndices().size(), equalTo(numBackingIndices + 1));
Expand All @@ -152,7 +152,7 @@ public void testAddBackingIndexToSystemDataStream() {
Arrays.stream(backingIndices).map(IndexMetadata::getIndex).map(Index::getName).toList().toArray(Strings.EMPTY_ARRAY)
)
);
IndexMetadata zeroIndex = newState.metadata().index(ds.getIndices().get(0));
IndexMetadata zeroIndex = newState.index(ds.getIndices().get(0));
assertThat(zeroIndex.getIndex(), equalTo(indexToAdd.getIndex()));
assertThat(zeroIndex.getSettings().get("index.hidden"), equalTo("true"));
assertThat(zeroIndex.isSystem(), equalTo(true));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import org.elasticsearch.client.internal.Client;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.metadata.IndexMetadata;
import org.elasticsearch.cluster.metadata.Metadata;
import org.elasticsearch.cluster.metadata.ProjectMetadata;
import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.settings.Settings;
Expand Down Expand Up @@ -150,10 +150,10 @@ public abstract class AbstractFeatureMigrationIntegTest extends ESIntegTestCase
protected String masterAndDataNode;
protected String masterName;

protected static Metadata assertMetadataAfterMigration(String featureName) {
Metadata finalMetadata = clusterAdmin().prepareState(TEST_REQUEST_TIMEOUT).get().getState().metadata();
protected static ProjectMetadata assertMetadataAfterMigration(String featureName) {
ProjectMetadata finalMetadata = clusterAdmin().prepareState(TEST_REQUEST_TIMEOUT).get().getState().metadata().getProject();
// Check that the results metadata is what we expect.
FeatureMigrationResults currentResults = finalMetadata.getProject().custom(FeatureMigrationResults.TYPE);
FeatureMigrationResults currentResults = finalMetadata.custom(FeatureMigrationResults.TYPE);
assertThat(currentResults, notNullValue());
assertThat(currentResults.getFeatureStatuses(), allOf(aMapWithSize(1), hasKey(featureName)));
assertThat(currentResults.getFeatureStatuses().get(featureName).succeeded(), is(true));
Expand Down Expand Up @@ -268,14 +268,14 @@ static String createMapping(boolean descriptorManaged, boolean descriptorInterna
}

protected void assertIndexHasCorrectProperties(
Metadata metadata,
ProjectMetadata metadata,
String indexName,
int settingsFlagValue,
boolean isManaged,
boolean isInternal,
Collection<String> aliasNames
) {
IndexMetadata imd = metadata.getProject().index(indexName);
IndexMetadata imd = metadata.index(indexName);
assertThat(imd.getSettings().get(FlAG_SETTING_KEY), equalTo(Integer.toString(settingsFlagValue)));
final Map<String, Object> mapping = imd.mapping().getSourceAsMap();
@SuppressWarnings("unchecked")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.elasticsearch.cluster.metadata.ComposableIndexTemplate;
import org.elasticsearch.cluster.metadata.IndexMetadata;
import org.elasticsearch.cluster.metadata.Metadata;
import org.elasticsearch.cluster.metadata.ProjectMetadata;
import org.elasticsearch.cluster.metadata.Template;
import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.common.Strings;
Expand Down Expand Up @@ -194,7 +195,7 @@ public void testMigrateSystemIndex() throws Exception {
assertTrue("the pre-migration hook wasn't actually called", preUpgradeHookCalled.get());
assertTrue("the post-migration hook wasn't actually called", postUpgradeHookCalled.get());

Metadata finalMetadata = assertMetadataAfterMigration(FEATURE_NAME);
ProjectMetadata finalMetadata = assertMetadataAfterMigration(FEATURE_NAME);

assertIndexHasCorrectProperties(
finalMetadata,
Expand Down Expand Up @@ -359,7 +360,7 @@ public void testMigrateUsingScript() throws Exception {
executeMigration(SCRIPTED_INDEX_FEATURE_NAME);
ensureGreen();

Metadata metadata = assertMetadataAfterMigration(SCRIPTED_INDEX_FEATURE_NAME);
ProjectMetadata metadata = assertMetadataAfterMigration(SCRIPTED_INDEX_FEATURE_NAME);
String newIndexName = ".int-mans-old" + UPGRADED_INDEX_SUFFIX;
assertIndexHasCorrectProperties(
metadata,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.client.internal.Client;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.metadata.Metadata;
import org.elasticsearch.cluster.metadata.ProjectMetadata;
import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.settings.Settings;
Expand Down Expand Up @@ -193,9 +193,9 @@ public void testMultipleFeatureMigration() throws Exception {
assertTrue("the second plugin's pre-migration hook wasn't actually called", secondPluginPreMigrationHookCalled.get());
assertTrue("the second plugin's post-migration hook wasn't actually called", secondPluginPostMigrationHookCalled.get());

Metadata finalMetadata = clusterAdmin().prepareState(TEST_REQUEST_TIMEOUT).get().getState().metadata();
ProjectMetadata finalMetadata = clusterAdmin().prepareState(TEST_REQUEST_TIMEOUT).get().getState().metadata().getProject();
// Check that the results metadata is what we expect
FeatureMigrationResults currentResults = finalMetadata.getProject().custom(FeatureMigrationResults.TYPE);
FeatureMigrationResults currentResults = finalMetadata.custom(FeatureMigrationResults.TYPE);
assertThat(currentResults, notNullValue());
assertThat(currentResults.getFeatureStatuses(), allOf(aMapWithSize(2), hasKey(FEATURE_NAME), hasKey(SECOND_FEATURE_NAME)));
assertThat(currentResults.getFeatureStatuses().get(FEATURE_NAME).succeeded(), is(true));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.elasticsearch.cluster.metadata.DataStreamTestHelper;
import org.elasticsearch.cluster.metadata.IndexMetadata;
import org.elasticsearch.cluster.metadata.Metadata;
import org.elasticsearch.cluster.metadata.ProjectMetadata;
import org.elasticsearch.cluster.metadata.Template;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.settings.Settings;
Expand Down Expand Up @@ -124,7 +125,7 @@ public void testMigrateSystemDataStream() throws Exception {
// Waiting for shards to stabilize if indices were moved around
ensureGreen();

Metadata finalMetadata = assertMetadataAfterMigration(DATA_STREAM_FEATURE);
ProjectMetadata finalMetadata = assertMetadataAfterMigration(DATA_STREAM_FEATURE);

DataStream dataStream = finalMetadata.dataStreams().get(TEST_DATA_STREAM_NAME);
assertNotNull(dataStream);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ private Metadata fromJsonXContentStringWithPersistentTasks(String json) throws I
mock(Client.class),
clusterService,
mock(SystemIndices.class),
IndexScopedSettings.DEFAULT_SCOPED_SETTINGS
IndexScopedSettings.DEFAULT_SCOPED_SETTINGS,
mock(ThreadPool.class)
);
new PersistentTasksExecutorRegistry(List.of(healthNodeTaskExecutor, systemIndexMigrationExecutor));

Expand Down
Loading