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] Add fleet server host UI #142894

Merged
merged 26 commits into from
Oct 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
60ee8aa
[Fleet] Add UI to edit Fleet server hosts
nchaulet Oct 6, 2022
583be59
Fix jest tests
criamico Oct 11, 2022
3aa0060
Merge branch 'main' into feature-fleet-server-host-ui
kibanamachine Oct 11, 2022
8ea731b
Fix translations
criamico Oct 11, 2022
f38eccb
Add agent policy handling
criamico Oct 11, 2022
0ff3209
Merge branch 'main' into feature-fleet-server-host-ui
kibanamachine Oct 12, 2022
ed388be
Merge branch 'main' into feature-fleet-server-host-ui
kibanamachine Oct 12, 2022
582e9f7
Merge branch 'main' into feature-fleet-server-host-ui
kibanamachine Oct 17, 2022
bad7b3a
Merge branch 'main' into feature-fleet-server-host-ui
kibanamachine Oct 19, 2022
bf0aa59
Update quick start form
criamico Oct 19, 2022
5b4e681
Update advanced form
criamico Oct 24, 2022
5a51794
Merge branch 'main' into feature-fleet-server-host-ui
kibanamachine Oct 24, 2022
917aeef
Fix tests
nchaulet Oct 25, 2022
28b1596
Merge branch 'main' of github.com:elastic/kibana into feature-fleet-s…
nchaulet Oct 25, 2022
025d217
Fix checks and translations
criamico Oct 25, 2022
469fd89
Fix socket hangup error
nchaulet Oct 25, 2022
b308e89
[CI] Auto-commit changed files from 'node scripts/precommit_hook.js -…
kibanamachine Oct 25, 2022
823c917
Fix cypress tests
criamico Oct 26, 2022
8b4be95
Fix API request in cypress test
criamico Oct 26, 2022
b2b2707
Merge branch 'main' into feature-fleet-server-host-ui
kibanamachine Oct 26, 2022
4e5b01a
Fix last failing test
criamico Oct 27, 2022
d00c606
Add timeout
criamico Oct 27, 2022
d2c3b1b
Fix tests
nchaulet Oct 27, 2022
c177dfb
Fix tests
nchaulet Oct 27, 2022
cde1379
Merge branch 'main' into feature-fleet-server-host-ui
kibanamachine Oct 28, 2022
234bb69
Merge branch 'main' into feature-fleet-server-host-ui
kibanamachine Oct 28, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions x-pack/plugins/fleet/common/services/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
K8S_API_ROUTES,
PRECONFIGURATION_API_ROUTES,
DOWNLOAD_SOURCE_API_ROUTES,
FLEET_SERVER_HOST_API_ROUTES,
} from '../constants';

export const epmRouteService = {
Expand Down Expand Up @@ -218,6 +219,17 @@ export const outputRoutesService = {
getCreateLogstashApiKeyPath: () => OUTPUT_API_ROUTES.LOGSTASH_API_KEY_PATTERN,
};

export const fleetServerHostsRoutesService = {
getInfoPath: (itemId: string) =>
FLEET_SERVER_HOST_API_ROUTES.INFO_PATTERN.replace('{itemId}', itemId),
getUpdatePath: (itemId: string) =>
FLEET_SERVER_HOST_API_ROUTES.UPDATE_PATTERN.replace('{itemId}', itemId),
getListPath: () => FLEET_SERVER_HOST_API_ROUTES.LIST_PATTERN,
getDeletePath: (itemId: string) =>
FLEET_SERVER_HOST_API_ROUTES.DELETE_PATTERN.replace('{itemId}', itemId),
getCreatePath: () => FLEET_SERVER_HOST_API_ROUTES.CREATE_PATTERN,
};

export const settingsRoutesService = {
getInfoPath: () => SETTINGS_API_ROUTES.INFO_PATTERN,
getUpdatePath: () => SETTINGS_API_ROUTES.UPDATE_PATTERN,
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/fleet/common/types/models/agent_policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export interface NewAgentPolicy {
data_output_id?: string | null;
monitoring_output_id?: string | null;
download_source_id?: string | null;
fleet_server_host_id?: string | null;
schema_version?: string;
}

Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/fleet/common/types/models/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import type { SavedObjectAttributes } from '@kbn/core/public';

export interface BaseSettings {
has_seen_add_data_notice?: boolean;
fleet_server_hosts: string[];
fleet_server_hosts?: string[];
}

export interface Settings extends BaseSettings {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,23 @@ import type { FleetServerHost } from '../models';
import type { ListResult } from './common';

export type GetFleetServerHostsResponse = ListResult<FleetServerHost>;

export interface PutFleetServerHostsRequest {
params: {
itemId: string;
};
body: {
name?: string;
host_urls?: string[];
is_default?: boolean;
};
}

export interface PostFleetServerHostsRequest {
body: {
id?: string;
name?: string;
host_urls?: string[];
is_default?: boolean;
};
}
9 changes: 6 additions & 3 deletions x-pack/plugins/fleet/cypress/e2e/a11y/home_page.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
DATA_STREAMS_TAB,
SETTINGS_TAB,
SETTINGS_FLEET_SERVER_HOST_HEADING,
FLEET_SERVER_HOST_INPUT,
FLEET_SERVER_SETUP,
} from '../../screens/fleet';
import { AGENT_POLICY_NAME_LINK } from '../../screens/integrations';
import { cleanupAgentPolicies, unenrollAgent } from '../../tasks/cleanup';
Expand All @@ -42,8 +42,9 @@ describe('Home page', () => {
checkA11y({ skipFailures: false });
});
it('Install Fleet Server', () => {
cy.getBySel(FLEET_SERVER_HOST_INPUT, { timeout: 15000 }).should('be.visible');
cy.getBySel(FLEET_SERVER_HOST_INPUT).getBySel('comboBoxSearchInput').type(fleetServerHost);
cy.getBySel(FLEET_SERVER_SETUP.NAME_INPUT).type('Host edited');
cy.get('[placeholder="Specify host URL"', { timeout: 15000 }).should('be.visible');
cy.get('[placeholder="Specify host URL"').type(fleetServerHost);
cy.getBySel(GENERATE_FLEET_SERVER_POLICY_BUTTON).click();
cy.getBySel(PLATFORM_TYPE_LINUX_BUTTON, { timeout: 15000 }).should('be.visible');
checkA11y({ skipFailures: false });
Expand All @@ -58,6 +59,8 @@ describe('Home page', () => {
checkA11y({ skipFailures: false });
});
it('Add your fleet sever host', () => {
cy.getBySel(FLEET_SERVER_SETUP.NAME_INPUT).type('New host');
cy.get('[placeholder="Specify host URL"').type('https://localhost:8220');
cy.getBySel(ADVANCED_FLEET_SERVER_ADD_HOST_BUTTON).click();
checkA11y({ skipFailures: false });
});
Expand Down
44 changes: 30 additions & 14 deletions x-pack/plugins/fleet/cypress/e2e/fleet_settings.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,27 @@
*/

import { TOAST_CLOSE_BTN, CONFIRM_MODAL } from '../screens/navigation';
import { SETTINGS_SAVE_BTN, SETTINGS_OUTPUTS } from '../screens/fleet';
import {
SETTINGS_SAVE_BTN,
SETTINGS_OUTPUTS,
SETTINGS_FLEET_SERVER_HOSTS,
FLEET_SERVER_HOST_FLYOUT,
} from '../screens/fleet';

describe('Edit settings', () => {
beforeEach(() => {
cy.intercept('/api/fleet/settings', {
item: { id: 'fleet-default-settings', fleet_server_hosts: [] },
cy.intercept('/api/fleet/fleet_server_hosts', {
items: [
{
id: 'fleet-default-settings',
name: 'Host',
host_urls: ['https://localhost:8220'],
is_default: true,
},
],
page: 1,
perPage: 10000,
total: 0,
});
cy.intercept('/api/fleet/outputs', {
items: [
Expand All @@ -29,22 +44,23 @@ describe('Edit settings', () => {
cy.getBySel(TOAST_CLOSE_BTN).click();
});

it('should update Fleet server hosts', () => {
cy.getBySel(SETTINGS_OUTPUTS.EDIT_HOSTS_BTN).click();
cy.get('[placeholder="Specify host URL"').type('https://localhost:8220');
it('should allow to update Fleet server hosts', () => {
cy.getBySel(SETTINGS_FLEET_SERVER_HOSTS.ADD_BUTTON).click();
cy.getBySel(FLEET_SERVER_HOST_FLYOUT.NAME_INPUT).type('Host edited');
cy.getBySel(FLEET_SERVER_HOST_FLYOUT.DEFAULT_SWITCH).click();
cy.get('[placeholder="Specify host URL"').type('https://localhost:8221');

cy.intercept('/api/fleet/settings', {
item: { id: 'fleet-default-settings', fleet_server_hosts: ['https://localhost:8220'] },
});
cy.intercept('PUT', '/api/fleet/settings', {
fleet_server_hosts: ['https://localhost:8220'],
}).as('updateSettings');
cy.intercept('POST', '/api/fleet/fleet_server_hosts', {
name: 'Host edited',
host_urls: ['https://localhost:8221'],
is_default: true,
}).as('updateFleetServerHosts');

cy.getBySel(SETTINGS_SAVE_BTN).click();
cy.getBySel(CONFIRM_MODAL.CONFIRM_BUTTON).click();

cy.wait('@updateSettings').then((interception) => {
expect(interception.request.body.fleet_server_hosts[0]).to.equal('https://localhost:8220');
cy.wait('@updateFleetServerHosts').then((interception) => {
expect(interception.request.body.host_urls[0]).to.equal('https://localhost:8221');
});
});

Expand Down
7 changes: 3 additions & 4 deletions x-pack/plugins/fleet/cypress/e2e/fleet_startup.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import {
AGENT_FLYOUT,
CREATE_FLEET_SERVER_POLICY_BTN,
AGENT_POLICY_CREATE_STATUS_CALLOUT,
FLEET_SERVER_HOST_INPUT,
ADVANCED_FLEET_SERVER_ADD_HOST_BUTTON,
ADVANCED_FLEET_SERVER_GENERATE_SERVICE_TOKEN_BUTTON,
FLEET_SERVER_SETUP,
} from '../screens/fleet';
import { cleanupAgentPolicies, unenrollAgent } from '../tasks/cleanup';
import { verifyPolicy, verifyAgentPackage, navigateToTab } from '../tasks/fleet';
Expand Down Expand Up @@ -98,9 +98,8 @@ describe('Fleet startup', () => {
cy.getBySel(AGENT_FLYOUT.POLICY_DROPDOWN);

// verify fleet server enroll command contains created policy id
cy.getBySel(FLEET_SERVER_HOST_INPUT)
.getBySel('comboBoxSearchInput')
.type('https://localhost:8220');
cy.getBySel(FLEET_SERVER_SETUP.NAME_INPUT).type('New host');
cy.get('[placeholder="Specify host URL"').type('https://localhost:8220');

cy.getBySel(ADVANCED_FLEET_SERVER_ADD_HOST_BUTTON).click();
cy.getBySel(ADVANCED_FLEET_SERVER_GENERATE_SERVICE_TOKEN_BUTTON).click();
Expand Down
17 changes: 15 additions & 2 deletions x-pack/plugins/fleet/cypress/screens/fleet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const SETTINGS_SAVE_BTN = 'saveApplySettingsBtn';
export const AGENT_POLICY_SYSTEM_MONITORING_CHECKBOX = 'agentPolicyFormSystemMonitoringCheckbox';
export const INSTALL_INTEGRATIONS_ADVANCE_OPTIONS_BTN = 'AgentPolicyAdvancedOptions.AccordionBtn';
export const AGENT_POLICY_CREATE_STATUS_CALLOUT = 'agentPolicyCreateStatusCallOut';
export const FLEET_SERVER_HOST_INPUT = 'fleetServerHostInput';

export const EXISTING_HOSTS_TAB = 'existingHostsTab';
export const NEW_HOSTS_TAB = 'newHostsTab';

Expand Down Expand Up @@ -96,11 +96,14 @@ export const AGENT_BINARY_SOURCES_FLYOUT = {
export const SETTINGS_OUTPUTS = {
EDIT_BTN: 'editOutputBtn',
ADD_BTN: 'addOutputBtn',
EDIT_HOSTS_BTN: 'editHostsBtn',
NAME_INPUT: 'settingsOutputsFlyout.nameInput',
TYPE_INPUT: 'settingsOutputsFlyout.typeInput',
};

export const SETTINGS_FLEET_SERVER_HOSTS = {
ADD_BUTTON: 'settings.fleetServerHosts.addFleetServerHostBtn',
};

export const AGENT_POLICY_FORM = {
DOWNLOAD_SOURCE_SELECT: 'agentPolicyForm.downloadSource.select',
};
Expand All @@ -114,3 +117,13 @@ export const FLEET_AGENT_LIST_PAGE = {
CHECKBOX_SELECT_ALL: 'checkboxSelectAll',
BULK_ACTIONS_BUTTON: 'agentBulkActionsButton',
};

export const FLEET_SERVER_HOST_FLYOUT = {
NAME_INPUT: 'fleetServerHostsFlyout.nameInput',
DEFAULT_SWITCH: 'fleetServerHostsFlyout.isDefaultSwitch',
};

export const FLEET_SERVER_SETUP = {
NAME_INPUT: 'fleetServerSetup.nameInput',
HOST_INPUT: 'fleetServerSetup.multiRowInput',
};
8 changes: 5 additions & 3 deletions x-pack/plugins/fleet/cypress/tasks/fleet_server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,13 @@ export function setupFleetServer() {

export function setFleetServerHost(host = 'https://fleetserver:8220') {
cy.request({
method: 'PUT',
url: '/api/fleet/settings',
method: 'POST',
url: '/api/fleet/fleet_server_hosts',
headers: { 'kbn-xsrf': 'xx' },
body: {
fleet_server_hosts: [host],
name: 'Default host',
host_urls: [host],
is_default: true,
},
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export const AdvancedTab: React.FunctionComponent<AdvancedTabProps> = ({ selecte
getInstallFleetServerStep({
isFleetServerReady,
serviceToken,
fleetServerHost: fleetServerHostForm.fleetServerHost,
fleetServerHost: fleetServerHostForm.fleetServerHost?.host_urls[0],
fleetServerPolicyId: fleetServerPolicyId || selectedPolicyId,
deploymentMode,
disabled: !Boolean(serviceToken),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@
*/
import React, { useState } from 'react';
import type { EuiComboBoxOptionOption } from '@elastic/eui';

import { EuiComboBox, EuiText } from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n-react';
import { i18n } from '@kbn/i18n';

import type { FleetServerHost } from '../../../types';

interface Props {
fleetServerHost: string | undefined;
fleetServerHost: FleetServerHost | undefined;
fleetServerHostSettings: string[];
isDisabled: boolean;
isInvalid: boolean;
Expand Down Expand Up @@ -42,7 +45,6 @@ export const FleetServerHostComboBox: React.FunctionComponent<Props> = ({
setCreatedOptions([...createdOptions, option]);
onFleetServerHostChange(option);
};

return (
<EuiComboBox<string>
fullWidth
Expand All @@ -57,7 +59,11 @@ export const FleetServerHostComboBox: React.FunctionComponent<Props> = ({
values: { searchValuePlaceholder: '{searchValue}' },
}
)}
selectedOptions={fleetServerHost ? [{ label: fleetServerHost, value: fleetServerHost }] : []}
selectedOptions={
fleetServerHost
? [{ label: fleetServerHost.host_urls[0], value: fleetServerHost.host_urls[0] }]
: []
}
prepend={
<EuiText>
<FormattedMessage
Expand Down
Loading