Skip to content
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 @@ -93,20 +93,14 @@ const warmupModelKnowledgeBase = createObservabilityAIAssistantServerRoute({

const reIndexKnowledgeBase = createObservabilityAIAssistantServerRoute({
endpoint: 'POST /internal/observability_ai_assistant/kb/reindex',
params: t.type({
query: t.type({
inference_id: t.string,
}),
}),
security: {
authz: {
requiredPrivileges: ['ai_assistant'],
},
},
handler: async (resources): Promise<{ success: boolean }> => {
const client = await resources.service.getClient({ request: resources.request });
const { inference_id: inferenceId } = resources.params.query;
await client.reIndexKnowledgeBaseWithLock(inferenceId);
await client.reIndexKnowledgeBaseWithLock();
return { success: true };
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,6 @@ export class ObservabilityAIAssistantClient {
core,
logger,
esClient,
inferenceId: nextInferenceId,
});
await populateMissingSemanticTextFieldWithLock({
core,
Expand Down Expand Up @@ -742,12 +741,11 @@ export class ObservabilityAIAssistantClient {
});
};

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,16 @@ import { Logger } from '@kbn/logging';
export async function createKnowledgeBaseIndex({
esClient,
logger,
inferenceId,
indexName,
}: {
esClient: { asInternalUser: ElasticsearchClient };
logger: Logger;
inferenceId: string;
indexName: string;
}) {
logger.debug(`Creating knowledge base write index "${indexName}"`);

try {
await esClient.asInternalUser.indices.create({
index: indexName,
mappings: {
properties: {
semantic_text: {
type: 'semantic_text',
inference_id: inferenceId,
},
},
},
});
await esClient.asInternalUser.indices.create({ index: indexName });
Comment on lines -26 to +24
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@viduni94 I think this was leftover from #218448. We don't need to add the inference id to the index, since we already update the component template.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ah my bad, thanks for updating this @sorenlouv 🙏🏻

} catch (error) {
if (
error instanceof errors.ResponseError &&
Expand All @@ -43,6 +31,7 @@ export async function createKnowledgeBaseIndex({
`Write index "${indexName}" already exists. Please delete it before creating a new index.`
);
}
logger.error(`Failed to create write index "${indexName}": ${error.message}`);
throw error;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import { recallFromSearchConnectors } from './recall_from_search_connectors';
import { ObservabilityAIAssistantPluginStartDependencies } from '../../types';
import { ObservabilityAIAssistantConfig } from '../../config';
import { hasKbWriteIndex } from './has_kb_index';
import { getInferenceIdFromWriteIndex } from './get_inference_id_from_write_index';
import { reIndexKnowledgeBaseWithLock } from './reindex_knowledge_base';
import { isSemanticTextUnsupportedError } from '../startup_migrations/run_startup_migrations';

Expand Down Expand Up @@ -440,13 +439,10 @@ export class KnowledgeBaseService {
}

if (isSemanticTextUnsupportedError(error)) {
const inferenceId = await getInferenceIdFromWriteIndex(this.dependencies.esClient);

reIndexKnowledgeBaseWithLock({
core: this.dependencies.core,
logger: this.dependencies.logger,
esClient: this.dependencies.esClient,
inferenceId,
}).catch((e) => {
if (isLockAcquisitionError(e)) {
this.dependencies.logger.info(`Re-indexing operation is already in progress`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,25 @@ export async function reIndexKnowledgeBaseWithLock({
core,
logger,
esClient,
inferenceId,
}: {
core: CoreSetup<ObservabilityAIAssistantPluginStartDependencies>;
logger: Logger;
esClient: {
asInternalUser: ElasticsearchClient;
};
inferenceId: string;
}): Promise<void> {
const lmService = new LockManagerService(core, logger);
return lmService.withLock(KB_REINDEXING_LOCK_ID, () =>
reIndexKnowledgeBase({ logger, esClient, inferenceId })
reIndexKnowledgeBase({ logger, esClient })
);
}

async function reIndexKnowledgeBase({
logger,
esClient,
inferenceId,
}: {
logger: Logger;
esClient: { asInternalUser: ElasticsearchClient };
inferenceId: string;
}): Promise<void> {
const activeReindexingTask = await getActiveReindexingTaskId(esClient);
if (activeReindexingTask) {
Expand All @@ -57,7 +53,7 @@ async function reIndexKnowledgeBase({
logger,
});

await createKnowledgeBaseIndex({ esClient, logger, inferenceId, indexName: nextWriteIndexName });
await createKnowledgeBaseIndex({ esClient, logger, indexName: nextWriteIndexName });

logger.info(
`Re-indexing knowledge base from "${currentWriteIndexName}" to index "${nextWriteIndexName}"...`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,15 @@ export async function updateKnowledgeBaseWriteIndexAlias({
`Updating write index alias from "${currentWriteIndexName}" to "${nextWriteIndexName}"`
);
const alias = resourceNames.writeIndexAlias.kb;
await esClient.asInternalUser.indices.updateAliases({
actions: [
{ remove: { index: currentWriteIndexName, alias } },
{ add: { index: nextWriteIndexName, alias, is_write_index: true } },
],
});
try {
await esClient.asInternalUser.indices.updateAliases({
actions: [
{ remove: { index: currentWriteIndexName, alias } },
{ add: { index: nextWriteIndexName, alias, is_write_index: true } },
],
});
} catch (error) {
logger.error(`Failed to update write index alias: ${error.message}`);
throw error;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import { ObservabilityAIAssistantConfig } from '../../config';
import { reIndexKnowledgeBaseWithLock } from '../knowledge_base_service/reindex_knowledge_base';
import { populateMissingSemanticTextFieldWithLock } from './populate_missing_semantic_text_fields';
import { hasKbWriteIndex } from '../knowledge_base_service/has_kb_index';
import { getInferenceIdFromWriteIndex } from '../knowledge_base_service/get_inference_id_from_write_index';
import { updateExistingIndexAssets } from '../index_assets/update_existing_index_assets';

const PLUGIN_STARTUP_LOCK_ID = 'observability_ai_assistant:startup_migrations';
Expand Down Expand Up @@ -56,8 +55,7 @@ export async function runStartupMigrations({
});

if (!isKbSemanticTextCompatible) {
const inferenceId = await getInferenceIdFromWriteIndex(esClient);
await reIndexKnowledgeBaseWithLock({ core, logger, esClient, inferenceId });
await reIndexKnowledgeBaseWithLock({ core, logger, esClient });
}

await pRetry(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export default function ApiTest({ getService }: DeploymentAgnosticFtrProviderCon
const observabilityAIAssistantAPIClient = getService('observabilityAIAssistantApi');

describe('alerts', function () {
// Fails on MKI: https://github.com/elastic/kibana/issues/205581
// LLM Proxy is not yet support in MKI: https://github.com/elastic/obs-ai-assistant-team/issues/199
this.tags(['skipCloud']);
let proxy: LlmProxy;
let connectorId: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ export default function ApiTest({ getService }: DeploymentAgnosticFtrProviderCon
const log = getService('log');

describe('context', function () {
this.tags(['failsOnMKI']);
// LLM Proxy is not yet support in MKI: https://github.com/elastic/obs-ai-assistant-team/issues/199
this.tags(['skipCloud']);
let llmProxy: LlmProxy;
let connectorId: string;
let messageAddedEvents: MessageAddEvent[];
Expand All @@ -84,7 +85,7 @@ export default function ApiTest({ getService }: DeploymentAgnosticFtrProviderCon
connectorId = await observabilityAIAssistantAPIClient.createProxyActionConnector({
port: llmProxy.getPort(),
});
await restoreIndexAssets(observabilityAIAssistantAPIClient, es);
await restoreIndexAssets(getService);
await deployTinyElserAndSetupKb(getService);
await addSampleDocsToInternalKb(getService, sampleDocsForInternalKb);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default function ApiTest({ getService }: DeploymentAgnosticFtrProviderCon
const observabilityAIAssistantAPIClient = getService('observabilityAIAssistantApi');

describe('elasticsearch', function () {
// Fails on MKI: https://github.com/elastic/kibana/issues/205581
// LLM Proxy is not yet support in MKI: https://github.com/elastic/obs-ai-assistant-team/issues/199
this.tags(['skipCloud']);
let proxy: LlmProxy;
let connectorId: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default function ApiTest({ getService }: DeploymentAgnosticFtrProviderCon
const observabilityAIAssistantAPIClient = getService('observabilityAIAssistantApi');

describe('summarize', function () {
// Fails on MKI: https://github.com/elastic/kibana/issues/205581
// LLM Proxy is not yet support in MKI: https://github.com/elastic/obs-ai-assistant-team/issues/199
this.tags(['skipCloud']);
let proxy: LlmProxy;
let connectorId: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ export default function ApiTest({ getService }: DeploymentAgnosticFtrProviderCon
const logger = getLoggerMock(log);

describe('LockManager', function () {
// see details: https://github.com/elastic/kibana/issues/219091
this.tags(['failsOnMKI']);
// These tests should be moved to Jest Integration tests: https://github.com/elastic/kibana/issues/216690
this.tags(['skipCloud']);
before(async () => {
// delete existing index mappings to ensure we start from a clean state
await deleteLockIndexAssets(es, log);
Expand All @@ -52,7 +52,6 @@ export default function ApiTest({ getService }: DeploymentAgnosticFtrProviderCon
});

describe('Manual locking API', function () {
this.tags(['failsOnMKI']);
before(async () => {
await clearAllLocks(es, log);
});
Expand Down Expand Up @@ -454,7 +453,6 @@ export default function ApiTest({ getService }: DeploymentAgnosticFtrProviderCon
});

describe('withLock API', function () {
this.tags(['failsOnMKI']);
before(async () => {
await clearAllLocks(es, log);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default function ApiTest({ getService }: DeploymentAgnosticFtrProviderCon

describe('index assets: creating mappings, templates, aliases and write indices', () => {
before(async () => {
await restoreIndexAssets(observabilityAIAssistantAPIClient, es);
await restoreIndexAssets(getService);
});

for (const componentTemplateName of Object.values(resourceNames.componentTemplate)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export default function ApiTest({ getService }: DeploymentAgnosticFtrProviderCon

after(async () => {
log.info('Restoring index assets');
await restoreIndexAssets(observabilityAIAssistantAPIClient, es);
await restoreIndexAssets(getService);

log.info('Tearing down tiny ELSER model and inference endpoint');
await teardownTinyElserModelAndInferenceEndpoint(getService);
Expand All @@ -57,7 +57,7 @@ export default function ApiTest({ getService }: DeploymentAgnosticFtrProviderCon
describe('before running migrations', () => {
before(async () => {
log.info('Delete index assets');
await deleteIndexAssets(es);
await deleteIndexAssets(getService);

log.info('Restoring snapshot');
await restoreKbSnapshot({
Expand Down Expand Up @@ -99,7 +99,7 @@ export default function ApiTest({ getService }: DeploymentAgnosticFtrProviderCon

describe('after running migrations', () => {
beforeEach(async () => {
await deleteIndexAssets(es);
await deleteIndexAssets(getService);
await restoreKbSnapshot({
log,
es,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export default function ApiTest({ getService }: DeploymentAgnosticFtrProviderCon

before(async () => {
await teardownTinyElserModelAndInferenceEndpoint(getService);
await deleteIndexAssets(es);
await deleteIndexAssets(getService);
await restoreKbSnapshot({
log,
es,
Expand All @@ -56,7 +56,7 @@ export default function ApiTest({ getService }: DeploymentAgnosticFtrProviderCon

after(async () => {
await teardownTinyElserModelAndInferenceEndpoint(getService);
await restoreIndexAssets(observabilityAIAssistantAPIClient, es);
await restoreIndexAssets(getService);
});

describe('before migrating', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ export default function ApiTest({ getService }: DeploymentAgnosticFtrProviderCon
const es = getService('es');
const retry = getService('retry');
const log = getService('log');
const ml = getService('ml');

// In 8.18 inference happens via the custom inference endpoint "obs_ai_assistant_kb_inference"
// In 8.19 / 9.1 the custom inference endpoint ("obs_ai_assistant_kb_inference") is replaced with the preconfigured endpoint ".elser-2-elasticsearch"
Expand All @@ -39,12 +38,12 @@ export default function ApiTest({ getService }: DeploymentAgnosticFtrProviderCon
this.tags(['skipServerless']);

before(async () => {
await importModel(ml, { modelId: TINY_ELSER_MODEL_ID });
await importModel(getService, { modelId: TINY_ELSER_MODEL_ID });
await createTinyElserInferenceEndpoint(getService, {
inferenceId: LEGACY_CUSTOM_INFERENCE_ID,
});

await deleteIndexAssets(es);
await deleteIndexAssets(getService);
await restoreKbSnapshot({
log,
es,
Expand All @@ -57,7 +56,7 @@ export default function ApiTest({ getService }: DeploymentAgnosticFtrProviderCon
});

after(async () => {
await restoreIndexAssets(observabilityAIAssistantAPIClient, es);
await restoreIndexAssets(getService);
await deleteModel(getService, { modelId: TINY_ELSER_MODEL_ID });
await deleteInferenceEndpoint(getService, { inferenceId: LEGACY_CUSTOM_INFERENCE_ID });
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export default function ApiTest({ getService }: DeploymentAgnosticFtrProviderCon
let e5WriteIndex: string;

before(async () => {
await importModel(ml, { modelId: TINY_ELSER_MODEL_ID });
await importModel(getService, { modelId: TINY_ELSER_MODEL_ID });
await createTinyElserInferenceEndpoint(getService, { inferenceId: TINY_ELSER_INFERENCE_ID });
await setupKnowledgeBase(observabilityAIAssistantAPIClient, TINY_ELSER_INFERENCE_ID);
await waitForKnowledgeBaseReady(getService);
Expand All @@ -71,7 +71,7 @@ export default function ApiTest({ getService }: DeploymentAgnosticFtrProviderCon
elserWriteIndex = await getConcreteWriteIndexFromAlias(es);

// setup KB with E5-like model
await importModel(ml, { modelId: TINY_TEXT_EMBEDDING_MODEL_ID });
await importModel(getService, { modelId: TINY_TEXT_EMBEDDING_MODEL_ID });
await ml.api.startTrainedModelDeploymentES(TINY_TEXT_EMBEDDING_MODEL_ID);
await createTinyTextEmbeddingInferenceEndpoint(getService, {
inferenceId: TINY_TEXT_EMBEDDING_INFERENCE_ID,
Expand Down Expand Up @@ -99,7 +99,7 @@ export default function ApiTest({ getService }: DeploymentAgnosticFtrProviderCon
await deleteModel(getService, { modelId: TINY_TEXT_EMBEDDING_MODEL_ID });
await deleteInferenceEndpoint(getService, { inferenceId: TINY_TEXT_EMBEDDING_INFERENCE_ID });

await restoreIndexAssets(observabilityAIAssistantAPIClient, es);
await restoreIndexAssets(getService);
});

describe('when model is ELSER', () => {
Expand Down
Loading