[Obs AI Assistant] Defer KB migration until index assets have been updated (#211523)

Follow-up to https://github.com/elastic/kibana/pull/210386
Closes: https://github.com/elastic/kibana/issues/211525

This ensures that we don't start executing the knowledge base migration
until index assets have been updated
This commit is contained in:
Søren Louv-Jansen 2025-02-18 12:50:01 +01:00 committed by GitHub
parent e5bd422f6e
commit 4cd9ef318b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 10 additions and 3 deletions

View file

@ -130,9 +130,10 @@ export class ObservabilityAIAssistantPlugin
}));
// Update existing index assets (mappings, templates, etc). This will not create assets if they do not exist.
updateExistingIndexAssets({ logger: this.logger.get('index_assets'), core }).catch((e) =>
this.logger.error(`Index assets could not be updated: ${e.message}`)
);
const indexAssetsUpdatedPromise = updateExistingIndexAssets({
logger: this.logger.get('index_assets'),
core,
}).catch((e) => this.logger.error(`Index assets could not be updated: ${e.message}`));
// register task to migrate knowledge base entries to include semantic_text field
registerAndScheduleKbSemanticTextMigrationTask({
@ -140,6 +141,7 @@ export class ObservabilityAIAssistantPlugin
taskManager: plugins.taskManager,
logger: this.logger.get('kb_semantic_text_migration_task'),
config: this.config,
indexAssetsUpdatedPromise,
}).catch((e) =>
this.logger.error(
`Knowledge base semantic_text migration task could not be registered: ${e.message}`

View file

@ -28,17 +28,22 @@ export async function registerAndScheduleKbSemanticTextMigrationTask({
logger,
core,
config,
indexAssetsUpdatedPromise,
}: {
taskManager: TaskManagerSetupContract;
logger: Logger;
core: CoreSetup<ObservabilityAIAssistantPluginStartDependencies>;
config: ObservabilityAIAssistantConfig;
indexAssetsUpdatedPromise: Promise<void>;
}) {
const [coreStart, pluginsStart] = await core.getStartServices();
// register task
registerKbSemanticTextMigrationTask({ taskManager, logger, coreStart, config });
// wait for index assets to be updated
await indexAssetsUpdatedPromise;
// schedule task
await scheduleKbSemanticTextMigrationTask({ taskManager: pluginsStart.taskManager, logger });
}