Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
b127ea0
[Obs AI Assistant] Replace Kibana task with LockManager
sorenlouv Apr 2, 2025
65b8bca
Renaming files and tests
sorenlouv Apr 3, 2025
c5d51dc
Fix api tests
sorenlouv Apr 3, 2025
3609709
Merge branch 'main' of github.com:elastic/kibana into replace-tasks-w…
sorenlouv Apr 3, 2025
139690a
Fix api tests
sorenlouv Apr 3, 2025
506c0bc
Add tests for re-index endpoint
sorenlouv Apr 3, 2025
d8120b7
Merge branch 'main' of github.com:elastic/kibana into replace-tasks-w…
sorenlouv Apr 3, 2025
ada7bb9
Remove task
sorenlouv Apr 3, 2025
4d922d9
Improve log message
sorenlouv Apr 4, 2025
fe44ab2
Remove `refresh:true`
sorenlouv Apr 4, 2025
cc41b68
Reduce TTL to 30 seconds and minor cleanup
sorenlouv Apr 4, 2025
69b0efa
Minor cleanup
sorenlouv Apr 4, 2025
4fe7ca6
Update the lock with subsequent acquire calls
sorenlouv Apr 4, 2025
fbe1a82
Add tests that retries obtaining the lock
sorenlouv Apr 6, 2025
c07bd0a
Remove `acquireWithRetry`
sorenlouv Apr 6, 2025
e2e93c6
Add test for retrying
sorenlouv Apr 6, 2025
d6237d0
Add test cleanup
sorenlouv Apr 6, 2025
7312d94
Improve tests of retry logic
sorenlouv Apr 7, 2025
6d4d778
Resolve lint issue
sorenlouv Apr 7, 2025
9ba4ea1
Merge branch 'main' into replace-tasks-with-locks
sorenlouv Apr 7, 2025
4a97877
Rename `reIndexKnowledgeBaseAndPopulateMissingSemanticTextField` to `…
sorenlouv Apr 7, 2025
057c301
Update x-pack/platform/plugins/shared/observability_ai_assistant/serv…
sorenlouv Apr 7, 2025
004c2ff
Update x-pack/platform/plugins/shared/observability_ai_assistant/serv…
sorenlouv Apr 7, 2025
64c4b85
Update x-pack/test/api_integration/deployment_agnostic/apis/observabi…
sorenlouv Apr 7, 2025
353b47c
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine Apr 7, 2025
bb7e615
Match both http (stateful) and https (serverless)
sorenlouv Apr 7, 2025
219c6f6
Update x-pack/test/api_integration/deployment_agnostic/apis/observabi…
sorenlouv Apr 7, 2025
f6df04d
Address feedback
sorenlouv Apr 7, 2025
f6e309c
Merge branch 'replace-tasks-with-locks' of github.com:sorenlouv/kiban…
sorenlouv Apr 7, 2025
24773a2
Change lock id format
sorenlouv Apr 7, 2025
656e898
exclude the removed task when polling for new tasks
sorenlouv Apr 7, 2025
d4dda50
Fix tests
sorenlouv Apr 7, 2025
4804571
Fix APi test
sorenlouv Apr 8, 2025
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 @@ -31,8 +31,8 @@ import { registerFunctions } from './functions';
import { recallRankingEvent } from './analytics/recall_ranking';
import { initLangtrace } from './service/client/instrumentation/init_langtrace';
import { aiAssistantCapabilities } from '../common/capabilities';
import { registerAndScheduleKbSemanticTextMigrationTask } from './service/task_manager_definitions/register_kb_semantic_text_migration_task';
import { updateExistingIndexAssets } from './service/create_or_update_index_assets';
import { populateMissingSemanticTextFieldMigration } from './service/startup_migrations/populate_missing_semantic_text_field_migration';
import { updateExistingIndexAssets } from './service/startup_migrations/create_or_update_index_assets';

export class ObservabilityAIAssistantPlugin
implements
Expand Down Expand Up @@ -130,23 +130,19 @@ export class ObservabilityAIAssistantPlugin
}));

// Update existing index assets (mappings, templates, etc). This will not create assets if they do not exist.
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({
core,
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}`
updateExistingIndexAssets({ logger: this.logger, core })
.then(() =>
populateMissingSemanticTextFieldMigration({
core,
logger: this.logger,
config: this.config,
})
)
);
.catch((e) =>
Copy link
Copy Markdown
Contributor

@neptunian neptunian Apr 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does createOrUpdateIndexAssets need to throw in order for an error in there to be caught here and prevent populateMissingSemanticTextFieldMigration from running if that's the intention?

this.logger.error(
`Error during knowledge base migration in AI Assistant plugin startup: ${e.message}`
)
);

service.register(registerFunctions);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,23 @@ const resetKnowledgeBase = createObservabilityAIAssistantServerRoute({
},
});

const reIndexKnowledgeBase = createObservabilityAIAssistantServerRoute({
endpoint: 'POST /internal/observability_ai_assistant/kb/reindex',
security: {
authz: {
requiredPrivileges: ['ai_assistant'],
},
},
handler: async (resources): Promise<{ result: boolean }> => {
const client = await resources.service.getClient({ request: resources.request });
const result = await client.reIndexKnowledgeBaseWithLock();
return { result };
},
});

const semanticTextMigrationKnowledgeBase = createObservabilityAIAssistantServerRoute({
endpoint: 'POST /internal/observability_ai_assistant/kb/migrations/kb_semantic_text',
endpoint:
'POST /internal/observability_ai_assistant/kb/migrations/populate_missing_semantic_text_field',
security: {
authz: {
requiredPrivileges: ['ai_assistant'],
Expand Down Expand Up @@ -320,6 +335,7 @@ const importKnowledgeBaseEntries = createObservabilityAIAssistantServerRoute({
});

export const knowledgeBaseRoutes = {
...reIndexKnowledgeBase,
...semanticTextMigrationKnowledgeBase,
...setupKnowledgeBase,
...resetKnowledgeBase,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import { createOrUpdateIndexAssets } from '../../service/create_or_update_index_assets';
import { createOrUpdateIndexAssets } from '../../service/startup_migrations/create_or_update_index_assets';
import { createObservabilityAIAssistantServerRoute } from '../create_observability_ai_assistant_server_route';

const createOrUpdateIndexAssetsRoute = createObservabilityAIAssistantServerRoute({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,12 @@ import { continueConversation } from './operators/continue_conversation';
import { convertInferenceEventsToStreamingEvents } from './operators/convert_inference_events_to_streaming_events';
import { extractMessages } from './operators/extract_messages';
import { getGeneratedTitle } from './operators/get_generated_title';
import {
reIndexKnowledgeBaseAndPopulateSemanticTextField,
scheduleKbSemanticTextMigrationTask,
} from '../task_manager_definitions/register_kb_semantic_text_migration_task';
import { populateMissingSemanticTextFieldMigration } from '../startup_migrations/populate_missing_semantic_text_field_migration';
import { ObservabilityAIAssistantPluginStartDependencies } from '../../types';
import { ObservabilityAIAssistantConfig } from '../../config';
import { getElserModelId } from '../knowledge_base_service/get_elser_model_id';
import { apmInstrumentation } from './operators/apm_instrumentation';
import { reIndexKnowledgeBaseWithLock } from '../knowledge_base_service/reindex_knowledge_base';

const MAX_FUNCTION_CALLS = 8;

Expand Down Expand Up @@ -680,14 +678,15 @@ export class ObservabilityAIAssistantClient {
// setup the knowledge base
const res = await knowledgeBaseService.setup(esClient, modelId);

core
.getStartServices()
.then(([_, pluginsStart]) =>
scheduleKbSemanticTextMigrationTask({ taskManager: pluginsStart.taskManager, logger })
)
.catch((error) => {
logger.error(`Failed to schedule semantic text migration task: ${error}`);
});
populateMissingSemanticTextFieldMigration({
core,
logger,
config: this.dependencies.config,
}).catch((e) => {
this.dependencies.logger.error(
`Failed to populate missing semantic text fields: ${e.message}`
);
});

return res;
};
Expand All @@ -697,14 +696,21 @@ export class ObservabilityAIAssistantClient {
return this.dependencies.knowledgeBaseService.reset(esClient);
};

reIndexKnowledgeBaseAndPopulateSemanticTextField = () => {
return reIndexKnowledgeBaseAndPopulateSemanticTextField({
reIndexKnowledgeBaseWithLock = () => {
return reIndexKnowledgeBaseWithLock({
core: this.dependencies.core,
esClient: this.dependencies.esClient,
logger: this.dependencies.logger,
config: this.dependencies.config,
});
};

reIndexKnowledgeBaseAndPopulateSemanticTextField = () => {
return populateMissingSemanticTextFieldMigration({
core: this.dependencies.core,
logger: this.dependencies.logger,
config: this.dependencies.config,
});
};
addUserInstruction = async ({
entry,
}: {
Expand Down
Loading