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] Enable per policy outputs #126692

Merged
merged 5 commits into from
Mar 3, 2022

Conversation

nchaulet
Copy link
Member

@nchaulet nchaulet commented Mar 2, 2022

Summary

Resolve #104985

Allow user to set per policy outputs (that feature is only accessible for user with platinum licence)

UI Changes

With Platinum licence

Screen Shot 2022-03-02 at 10 41 51 AM

Screen Shot 2022-03-02 at 10 41 57 AM

With an expired platinum licence and previously configured per policy output

Screen Shot 2022-03-02 at 10 49 28 AM

Without platinum licence

Screen Shot 2022-03-02 at 10 49 35 AM

How to test

you can use this in your kibana.dev.yml to quickly get some outputs to test

xpack.fleet.outputs:
  - id: test1
    name: Elasticsearch 1
    hosts: [https://es1:9200]
    type: "elasticsearch"
    is_default: true
    is_default_monitoring: true
  - id: test2
    name: Elasticsearch 2
    hosts: [https://es2:9200]
    type: "elasticsearch"
    is_default: false
    is_default_monitoring: false
  - id: test3
    name: Elasticsearch 3
    hosts: [https://es3:9200]
    type: "elasticsearch"
    is_default: false
    is_default_monitoring: false

tests

Cover with unit tests:

  • the policy generation with different output(previously done)
  • the output option generation client side.
  • the agent policy output validation server side.

@nchaulet nchaulet added release_note:skip Skip the PR/issue when compiling release notes backport:skip This commit does not require backporting Team:Fleet Team label for Observability Data Collection Fleet team auto-backport Deprecated: Automatically backport this PR after it's merged v8.2.0 labels Mar 2, 2022
@nchaulet nchaulet requested a review from a team as a code owner March 2, 2022 15:56
@nchaulet nchaulet self-assigned this Mar 2, 2022
@elasticmachine
Copy link
Contributor

Pinging @elastic/fleet (Team:Fleet)

@@ -25,8 +25,8 @@ export interface NewAgentPolicy {
monitoring_enabled?: MonitoringType;
unenroll_timeout?: number;
is_preconfigured?: boolean;
data_output_id?: string;
monitoring_output_id?: string;
data_output_id?: string | null;
Copy link
Member Author

Choose a reason for hiding this comment

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

These fields are nullable to allow to clear them to use the default output

Copy link
Contributor

Choose a reason for hiding this comment

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

Good note. Would you mind adding that as a comment directly in the code?


import { useGetOutputs, useLicense } from '../../../../hooks';

export const DEFAULT_OUTPUT_VALUE = '@@##DEFAULT_OUTPUT_VALUE##@@';
Copy link
Member Author

Choose a reason for hiding this comment

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

the super select component do not support null or '' as a value so I come with that not super elegant solution

@nchaulet
Copy link
Member Author

nchaulet commented Mar 2, 2022

@mostlyjason @dborodyansky In the case we have disabled options (with an expired platinum for example) I am wondering if we can have something similiar to what you designed for the logstash output and policy using APM. (A copy explaining why it's disabled)

Screen Shot 2022-03-02 at 10 49 28 AM

@@ -25,8 +25,8 @@ export interface NewAgentPolicy {
monitoring_enabled?: MonitoringType;
unenroll_timeout?: number;
is_preconfigured?: boolean;
data_output_id?: string;
monitoring_output_id?: string;
data_output_id?: string | null;
Copy link
Contributor

Choose a reason for hiding this comment

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

Good note. Would you mind adding that as a comment directly in the code?

const outputsRequest = useGetOutputs();
const licenseService = useLicense();

const isPlatinium = useMemo(() => licenseService.isPlatinium(), [licenseService]);
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm curious if our heavy usages of useMemo is really necessary. I find it makes our UI code much harder to read and I don't think it's necessary unless there's an expensive calculation that we need to avoid. In this case, I think everything we're doing here is pretty fast.

I'd be curious to get the entire @elastic/fleet team's input on this.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes you are right we are probably using too much useMemo for non heavy computation return scalar values

} as any);
}

describe('validateOutputForPolicy', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you for these unit tests!

Comment on lines 57 to 61
return (
this.licenseInformation?.isAvailable &&
this.licenseInformation?.isActive &&
this.licenseInformation?.hasAtLeast('platinum')
);
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: this could be simpler probably, but then also maybe we don't need these helper methods for each license type?

Suggested change
return (
this.licenseInformation?.isAvailable &&
this.licenseInformation?.isActive &&
this.licenseInformation?.hasAtLeast('platinum')
);
return this.hasAtLeast('platinum');

Copy link
Member Author

Choose a reason for hiding this comment

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

👍 I used directly the hasAtLeast and refactored the existing helper to use hasAtLeast too

@nchaulet nchaulet requested review from joshdover and a team March 3, 2022 15:17
@joshdover
Copy link
Contributor

What should the behavior be when an output is removed? When I removed the preconfigured outputs from my kibana.yml, my agent policy that was not using those outputs looked like this and the latest revision doc in .fleet-policies index still pointed to the old outputs.

image

In the case of removing preconfigured outputs, I wonder if we should actually log a warning when a preconfigured output is removed that is still in use and then don't delete and make it "unmanaged". We definitely shouldn't allow removing the default output from preconfiguration.

For outputs removed from the UI, it seems we already show a warning that this will update X agent policies and affect Y agents (I assume we revert affected policies to the default output) 👍

@nchaulet
Copy link
Member Author

nchaulet commented Mar 3, 2022

What should the behavior be when an output is removed? When I removed the preconfigured outputs from my kibana.yml, my agent policy that was not using those outputs looked like this and the latest revision doc in .fleet-policies index still pointed to the old outputs.

I think something like this could work, I created a new issue, so I can tackle this as a follow up PR and document the decision we take too #126810

@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
fleet 569 570 +1

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 1233 1234 +1

Async chunks

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

id before after diff
fleet 661.7KB 664.5KB +2.8KB

Page load bundle

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

id before after diff
fleet 110.5KB 110.3KB -287.0B
Unknown metric groups

API count

id before after diff
fleet 1350 1351 +1

ESLint disabled line counts

id before after diff
fleet 41 45 +4

Total ESLint disabled count

id before after diff
fleet 49 53 +4

History

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

cc @nchaulet

Copy link
Contributor

@joshdover joshdover left a comment

Choose a reason for hiding this comment

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

Thanks for filing the follow up, LGTM!

@nchaulet nchaulet merged commit 247d3a5 into elastic:main Mar 3, 2022
@nchaulet nchaulet deleted the feature-enable-per-policy-output branch March 3, 2022 19:07
@kibanamachine
Copy link
Contributor

⚪ Backport skipped

The pull request was not backported as there were no branches to backport to. If this is a mistake, please apply the desired version labels or run the backport tool manually.

Manual backport

To create the backport manually run:

node scripts/backport --pr 126692

Questions ?

Please refer to the Backport tool documentation

@nchaulet nchaulet removed the auto-backport Deprecated: Automatically backport this PR after it's merged label Mar 3, 2022
lucasfcosta pushed a commit to lucasfcosta/kibana that referenced this pull request Mar 8, 2022
lucasfcosta pushed a commit to lucasfcosta/kibana that referenced this pull request Mar 8, 2022
@dikshachauhan-qasource
Copy link

Hi @joshdover

We have validated above UI changes and found available on latest builds of 8.2 snapshot.

  • Both policy outputs are displayed while creating policy.
  • Also, when navigated to policy's settings tab.
  • User is able to select value from dropdown for current policy.
  • By default, default output is pre selected at both fields.

Screenshot:
image

Build checked at: BUILD: 51365
COMMIT: 130823a

Further, we have created proposed test cases for same under related ticket (#104987) at doc

We will testing the complete scenario when feature will be fully available and will share our observations.

Thanks
QAS

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip This commit 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 v8.2.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Fleet] Set outputs for an agent policy
6 participants