Skip to content

Commit

Permalink
[Search] Fix issue with crawler not getting deleted (#195440)
Browse files Browse the repository at this point in the history
## Summary

The bug is that connector doc can be of `elastic-crawler` service type,
we forgot about this in the logic that handles detaching the index from
connector upon index delation.

This change checks if a connector doc, matching the `index_name` to be
deleted, is of crawler type:
- If yes, delete the connector (crawler) doc, as crawler is always tied
1:1 to an index
- If no, detach the index, leave the connector doc in the connector
index

This bug was likely introduced as a part of:
#183833 (some lazy engineer forgot
to test for this edge case ...)

## Validation

### Delete Crawler case 1: Delete Crawler deletes crawler doc + related
index

https://github.com/user-attachments/assets/68ad14f7-4a7f-408c-8731-6ed0465f9ef1

### Delete Crawler case 2: Delete crawler-related index deletes crawler
doc

https://github.com/user-attachments/assets/e2995697-32c4-4f8f-90ce-9c06c7e6d208
(cherry picked from commit bf62169)
  • Loading branch information
jedrazb committed Oct 8, 2024
1 parent c6c4d20 commit 375332e
Showing 1 changed file with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ import { schema } from '@kbn/config-schema';

import { i18n } from '@kbn/i18n';

import { deleteConnectorSecret, updateConnectorIndexName } from '@kbn/search-connectors';
import {
CRAWLER_SERVICE_TYPE,
deleteConnectorSecret,
deleteConnectorById,
updateConnectorIndexName,
} from '@kbn/search-connectors';
import {
fetchConnectorByIndexName,
fetchConnectors,
Expand Down Expand Up @@ -207,13 +212,17 @@ export function registerIndexRoutes({
}

if (connector) {
// detach the deleted index without removing the connector
await updateConnectorIndexName(client.asCurrentUser, connector.id, null);
if (connector.api_key_id) {
await client.asCurrentUser.security.invalidateApiKey({ ids: [connector.api_key_id] });
}
if (connector.api_key_secret_id) {
await deleteConnectorSecret(client.asCurrentUser, connector.api_key_secret_id);
if (connector.service_type === CRAWLER_SERVICE_TYPE) {
await deleteConnectorById(client.asCurrentUser, connector.id);
} else {
// detach the deleted index without removing the connector
await updateConnectorIndexName(client.asCurrentUser, connector.id, null);
if (connector.api_key_id) {
await client.asCurrentUser.security.invalidateApiKey({ ids: [connector.api_key_id] });
}
if (connector.api_key_secret_id) {
await deleteConnectorSecret(client.asCurrentUser, connector.api_key_secret_id);
}
}
}

Expand Down

0 comments on commit 375332e

Please sign in to comment.