Skip to content

[Fleet] Refactor setup to load default packages/policies with preconfiguration#97328

Merged
Zacqary merged 27 commits intoelastic:masterfrom
Zacqary:97106-default-config-policy
Apr 22, 2021
Merged

[Fleet] Refactor setup to load default packages/policies with preconfiguration#97328
Zacqary merged 27 commits intoelastic:masterfrom
Zacqary:97106-default-config-policy

Conversation

@Zacqary
Copy link
Copy Markdown
Contributor

@Zacqary Zacqary commented Apr 15, 2021

Summary

Closes #97016

This removes the bespoke functions for installing default packages and configuring the default agent policies, and instead sets these as the default Kibana Config values for the preconfiguration API.

Testing

Default setup

  1. Remove all references to xpack.fleet from your kibana.dev.yml
  2. Start Kibana and navigate to the Fleet app
  3. Ensure that the Default Agent Policy and Default Fleet Server Agent Policy have been created
  4. Ensure that the System, Endpoint Security, Elastic Agent, and Fleet Server integrations are installed

Overriding the defaults

  1. Restart your yarn es snapshot to clear your cluster, then set your kibana.dev.yml to:
xpack.fleet.packages:
  - name: system
    version: latest
  - name: endpoint
    version: latest
  - name: elastic_agent
    version: latest
  - name: fleet_server
    version: 0.2.0
  - name: apache
    version: latest

Ensure that all five of these integrations are installed, and that Fleet Server is installed with an outdated version.

  1. Restart yarn es snapshot again, then set your kibana.dev.yml to:
xpack.fleet.agentPolicies:
  - name: Alternative Default Agent Policy
    id: 1
    namespace: test
    is_default: true
    monitoring_enabled: []
    package_policies:
      - package:
          name: system
        name: System Integration
  - name: Alternative Default Fleet Server Agent Policy
    id: 2
    namespace: test
    is_default_fleet_server: true
    package_policies:
      - package:
          name: fleet_server
        name: Fleet Server Integration

Ensure that the default policies are created with these alternative names and that agent monitoring is disabled for the default policy, but enabled for the default fleet server policy. Try to delete them, and ensure that they fail to be deleted.

  1. Restart yarn es snapshot again, then change your kibana.dev.yml to:
xpack.fleet.agentPolicies:
  - name: Agent Policy With No Default
    id: 1
    namespace: test
    package_policies:
      - package:
          name: system
        name: System Integration

Ensure that Fleet starts with only this one policy, and that it can be deleted.

Checklist

@Zacqary Zacqary added Feature:Fleet Fleet team's agent central management project Team:Fleet Team label for Observability Data Collection Fleet team v7.13.0 v8.0.0 release_note:skip Skip the PR/issue when compiling release notes labels Apr 15, 2021
@Zacqary Zacqary self-assigned this Apr 15, 2021
@Zacqary Zacqary force-pushed the 97106-default-config-policy branch from 1232e32 to 70d002e Compare April 15, 2021 22:03
@Zacqary Zacqary changed the title [Fleet] Refactor setup to setup default packages/policies with preconfiguration [Fleet] Refactor setup to load default packages/policies with preconfiguration Apr 15, 2021
@Zacqary Zacqary marked this pull request as ready for review April 15, 2021 22:08
@Zacqary Zacqary requested a review from a team as a code owner April 15, 2021 22:08
@elasticmachine
Copy link
Copy Markdown
Contributor

Pinging @elastic/fleet (Feature:Fleet)

@ruflin ruflin requested review from afgomez and jen-huang April 16, 2021 11:56
@ruflin
Copy link
Copy Markdown
Contributor

ruflin commented Apr 16, 2021

Tried to run this locally and got the following error when accessing the Fleet page:

server    log   [14:08:07.108] [error][fleet][plugins] TypeError: Cannot read property 'search' of undefined
    at AgentPolicyService.getLatestFleetPolicy (/Users/ruflin/Dev/elastic/kibana/x-pack/plugins/fleet/server/services/agent_policy.ts:608:32)
    at map (/Users/ruflin/Dev/elastic/kibana/x-pack/plugins/fleet/server/services/agents/setup.ts:29:67)
    at Array.map (<anonymous>)
    at ensureAgentActionPolicyChangeExists (/Users/ruflin/Dev/elastic/kibana/x-pack/plugins/fleet/server/services/agents/setup.ts:28:19)
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at createSetupSideEffects (/Users/ruflin/Dev/elastic/kibana/x-pack/plugins/fleet/server/services/setup.ts:74:3)
    at awaitIfPending (/Users/ruflin/Dev/elastic/kibana/x-pack/plugins/fleet/server/services/setup_utils.ts:30:20)
    at fleetSetupHandler (/Users/ruflin/Dev/elastic/kibana/x-pack/plugins/fleet/server/routes/setup/handlers.ts:50:5)
    at Router.handle (/Users/ruflin/Dev/elastic/kibana/src/core/server/http/router/router.ts:272:30)
    at handler (/Users/ruflin/Dev/elastic/kibana/src/core/server/http/router/router.ts:227:11)
    at exports.Manager.execute (/Users/ruflin/Dev/elastic/kibana/node_modules/@hapi/hapi/lib/toolkit.js:60:28)
    at Object.internals.handler (/Users/ruflin/Dev/elastic/kibana/node_modules/@hapi/hapi/lib/handler.js:46:20)
    at exports.execute (/Users/ruflin/Dev/elastic/kibana/node_modules/@hapi/hapi/lib/handler.js:31:20)
    at Request._lifecycle (/Users/ruflin/Dev/elastic/kibana/node_modules/@hapi/hapi/lib/request.js:370:32)
    at Request._execute (/Users/ruflin/Dev/elastic/kibana/node_modules/@hapi/hapi/lib/request.js:279:9)

Screenshot 2021-04-16 at 14 08 31

The above is without any changes in the config file.

Copy link
Copy Markdown
Contributor

@afgomez afgomez left a comment

Choose a reason for hiding this comment

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

I did a first pass downloading the code and clicking around. I noticed the following things

  1. Default packages

I have this in my kibana.dev.yml

xpack.fleet.packages:
  - name: system
    version: latest
  - name: endpoint
    version: latest
  - name: elastic_agent
    version: latest
  - name: fleet_server
    version: 0.1.9
  - name: apache
    version: latest

Packages with latest version get installed, but fleet server is not.

Screenshot 2021-04-19 at 11 21 42

  1. Alternative default agent policies

I restarted everything with this on my kibana.dev.yml

xpack.fleet.agentPolicies:
  - name: Alternative Default Agent Policy
    id: 1
    namespace: test
    is_default: true
    package_policies:
      - package:
          name: system
        name: System Integration
  - name: Alternative Default Fleet Server Agent Policy
    id: 1
    namespace: test
    is_default_fleet_server: true
    package_policies:
      - package:
          name: fleet_server
        name: Fleet Server Integration

No agent policies were added

Screenshot 2021-04-19 at 11 37 42

  1. Agent policy with no default

Same happens as in point 2 :(

@jen-huang
Copy link
Copy Markdown
Contributor

I am seeing the same as what @afgomez reported.

Zacqary added 2 commits April 19, 2021 11:03
…fig-policy

# Conflicts:
#	x-pack/plugins/fleet/server/services/epm/packages/install.ts
#	x-pack/plugins/fleet/server/services/setup.ts
export interface SetupStatus {
isInitialized: boolean;
preconfigurationError: { name: string; message: string } | undefined;
nonFatalPackageUpgradeErrors: DefaultPackagesInstallationError[];
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is this undoing my work from #97404 ? Is this intentional?
Cc @ruflin

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.

Not intentional, I just wasn't immediately sure how to deal with the merge conflict. I'll get this back in.

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 think this actually mostly duplicates the functionality of preconfigurationError. I'll reconcile the differences and streamline.

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.

As of the latest commit, running the test scenario from #97404 results in a preconfigurationError of:

Screen Shot 2021-04-19 at 2 20 39 PM

I can tweak this functionality as needed.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm not sure about getting rid of nonFatalPackageUpgradeErrors and DefaultPackagesInstallationError. I like the explicitness of that interface wrt to package installation and various install types/ops: install/upgrade/rollback. package install handling is a sensitive area that we will want to keep iterating and improving on so I would like to keep the error granularity here.

in contrast, preconfigurationError can be related to package and agent policy errors.

my suggestion, what do you think?:

// export generic `nonFatalErrors` property
export interface SetupStatus {
  isInitialized: boolean;
  nonFatalErrors?: Array<PreconfigurationError |  DefaultPackagesInstallationError>;
}

// add back `DefaultPackagesInstallationError` and return it where appropriate
export interface DefaultPackagesInstallationError {
  installType: InstallType;
  error: Error;
}

// define `PreconfigurationError`
export interface PreconfigurationError {
  package?: { name: string; version: string; };
  agentPolicy?: { name: string; }
  error: Error;
}

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.

Implemented this as best I could. Currently all properties besides error go unused on both error types, but the data is there at least.

@Zacqary
Copy link
Copy Markdown
Contributor Author

Zacqary commented Apr 19, 2021

Packages with latest version get installed, but fleet server is not.

@afgomez Try setting fleet_server to 0.2.0 instead of 0.1.9. I'll see if I can add some error handling for specifying invalid versions.

@Zacqary
Copy link
Copy Markdown
Contributor Author

Zacqary commented Apr 19, 2021

@afgomez As of latest commit, the original test scenario should result in:

Screen Shot 2021-04-19 at 2 26 00 PM

Changing the version to 0.2.0 works as expected.

@Zacqary Zacqary requested a review from afgomez April 19, 2021 19:39
@jfsiii jfsiii added the v7.13.0 label Apr 22, 2021
@jfsiii
Copy link
Copy Markdown
Contributor

jfsiii commented Apr 22, 2021

@spalger we want this to land in 7.13 so I restored the label. LMK if there's some reason we shouldn't use that label to backport to 7.13

@spalger
Copy link
Copy Markdown
Contributor

spalger commented Apr 22, 2021

@spalger we want this to land in 7.13 so I restored the label. LMK if there's some reason we shouldn't use that label to backport to 7.13

Nope, just wanted people to make that decision intentionally and ensure that we didn't have any more people auto-backport to 7.13 without backporting to 7.x.

@jen-huang jen-huang self-requested a review April 22, 2021 03:56
@afgomez
Copy link
Copy Markdown
Contributor

afgomez commented Apr 22, 2021

@elasticmachine merge upstream

@afgomez
Copy link
Copy Markdown
Contributor

afgomez commented Apr 22, 2021

^^^ I think the CI failures are unrelated to this PR. Merging master to trigger another build before @Zacqary comes back online

})
}),
{
defaultValue: [DEFAULT_AGENT_POLICY, DEFAULT_FLEET_SERVER_AGENT_POLICY],
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

what happens if the user has only specified either a default or a default fleet server policy in their preconfiguration? will we still ensure that whichever default one is missing, is added? what if their preconfiguration doesn't specify any default policies?

i think we might want to do the same sort of merging downstream like what you did for default packages

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 was under the impression from discussion on the issue (#97016) that we explicitly did not want to do downstream merging for agent policies, and that the config file should be the source of truth for what the "default policies" are.

Copy link
Copy Markdown
Member

@nchaulet nchaulet left a comment

Choose a reason for hiding this comment

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

Tested the default and a few scenarios, it is working well 👍
Also tested the upgrade from 7.12 to this change and looks good.

@Zacqary
Copy link
Copy Markdown
Contributor Author

Zacqary commented Apr 22, 2021

@jen-huang @nchaulet I'm gonna merge this because it meets the acceptance criteria of the initial issue and I really don't want to wait for the entire CI to run again and then potentially fail.

Can we open a new issue to discuss whether default agentPolicies should also be downstream-merged like required packages, or if the current behavior is fine?

@Zacqary Zacqary merged commit 57f84f8 into elastic:master Apr 22, 2021
@Zacqary Zacqary deleted the 97106-default-config-policy branch April 22, 2021 16:25
Zacqary added a commit to Zacqary/kibana that referenced this pull request Apr 22, 2021
…iguration (elastic#97328)

Co-authored-by: Nicolas Chaulet <nicolas.chaulet@elastic.co>
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
Zacqary added a commit to Zacqary/kibana that referenced this pull request Apr 22, 2021
…iguration (elastic#97328)

Co-authored-by: Nicolas Chaulet <nicolas.chaulet@elastic.co>
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
@jen-huang
Copy link
Copy Markdown
Contributor

@Zacqary 👍🏻 , I'm comfortable with that, thanks for the revisions on this PR over the past week. I'll continue poking and prodding on main branch and raise any issues that come up from there.

Zacqary added a commit that referenced this pull request Apr 22, 2021
…iguration (#97328) (#98053)

Co-authored-by: Nicolas Chaulet <nicolas.chaulet@elastic.co>
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>

Co-authored-by: Nicolas Chaulet <nicolas.chaulet@elastic.co>
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
Zacqary added a commit that referenced this pull request Apr 22, 2021
…iguration (#97328) (#98052)

Co-authored-by: Nicolas Chaulet <nicolas.chaulet@elastic.co>
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>

Co-authored-by: Nicolas Chaulet <nicolas.chaulet@elastic.co>
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
@kibanamachine
Copy link
Copy Markdown
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
fleet 991 993 +2

Async chunks

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

id before after diff
fleet 722.4KB 722.1KB -306.0B

Page load bundle

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

id before after diff
fleet 346.4KB 346.8KB +399.0B
Unknown metric groups

API count

id before after diff
fleet 1081 1083 +2

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

cc @Zacqary

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Feature:Fleet Fleet team's agent central management project release_note:skip Skip the PR/issue when compiling release notes Team:Fleet Team label for Observability Data Collection Fleet team v7.13.0 v7.14.0 v8.0.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Fleet] Define default agent policies using Kibana Config