Skip to content

Commit

Permalink
[8.7] [Synthetics] handle onboarding for onprem deployments (#152048) (
Browse files Browse the repository at this point in the history
…#153163)

# Backport

This will backport the following commits from `main` to `8.7`:
- [[Synthetics] handle onboarding for onprem deployments
(#152048)](#152048)

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

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

<!--BACKPORT [{"author":{"name":"Dominique
Clarke","email":"[email protected]"},"sourceCommit":{"committedDate":"2023-03-11T02:29:14Z","message":"[Synthetics]
handle onboarding for onprem deployments (#152048)\n\n##
Summary\r\n\r\nDirects on-prem users to create a private location,
before allowing\r\non-prem users to create monitors.\r\n\r\nAdmin
user\r\n[Monitor-Management-Synthetics---Kibana\r\n(6).webm](https://user-images.githubusercontent.com/11356435/222554184-3f399764-0c3d-41e4-9652-7ec5616a320c.webm)\r\n\r\nUser
without Fleet
privileges\r\n[Synthetics-Getting-Started-Synthetics---Kibana\r\n(3).webm](https://user-images.githubusercontent.com/11356435/222554216-893a9a79-a152-459d-b6e6-d5bdfc5014dc.webm)\r\n\r\n\r\n###
Testing\r\n\r\n1. Start ES with yarn es snapshot\r\n2. Remove all
`xpack.uptime.service` configs in your Kibana.dev.yml\r\n3. Start Kibana
connected to local ES\r\n4. Navigate to Synthetics and enable
monitor\r\n5. Confirm that Add monitor flow appears first before
creating a monitor\r\n\r\n---------\r\n\r\nCo-authored-by: Kibana
Machine
<[email protected]>\r\nCo-authored-by:
shahzad31 <[email protected]>\r\nCo-authored-by: florent-leborgne
<[email protected]>","sha":"01ba0270d9e9f62aadbe8cfc38b20810581619d7","branchLabelMapping":{"^v8.8.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["bug","Team:uptime","release_note:skip","v8.7.0","v8.8.0"],"number":152048,"url":"https://github.com/elastic/kibana/pull/152048","mergeCommit":{"message":"[Synthetics]
handle onboarding for onprem deployments (#152048)\n\n##
Summary\r\n\r\nDirects on-prem users to create a private location,
before allowing\r\non-prem users to create monitors.\r\n\r\nAdmin
user\r\n[Monitor-Management-Synthetics---Kibana\r\n(6).webm](https://user-images.githubusercontent.com/11356435/222554184-3f399764-0c3d-41e4-9652-7ec5616a320c.webm)\r\n\r\nUser
without Fleet
privileges\r\n[Synthetics-Getting-Started-Synthetics---Kibana\r\n(3).webm](https://user-images.githubusercontent.com/11356435/222554216-893a9a79-a152-459d-b6e6-d5bdfc5014dc.webm)\r\n\r\n\r\n###
Testing\r\n\r\n1. Start ES with yarn es snapshot\r\n2. Remove all
`xpack.uptime.service` configs in your Kibana.dev.yml\r\n3. Start Kibana
connected to local ES\r\n4. Navigate to Synthetics and enable
monitor\r\n5. Confirm that Add monitor flow appears first before
creating a monitor\r\n\r\n---------\r\n\r\nCo-authored-by: Kibana
Machine
<[email protected]>\r\nCo-authored-by:
shahzad31 <[email protected]>\r\nCo-authored-by: florent-leborgne
<[email protected]>","sha":"01ba0270d9e9f62aadbe8cfc38b20810581619d7"}},"sourceBranch":"main","suggestedTargetBranches":["8.7"],"targetPullRequestStates":[{"branch":"8.7","label":"v8.7.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.8.0","labelRegex":"^v8.8.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/152048","number":152048,"mergeCommit":{"message":"[Synthetics]
handle onboarding for onprem deployments (#152048)\n\n##
Summary\r\n\r\nDirects on-prem users to create a private location,
before allowing\r\non-prem users to create monitors.\r\n\r\nAdmin
user\r\n[Monitor-Management-Synthetics---Kibana\r\n(6).webm](https://user-images.githubusercontent.com/11356435/222554184-3f399764-0c3d-41e4-9652-7ec5616a320c.webm)\r\n\r\nUser
without Fleet
privileges\r\n[Synthetics-Getting-Started-Synthetics---Kibana\r\n(3).webm](https://user-images.githubusercontent.com/11356435/222554216-893a9a79-a152-459d-b6e6-d5bdfc5014dc.webm)\r\n\r\n\r\n###
Testing\r\n\r\n1. Start ES with yarn es snapshot\r\n2. Remove all
`xpack.uptime.service` configs in your Kibana.dev.yml\r\n3. Start Kibana
connected to local ES\r\n4. Navigate to Synthetics and enable
monitor\r\n5. Confirm that Add monitor flow appears first before
creating a monitor\r\n\r\n---------\r\n\r\nCo-authored-by: Kibana
Machine
<[email protected]>\r\nCo-authored-by:
shahzad31 <[email protected]>\r\nCo-authored-by: florent-leborgne
<[email protected]>","sha":"01ba0270d9e9f62aadbe8cfc38b20810581619d7"}}]}]
BACKPORT-->

Co-authored-by: Kibana Machine <[email protected]>
  • Loading branch information
dominiqueclarke and kibanamachine authored Mar 13, 2023
1 parent bfab6b1 commit 21c8d91
Show file tree
Hide file tree
Showing 21 changed files with 581 additions and 174 deletions.
2 changes: 2 additions & 0 deletions x-pack/plugins/synthetics/common/constants/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ export const GETTING_STARTED_ROUTE = '/monitors/getting-started';

export const SETTINGS_ROUTE = '/settings';

export const PRIVATE_LOCATIOSN_ROUTE = '/settings/private-locations';

export const SYNTHETICS_SETTINGS_ROUTE = '/settings/:tabId';

export const CERTIFICATES_ROUTE = '/certificates';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export const ServiceLocationsField = ({
const SELECT_ONE_OR_MORE_LOCATIONS = i18n.translate(
'xpack.synthetics.monitorManagement.selectOneOrMoreLocations',
{
defaultMessage: 'Select one or more locations',
defaultMessage: 'Select one or more locations.',
}
);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
/*
* 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 * as permissionsHooks from '../../hooks/use_fleet_permissions';
import { render } from '../../utils/testing/rtl_helpers';
import { GettingStartedPage } from './getting_started_page';
import * as privateLocationsHooks from '../settings/private_locations/hooks/use_locations_api';

describe('GettingStartedPage', () => {
beforeEach(() => {
jest.spyOn(privateLocationsHooks, 'usePrivateLocationsAPI').mockReturnValue({
loading: false,
privateLocations: [],
deleteLoading: false,
onSubmit: jest.fn(),
onDelete: jest.fn(),
formData: undefined,
});
jest.spyOn(permissionsHooks, 'useCanManagePrivateLocation').mockReturnValue(true);
});
it('works with cloud locations', () => {
const { getByText } = render(<GettingStartedPage />, {
state: {
serviceLocations: {
locations: [
{
id: 'us_central',
label: 'Us Central',
},
{
id: 'us_east',
label: 'US East',
},
],
locationsLoaded: true,
loading: false,
},
agentPolicies: {
loading: false,
},
},
});

// page is loaded
expect(getByText('Create a single page browser monitor')).toBeInTheDocument();
});

it('serves on prem getting started experience when locations are not available', () => {
const { getByText } = render(<GettingStartedPage />, {
state: {
serviceLocations: {
locations: [],
locationsLoaded: true,
loading: false,
},
},
});

// page is loaded
expect(getByText('Get started with synthetic monitoring')).toBeInTheDocument();
});

it('shows need agent flyout when isAddingNewPrivateLocation is true and agentPolicies.length === 0', async () => {
const { getByText, getByRole, queryByLabelText } = render(<GettingStartedPage />, {
state: {
serviceLocations: {
locations: [],
locationsLoaded: true,
loading: false,
},
agentPolicies: {
data: {
total: 0,
},
isAddingNewPrivateLocation: true,
},
},
});

// page is loaded
expect(getByText('Get started with synthetic monitoring')).toBeInTheDocument();

expect(getByRole('heading', { name: 'Create private location', level: 2 }));
expect(getByText('No agent policies found')).toBeInTheDocument();
expect(getByRole('link', { name: 'Create agent policy' })).toBeEnabled();
expect(queryByLabelText('Location name')).not.toBeInTheDocument();
expect(queryByLabelText('Agent policy')).not.toBeInTheDocument();
});

it('shows add location flyout when isAddingNewPrivateLocation is true and agentPolicies.length > 0', async () => {
const { getByText, getByRole, getByLabelText, queryByText } = render(<GettingStartedPage />, {
state: {
serviceLocations: {
locations: [],
locationsLoaded: true,
loading: false,
},
agentPolicies: {
data: {
total: 1,
items: [{}],
},
isAddingNewPrivateLocation: true,
},
},
});

// page is loaded
expect(getByText('Get started with synthetic monitoring')).toBeInTheDocument();

expect(getByRole('heading', { name: 'Create private location', level: 2 }));
expect(queryByText('No agent policies found')).not.toBeInTheDocument();
expect(getByLabelText('Location name')).toBeInTheDocument();
expect(getByLabelText('Agent policy')).toBeInTheDocument();
});

it('shows permissions callout and hides form when agent policies are available but the user does not have permissions', async () => {
jest.spyOn(permissionsHooks, 'useCanManagePrivateLocation').mockReturnValue(false);
const { getByText, getByRole, queryByLabelText, queryByRole } = render(<GettingStartedPage />, {
state: {
serviceLocations: {
locations: [],
locationsLoaded: true,
loading: false,
},
agentPolicies: {
data: {
total: 1,
items: [{}],
},
isAddingNewPrivateLocation: true,
},
},
});

// page is loaded
expect(getByText('Get started with synthetic monitoring')).toBeInTheDocument();

expect(getByRole('heading', { name: 'Create private location', level: 2 }));
expect(queryByLabelText('Location name')).not.toBeInTheDocument();
expect(queryByLabelText('Agent policy')).not.toBeInTheDocument();
expect(queryByRole('button', { name: 'Save' })).not.toBeInTheDocument();
expect(getByText("You're missing some Kibana privileges to manage private locations"));
});

it('shows permissions callout when agent policy is needed but the user does not have permissions', async () => {
jest.spyOn(permissionsHooks, 'useCanManagePrivateLocation').mockReturnValue(false);
const { getByText, getByRole, queryByLabelText } = render(<GettingStartedPage />, {
state: {
serviceLocations: {
locations: [],
locationsLoaded: true,
loading: false,
},
agentPolicies: {
data: undefined, // data will be undefined when user does not have permissions
isAddingNewPrivateLocation: true,
},
},
});

// page is loaded
expect(getByText('Get started with synthetic monitoring')).toBeInTheDocument();

expect(getByRole('heading', { name: 'Create private location', level: 2 }));
expect(queryByLabelText('Location name')).not.toBeInTheDocument();
expect(queryByLabelText('Agent policy')).not.toBeInTheDocument();
expect(getByText("You're missing some Kibana privileges to manage private locations"));
});
});
Loading

0 comments on commit 21c8d91

Please sign in to comment.