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] Updates to output logic #153226

Merged
merged 21 commits into from
Mar 23, 2023

Conversation

criamico
Copy link
Contributor

@criamico criamico commented Mar 15, 2023

Closes #152234

Summary

  • If the user changes an output from ES to logstash when there are Fleet server policies that use that output, we throw asking the user to create a new output
  • If the user changes the default output to a logstash one, we update the Fleet server policies to use the previous default output (that should be ES)
  • Removed limitations to basic licenses so that fleet server policies can select a per-policy output (between the available ES outputs). This means that "Basic" users should be able to set their default output to Logstash but still have the Fleet Server policy attached to an ES output.
  • Added some tests to cover new functionalities

UI changes

When editing a "logstash" output the modal displays a warning:

Screenshot 2023-03-16 at 15 04 54

Testing

  1. Edit existing logstash output to be default
  • Have a default ES output and a fleet server policy (verify that has fleet server integration)
  • Create a new logstash output
  • Update it to make it default (this is valid for both integrations and monitoring output)
  • Check that fleet server policy keeps the ES output, it can be verified from agent policies > fleet server policy > settings.
  • The other policies should be switched to the logstash output

Note if the previous output is logstash, it will be switched to the default one. However, users who updated the system and already had a logstash ouput set as a default will need to to manually set the output from the agent policy settings page.

  1. Edit existing ES output to become a logstash one
  • Have a default ES output and a fleet server policy (verify that has fleet server integration)
  • Edit the output and change it to type 'logstash'
  • Check that the endpoint throws with an error

Screenshot 2023-03-21 at 18 06 25

  1. Create new logstash output as default
  • Have a default ES output and a fleet server policy (verify that has fleet server integration)
  • Create a new logstash output as set it as default output
  • Check that the fleet server policy keeps the previous ES default output
  • basically this should behave like case 1 (PUT and POST should have the same behaviour)
  1. Delete ES Output
  • Once in the previous case (fleet server on ES output, other policies on logstash), try to delete the ES output
  • It should be prevented with an error

Screenshot 2023-03-16 at 15 05 44

  1. Custom output per policy
  • With "basic" license, go to an agent policy with fleet server > settings
  • Check that "output for integrations" can select any output of type elasticsearch, while the logstash ones are disabled

Screenshot 2023-03-21 at 18 09 29

Checklist

@criamico criamico changed the title [Fleet] Updates to output PUT logic [Fleet] Updates to output logic Mar 16, 2023
@criamico criamico self-assigned this Mar 16, 2023
@criamico criamico added Team:Fleet Team label for Observability Data Collection Fleet team v8.8.0 backport:prev-minor Backport to (8.x) the previous minor version (i.e. one version back from main) release_note:fix labels Mar 16, 2023
@criamico
Copy link
Contributor Author

@elasticmachine merge upstream

@criamico criamico marked this pull request as ready for review March 16, 2023 15:59
@criamico criamico requested a review from a team as a code owner March 16, 2023 15:59
@elasticmachine
Copy link
Contributor

Pinging @elastic/fleet (Team:Fleet)

@criamico
Copy link
Contributor Author

@elasticmachine merge upstream

@criamico
Copy link
Contributor Author

@elasticmachine merge upstream

@criamico criamico requested a review from nchaulet March 21, 2023 17:01
@jlind23 jlind23 requested a review from a team March 22, 2023 08:28
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.

LGTM!

@criamico criamico merged commit ec3294f into elastic:main Mar 23, 2023
kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Mar 23, 2023
Closes elastic#152234

## Summary

- If the user changes an output from `ES` to `logstash` when there are
Fleet server policies that use that output, we throw asking the user to
create a new output
- If the user changes the default output to a `logstash` one, we update
the Fleet server policies to use the previous default output (that
should be ES)
- Removed limitations to basic licenses so that fleet server policies
can select a per-policy output (between the available ES outputs). This
means that "Basic" users should be able to set their default output to
Logstash but still have the Fleet Server policy attached to an ES
output.
- Added some tests to cover new functionalities

### UI changes

When editing a "logstash" output the modal displays a warning:

<img width="878" alt="Screenshot 2023-03-16 at 15 04 54"
src="https://user-images.githubusercontent.com/16084106/225665515-6090b85c-b84f-4295-9b30-c480d2a84879.png">

### Testing

1. **Edit existing logstash output to be default**
- Have a default ES output and a fleet server policy (verify that has
fleet server integration)
- Create a new logstash output
- Update it to make it default (this is valid for both integrations and
monitoring output)
- Check that fleet server policy keeps the ES output, it can be verified
from agent policies > fleet server policy > settings.
- The other policies should be switched to the logstash output

**Note** if the previous output is logstash, it will be switched to the
default one. However, users who updated the system and already had a
logstash ouput set as a default will need to to manually set the output
from the agent policy settings page.

2. **Edit existing ES output to become a logstash one**
- Have a default ES output and a fleet server policy (verify that has
fleet server integration)
- Edit the output and change it to type 'logstash'
- Check that the endpoint throws with an error

<img width="366" alt="Screenshot 2023-03-21 at 18 06 25"
src="https://user-images.githubusercontent.com/16084106/226687174-296e6e2b-3cef-4649-8173-18ee70c6a4a7.png">

3. **Create new logstash output as default**
- Have a default ES output and a fleet server policy (verify that has
fleet server integration)
- Create a new logstash output as set it as default output
- Check that the fleet server policy keeps the previous ES default
output
- basically this should behave like case 1 (PUT and POST should have the
same behaviour)

