Skip to content
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

[UA] Upgrade assistant migration meta data can become stale #60789

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,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.
Expand Down Expand Up @@ -584,6 +590,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) {
Expand Down
23 changes: 21 additions & 2 deletions x-pack/plugins/upgrade_assistant/server/routes/cluster_checkup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -20,15 +22,32 @@ export function registerClusterCheckupRoutes({ cloud, router }: RouteDependencie
async (
{
core: {
savedObjects: { client: savedObjectsClient },
elasticsearch: { dataClient },
},
},
request,
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) {
Expand Down