Make Agentless Connectors task handle connector.deleted properly#206606
Conversation
jedrazb
left a comment
There was a problem hiding this comment.
Overall LGTM, I left a few comments that IMO are blocking (connector type def and handling nulls) and some nits
src/platform/packages/shared/kbn-search-connectors/types/connectors.ts
Outdated
Show resolved
Hide resolved
x-pack/solutions/search/plugins/search_connectors/server/services/index.ts
Show resolved
Hide resolved
| return connectors.filter( | ||
| (x) => packagePolicies.filter((y) => y.connector_metadata.id === x.id).length === 0 | ||
| (x) => | ||
| packagePolicies.filter((y) => y.connector_settings.id === x.id).length === 0 && |
There was a problem hiding this comment.
nit: I once got linked this on my PR Cognitive load is what matters: complex conditionals
I'm struggling to parse this boolean expression in my head, maybe we can split it up:
const statementIWithClearName1 = ...
const statementIWithClearName2 = ...
return statementIWithClearName1 && statementIWithClearName2
There was a problem hiding this comment.
maybe more elegant with every lib function:
| packagePolicies.filter((y) => y.connector_settings.id === x.id).length === 0 && | |
| packagePolicies.every((policy) => policy.connector_settings.id !== x.id) |
There was a problem hiding this comment.
Lemme see how I can make it simpler
| return packagePolicies.filter( | ||
| (x) => connectors.filter((y) => y.id === x.connector_metadata.id).length === 0 | ||
| (x) => | ||
| connectors.filter((y) => y.id === x.connector_settings.id && y.is_deleted === true).length > 0 |
There was a problem hiding this comment.
nit: same, maybe let's split it up into separate boolean statements and join with && in return
There was a problem hiding this comment.
instead of filter we can use some js lib function
| id: connector.id, | ||
| name: connector.name, | ||
| service_type: connector.service_type, | ||
| is_deleted: connector.deleted, |
There was a problem hiding this comment.
I would use !!connector.deleted or Boolean(connector.deleted)
This handles cases where deleted might be null (not present in connector doc) for older connectors by explicitly casting it to a boolean. Otherwise, you would need to account for this in your logic later on. JS is fun ...
There was a problem hiding this comment.
Makes sense :)
💚 Build Succeeded
Metrics [docs]Public APIs missing comments
Async chunks
History
|
…stic#206606) ## Summary This PR makes it so that the Agentless Kibana task implemented in elastic#203973 properly handles soft-deleted connectors. This helps with the situation when an integration policy has been created for an agentless connector but a connector record has not yet been created by an agentless host. With current Kibana task implementation it could lead to the Policy being deleted. With this change, only policies that refer to soft-deleted connectors will be cleaned up. ### Checklist Check the PR satisfies following conditions. Reviewers should verify this PR satisfies this list as well. - [ ] Any text added follows [EUI's writing guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md) - [ ] [Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html) was added for features that require explanation or tutorials - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios - [ ] If a plugin configuration key changed, check if it needs to be allowlisted in the cloud and added to the [docker list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker) - [ ] This was checked for breaking HTTP API changes, and any breaking changes have been approved by the breaking-change committee. The `release_note:breaking` label should be applied in these situations. - [ ] [Flaky Test Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was used on any tests changed - [ ] The PR description includes the appropriate Release Notes section, and the correct `release_note:*` label is applied per the [guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process) --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Summary
This PR makes it so that the Agentless Kibana task implemented in #203973 properly handles soft-deleted connectors.
This helps with the situation when an integration policy has been created for an agentless connector but a connector record has not yet been created by an agentless host.
With current Kibana task implementation it could lead to the Policy being deleted.
With this change, only policies that refer to soft-deleted connectors will be cleaned up.
Checklist
Check the PR satisfies following conditions.
Reviewers should verify this PR satisfies this list as well.
release_note:breakinglabel should be applied in these situations.release_note:*label is applied per the guidelines