Skip to content

Commit

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

# Backport

This will backport the following commits from `main` to `8.15`:
- [[Search] Fix issue with crawler not getting deleted
(#195440)](#195440)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Jedr
Blaszyk","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-10-08T17:30:46Z","message":"[Search]
Fix issue with crawler not getting deleted (#195440)\n\n##
Summary\r\n\r\nThe bug is that connector doc can be of `elastic-crawler`
service type,\r\nwe forgot about this in the logic that handles
detaching the index from\r\nconnector upon index delation.\r\n\r\nThis
change checks if a connector doc, matching the `index_name` to
be\r\ndeleted, is of crawler type:\r\n- If yes, delete the connector
(crawler) doc, as crawler is always tied\r\n1:1 to an index\r\n- If no,
detach the index, leave the connector doc in the
connector\r\nindex\r\n\r\nThis bug was likely introduced as a part
of:\r\nhttps://github.com//pull/183833 (some lazy engineer
forgot\r\nto test for this edge case ...)\r\n\r\n##
Validation\r\n\r\n### Delete Crawler case 1: Delete Crawler deletes
crawler doc +
related\r\nindex\r\n\r\n\r\nhttps://github.com/user-attachments/assets/68ad14f7-4a7f-408c-8731-6ed0465f9ef1\r\n\r\n###
Delete Crawler case 2: Delete crawler-related index deletes
crawler\r\ndoc\r\n\r\n\r\nhttps://github.com/user-attachments/assets/e2995697-32c4-4f8f-90ce-9c06c7e6d208","sha":"bf621693f20b012593ec5fcb84c7386da952aeb3","branchLabelMapping":{"^v9.0.0$":"main","^v8.16.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","v9.0.0","v8.16.0","backport:version","v8.15.3"],"title":"[Search]
Fix issue with crawler not getting
deleted","number":195440,"url":"https://github.com/elastic/kibana/pull/195440","mergeCommit":{"message":"[Search]
Fix issue with crawler not getting deleted (#195440)\n\n##
Summary\r\n\r\nThe bug is that connector doc can be of `elastic-crawler`
service type,\r\nwe forgot about this in the logic that handles
detaching the index from\r\nconnector upon index delation.\r\n\r\nThis
change checks if a connector doc, matching the `index_name` to
be\r\ndeleted, is of crawler type:\r\n- If yes, delete the connector
(crawler) doc, as crawler is always tied\r\n1:1 to an index\r\n- If no,
detach the index, leave the connector doc in the
connector\r\nindex\r\n\r\nThis bug was likely introduced as a part
of:\r\nhttps://github.com//pull/183833 (some lazy engineer
forgot\r\nto test for this edge case ...)\r\n\r\n##
Validation\r\n\r\n### Delete Crawler case 1: Delete Crawler deletes
crawler doc +
related\r\nindex\r\n\r\n\r\nhttps://github.com/user-attachments/assets/68ad14f7-4a7f-408c-8731-6ed0465f9ef1\r\n\r\n###
Delete Crawler case 2: Delete crawler-related index deletes
crawler\r\ndoc\r\n\r\n\r\nhttps://github.com/user-attachments/assets/e2995697-32c4-4f8f-90ce-9c06c7e6d208","sha":"bf621693f20b012593ec5fcb84c7386da952aeb3"}},"sourceBranch":"main","suggestedTargetBranches":["8.x","8.15"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/195440","number":195440,"mergeCommit":{"message":"[Search]
Fix issue with crawler not getting deleted (#195440)\n\n##
Summary\r\n\r\nThe bug is that connector doc can be of `elastic-crawler`
service type,\r\nwe forgot about this in the logic that handles
detaching the index from\r\nconnector upon index delation.\r\n\r\nThis
change checks if a connector doc, matching the `index_name` to
be\r\ndeleted, is of crawler type:\r\n- If yes, delete the connector
(crawler) doc, as crawler is always tied\r\n1:1 to an index\r\n- If no,
detach the index, leave the connector doc in the
connector\r\nindex\r\n\r\nThis bug was likely introduced as a part
of:\r\nhttps://github.com//pull/183833 (some lazy engineer
forgot\r\nto test for this edge case ...)\r\n\r\n##
Validation\r\n\r\n### Delete Crawler case 1: Delete Crawler deletes
crawler doc +
related\r\nindex\r\n\r\n\r\nhttps://github.com/user-attachments/assets/68ad14f7-4a7f-408c-8731-6ed0465f9ef1\r\n\r\n###
Delete Crawler case 2: Delete crawler-related index deletes
crawler\r\ndoc\r\n\r\n\r\nhttps://github.com/user-attachments/assets/e2995697-32c4-4f8f-90ce-9c06c7e6d208","sha":"bf621693f20b012593ec5fcb84c7386da952aeb3"}},{"branch":"8.x","label":"v8.16.0","branchLabelMappingKey":"^v8.16.0$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.15","label":"v8.15.3","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Jedr Blaszyk <[email protected]>
  • Loading branch information
kibanamachine and jedrazb authored Oct 8, 2024
1 parent 9ae33e4 commit 42ba6b3
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 42ba6b3

Please sign in to comment.