Skip to content

Make Agentless Connectors task handle connector.deleted properly#206606

Merged
artem-shelkovnikov merged 9 commits intomainfrom
artem/make-agentless-connectors-task-handle-soft-deletion
Jan 16, 2025
Merged

Make Agentless Connectors task handle connector.deleted properly#206606
artem-shelkovnikov merged 9 commits intomainfrom
artem/make-agentless-connectors-task-handle-soft-deletion

Conversation

@artem-shelkovnikov
Copy link
Member

@artem-shelkovnikov artem-shelkovnikov commented Jan 14, 2025

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.

  • Any text added follows EUI's writing guidelines, uses sentence case text and includes i18n support
  • Documentation was added for features that require explanation or tutorials
  • Unit or functional tests 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
  • 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 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

@artem-shelkovnikov artem-shelkovnikov requested a review from a team as a code owner January 14, 2025 15:32
@artem-shelkovnikov artem-shelkovnikov added backport:skip This PR does not require backporting release_note:skip Skip the PR/issue when compiling release notes labels Jan 14, 2025
Copy link
Contributor

@jedrazb jedrazb left a comment

Choose a reason for hiding this comment

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

Overall LGTM, I left a few comments that IMO are blocking (connector type def and handling nulls) and some nits

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 &&
Copy link
Contributor

Choose a reason for hiding this comment

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

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

Copy link
Contributor

Choose a reason for hiding this comment

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

maybe more elegant with every lib function:

Suggested change
packagePolicies.filter((y) => y.connector_settings.id === x.id).length === 0 &&
packagePolicies.every((policy) => policy.connector_settings.id !== x.id)

Copy link
Member Author

Choose a reason for hiding this comment

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

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
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: same, maybe let's split it up into separate boolean statements and join with && in return

Copy link
Contributor

Choose a reason for hiding this comment

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

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,
Copy link
Contributor

@jedrazb jedrazb Jan 16, 2025

Choose a reason for hiding this comment

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

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 ...

Copy link
Member Author

Choose a reason for hiding this comment

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

Makes sense :)

Copy link
Contributor

@jedrazb jedrazb left a comment

Choose a reason for hiding this comment

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

LGTM! Nice one!

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Public APIs missing comments

Total count of every public API that lacks a comment. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats comments for more detailed information.

id before after diff
@kbn/search-connectors 3954 3956 +2

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
enterpriseSearch 1.6MB 1.6MB +20.0B
Unknown metric groups

API count

id before after diff
@kbn/search-connectors 3954 3956 +2

History

@artem-shelkovnikov artem-shelkovnikov merged commit f2a7d90 into main Jan 16, 2025
@artem-shelkovnikov artem-shelkovnikov deleted the artem/make-agentless-connectors-task-handle-soft-deletion branch January 16, 2025 11:54
viduni94 pushed a commit to viduni94/kibana that referenced this pull request Jan 23, 2025
…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport:skip This PR does not require backporting release_note:skip Skip the PR/issue when compiling release notes v9.0.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants