Skip to content

Commit

Permalink
[8.2] set browser type in case of monitor management (#132299) (#132383)
Browse files Browse the repository at this point in the history
* set browser type in case of monitor management (#132299)

Co-authored-by: shahzad31 <shahzad.muhammad@elastic.co>
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
(cherry picked from commit 5d4abda)

# Conflicts:
#	x-pack/plugins/synthetics/public/legacy_uptime/components/fleet_package/contexts/index.ts
#	x-pack/plugins/synthetics/public/legacy_uptime/components/fleet_package/contexts/policy_config_context.tsx
#	x-pack/plugins/synthetics/public/legacy_uptime/components/fleet_package/custom_fields.tsx

* adjust tests

* adjust test
  • Loading branch information
dominiqueclarke committed May 18, 2022
1 parent 7ab925b commit f788645
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 15 deletions.
4 changes: 2 additions & 2 deletions x-pack/plugins/uptime/e2e/journeys/monitor_details.journey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ journey('MonitorDetails', async ({ page, params }: { page: Page; params: any })
step('create basic monitor', async () => {
await uptime.enableMonitorManagement();
await uptime.clickAddMonitor();
await uptime.createBasicMonitorDetails({
await uptime.createBasicHTTPMonitorDetails({
name,
locations: ['US Central'],
apmServiceName: 'synthetics',
url: 'https://www.google.com',
});
await uptime.fillByTestSubj('syntheticsUrlField', 'https://www.google.com');
await uptime.confirmAndSave();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,15 @@ const configuration = {
[DataStream.BROWSER]: {
monitorConfig: {
...basicMonitorDetails,
schedule: '10',
name: browserName,
inlineScript: 'step("test step", () => {})',
locations: [basicMonitorDetails.location],
apmServiceName: 'Sample APM Service',
},
monitorDetails: {
...basicMonitorDetails,
schedule: '10',
name: browserName,
},
},
Expand Down
8 changes: 4 additions & 4 deletions x-pack/plugins/uptime/e2e/journeys/monitor_name.journey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ journey(`MonitorName`, async ({ page, params }: { page: Page; params: any }) =>
const uptime = monitorManagementPageProvider({ page, kibanaUrl: params.kibanaUrl });

const createBasicMonitor = async () => {
await uptime.createBasicMonitorDetails({
await uptime.createBasicHTTPMonitorDetails({
name,
locations: ['US Central'],
apmServiceName: 'synthetics',
url: 'https://www.google.com',
});
await uptime.fillByTestSubj('syntheticsUrlField', 'https://www.google.com');
};

before(async () => {
Expand All @@ -52,12 +52,12 @@ journey(`MonitorName`, async ({ page, params }: { page: Page; params: any }) =>

step(`shows error if name already exists`, async () => {
await uptime.navigateToAddMonitor();
await uptime.createBasicMonitorDetails({
await uptime.createBasicHTTPMonitorDetails({
name,
locations: ['US Central'],
apmServiceName: 'synthetics',
url: 'https://www.google.com',
});
await uptime.fillByTestSubj('syntheticsUrlField', 'https://www.google.com');

await uptime.assertText({ text: 'Monitor name already exists.' });

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ export function monitorManagementPageProvider({
apmServiceName: string;
locations: string[];
}) {
await this.selectMonitorType('http');
await this.createBasicMonitorDetails({ name, apmServiceName, locations });
await this.fillByTestSubj('syntheticsUrlField', url);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export type { IPolicyConfigContextProvider } from './policy_config_context';
export {
PolicyConfigContext,
PolicyConfigContextProvider,
initialValue as defaultPolicyConfig,
initialMonitorTypeValue as defaultPolicyConfig,
defaultContext as defaultPolicyConfigValues,
usePolicyConfigContext,
} from './policy_config_context';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
* 2.0.
*/

import React, { createContext, useContext, useMemo, useState } from 'react';
import React, { createContext, useContext, useEffect, useMemo, useState } from 'react';
import { useRouteMatch } from 'react-router-dom';
import { MONITOR_ADD_ROUTE } from '../../../../common/constants';
import { DEFAULT_NAMESPACE_STRING } from '../../../../common/constants';
import {
ScheduleUnit,
Expand Down Expand Up @@ -56,7 +58,7 @@ export interface IPolicyConfigContextProvider {
throttling?: ThrottlingOptions;
}

export const initialValue = DataStream.HTTP;
export const initialMonitorTypeValue = DataStream.HTTP;

export const defaultContext: IPolicyConfigContext = {
setMonitorType: (_monitorType: React.SetStateAction<DataStream>) => {
Expand All @@ -79,8 +81,8 @@ export const defaultContext: IPolicyConfigContext = {
setNamespace: (_namespace: React.SetStateAction<string>) => {
throw new Error('setNamespace was not initialized, set it when you invoke the context');
},
monitorType: initialValue, // mutable
defaultMonitorType: initialValue, // immutable,
monitorType: initialMonitorTypeValue, // mutable
defaultMonitorType: initialMonitorTypeValue, // immutable,
runsOnService: false,
defaultIsTLSEnabled: false,
defaultIsZipUrlTLSEnabled: false,
Expand All @@ -98,7 +100,7 @@ export const PolicyConfigContext = createContext(defaultContext);
export function PolicyConfigContextProvider<ExtraFields = unknown>({
children,
throttling = DEFAULT_THROTTLING,
defaultMonitorType = initialValue,
defaultMonitorType = initialMonitorTypeValue,
defaultIsTLSEnabled = false,
defaultIsZipUrlTLSEnabled = false,
defaultName = '',
Expand All @@ -116,6 +118,14 @@ export function PolicyConfigContextProvider<ExtraFields = unknown>({
const [isZipUrlTLSEnabled, setIsZipUrlTLSEnabled] = useState<boolean>(defaultIsZipUrlTLSEnabled);
const [namespace, setNamespace] = useState<string>(defaultNamespace);

const isAddMonitorRoute = useRouteMatch(MONITOR_ADD_ROUTE);

useEffect(() => {
if (isAddMonitorRoute?.isExact) {
setMonitorType(DataStream.BROWSER);
}
}, [isAddMonitorRoute?.isExact]);

const value = useMemo(() => {
return {
monitorType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ interface Props {
}

const dataStreamToString = [
{ value: DataStream.HTTP, text: 'HTTP' },
{ value: DataStream.TCP, text: 'TCP' },
{ value: DataStream.ICMP, text: 'ICMP' },
{
value: DataStream.BROWSER,
text: i18n.translate(
Expand All @@ -53,6 +50,9 @@ const dataStreamToString = [
}
),
},
{ value: DataStream.HTTP, text: 'HTTP' },
{ value: DataStream.TCP, text: 'TCP' },
{ value: DataStream.ICMP, text: 'ICMP' },
];

export const CustomFields = memo<Props>(
Expand Down

0 comments on commit f788645

Please sign in to comment.