5. **Delete ES Output**
- Once in the previous case (fleet server on ES output, other policies
on logstash), try to delete the ES output
- It should be prevented with an error

<img width="444" alt="Screenshot 2023-03-16 at 15 05 44"
src="https://user-images.githubusercontent.com/16084106/226687206-f22e1330-4435-4077-a7ef-f29846f25e00.png">

6. **Custom output per policy**
- With "basic" license, go to an agent policy with fleet server >
settings
- Check that "output for integrations" can select any output of type
`elasticsearch`, while the logstash ones are disabled

<img width="981" alt="Screenshot 2023-03-21 at 18 09 29"
src="https://user-images.githubusercontent.com/16084106/226687854-95d239a3-4122-470a-88e0-73c456ad5f7d.png">

### Checklist

- [x] 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/packages/kbn-i18n/README.md)
- [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: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
(cherry picked from commit ec3294f)
@kibanamachine
Copy link
Contributor

💚 All backports created successfully

Status Branch Result
8.7

Note: Successful backport PRs will be merged automatically after passing CI.

Questions ?

Please refer to the Backport tool documentation

kibanamachine added a commit that referenced this pull request Mar 23, 2023
# Backport

This will backport the following commits from `main` to `8.7`:
- [[Fleet] Updates to output logic
(#153226)](#153226)

<!--- Backport version: 8.9.7 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Cristina
Amico","email":"criamico@users.noreply.github.com"},"sourceCommit":{"committedDate":"2023-03-23T08:00:26Z","message":"[Fleet]
Updates to output logic (#153226)\n\nCloses
https://github.com/elastic/kibana/issues/152234\r\n\r\n##
Summary\r\n\r\n- If the user changes an output from `ES` to `logstash`
when there are\r\nFleet server policies that use that output, we throw
asking the user to\r\ncreate a new output\r\n- If the user changes the
default output to a `logstash` one, we update\r\nthe Fleet server
policies to use the previous default output (that\r\nshould be ES)\r\n-
Removed limitations to basic licenses so that fleet server
policies\r\ncan select a per-policy output (between the available ES
outputs). This\r\nmeans that \"Basic\" users should be able to set their
default output to\r\nLogstash but still have the Fleet Server policy
attached to an ES\r\noutput.\r\n- Added some tests to cover new
functionalities\r\n\r\n### UI changes\r\n\r\nWhen editing a \"logstash\"
output the modal displays a warning:\r\n\r\n<img width=\"878\"
alt=\"Screenshot 2023-03-16 at 15 04
54\"\r\nsrc=\"https://user-images.githubusercontent.com/16084106/225665515-6090b85c-b84f-4295-9b30-c480d2a84879.png\">\r\n\r\n###
Testing\r\n\r\n1. **Edit existing logstash output to be default**\r\n-
Have a default ES output and a fleet server policy (verify that
has\r\nfleet server integration)\r\n- Create a new logstash output \r\n-
Update it to make it default (this is valid for both integrations
and\r\nmonitoring output)\r\n- Check that fleet server policy keeps the
ES output, it can be verified\r\nfrom agent policies > fleet server
policy > settings.\r\n- The other policies should be switched to the
logstash output\r\n\r\n**Note** if the previous output is logstash, it
will be switched to the\r\ndefault one. However, users who updated the
system and already had a\r\nlogstash ouput set as a default will need to
to manually set the output\r\nfrom the agent policy settings
page.\r\n\r\n2. **Edit existing ES output to become a logstash
one**\r\n- Have a default ES output and a fleet server policy (verify
that has\r\nfleet server integration)\r\n- Edit the output and change it
to type 'logstash' \r\n- Check that the endpoint throws with an
error\r\n\r\n<img width=\"366\" alt=\"Screenshot 2023-03-21 at 18 06
25\"\r\nsrc=\"https://user-images.githubusercontent.com/16084106/226687174-296e6e2b-3cef-4649-8173-18ee70c6a4a7.png\">\r\n\r\n3.
**Create new logstash output as default**\r\n- Have a default ES output
and a fleet server policy (verify that has\r\nfleet server
integration)\r\n- Create a new logstash output as set it as default
output\r\n- Check that the fleet server policy keeps the previous ES
default\r\noutput\r\n- basically this should behave like case 1 (PUT and
POST should have the\r\nsame behaviour)\r\n\r\n5. **Delete ES
Output**\r\n- Once in the previous case (fleet server on ES output,
other policies\r\non logstash), try to delete the ES output\r\n- It
should be prevented with an error\r\n\r\n<img width=\"444\"
alt=\"Screenshot 2023-03-16 at 15 05
44\"\r\nsrc=\"https://user-images.githubusercontent.com/16084106/226687206-f22e1330-4435-4077-a7ef-f29846f25e00.png\">\r\n\r\n6.
**Custom output per policy**\r\n- With \"basic\" license, go to an agent
policy with fleet server >\r\nsettings\r\n- Check that \"output for
integrations\" can select any output of type\r\n`elasticsearch`, while
the logstash ones are disabled\r\n\r\n<img width=\"981\"
alt=\"Screenshot 2023-03-21 at 18 09
29\"\r\nsrc=\"https://user-images.githubusercontent.com/16084106/226687854-95d239a3-4122-470a-88e0-73c456ad5f7d.png\">\r\n\r\n###
Checklist\r\n\r\n- [x] Any text added follows [EUI's
writing\r\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\r\nsentence case text and includes
[i18n\r\nsupport](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)\r\n-
[x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios\r\n\r\n---------\r\n\r\nCo-authored-by: Kibana Machine
<42973632+kibanamachine@users.noreply.github.com>","sha":"ec3294f2b340a5f6dbfdada3a997e17047bc8f17","branchLabelMapping":{"^v8.8.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","Team:Fleet","backport:prev-minor","v8.8.0"],"number":153226,"url":"https://github.com/elastic/kibana/pull/153226","mergeCommit":{"message":"[Fleet]
Updates to output logic (#153226)\n\nCloses
https://github.com/elastic/kibana/issues/152234\r\n\r\n##
Summary\r\n\r\n- If the user changes an output from `ES` to `logstash`
when there are\r\nFleet server policies that use that output, we throw
asking the user to\r\ncreate a new output\r\n- If the user changes the
default output to a `logstash` one, we update\r\nthe Fleet server
policies to use the previous default output (that\r\nshould be ES)\r\n-
Removed limitations to basic licenses so that fleet server
policies\r\ncan select a per-policy output (between the available ES
outputs). This\r\nmeans that \"Basic\" users should be able to set their
default output to\r\nLogstash but still have the Fleet Server policy
attached to an ES\r\noutput.\r\n- Added some tests to cover new
functionalities\r\n\r\n### UI changes\r\n\r\nWhen editing a \"logstash\"
output the modal displays a warning:\r\n\r\n<img width=\"878\"
alt=\"Screenshot 2023-03-16 at 15 04
54\"\r\nsrc=\"https://user-images.githubusercontent.com/16084106/225665515-6090b85c-b84f-4295-9b30-c480d2a84879.png\">\r\n\r\n###
Testing\r\n\r\n1. **Edit existing logstash output to be default**\r\n-
Have a default ES output and a fleet server policy (verify that
has\r\nfleet server integration)\r\n- Create a new logstash output \r\n-
Update it to make it default (this is valid for both integrations
and\r\nmonitoring output)\r\n- Check that fleet server policy keeps the
ES output, it can be verified\r\nfrom agent policies > fleet server
policy > settings.\r\n- The other policies should be switched to the
logstash output\r\n\r\n**Note** if the previous output is logstash, it
will be switched to the\r\ndefault one. However, users who updated the
system and already had a\r\nlogstash ouput set as a default will need to
to manually set the output\r\nfrom the agent policy settings
page.\r\n\r\n2. **Edit existing ES output to become a logstash
one**\r\n- Have a default ES output and a fleet server policy (verify
that has\r\nfleet server integration)\r\n- Edit the output and change it
to type 'logstash' \r\n- Check that the endpoint throws with an
error\r\n\r\n<img width=\"366\" alt=\"Screenshot 2023-03-21 at 18 06
25\"\r\nsrc=\"https://user-images.githubusercontent.com/16084106/226687174-296e6e2b-3cef-4649-8173-18ee70c6a4a7.png\">\r\n\r\n3.
**Create new logstash output as default**\r\n- Have a default ES output
and a fleet server policy (verify that has\r\nfleet server
integration)\r\n- Create a new logstash output as set it as default
output\r\n- Check that the fleet server policy keeps the previous ES
default\r\noutput\r\n- basically this should behave like case 1 (PUT and
POST should have the\r\nsame behaviour)\r\n\r\n5. **Delete ES
Output**\r\n- Once in the previous case (fleet server on ES output,
other policies\r\non logstash), try to delete the ES output\r\n- It
should be prevented with an error\r\n\r\n<img width=\"444\"
alt=\"Screenshot 2023-03-16 at 15 05
44\"\r\nsrc=\"https://user-images.githubusercontent.com/16084106/226687206-f22e1330-4435-4077-a7ef-f29846f25e00.png\">\r\n\r\n6.
**Custom output per policy**\r\n- With \"basic\" license, go to an agent
policy with fleet server >\r\nsettings\r\n- Check that \"output for
integrations\" can select any output of type\r\n`elasticsearch`, while
the logstash ones are disabled\r\n\r\n<img width=\"981\"
alt=\"Screenshot 2023-03-21 at 18 09
29\"\r\nsrc=\"https://user-images.githubusercontent.com/16084106/226687854-95d239a3-4122-470a-88e0-73c456ad5f7d.png\">\r\n\r\n###
Checklist\r\n\r\n- [x] Any text added follows [EUI's
writing\r\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\r\nsentence case text and includes
[i18n\r\nsupport](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)\r\n-
[x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios\r\n\r\n---------\r\n\r\nCo-authored-by: Kibana Machine
<42973632+kibanamachine@users.noreply.github.com>","sha":"ec3294f2b340a5f6dbfdada3a997e17047bc8f17"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v8.8.0","labelRegex":"^v8.8.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/153226","number":153226,"mergeCommit":{"message":"[Fleet]
Updates to output logic (#153226)\n\nCloses
https://github.com/elastic/kibana/issues/152234\r\n\r\n##
Summary\r\n\r\n- If the user changes an output from `ES` to `logstash`
when there are\r\nFleet server policies that use that output, we throw
asking the user to\r\ncreate a new output\r\n- If the user changes the
default output to a `logstash` one, we update\r\nthe Fleet server
policies to use the previous default output (that\r\nshould be ES)\r\n-
Removed limitations to basic licenses so that fleet server
policies\r\ncan select a per-policy output (between the available ES
outputs). This\r\nmeans that \"Basic\" users should be able to set their
default output to\r\nLogstash but still have the Fleet Server policy
attached to an ES\r\noutput.\r\n- Added some tests to cover new
functionalities\r\n\r\n### UI changes\r\n\r\nWhen editing a \"logstash\"
output the modal displays a warning:\r\n\r\n<img width=\"878\"
alt=\"Screenshot 2023-03-16 at 15 04
54\"\r\nsrc=\"https://user-images.githubusercontent.com/16084106/225665515-6090b85c-b84f-4295-9b30-c480d2a84879.png\">\r\n\r\n###
Testing\r\n\r\n1. **Edit existing logstash output to be default**\r\n-
Have a default ES output and a fleet server policy (verify that
has\r\nfleet server integration)\r\n- Create a new logstash output \r\n-
Update it to make it default (this is valid for both integrations
and\r\nmonitoring output)\r\n- Check that fleet server policy keeps the
ES output, it can be verified\r\nfrom agent policies > fleet server
policy > settings.\r\n- The other policies should be switched to the
logstash output\r\n\r\n**Note** if the previous output is logstash, it
will be switched to the\r\ndefault one. However, users who updated the
system and already had a\r\nlogstash ouput set as a default will need to
to manually set the output\r\nfrom the agent policy settings
page.\r\n\r\n2. **Edit existing ES output to become a logstash
one**\r\n- Have a default ES output and a fleet server policy (verify
that has\r\nfleet server integration)\r\n- Edit the output and change it
to type 'logstash' \r\n- Check that the endpoint throws with an
error\r\n\r\n<img width=\"366\" alt=\"Screenshot 2023-03-21 at 18 06
25\"\r\nsrc=\"https://user-images.githubusercontent.com/16084106/226687174-296e6e2b-3cef-4649-8173-18ee70c6a4a7.png\">\r\n\r\n3.
**Create new logstash output as default**\r\n- Have a default ES output
and a fleet server policy (verify that has\r\nfleet server
integration)\r\n- Create a new logstash output as set it as default
output\r\n- Check that the fleet server policy keeps the previous ES
default\r\noutput\r\n- basically this should behave like case 1 (PUT and
POST should have the\r\nsame behaviour)\r\n\r\n5. **Delete ES
Output**\r\n- Once in the previous case (fleet server on ES output,
other policies\r\non logstash), try to delete the ES output\r\n- It
should be prevented with an error\r\n\r\n<img width=\"444\"
alt=\"Screenshot 2023-03-16 at 15 05
44\"\r\nsrc=\"https://user-images.githubusercontent.com/16084106/226687206-f22e1330-4435-4077-a7ef-f29846f25e00.png\">\r\n\r\n6.
**Custom output per policy**\r\n- With \"basic\" license, go to an agent
policy with fleet server >\r\nsettings\r\n- Check that \"output for
integrations\" can select any output of type\r\n`elasticsearch`, while
the logstash ones are disabled\r\n\r\n<img width=\"981\"
alt=\"Screenshot 2023-03-21 at 18 09
29\"\r\nsrc=\"https://user-images.githubusercontent.com/16084106/226687854-95d239a3-4122-470a-88e0-73c456ad5f7d.png\">\r\n\r\n###
Checklist\r\n\r\n- [x] Any text added follows [EUI's
writing\r\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\r\nsentence case text and includes
[i18n\r\nsupport](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)\r\n-
[x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios\r\n\r\n---------\r\n\r\nCo-authored-by: Kibana Machine
<42973632+kibanamachine@users.noreply.github.com>","sha":"ec3294f2b340a5f6dbfdada3a997e17047bc8f17"}}]}]
BACKPORT-->

Co-authored-by: Cristina Amico <criamico@users.noreply.github.com>
jen-huang pushed a commit that referenced this pull request Mar 28, 2023
Fixes #153622

## Summary
[Fleet] Fix an error when creating new logstash output. 

The bug was added with #153226 and
depended on this [else
branch](https://github.com/criamico/kibana/blob/30d3843b142142d19f1fda8f8107f088c03ff1cb/x-pack/plugins/fleet/server/services/output.ts#L309-L312)
that shouldn't have been added.

I also added unit and integration tests to cover for this and other
cases.


### Testing
- Create a new `logstash` output, it can be `default` or not
- The output creation works as expected in both cases

### 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: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Mar 28, 2023
Fixes elastic#153622

## Summary
[Fleet] Fix an error when creating new logstash output.

The bug was added with elastic#153226 and
depended on this [else
branch](https://github.com/criamico/kibana/blob/30d3843b142142d19f1fda8f8107f088c03ff1cb/x-pack/plugins/fleet/server/services/output.ts#L309-L312)
that shouldn't have been added.

I also added unit and integration tests to cover for this and other
cases.

### Testing
- Create a new `logstash` output, it can be `default` or not
- The output creation works as expected in both cases

### 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: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
(cherry picked from commit 2e08470)
kibanamachine added a commit that referenced this pull request Mar 28, 2023
…153819)

# Backport

This will backport the following commits from `main` to `8.7`:
- [[Fleet] Fix error when creating new logstash output
(#153752)](#153752)

<!--- Backport version: 8.9.7 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Cristina
Amico","email":"criamico@users.noreply.github.com"},"sourceCommit":{"committedDate":"2023-03-28T00:43:03Z","message":"[Fleet]
Fix error when creating new logstash output (#153752)\n\nFixes
https://github.com/elastic/kibana/issues/153622\r\n\r\n##
Summary\r\n[Fleet] Fix an error when creating new logstash output.
\r\n\r\nThe bug was added with
#153226 and\r\ndepended on this
[else\r\nbranch](https://github.com/criamico/kibana/blob/30d3843b142142d19f1fda8f8107f088c03ff1cb/x-pack/plugins/fleet/server/services/output.ts#L309-L312)\r\nthat
shouldn't have been added.\r\n\r\nI also added unit and integration
tests to cover for this and other\r\ncases.\r\n\r\n\r\n### Testing\r\n-
Create a new `logstash` output, it can be `default` or not\r\n- The
output creation works as expected in both cases\r\n\r\n###
Checklist\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios\r\n\r\n---------\r\n\r\nCo-authored-by: Kibana Machine
<42973632+kibanamachine@users.noreply.github.com>","sha":"2e0847007a6e870b87b9401cf2360c015afb82a2","branchLabelMapping":{"^v8.8.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","Team:Fleet","backport:prev-minor","v8.8.0"],"number":153752,"url":"https://github.com/elastic/kibana/pull/153752","mergeCommit":{"message":"[Fleet]
Fix error when creating new logstash output (#153752)\n\nFixes
https://github.com/elastic/kibana/issues/153622\r\n\r\n##
Summary\r\n[Fleet] Fix an error when creating new logstash output.
\r\n\r\nThe bug was added with
#153226 and\r\ndepended on this
[else\r\nbranch](https://github.com/criamico/kibana/blob/30d3843b142142d19f1fda8f8107f088c03ff1cb/x-pack/plugins/fleet/server/services/output.ts#L309-L312)\r\nthat
shouldn't have been added.\r\n\r\nI also added unit and integration
tests to cover for this and other\r\ncases.\r\n\r\n\r\n### Testing\r\n-
Create a new `logstash` output, it can be `default` or not\r\n- The
output creation works as expected in both cases\r\n\r\n###
Checklist\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios\r\n\r\n---------\r\n\r\nCo-authored-by: Kibana Machine
<42973632+kibanamachine@users.noreply.github.com>","sha":"2e0847007a6e870b87b9401cf2360c015afb82a2"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v8.8.0","labelRegex":"^v8.8.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/153752","number":153752,"mergeCommit":{"message":"[Fleet]
Fix error when creating new logstash output (#153752)\n\nFixes
https://github.com/elastic/kibana/issues/153622\r\n\r\n##
Summary\r\n[Fleet] Fix an error when creating new logstash output.
\r\n\r\nThe bug was added with
#153226 and\r\ndepended on this
[else\r\nbranch](https://github.com/criamico/kibana/blob/30d3843b142142d19f1fda8f8107f088c03ff1cb/x-pack/plugins/fleet/server/services/output.ts#L309-L312)\r\nthat
shouldn't have been added.\r\n\r\nI also added unit and integration
tests to cover for this and other\r\ncases.\r\n\r\n\r\n### Testing\r\n-
Create a new `logstash` output, it can be `default` or not\r\n- The
output creation works as expected in both cases\r\n\r\n###
Checklist\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios\r\n\r\n---------\r\n\r\nCo-authored-by: Kibana Machine
<42973632+kibanamachine@users.noreply.github.com>","sha":"2e0847007a6e870b87b9401cf2360c015afb82a2"}}]}]
BACKPORT-->

Co-authored-by: Cristina Amico <criamico@users.noreply.github.com>
@kpollich kpollich added v8.7.1 QA:Needs Validation Issue needs to be validated by QA and removed v8.7.0 labels Apr 5, 2023
criamico added a commit that referenced this pull request Apr 11, 2023
…igured policies (#154445)

Closes #154326

## Summary

After the merge of #153226, when
creating/updating a Logstash output as default, the `Elastic Cloud agent
policy` preconfigured on Cloud gets reassigned to the "default" ES
policy instead than keeping the `Elastic Cloud internal output`.

<img width="1418" alt="Screenshot 2023-04-04 at 12 51 21"
src="https://user-images.githubusercontent.com/16084106/230112067-a2767d1a-1191-4877-8dec-546d1590e41f.png">

Tee bug is fixed by checking if any given fleet server policy is
`preconfigured` or if it has already an assigned `data_output_id`, in
which cases it doesn't get updated.

### Testing
- Create an ES output additional to the default one
- Create a preconfigured fleet server policy and make sure it has
`fleet-server` integration (this is to simulate the preconfigured cloud
policy)
- Assign the previous output to the preconfigured policy
- Now create a new `logstash` output and make it default
- Check that the preconfigured policy maintains the custom output
previously assigned

### 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: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: Nicolas Chaulet <nicolas.chaulet@elastic.co>
nchaulet pushed a commit to nchaulet/kibana that referenced this pull request Apr 11, 2023
…igured policies (elastic#154445)

Closes elastic#154326

## Summary

After the merge of elastic#153226, when
creating/updating a Logstash output as default, the `Elastic Cloud agent
policy` preconfigured on Cloud gets reassigned to the "default" ES
policy instead than keeping the `Elastic Cloud internal output`.

<img width="1418" alt="Screenshot 2023-04-04 at 12 51 21"
src="https://user-images.githubusercontent.com/16084106/230112067-a2767d1a-1191-4877-8dec-546d1590e41f.png">

Tee bug is fixed by checking if any given fleet server policy is
`preconfigured` or if it has already an assigned `data_output_id`, in
which cases it doesn't get updated.

### Testing
- Create an ES output additional to the default one
- Create a preconfigured fleet server policy and make sure it has
`fleet-server` integration (this is to simulate the preconfigured cloud
policy)
- Assign the previous output to the preconfigured policy
- Now create a new `logstash` output and make it default
- Check that the preconfigured policy maintains the custom output
previously assigned

### 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: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: Nicolas Chaulet <nicolas.chaulet@elastic.co>
(cherry picked from commit a5de314)

# Conflicts:
#	x-pack/plugins/fleet/server/services/output.test.ts
nchaulet added a commit that referenced this pull request Apr 12, 2023
…reconfigured policies (#154445) (#154771)

# Backport

This will backport the following commits from `main` to `8.7`:
- [[Fleet] Logstash Output - prevent updating data_output_id for
preconfigured policies
(#154445)](#154445)

<!--- Backport version: 8.9.7 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Cristina
Amico","email":"criamico@users.noreply.github.com"},"sourceCommit":{"committedDate":"2023-04-11T18:38:17Z","message":"[Fleet]
Logstash Output - prevent updating data_output_id for preconfigured
policies (#154445)\n\nCloses
https://github.com/elastic/kibana/issues/154326\r\n\r\n##
Summary\r\n\r\nAfter the merge of
#153226, when\r\ncreating/updating
a Logstash output as default, the `Elastic Cloud agent\r\npolicy`
preconfigured on Cloud gets reassigned to the \"default\" ES\r\npolicy
instead than keeping the `Elastic Cloud internal output`.\r\n\r\n<img
width=\"1418\" alt=\"Screenshot 2023-04-04 at 12 51
21\"\r\nsrc=\"https://user-images.githubusercontent.com/16084106/230112067-a2767d1a-1191-4877-8dec-546d1590e41f.png\">\r\n\r\nTee
bug is fixed by checking if any given fleet server policy
is\r\n`preconfigured` or if it has already an assigned `data_output_id`,
in\r\nwhich cases it doesn't get updated.\r\n\r\n### Testing\r\n- Create
an ES output additional to the default one\r\n- Create a preconfigured
fleet server policy and make sure it has\r\n`fleet-server` integration
(this is to simulate the preconfigured cloud\r\npolicy)\r\n- Assign the
previous output to the preconfigured policy\r\n- Now create a new
`logstash` output and make it default\r\n- Check that the preconfigured
policy maintains the custom output\r\npreviously assigned\r\n\r\n###
Checklist\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios\r\n\r\n---------\r\n\r\nCo-authored-by: Kibana Machine
<42973632+kibanamachine@users.noreply.github.com>\r\nCo-authored-by:
Nicolas Chaulet
<nicolas.chaulet@elastic.co>","sha":"a5de314687a195f4b73fb4b10bf6d3f7f5e58fd9","branchLabelMapping":{"^v8.8.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","Team:Fleet","backport:prev-minor","v8.8.0"],"number":154445,"url":"https://github.com/elastic/kibana/pull/154445","mergeCommit":{"message":"[Fleet]
Logstash Output - prevent updating data_output_id for preconfigured
policies (#154445)\n\nCloses
https://github.com/elastic/kibana/issues/154326\r\n\r\n##
Summary\r\n\r\nAfter the merge of
#153226, when\r\ncreating/updating
a Logstash output as default, the `Elastic Cloud agent\r\npolicy`
preconfigured on Cloud gets reassigned to the \"default\" ES\r\npolicy
instead than keeping the `Elastic Cloud internal output`.\r\n\r\n<img
width=\"1418\" alt=\"Screenshot 2023-04-04 at 12 51
21\"\r\nsrc=\"https://user-images.githubusercontent.com/16084106/230112067-a2767d1a-1191-4877-8dec-546d1590e41f.png\">\r\n\r\nTee
bug is fixed by checking if any given fleet server policy
is\r\n`preconfigured` or if it has already an assigned `data_output_id`,
in\r\nwhich cases it doesn't get updated.\r\n\r\n### Testing\r\n- Create
an ES output additional to the default one\r\n- Create a preconfigured
fleet server policy and make sure it has\r\n`fleet-server` integration
(this is to simulate the preconfigured cloud\r\npolicy)\r\n- Assign the
previous output to the preconfigured policy\r\n- Now create a new
`logstash` output and make it default\r\n- Check that the preconfigured
policy maintains the custom output\r\npreviously assigned\r\n\r\n###
Checklist\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios\r\n\r\n---------\r\n\r\nCo-authored-by: Kibana Machine
<42973632+kibanamachine@users.noreply.github.com>\r\nCo-authored-by:
Nicolas Chaulet
<nicolas.chaulet@elastic.co>","sha":"a5de314687a195f4b73fb4b10bf6d3f7f5e58fd9"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v8.8.0","labelRegex":"^v8.8.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/154445","number":154445,"mergeCommit":{"message":"[Fleet]
Logstash Output - prevent updating data_output_id for preconfigured
policies (#154445)\n\nCloses
https://github.com/elastic/kibana/issues/154326\r\n\r\n##
Summary\r\n\r\nAfter the merge of
#153226, when\r\ncreating/updating
a Logstash output as default, the `Elastic Cloud agent\r\npolicy`
preconfigured on Cloud gets reassigned to the \"default\" ES\r\npolicy
instead than keeping the `Elastic Cloud internal output`.\r\n\r\n<img
width=\"1418\" alt=\"Screenshot 2023-04-04 at 12 51
21\"\r\nsrc=\"https://user-images.githubusercontent.com/16084106/230112067-a2767d1a-1191-4877-8dec-546d1590e41f.png\">\r\n\r\nTee
bug is fixed by checking if any given fleet server policy
is\r\n`preconfigured` or if it has already an assigned `data_output_id`,
in\r\nwhich cases it doesn't get updated.\r\n\r\n### Testing\r\n- Create
an ES output additional to the default one\r\n- Create a preconfigured
fleet server policy and make sure it has\r\n`fleet-server` integration
(this is to simulate the preconfigured cloud\r\npolicy)\r\n- Assign the
previous output to the preconfigured policy\r\n- Now create a new
`logstash` output and make it default\r\n- Check that the preconfigured
policy maintains the custom output\r\npreviously assigned\r\n\r\n###
Checklist\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios\r\n\r\n---------\r\n\r\nCo-authored-by: Kibana Machine
<42973632+kibanamachine@users.noreply.github.com>\r\nCo-authored-by:
Nicolas Chaulet
<nicolas.chaulet@elastic.co>","sha":"a5de314687a195f4b73fb4b10bf6d3f7f5e58fd9"}}]}]
BACKPORT-->

---------

Co-authored-by: Cristina Amico <criamico@users.noreply.github.com>
@amolnater-qasource
Copy link

Hi @criamico

We have revalidated this PR on latest 8.7.1 BC1 kibana cloud environment

We created a policy with Fleet Server integration and had below observations:

  1. Edit existing logstash output to be default
  • For this scenario, we observed that user is successfully able to set logstash output default.
  • Under Policy settings Integration monitoring remains with Elasticsearch output, however Output for agent monitoring moved to Logstash output.

Screenshots:
5
4
2

  1. Edit existing ES output to become a logstash one
  • For this, we are not able to convert the default ES output to logstash and getting appropriate error.

Screenshot:
3

  1. Create new logstash output as default
  • For this scenario, we observed that user is successfully able to set logstash output default.
  • Under Policy settings Integration monitoring remains with Elasticsearch output, however Output for agent monitoring moved to Logstash output.

Screenshots:
Same as scenario 1.

  1. Delete ES Output
  • For this scenario we are unable to delete ES output as Integration monitoring is selected with ES output.

Screenshot:
6

  1. Custom output per policy
  • On changing license to Basic, we are not able to select Logstash output for integration monitoring, however for agent monitoring we are still able to select logstash.
    Please let us know if this is expected for policy having Fleet Server integration.

Screenshots:
7
9
8
10

Build details:
8.7.1 BC1
BUILD: 61183
COMMIT: a499452

Could you please confirm if the above shared results are expected?
cc: @kpollich

Please let us know if we are missing anything here.

Thanks!

@criamico
Copy link
Contributor Author

Hi @amolnater-qasource, I can confirm that these are all following the expected behavior.

@amolnater-qasource
Copy link

Hi Team,

We have executed test run for this feature on latest 8.7.1 BC3 kibana cloud environment at link:

Status:
PASS: 05

Build details:
BUILD: 61211
COMMIT: fde13a9

Hence we are marking this feature as QA:Validated.
Thanks

@amolnater-qasource amolnater-qasource added QA:Validated Issue has been validated by QA and removed QA:Needs Validation Issue needs to be validated by QA labels Apr 25, 2023
jillguyonnet added a commit that referenced this pull request Jul 18, 2023
## Summary

Closes #155725

### Context

Basic license users cannot use Synthetics private locations and a
default Logstash output (cf. [this
comment](#155725 (comment))).
This is because under Basic license per policy output is not allowed.

There was a [similar
issue](#152234) with Fleet
server that was fixed by adding logic to exclude the fleet server
integration from the checks
([PR](#153226)).

This PR follows a very similar approach for the synthetics integration.

### Changes

Compare these to [the corresponding changes that were made for Fleet
server](#153226).

- If the user tries to change the default output from ES to Logstash and
there are agent policies using synthetics, then an error is thrown.
- If an existing Logstash output is made to be the default output and
there are agent policies using synthetics, then these policies will
still be using the previous default ES output.
- If the default output is of type Logstash with an agent policy using
synthetics and another ES output, then if the user tries to delete the
ES output an error is thrown.
- Logstash type outputs are disabled in the agent policy settings if the
policy uses synthetics.

### Steps for testing

⚠️ Ideally the complete scenario reported
[here](#155725 (comment))
should be tested. I was having some issues running a dev setup with a
proper Logstash output, so the steps below are not end-to-end (similar
to #153226).

1. Start with a single default ES output, an agent policy (1) with
synthetics and another (2) without (NB: you can also test combinations
with fleet server; if an error is thrown, the error for fleet server
would be thrown before the one for synthetics).
2. Edit the default ES output to be a Logstash output; this should fail
and thrown the following error:
![Screenshot 2023-07-14 at 15 07
56](https://github.com/elastic/kibana/assets/23701614/bf716a7a-745b-4b89-aa49-0ced2cc825a2)
3. Create a new Logstash output and make it default on creation. Go the
agent policies and check the policies settings: the `Output for
integrations` setting should still be set to the previous ES default
output for policies with synthetics (and/or fleet server), and should
have switched to the new Logstash default for other policies.
4. Repeat the previous steps, but this time first create the Logstash
output and then edit it to make it default. This tests the update
behaviour as opposed to create. You will see the following warning:
![Screenshot 2023-07-14 at 15 06
35](https://github.com/elastic/kibana/assets/23701614/283ee6c2-6d84-4847-bd3d-3c4ff734b2d6)
5. Still with the default Logstash output, try to delete the ES output
(that is still used by policies with synthetics/fleet server(. This
should fail with the following error:
![Screenshot 2023-07-14 at 15 16
03](https://github.com/elastic/kibana/assets/23701614/62dfe4c1-aed6-4d85-83f0-92985eab9336)
6. (Basic license constraint) Create another ES output (not default). Go
the agent policies and check the policies settings: policies with
synthetics (or fleet server) should be allowed to switch the `Output for
integrations` setting to the new ES output:
![Screenshot 2023-07-14 at 15 18
56](https://github.com/elastic/kibana/assets/23701614/98deb4fc-abb1-40e2-9556-1a4ecfa96923)
In contrast, policies without these integrations should be constrained
to the default Logstash output:
![Screenshot 2023-07-14 at 15 19
19](https://github.com/elastic/kibana/assets/23701614/9856de1f-675b-47db-a471-9796239f0f85)

### Checklist

- [ ]
[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)
was added for features that require explanation or tutorials
- [ ] [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: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
ThomThomson pushed a commit to ThomThomson/kibana that referenced this pull request Aug 1, 2023
## Summary

Closes elastic#155725

### Context

Basic license users cannot use Synthetics private locations and a
default Logstash output (cf. [this
comment](elastic#155725 (comment))).
This is because under Basic license per policy output is not allowed.

There was a [similar
issue](elastic#152234) with Fleet
server that was fixed by adding logic to exclude the fleet server
integration from the checks
([PR](elastic#153226)).

This PR follows a very similar approach for the synthetics integration.

### Changes

Compare these to [the corresponding changes that were made for Fleet
server](elastic#153226).

- If the user tries to change the default output from ES to Logstash and
there are agent policies using synthetics, then an error is thrown.
- If an existing Logstash output is made to be the default output and
there are agent policies using synthetics, then these policies will
still be using the previous default ES output.
- If the default output is of type Logstash with an agent policy using
synthetics and another ES output, then if the user tries to delete the
ES output an error is thrown.
- Logstash type outputs are disabled in the agent policy settings if the
policy uses synthetics.

### Steps for testing

⚠️ Ideally the complete scenario reported
[here](elastic#155725 (comment))
should be tested. I was having some issues running a dev setup with a
proper Logstash output, so the steps below are not end-to-end (similar
to elastic#153226).

1. Start with a single default ES output, an agent policy (1) with
synthetics and another (2) without (NB: you can also test combinations
with fleet server; if an error is thrown, the error for fleet server
would be thrown before the one for synthetics).
2. Edit the default ES output to be a Logstash output; this should fail
and thrown the following error:
![Screenshot 2023-07-14 at 15 07
56](https://github.com/elastic/kibana/assets/23701614/bf716a7a-745b-4b89-aa49-0ced2cc825a2)
3. Create a new Logstash output and make it default on creation. Go the
agent policies and check the policies settings: the `Output for
integrations` setting should still be set to the previous ES default
output for policies with synthetics (and/or fleet server), and should
have switched to the new Logstash default for other policies.
4. Repeat the previous steps, but this time first create the Logstash
output and then edit it to make it default. This tests the update
behaviour as opposed to create. You will see the following warning:
![Screenshot 2023-07-14 at 15 06
35](https://github.com/elastic/kibana/assets/23701614/283ee6c2-6d84-4847-bd3d-3c4ff734b2d6)
5. Still with the default Logstash output, try to delete the ES output
(that is still used by policies with synthetics/fleet server(. This
should fail with the following error:
![Screenshot 2023-07-14 at 15 16
03](https://github.com/elastic/kibana/assets/23701614/62dfe4c1-aed6-4d85-83f0-92985eab9336)
6. (Basic license constraint) Create another ES output (not default). Go
the agent policies and check the policies settings: policies with
synthetics (or fleet server) should be allowed to switch the `Output for
integrations` setting to the new ES output:
![Screenshot 2023-07-14 at 15 18
56](https://github.com/elastic/kibana/assets/23701614/98deb4fc-abb1-40e2-9556-1a4ecfa96923)
In contrast, policies without these integrations should be constrained
to the default Logstash output:
![Screenshot 2023-07-14 at 15 19
19](https://github.com/elastic/kibana/assets/23701614/9856de1f-675b-47db-a471-9796239f0f85)

### Checklist

- [ ]
[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)
was added for features that require explanation or tutorials
- [ ] [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: 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
backport:prev-minor Backport to (8.x) the previous minor version (i.e. one version back from main) QA:Validated Issue has been validated by QA release_note:fix Team:Fleet Team label for Observability Data Collection Fleet team v8.7.1 v8.8.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Fleet] Prevent output changing types from Elasticsearch -> Logstash if a Fleet Server policy uses it
8 participants