Skip to content

Commit

Permalink
Implement framework for migrating system indices (#78951)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
gwbrown authored Oct 20, 2021
1 parent fcc474d commit 35dc030
Show file tree
Hide file tree
Showing 27 changed files with 3,077 additions and 188 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
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 {

Expand Down Expand Up @@ -73,11 +73,8 @@ public void testGetFeatureUpgradeStatus() throws IOException {
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"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,14 @@ protected org.elasticsearch.action.admin.cluster.migration.GetFeatureUpgradeStat
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())
);
Expand Down Expand Up @@ -78,12 +82,12 @@ protected void assertInstances(
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()));
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion docs/reference/migration/apis/feature_upgrade.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ and to trigger an automated system upgrade that might potentially involve downti
==== {api-prereq-title}

* If the {es} {security-features} are enabled, you must have the `manage`
<<privileges-list-cluster,cluster privilege>> to use this API. (TODO: true?)
<<privileges-list-cluster,cluster privilege>> to use this API.

[[feature-upgrade-api-example]]
==== {api-examples-title}
Expand Down Expand Up @@ -144,6 +144,7 @@ Example response:
]
}
--------------------------------------------------
// TESTRESPONSE[skip: can't actually upgrade system indices in these tests]

This tells us that the security index is being upgraded. To check the
overall status of the upgrade, call the endpoint with GET.
Expand Down
Loading

0 comments on commit 35dc030

Please sign in to comment.