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] Support space_id in preconfiguration #183920

Merged
merged 6 commits into from
May 23, 2024

Conversation

nchaulet
Copy link
Member

@nchaulet nchaulet commented May 21, 2024

Summary

Resolve #182817

As discussed change the SO type for package to be agnostic #172963

That PR allow to configure space aware preconfigured agent policies. By default preconfigured agent policy are created in the default namespace, by using the space_id property you could create a policy in a different space.

Example

You need to enable the space experimental feature to test this:

xpack.fleet.enableExperimental: ['useSpaceAwareness']
xpack.fleet.packages:
  - name: system
    version: latest
  - name: nginx
    version: latest
xpack.fleet.agentPolicies:
  - name: Test Kibana spaces
    space_id: test
    description: TEST
    id: test-policy
    is_default: false
    is_managed: true
    is_default_fleet_server: false
    package_policies:
      - id: test-nginx-1
        name: nginx-1
        package:
          name: nginx
        description: ''
        namespace: ''
        inputs:
          'nginx-logfile':
            enabled: true
            streams:
              '[nginx.error]':
                enabled: false
              '[nginx.access]':
                enabled: true
                vars:
                  paths:
                    - '/var/log/test/nginx/access.log*'
                  tags:
                    - nginx-access
                  preserve_original_event: false
                  ignore_older: 72h
          nginx-httpjson:
            enabled: false
    keep_monitoring_alive: true

Automated tests

I added unit test to the preconfiguration service

@nchaulet
Copy link
Member Author

/ci

@apmmachine
Copy link
Contributor

🤖 GitHub comments

Expand to view the GitHub comments

Just comment with:

  • /oblt-deploy : Deploy a Kibana instance using the Observability test environments.
  • run docs-build : Re-trigger the docs validation. (use unformatted text in the comment!)

@@ -24,6 +24,7 @@ export type InputsOverride = Partial<NewPackagePolicyInput> & {

export interface PreconfiguredAgentPolicy extends Omit<NewAgentPolicy, 'namespace' | 'id'> {
id: string | number;
kibana_namespace?: string;
Copy link
Member Author

@nchaulet nchaulet May 21, 2024

Choose a reason for hiding this comment

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

namespace is already used, curious if someone has better naming idea for that one

Copy link
Member

Choose a reason for hiding this comment

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

namespace is generally used more "internally" in Kibana code whereas space is used more in the public-facing docs, UI, etc. Maybe kibana_space_id would make sense here?

Copy link
Member

Choose a reason for hiding this comment

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

namespace is generally used more "internally" in Kibana code whereas space is used more in the public-facing docs, UI, etc. Maybe kibana_space_id would make sense here?

++ either kibana_space_id or space_id would be preferred. @kpollich is right that namespace is the internal name (for fun historical reasons) that we try not to leak.

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 will update to space_id as it seems more used in other plugins

@nchaulet nchaulet added the release_note:skip Skip the PR/issue when compiling release notes label May 21, 2024
@nchaulet nchaulet marked this pull request as ready for review May 21, 2024 15:08
@nchaulet nchaulet requested review from a team as code owners May 21, 2024 15:08
@nchaulet
Copy link
Member Author

/ci

@nchaulet nchaulet force-pushed the feature-preconfigured-namespaces branch from 099e742 to d9aca86 Compare May 21, 2024 15:10
@botelastic botelastic bot added the Team:Fleet Team label for Observability Data Collection Fleet team label May 21, 2024
@elasticmachine
Copy link
Contributor

Pinging @elastic/fleet (Team:Fleet)

@nchaulet
Copy link
Member Author

@elasticmachine merge upstream

@nchaulet nchaulet requested review from kpollich and legrego May 21, 2024 19:01
@nchaulet nchaulet self-assigned this May 22, 2024
@nchaulet nchaulet requested a review from jen-huang May 22, 2024 12:12
@kibana-ci
Copy link
Collaborator

💛 Build succeeded, but was flaky

Failed CI Steps

Test Failures

  • [job] [logs] FTR Configs #9 / endpoint "before all" hook in "endpoint"

Metrics [docs]

✅ unchanged

History

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

cc @nchaulet

Copy link
Contributor

@jen-huang jen-huang left a comment

Choose a reason for hiding this comment

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

Left a few small suggestions but otherwise code LGTM. I tested locally with kibana.yml

I get this error in the UI but I assume this is out of the scope of this PR and will be tackled in future tasks:

image

@@ -1124,6 +1125,69 @@ describe('policy preconfiguration', () => {
expect(policies[0].id).toBe('test-id');
expect(nonFatalErrorsB.length).toBe(0);
});

it('should used a namespaced saved objet client if the agent policy space_id is set', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
it('should used a namespaced saved objet client if the agent policy space_id is set', async () => {
it('should used a namespaced saved object client if the agent policy space_id is set', async () => {

}),
expect.anything() // options
);
});
Copy link
Contributor

Choose a reason for hiding this comment

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

it would be nice to add another test for changing the space_id for the same policy id

when I tested manually, it just created another policy in the second space, rather than "moving" the original policy, because space_id becomes part of the saved object ID. I think this is ok but want to make sure

Copy link
Contributor

@kc13greiner kc13greiner left a comment

Choose a reason for hiding this comment

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

LGTM!
Screenshot 2024-05-22 at 1 26 53 PM

@nchaulet
Copy link
Member Author

I get this error in the UI but I assume this is out of the scope of this PR and will be tackled in future tasks:

@jen-huang Could I ask you how you get the error? just to check if I did not introduced a new bug

@jen-huang
Copy link
Contributor

@jen-huang Could I ask you how you get the error? just to check if I did not introduced a new bug

This is when I have a policy using test space_id, but I did not set up that space yet, so I log into Kibana with default space and get that error when I load Fleet.

@kc13greiner
Copy link
Contributor

I get this error in the UI but I assume this is out of the scope of this PR and will be tackled in future tasks:

@jen-huang Could I ask you how you get the error? just to check if I did not introduced a new bug

I also see the error if you start up KB locally with the config listed in the description, if the space 'test' is not created and the user navigates to fleet

@kc13greiner
Copy link
Contributor

Initial load:
Screenshot 2024-05-22 at 2 29 49 PM

First reload:
Screenshot 2024-05-22 at 2 30 01 PM

Next reload:
Screenshot 2024-05-22 at 2 30 12 PM

@nchaulet
Copy link
Member Author

Thanks I am able to reproduce it, it seems to be related to the deploy policy code, I will create a follow up PR for that specific issue

@nchaulet nchaulet merged commit f6c2fec into elastic:main May 23, 2024
21 checks passed
@kibanamachine kibanamachine added v8.15.0 backport:skip This commit does not require backporting labels May 23, 2024
kaanyalti pushed a commit to kaanyalti/kibana that referenced this pull request May 23, 2024
@ycombinator ycombinator changed the title [Fleet] Support kibana_namespace in preconfiguration [Fleet] Support space_id in preconfiguration May 23, 2024
rshen91 pushed a commit to rshen91/kibana that referenced this pull request May 30, 2024
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.15.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Fleet] Make preconfiguration space-aware
9 participants