[UA] Upgrade assistant migration meta data can become stale (#60789)
This commit is contained in:
parent
3c66662630
commit
85481a7017
|
@ -76,6 +76,12 @@ export interface ReindexService {
|
|||
*/
|
||||
findReindexOperation(indexName: string): Promise<ReindexSavedObject | null>;
|
||||
|
||||
/**
|
||||
* Delete reindex operations for completed indices with deprecations.
|
||||
* @param indexNames
|
||||
*/
|
||||
cleanupReindexOperations(indexNames: string[]): Promise<void> | null;
|
||||
|
||||
/**
|
||||
* Process the reindex operation through one step of the state machine and resolves
|
||||
* to the updated reindex operation.
|
||||
|
@ -603,6 +609,23 @@ export const reindexServiceFactory = (
|
|||
return findResponse.saved_objects[0];
|
||||
},
|
||||
|
||||
async cleanupReindexOperations(indexNames: string[]) {
|
||||
const performCleanup = async (indexName: string) => {
|
||||
const existingReindexOps = await actions.findReindexOperations(indexName);
|
||||
|
||||
if (existingReindexOps && existingReindexOps.total !== 0) {
|
||||
const existingOp = existingReindexOps.saved_objects[0];
|
||||
if (existingOp.attributes.status === ReindexStatus.completed) {
|
||||
// Delete the existing one if its status is completed, but still contains deprecation warnings
|
||||
// example scenario: index was upgraded, but then deleted and restored with an old snapshot
|
||||
await actions.deleteReindexOp(existingOp);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
await Promise.all(indexNames.map(performCleanup));
|
||||
},
|
||||
|
||||
findAllByStatus: actions.findAllByStatus,
|
||||
|
||||
async processNextStep(reindexOp: ReindexSavedObject) {
|
||||
|
|
|
@ -7,8 +7,10 @@
|
|||
import { getUpgradeAssistantStatus } from '../lib/es_migration_apis';
|
||||
import { versionCheckHandlerWrapper } from '../lib/es_version_precheck';
|
||||
import { RouteDependencies } from '../types';
|
||||
import { reindexActionsFactory } from '../lib/reindexing/reindex_actions';
|
||||
import { reindexServiceFactory } from '../lib/reindexing';
|
||||
|
||||
export function registerClusterCheckupRoutes({ cloud, router }: RouteDependencies) {
|
||||
export function registerClusterCheckupRoutes({ cloud, router, licensing, log }: RouteDependencies) {
|
||||
const isCloudEnabled = Boolean(cloud?.isCloudEnabled);
|
||||
|
||||
router.get(
|
||||
|
@ -20,6 +22,7 @@ export function registerClusterCheckupRoutes({ cloud, router }: RouteDependencie
|
|||
async (
|
||||
{
|
||||
core: {
|
||||
savedObjects: { client: savedObjectsClient },
|
||||
elasticsearch: { dataClient },
|
||||
},
|
||||
},
|
||||
|
@ -27,8 +30,24 @@ export function registerClusterCheckupRoutes({ cloud, router }: RouteDependencie
|
|||
response
|
||||
) => {
|
||||
try {
|
||||
const status = await getUpgradeAssistantStatus(dataClient, isCloudEnabled);
|
||||
|
||||
const callAsCurrentUser = dataClient.callAsCurrentUser.bind(dataClient);
|
||||
const reindexActions = reindexActionsFactory(savedObjectsClient, callAsCurrentUser);
|
||||
const reindexService = reindexServiceFactory(
|
||||
callAsCurrentUser,
|
||||
reindexActions,
|
||||
log,
|
||||
licensing
|
||||
);
|
||||
const indexNames = status.indices
|
||||
.filter(({ index }) => typeof index !== 'undefined')
|
||||
.map(({ index }) => index as string);
|
||||
|
||||
await reindexService.cleanupReindexOperations(indexNames);
|
||||
|
||||
return response.ok({
|
||||
body: await getUpgradeAssistantStatus(dataClient, isCloudEnabled),
|
||||
body: status,
|
||||
});
|
||||
} catch (e) {
|
||||
if (e.status === 403) {
|
||||
|
|
Loading…
Reference in a new issue