-
Notifications
You must be signed in to change notification settings - Fork 8.5k
[Fleet] Add collector onboarding steps to UI #254491
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
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
711369c
add collector UI
juliaElastic c61c34c
Merge branch 'main' into add-collector-ui
juliaElastic eeebf86
Changes from make api-docs
kibanamachine 270b466
filter out opamp policy from Agent policy list UI
juliaElastic ce8524e
fix i18n
juliaElastic 891f1e7
fix i18n
juliaElastic 6a36bbc
fix api test
juliaElastic c7e2ace
add unit tests
juliaElastic b08c6f1
move buttons to context menu
juliaElastic fe0458c
replace useEffect with useQuery
juliaElastic 0617232
fixed test
juliaElastic f7e9e31
create opamp policy per space
juliaElastic 6657e4f
Merge branch 'main' into add-collector-ui
juliaElastic ce53bc5
Merge branch 'main' into add-collector-ui
juliaElastic 00fde67
always show agent dashboard link for opamp collectors
juliaElastic 7b9ff93
Update x-pack/platform/plugins/shared/fleet/public/applications/fleet…
juliaElastic 06189db
Merge branch 'main' into add-collector-ui
juliaElastic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -89,7 +89,8 @@ export const AgentDashboardLink: React.FunctionComponent<{ | |
| const { isInstalled, link, isLoading } = useAgentDashboardLink(agent, packageName); | ||
| const { getHref } = useLink(); | ||
|
|
||
| const isLogAndMetricsEnabled = agentPolicy?.monitoring_enabled?.length ?? 0 > 0; | ||
| const isLogAndMetricsEnabled = | ||
| (agentPolicy?.monitoring_enabled?.length ?? 0) > 0 || agent.type === 'OPAMP'; | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| const buttonArgs = | ||
| !isInstalled || isLoading || !isLogAndMetricsEnabled ? { disabled: true } : { href: link }; | ||
|
|
||
209 changes: 209 additions & 0 deletions
209
...plications/fleet/sections/agents/agent_list_page/components/add_collector_flyout.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,209 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0; you may not use this file except in compliance with the Elastic License | ||
| * 2.0. | ||
| */ | ||
|
|
||
| import React from 'react'; | ||
| import { waitFor } from '@testing-library/react'; | ||
| import { QueryClient, QueryClientProvider } from '@kbn/react-query'; | ||
|
|
||
| import type { TestRenderer } from '../../../../../../mock'; | ||
| import { createFleetTestRendererMock } from '../../../../../../mock'; | ||
| import { | ||
| sendCreateAgentPolicyForRq, | ||
| sendGetEnrollmentAPIKeys, | ||
| sendGetOneAgentPolicy, | ||
| useGetFleetServerHosts, | ||
| useFleetStatus, | ||
| } from '../../../../hooks'; | ||
| import { usePollingAgentCount } from '../../../../components'; | ||
|
|
||
| import { AddCollectorFlyout } from './add_collector_flyout'; | ||
|
|
||
| jest.mock('../../../../hooks', () => ({ | ||
| ...jest.requireActual('../../../../hooks'), | ||
| sendGetOneAgentPolicy: jest.fn(), | ||
| sendCreateAgentPolicyForRq: jest.fn(), | ||
| sendGetEnrollmentAPIKeys: jest.fn(), | ||
| useGetFleetServerHosts: jest.fn(), | ||
| useFleetStatus: jest.fn(), | ||
| })); | ||
| jest.mock('../../../../components', () => ({ | ||
| AgentEnrollmentConfirmationStep: () => ({ | ||
| title: 'Confirm enrollment', | ||
| children: <div>Confirmation</div>, | ||
| }), | ||
| usePollingAgentCount: jest.fn(), | ||
| })); | ||
|
|
||
| const mockedSendGetOneAgentPolicy = jest.mocked(sendGetOneAgentPolicy); | ||
| const mockedSendCreateAgentPolicyForRq = jest.mocked(sendCreateAgentPolicyForRq); | ||
| const mockedSendGetEnrollmentAPIKeys = jest.mocked(sendGetEnrollmentAPIKeys); | ||
| const mockedUseGetFleetServerHosts = jest.mocked(useGetFleetServerHosts); | ||
| const mockedUsePollingAgentCount = jest.mocked(usePollingAgentCount); | ||
| const mockedUseFleetStatus = jest.mocked(useFleetStatus); | ||
|
|
||
| describe('AddCollectorFlyout', () => { | ||
| let renderer: TestRenderer; | ||
|
|
||
| const renderFlyout = () => | ||
| renderer.render(<AddCollectorFlyout onClose={jest.fn()} onClickViewAgents={jest.fn()} />); | ||
|
|
||
| beforeEach(() => { | ||
| renderer = createFleetTestRendererMock(); | ||
| jest.clearAllMocks(); | ||
|
|
||
| mockedUseGetFleetServerHosts.mockReturnValue({ | ||
| data: { | ||
| items: [ | ||
| { | ||
| is_default: true, | ||
| host_urls: ['https://fleet.example:8220'], | ||
| }, | ||
| ], | ||
| }, | ||
| isLoading: false, | ||
| isError: false, | ||
| resendRequest: jest.fn(), | ||
| } as any); | ||
|
|
||
| mockedUsePollingAgentCount.mockReturnValue({ | ||
| enrolledAgentIds: [], | ||
| total: 0, | ||
| } as any); | ||
|
|
||
| mockedUseFleetStatus.mockReturnValue({ spaceId: 'default' } as any); | ||
| }); | ||
|
|
||
| it('uses existing OpAMP policy and renders generated configuration', async () => { | ||
| mockedSendGetOneAgentPolicy.mockResolvedValue({ | ||
| data: { item: { id: 'opamp' } }, | ||
| } as any); | ||
| mockedSendGetEnrollmentAPIKeys.mockResolvedValue({ | ||
| data: { items: [{ api_key: 'existing-token' }] }, | ||
| } as any); | ||
|
|
||
| const component = renderFlyout(); | ||
|
|
||
| await waitFor(() => { | ||
| expect(mockedSendGetOneAgentPolicy).toHaveBeenCalledWith('opamp'); | ||
| expect(mockedSendCreateAgentPolicyForRq).not.toHaveBeenCalled(); | ||
| expect(mockedSendGetEnrollmentAPIKeys).toHaveBeenCalledWith({ | ||
| page: 1, | ||
| perPage: 1, | ||
| kuery: 'policy_id:"opamp"', | ||
| }); | ||
| }); | ||
|
|
||
| const configYaml = component.getByTestId('opampConfigYaml').textContent; | ||
| expect(configYaml).toContain('Authorization: ApiKey existing-token'); | ||
| expect(configYaml).toContain('endpoint: https://fleet.example:8220/v1/opamp'); | ||
| }); | ||
|
|
||
| it('creates OpAMP policy when missing and then fetches enrollment token', async () => { | ||
| mockedSendGetOneAgentPolicy.mockResolvedValue({ | ||
| error: { statusCode: 404 }, | ||
| } as any); | ||
| mockedSendCreateAgentPolicyForRq.mockResolvedValue({ | ||
| item: { id: 'opamp' }, | ||
| } as any); | ||
| mockedSendGetEnrollmentAPIKeys.mockResolvedValue({ | ||
| data: { items: [{ api_key: 'created-token' }] }, | ||
| } as any); | ||
|
|
||
| const component = renderFlyout(); | ||
|
|
||
| await waitFor(() => { | ||
| expect(mockedSendCreateAgentPolicyForRq).toHaveBeenCalledWith({ | ||
| name: 'OpAMP', | ||
| id: 'opamp', | ||
| namespace: 'default', | ||
| description: 'Agent policy for OpAMP collectors', | ||
| is_managed: true, | ||
| }); | ||
| }); | ||
|
|
||
| const configYaml = component.getByTestId('opampConfigYaml').textContent; | ||
| expect(configYaml).toContain('Authorization: ApiKey created-token'); | ||
| }); | ||
|
|
||
| it('uses space-prefixed policy ID when spaceId is non-default', async () => { | ||
| mockedUseFleetStatus.mockReturnValue({ spaceId: 'my-space' } as any); | ||
|
|
||
| mockedSendGetOneAgentPolicy.mockResolvedValue({ | ||
| data: { item: { id: 'my-space-opamp' } }, | ||
| } as any); | ||
| mockedSendGetEnrollmentAPIKeys.mockResolvedValue({ | ||
| data: { items: [{ api_key: 'space-token' }] }, | ||
| } as any); | ||
|
|
||
| const component = renderFlyout(); | ||
|
|
||
| await waitFor(() => { | ||
| expect(mockedSendGetOneAgentPolicy).toHaveBeenCalledWith('my-space-opamp'); | ||
| expect(mockedSendGetEnrollmentAPIKeys).toHaveBeenCalledWith({ | ||
| page: 1, | ||
| perPage: 1, | ||
| kuery: 'policy_id:"my-space-opamp"', | ||
| }); | ||
| }); | ||
|
|
||
| const configYaml = component.getByTestId('opampConfigYaml').textContent; | ||
| expect(configYaml).toContain('Authorization: ApiKey space-token'); | ||
| }); | ||
|
|
||
| it('creates space-prefixed policy when missing in non-default space', async () => { | ||
| mockedUseFleetStatus.mockReturnValue({ spaceId: 'my-space' } as any); | ||
|
|
||
| mockedSendGetOneAgentPolicy.mockResolvedValue({ | ||
| error: { statusCode: 404 }, | ||
| } as any); | ||
| mockedSendCreateAgentPolicyForRq.mockResolvedValue({ | ||
| item: { id: 'my-space-opamp' }, | ||
| } as any); | ||
| mockedSendGetEnrollmentAPIKeys.mockResolvedValue({ | ||
| data: { items: [{ api_key: 'space-created-token' }] }, | ||
| } as any); | ||
|
|
||
| const component = renderFlyout(); | ||
|
|
||
| await waitFor(() => { | ||
| expect(mockedSendCreateAgentPolicyForRq).toHaveBeenCalledWith({ | ||
| name: 'OpAMP', | ||
| id: 'my-space-opamp', | ||
| namespace: 'default', | ||
| description: 'Agent policy for OpAMP collectors', | ||
| is_managed: true, | ||
| }); | ||
| }); | ||
|
|
||
| const configYaml = component.getByTestId('opampConfigYaml').textContent; | ||
| expect(configYaml).toContain('Authorization: ApiKey space-created-token'); | ||
| }); | ||
|
|
||
| it('renders a user-facing error when policy/token setup fails', async () => { | ||
| mockedSendGetOneAgentPolicy.mockRejectedValue(new Error('setup failed')); | ||
|
|
||
| const queryClient = new QueryClient({ | ||
| defaultOptions: { | ||
| queries: { retry: false }, | ||
| }, | ||
| }); | ||
| const wrapper = ({ children }: { children: React.ReactNode }) => ( | ||
| <renderer.AppWrapper> | ||
| <QueryClientProvider client={queryClient}>{children}</QueryClientProvider> | ||
| </renderer.AppWrapper> | ||
| ); | ||
|
|
||
| const component = renderer.render( | ||
| <AddCollectorFlyout onClose={jest.fn()} onClickViewAgents={jest.fn()} />, | ||
| { wrapper } | ||
| ); | ||
|
|
||
| await waitFor(() => { | ||
| expect(component.getByText('setup failed')).toBeInTheDocument(); | ||
| }); | ||
| }); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.


There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why hiding OpAmp agents?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The agents won't be hidden, only the agent policy "OpAMP" because it's not intended to be used for anything else. We could probably show it as a managed policy (so users can't enroll Elastic Agents to it).