Implement framework for migrating system indices (#78951)

This PR adds a framework for migrating system indices as necessary prior
to Elasticsearch upgrades. This framework uses REST APIs added in
another commit:
- GET _migration/system_features

This API, which gets the status of "features" (plugins which own system
indices) with regards to whether they need to be upgraded or not. As of
this PR, this API also reports errors encountered while migrating system
indices alongside the index that was being processed when this occurred.

As an example of this error reporting:

```json
{
    "feature_name": "logstash_management",
    "minimum_index_version": "8.0.0",
    "upgrade_status": "ERROR",
    "indices": [
        {
            "index": ".logstash",
            "version": "8.0.0",
            "failure_cause": {
                "error": {
                    "root_cause": [
                        {
                            "type": "runtime_exception",
                            "reason": "whoopsie",
                            "stack_trace": "<omitted for brevity>"
                        }
                    ],
                    "type": "runtime_exception",
                    "reason": "whoopsie",
                    "stack_trace": "<omitted for brevity>"
                }
            }
        }
    ]
}
```

- POST _migration/system_features

This API starts the migration process. The API for this has no changes,
but when called, any system indices which need to be migrated will be
migrated, with status information stored in the cluster state for later
use by the GET _migration/system_features API.
This commit is contained in:
Gordon Brown 2021-10-19 20:16:39 -06:00 committed by GitHub
parent fcc474df8a
commit 35dc030ed8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
27 changed files with 3076 additions and 187 deletions

View file

@ -28,8 +28,8 @@ import static org.hamcrest.Matchers.anEmptyMap;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue;
public class MigrationIT extends ESRestHighLevelClientTestCase {
@ -73,11 +73,8 @@ public class MigrationIT extends ESRestHighLevelClientTestCase {
public void testPostFeatureUpgradeStatus() throws IOException {
PostFeatureUpgradeRequest request = new PostFeatureUpgradeRequest();
PostFeatureUpgradeResponse response = highLevelClient().migration().postFeatureUpgrade(request, RequestOptions.DEFAULT);
assertThat(response.isAccepted(), equalTo(true));
assertThat(response.getFeatures().size(), equalTo(1));
PostFeatureUpgradeResponse.Feature feature = response.getFeatures().get(0);
assertThat(feature.getFeatureName(), equalTo("security"));
assertThat(response.getReason(), nullValue());
assertThat(response.getElasticsearchException(), nullValue());
assertThat(response.isAccepted(), equalTo(false));
assertThat(response.getFeatures(), hasSize(0));
assertThat(response.getReason(), equalTo("No system indices require migration"));
}
}

View file

@ -40,10 +40,14 @@ public class GetFeatureUpgradeStatusResponseTests extends AbstractResponseTestCa
randomAlphaOfLengthBetween(3, 20),
randomFrom(Version.CURRENT, Version.CURRENT.minimumCompatibilityVersion()),
randomFrom(org.elasticsearch.action.admin.cluster.migration.GetFeatureUpgradeStatusResponse.UpgradeStatus.values()),
randomList(4,
() -> new org.elasticsearch.action.admin.cluster.migration.GetFeatureUpgradeStatusResponse.IndexVersion(
randomList(
4,
() -> new org.elasticsearch.action.admin.cluster.migration.GetFeatureUpgradeStatusResponse.IndexInfo(
randomAlphaOfLengthBetween(3, 20),
randomFrom(Version.CURRENT, Version.CURRENT.minimumCompatibilityVersion())))
randomFrom(Version.CURRENT, Version.CURRENT.minimumCompatibilityVersion()),
null
)
)
)),
randomFrom(org.elasticsearch.action.admin.cluster.migration.GetFeatureUpgradeStatusResponse.UpgradeStatus.values())
);
@ -78,12 +82,12 @@ public class GetFeatureUpgradeStatusResponseTests extends AbstractResponseTestCa
assertThat(clientStatus.getIndexVersions(), hasSize(serverTestStatus.getIndexVersions().size()));
for (int j = 0; i < clientStatus.getIndexVersions().size(); i++) {
org.elasticsearch.action.admin.cluster.migration.GetFeatureUpgradeStatusResponse.IndexVersion serverIndexVersion
org.elasticsearch.action.admin.cluster.migration.GetFeatureUpgradeStatusResponse.IndexInfo serverIndexInfo
= serverTestStatus.getIndexVersions().get(j);
GetFeatureUpgradeStatusResponse.IndexVersion clientIndexVersion = clientStatus.getIndexVersions().get(j);
assertThat(clientIndexVersion.getIndexName(), equalTo(serverIndexVersion.getIndexName()));
assertThat(clientIndexVersion.getVersion(), equalTo(serverIndexVersion.getVersion().toString()));
assertThat(clientIndexVersion.getIndexName(), equalTo(serverIndexInfo.getIndexName()));
assertThat(clientIndexVersion.getVersion(), equalTo(serverIndexInfo.getVersion().toString()));
}
}
}