Skip to content

[Fleet] Auto install content packages task#226523

Merged
juliaElastic merged 22 commits intoelastic:mainfrom
juliaElastic:auto-install-content-packages
Jul 15, 2025
Merged

[Fleet] Auto install content packages task#226523
juliaElastic merged 22 commits intoelastic:mainfrom
juliaElastic:auto-install-content-packages

Conversation

@juliaElastic
Copy link
Copy Markdown
Contributor

@juliaElastic juliaElastic commented Jul 4, 2025

Summary

Adjusted to datasets field elastic/package-spec#922

Closes https://github.com/elastic/ingest-dev/issues/5685

Added kibana task to check discovery dataset fields of content packages in EPR, check recent data ingested for matching fields, and install content packages if not installed yet.

Added telemetry mappings: https://github.com/elastic/telemetry/pull/4940

To verify:

  • enable feature flag in kibana.dev.yml: xpack.fleet.enableExperimental: ['enableAutoInstallContentPackages']
  • TODO start local epr with test package that has a discovery.datasets with a value (e.g. system.cpu), depends on package-spec change to be available
  • enroll an agent and wait until some data is ingested to the dataset above
  • wait 10m for the task to run
  • verify that the test package is installed

Kibana logs:

[2025-07-10T14:07:13.177+02:00][INFO ][plugins.fleet.fleet:auto-install-content-packages-task:1.0.1] [runTask()] started
[2025-07-10T14:07:13.206+02:00][DEBUG][plugins.fleet.fleet:auto-install-content-packages-task:1.0.1] [AutoInstallContentPackagesTask] ESQL query took: 11ms
[2025-07-10T14:07:13.207+02:00][DEBUG][plugins.fleet.fleet:auto-install-content-packages-task:1.0.1] [AutoInstallContentPackagesTask] Found datasets with data: fleet_server.agent_versions, fleet_server.agent_status, elastic_agent.fleet_server
[2025-07-10T14:07:13.207+02:00][DEBUG][plugins.fleet.fleet:auto-install-content-packages-task:1.0.1] [AutoInstallContentPackagesTask] Content packages to install: kubernetes_otel@1.1.0
[2025-07-10T14:07:13.208+02:00][DEBUG][plugins.fleet] Kicking off install of kubernetes_otel-1.1.0 from registry
[2025-07-10T14:07:15.605+02:00][INFO ][plugins.fleet.fleet:auto-install-content-packages-task:1.0.1] [AutoInstallContentPackagesTask] runTask ended: success

Checklist

@juliaElastic juliaElastic self-assigned this Jul 4, 2025
@juliaElastic juliaElastic added backport:skip This PR does not require backporting release_note:feature Makes this part of the condensed release notes labels Jul 4, 2025
@juliaElastic juliaElastic marked this pull request as ready for review July 7, 2025 11:36
@juliaElastic juliaElastic requested review from a team as code owners July 7, 2025 11:36
@botelastic botelastic bot added the Team:Fleet Team label for Observability Data Collection Fleet team label Jul 7, 2025
@elasticmachine
Copy link
Copy Markdown
Contributor

Pinging @elastic/fleet (Team:Fleet)

@juliaElastic juliaElastic marked this pull request as draft July 8, 2025 08:25
telemetryEvent.currentVersion = installedPkg?.attributes.version || 'not_installed';
telemetryEvent.packageType = packageInfo.type;
telemetryEvent.discoveryFields = packageInfo.discovery?.fields;
telemetryEvent.automaticInstall = automaticInstall;
Copy link
Copy Markdown
Contributor Author

@juliaElastic juliaElastic Jul 8, 2025

Choose a reason for hiding this comment

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

sending telemetry event like this:

{
  packageName: 'kubernetes_otel',
  currentVersion: 'not_installed',
  newVersion: '1.1.0',
  status: 'success',
  dryRun: false,
  eventType: 'package-install',
  installType: 'install',
  packageType: 'content',
  discoveryDatasets: [ { name: 'system.cpu' } ],
  automaticInstall: true
}

@juliaElastic juliaElastic marked this pull request as ready for review July 9, 2025 07:46
continue;
}

const hasData = await this.hasDiscoveryFieldData(esClient, dataset);
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.

I'm not sure how much overlap there will be in content packs dataset fields.
Currently doing an ES search for each dataset value (as they can map to multiple packages).

Alternatively we could go by package and do a single terms query with all dataset values at once.
Another option would be to do a single terms aggregation on the dataset field, and compare results with dataset fields in content packages.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is it worth exploring ESQL for these queries at all to simplify anything here, or is the DSL our best bet? We definitely want to minimize the amount of queries we run here and keep them lightweight as the index patterns we query are going to be under heavy write pressure from agents, collectors, etc in large environments.

Copy link
Copy Markdown
Contributor Author

@juliaElastic juliaElastic Jul 10, 2025

Choose a reason for hiding this comment

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

Changed the implementation to use a single ESQL query to get the unique datasets that appear in the recently ingested data, filtering out the dataset fields from the already installed content packs.
We would have to test the performance of this query on large clusters.

Copy link
Copy Markdown
Contributor

@MichelLosier MichelLosier left a comment

Choose a reason for hiding this comment

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

Code looks good! Working on the local setup to verify

juliaElastic and others added 2 commits July 14, 2025 09:00
@elasticmachine
Copy link
Copy Markdown
Contributor

💛 Build succeeded, but was flaky

Failed CI Steps

Test Failures

  • [job] [logs] Fleet Cypress Tests #2 / View agents list Agent status filter should filter on healthy and unhealthy
  • [job] [logs] Fleet Cypress Tests #2 / View agents list Bulk actions should allow to bulk upgrade agents and cancel that upgrade

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
fleet 1433 1435 +2

Public APIs missing exports

Total count of every type that is part of your API that should be exported but is not. This will cause broken links in the API documentation system. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats exports for more detailed information.

id before after diff
fleet 97 98 +1

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
fleet 166.9KB 166.9KB +36.0B
Unknown metric groups

API count

id before after diff
fleet 1564 1566 +2

History

cc @juliaElastic

Copy link
Copy Markdown
Contributor

@ersin-erdal ersin-erdal left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Copy Markdown
Contributor

@MichelLosier MichelLosier left a comment

Choose a reason for hiding this comment

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

Runs as expected!

  • Ran it with this package-registry PR: elastic/package-registry#1338
  • For the good_content package discovery fields to get picked up I had to:
    • In auto_install_content_packages_task:322 I set prerelease to true
    • In Registry.fetchList comment out the setConstraints
    • Also added elastic_agent.filebeat as a discovery field to good_content

@juliaElastic juliaElastic merged commit 4df9932 into elastic:main Jul 15, 2025
11 of 12 checks passed
Bluefinger pushed a commit to Bluefinger/kibana that referenced this pull request Jul 22, 2025
## Summary

Adjusted to datasets field
elastic/package-spec#922

Closes elastic/ingest-dev#5685

Added kibana task to check discovery dataset fields of content packages
in EPR, check recent data ingested for matching fields, and install
content packages if not installed yet.

Added telemetry mappings: elastic/telemetry#4940

To verify:
- enable feature flag in `kibana.dev.yml`:
`xpack.fleet.enableExperimental: ['enableAutoInstallContentPackages']`
- TODO start local epr with test package that has a `discovery.datasets`
with a value (e.g. system.cpu), depends on
[package-spec](elastic/package-spec#922) change
to be available
- enroll an agent and wait until some data is ingested to the dataset
above
- wait 10m for the task to run
- verify that the test package is installed

Kibana logs:
```
[2025-07-10T14:07:13.177+02:00][INFO ][plugins.fleet.fleet:auto-install-content-packages-task:1.0.1] [runTask()] started
[2025-07-10T14:07:13.206+02:00][DEBUG][plugins.fleet.fleet:auto-install-content-packages-task:1.0.1] [AutoInstallContentPackagesTask] ESQL query took: 11ms
[2025-07-10T14:07:13.207+02:00][DEBUG][plugins.fleet.fleet:auto-install-content-packages-task:1.0.1] [AutoInstallContentPackagesTask] Found datasets with data: fleet_server.agent_versions, fleet_server.agent_status, elastic_agent.fleet_server
[2025-07-10T14:07:13.207+02:00][DEBUG][plugins.fleet.fleet:auto-install-content-packages-task:1.0.1] [AutoInstallContentPackagesTask] Content packages to install: kubernetes_otel@1.1.0
[2025-07-10T14:07:13.208+02:00][DEBUG][plugins.fleet] Kicking off install of kubernetes_otel-1.1.0 from registry
[2025-07-10T14:07:15.605+02:00][INFO ][plugins.fleet.fleet:auto-install-content-packages-task:1.0.1] [AutoInstallContentPackagesTask] runTask ended: success
```

### Checklist

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

---------

Co-authored-by: Michel Losier <mikelosier@gmail.com>
kertal pushed a commit to kertal/kibana that referenced this pull request Jul 25, 2025
## Summary

Adjusted to datasets field
elastic/package-spec#922

Closes elastic/ingest-dev#5685

Added kibana task to check discovery dataset fields of content packages
in EPR, check recent data ingested for matching fields, and install
content packages if not installed yet.

Added telemetry mappings: elastic/telemetry#4940

To verify:
- enable feature flag in `kibana.dev.yml`:
`xpack.fleet.enableExperimental: ['enableAutoInstallContentPackages']`
- TODO start local epr with test package that has a `discovery.datasets`
with a value (e.g. system.cpu), depends on
[package-spec](elastic/package-spec#922) change
to be available
- enroll an agent and wait until some data is ingested to the dataset
above
- wait 10m for the task to run
- verify that the test package is installed

Kibana logs:
```
[2025-07-10T14:07:13.177+02:00][INFO ][plugins.fleet.fleet:auto-install-content-packages-task:1.0.1] [runTask()] started
[2025-07-10T14:07:13.206+02:00][DEBUG][plugins.fleet.fleet:auto-install-content-packages-task:1.0.1] [AutoInstallContentPackagesTask] ESQL query took: 11ms
[2025-07-10T14:07:13.207+02:00][DEBUG][plugins.fleet.fleet:auto-install-content-packages-task:1.0.1] [AutoInstallContentPackagesTask] Found datasets with data: fleet_server.agent_versions, fleet_server.agent_status, elastic_agent.fleet_server
[2025-07-10T14:07:13.207+02:00][DEBUG][plugins.fleet.fleet:auto-install-content-packages-task:1.0.1] [AutoInstallContentPackagesTask] Content packages to install: kubernetes_otel@1.1.0
[2025-07-10T14:07:13.208+02:00][DEBUG][plugins.fleet] Kicking off install of kubernetes_otel-1.1.0 from registry
[2025-07-10T14:07:15.605+02:00][INFO ][plugins.fleet.fleet:auto-install-content-packages-task:1.0.1] [AutoInstallContentPackagesTask] runTask ended: success
```

### Checklist

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

---------

Co-authored-by: Michel Losier <mikelosier@gmail.com>
@juliaElastic juliaElastic added release_note:skip Skip the PR/issue when compiling release notes and removed release_note:feature Makes this part of the condensed release notes labels Aug 22, 2025
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 Team:Fleet Team label for Observability Data Collection Fleet team v9.2.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants