Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fleet] Simplified package policy create API, enriching default values #119739

Merged
merged 19 commits into from
Dec 7, 2021

Conversation

juliaElastic
Copy link
Contributor

@juliaElastic juliaElastic commented Nov 25, 2021

Summary

Closes #113750

Made most properties optional in POST /api/fleet/package_policies, loading default values from base package.
This is not a breaking change.

Remaining tasks:

  • add/update unit tests - DONE
  • update openapi spec - DONE

To verify:

  • send minimal request to API to check package policy is created with correct defaults
  • if one input is set to enabled: false, it is propagated down to all inputs.streams
  • if package.version does not match the installed base package version, there is an error coming
    e.g.
POST http://elastic:changeme@localhost:5601/julia/api/fleet/package_policies
kbn-xsrf: kibana

{"name":"apache-5","inputs":[{"type":"logfile","enabled":true},{"type":"apache/metrics","enabled":false}],"package":{"name":"apache","version":"0.3.3"}}

image

  • create package policy from UI and customize values (agent_policy, input stream values, etc.) and verify custom values are persisted
    image

Update on Nov 30, simplified update API. To verify:

  • create a package policy, note down the policy id
  • send a PUT request with minimal body (no required fields here) e.g. update namespace or description
  • verify that request was successful and only modified field has changed
  • the API allows resetting values as well e.g. description: "", enabled: false
  • example:
PUT http://elastic:changeme@localhost:5620/api/fleet/package_policies/64f13192-5dca-42f3-aa9c-62bc94c2f12c
kbn-xsrf: kibana

{ "description":"desc"}

Verify updated open api spec here:

Checklist

For maintainers

@juliaElastic juliaElastic added v8.0.0 release_note:skip Skip the PR/issue when compiling release notes auto-backport Deprecated - use backport:version if exact versions are needed v8.1.0 labels Nov 25, 2021
@juliaElastic juliaElastic requested a review from a team as a code owner November 25, 2021 14:56
@juliaElastic juliaElastic self-assigned this Nov 25, 2021
@botelastic botelastic bot added the Team:Fleet Team label for Observability Data Collection Fleet team label Nov 25, 2021
@elasticmachine
Copy link
Contributor

Pinging @elastic/fleet (Team:Fleet)

@juliaElastic
Copy link
Contributor Author

@elasticmachine merge upstream

@juliaElastic
Copy link
Contributor Author

@elasticmachine merge upstream

@juliaElastic
Copy link
Contributor Author

@elasticmachine merge upstream

);
if (newPP) {
const inputs = newPolicy.inputs.map((input) => {
const defaultInput = newPP.inputs.find((i) => i.type === input.type);
Copy link
Member

Choose a reason for hiding this comment

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

Should we map on policy_template too here for granular integration like AWS?

Copy link
Contributor Author

@juliaElastic juliaElastic Dec 3, 2021

Choose a reason for hiding this comment

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

@nchaulet In request only input.type and enabled is mandatory, so this code is mapping the rest of properties from the base package (streams, vars, etc.).
Could you give an example what you mean by the AWS use case?

Copy link
Member

Choose a reason for hiding this comment

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

Sure for example when you try to add the AWS billing integration this we are sending the following payload
Screen Shot 2021-12-06 at 10 44 54 AM

as there is multiple input with the same type, so I think in the case where there is a policy_template on the payload input we should probably use it to find the default input.

It is clearer? I can rephrase otherwise :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, it is clear now, so the enrich should consider policy_template too if set
I'll update it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@nchaulet done, please check again when you get a chance

@criamico
Copy link
Contributor

criamico commented Dec 3, 2021

I tested locally and I'm having an issue when trying to update an integration policy for the fleet server package (I did PUT /package_policies/{packagePolicyId} with body { description: "desc"}. I'm getting a 500 with message [inputs.0.compiled_input]: definition for this key is missing.
I tried with other integrations (apache, aws, etc) and they are working fine. I'm not sure why this package would be different.

@juliaElastic
Copy link
Contributor Author

@criamico good catch! I've fixed in latest commit, thanks

@juliaElastic
Copy link
Contributor Author

@elasticmachine merge upstream

Copy link
Contributor

@criamico criamico left a comment

Choose a reason for hiding this comment

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

LGTM

@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

✅ unchanged

History

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

cc @juliaElastic

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

🚀

@juliaElastic juliaElastic merged commit ccffda0 into elastic:main Dec 7, 2021
@juliaElastic juliaElastic deleted the package-policy-api branch December 7, 2021 07:50
kibanamachine added a commit to kibanamachine/kibana that referenced this pull request Dec 7, 2021
elastic#119739)

* simplified api, enriching default values

* removed comment

* reverted changes in common models

* fixed handlers test

* separated create schema

* fixed test

* removed throwing error

* getting package info from registry only

* fix type

* fix test and new tests

* simplified update api

* updated open api spec

* fixed compiled_input

* added policy_template enrich

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
@kibanamachine
Copy link
Contributor

💚 Backport successful

Status Branch Result
8.0

This backport PR will be merged automatically after passing CI.

kibanamachine added a commit that referenced this pull request Dec 7, 2021
#119739) (#120576)

* simplified api, enriching default values

* removed comment

* reverted changes in common models

* fixed handlers test

* separated create schema

* fixed test

* removed throwing error

* getting package info from registry only

* fix type

* fix test and new tests

* simplified update api

* updated open api spec

* fixed compiled_input

* added policy_template enrich

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>

Co-authored-by: Julia Bardi <90178898+juliaElastic@users.noreply.github.com>
jloleysens added a commit to jloleysens/kibana that referenced this pull request Dec 7, 2021
…-chromium-before-compiling-pdf

* 'main' of github.com:elastic/kibana: (121 commits)
  FTR should use the new kibana_system user (elastic#120436)
  [Lens] Temporarily exclude Mosaic/Waffle from the suggestions list (elastic#120488)
  [Reporting] Fix slow CSV with large max size bytes (elastic#120365)
  [CTI] Threat Intel Card on Overview page needs to accommodate Fleet TI integrations -  (elastic#120459)
  [Dashboard] Added KibanaThemeProvider.  (elastic#120122)
  add more rule_registry unit tests (elastic#120323)
  [Lens] update xpack.lens.pie.smallValuesWarningMessage text (elastic#120478)
  [Fleet] Simplified package policy create API, enriching default values (elastic#119739)
  mock `elastic-apm-node` in `@kbn/test` jest preset (elastic#120324)
  [RAC] Rename occurrences of alert_type to rule_type in Infra (elastic#120455)
  [Security Solutions] Removes tech debt of exporting all from linter rule for timeline plugin (elastic#120437)
  [Workplace Search] Add API Keys view to replace Access tokens (elastic#120147)
  [Security Solutions] Removes tech debt of exporting all from linter rule for cases plugin in the server section (elastic#120411)
  Add support for threat.feed.name (elastic#120250)
  [Rule Registry] Rewrite APM registry rules for Observability (elastic#117740)
  [docs] Fix artifact layout formatting (elastic#119386)
  [Workplace Search] Add a technical preview of connecting GitHub via GitHub apps (elastic#119764)
  add osquery notes for 7.16 (elastic#120407)
  chore(NA): splits types from code on @kbn/docs-utils (elastic#120533)
  [Reporting] Decouple screenshotting plugin from the reporting (elastic#120110)
  ...

# Conflicts:
#	x-pack/plugins/reporting/server/browsers/chromium/driver_factory/index.test.ts
#	x-pack/plugins/reporting/server/browsers/chromium/driver_factory/index.ts
#	x-pack/plugins/reporting/server/lib/screenshots/observable.test.ts
#	x-pack/plugins/reporting/server/lib/screenshots/observable.ts
#	x-pack/plugins/reporting/server/test_helpers/create_mock_browserdriverfactory.ts
TinLe pushed a commit to TinLe/kibana that referenced this pull request Dec 22, 2021
elastic#119739)

* simplified api, enriching default values

* removed comment

* reverted changes in common models

* fixed handlers test

* separated create schema

* fixed test

* removed throwing error

* getting package info from registry only

* fix type

* fix test and new tests

* simplified update api

* updated open api spec

* fixed compiled_input

* added policy_template enrich

Co-authored-by: Kibana Machine <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
auto-backport Deprecated - use backport:version if exact versions are needed release_note:skip Skip the PR/issue when compiling release notes Team:Fleet Team label for Observability Data Collection Fleet team v8.0.0 v8.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Fleet] Improve public API for Agent Policy, Package Policy
6 participants