Skip to content

Commit

Permalink
Merge branch '7.17' into backport/7.17/pr-123464
Browse files Browse the repository at this point in the history
  • Loading branch information
kibanamachine committed Jan 24, 2022
2 parents 1beddff + 99798fd commit da6dbc5
Show file tree
Hide file tree
Showing 18 changed files with 337 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ export const StepDetailsForm: FC<StepDetailsFormProps> = React.memo(
defaults.isRetentionPolicyEnabled
);
const [retentionPolicyDateField, setRetentionPolicyDateField] = useState(
isRetentionPolicyAvailable ? dateFieldNames[0] : ''
isRetentionPolicyAvailable ? defaults.retentionPolicyDateField : ''
);
const [retentionPolicyMaxAge, setRetentionPolicyMaxAge] = useState(
defaults.retentionPolicyMaxAge
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ export const EditTransformFlyoutForm: FC<EditTransformFlyoutFormProps> = ({
);

const retentionDateFieldOptions = useMemo(() => {
return Array.isArray(dateFieldNames) ? dateFieldNames.map((text: string) => ({ text })) : [];
return Array.isArray(dateFieldNames)
? dateFieldNames.map((text: string) => ({ text, value: text }))
: [];
}, [dateFieldNames]);

return (
Expand Down Expand Up @@ -181,6 +183,11 @@ export const EditTransformFlyoutForm: FC<EditTransformFlyoutFormProps> = ({
onChange={(e) =>
dispatch({ field: 'retentionPolicyField', value: e.target.value })
}
hasNoInitialSelection={
!retentionDateFieldOptions
.map((d) => d.text)
.includes(formFields.retentionPolicyField.value)
}
/>
</EuiFormRow>
) : (
Expand Down
9 changes: 9 additions & 0 deletions x-pack/plugins/uptime/e2e/journeys/alerts/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* 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.
*/

export * from './tls_alert_flyouts_in_alerting_app';
export * from './status_alert_flyouts_in_alerting_app';
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* 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 { journey, step, expect, before } from '@elastic/synthetics';
import { assertText, byTestId, loginToKibana, waitForLoadingToFinish } from '../utils';

journey('StatusFlyoutInAlertingApp', async ({ page, params }) => {
before(async () => {
await waitForLoadingToFinish({ page });
});

const baseUrl = `${params.kibanaUrl}/app/management/insightsAndAlerting/triggersActions/rules`;

step('Go to Alerting app', async () => {
await page.goto(`${baseUrl}`, {
waitUntil: 'networkidle',
});
await loginToKibana({ page });
});

step('Open monitor status flyout', async () => {
await page.click(byTestId('createFirstAlertButton'));
await waitForLoadingToFinish({ page });
await page.click(byTestId('"xpack.uptime.alerts.monitorStatus-SelectOption"'));
await waitForLoadingToFinish({ page });
await assertText({ page, text: 'This alert will apply to approximately 0 monitors.' });
});

step('can add filters', async () => {
await page.click('text=Add filter');
await page.click(byTestId('"uptimeAlertAddFilter.monitor.type"'));
await page.click(byTestId('"uptimeCreateStatusAlert.filter_scheme"'));
});

step('can open query bar', async () => {
await page.click(byTestId('"xpack.uptime.alerts.monitorStatus.filterBar"'));

await page.fill(byTestId('"xpack.uptime.alerts.monitorStatus.filterBar"'), 'monitor.type : ');

await waitForLoadingToFinish({ page });

await assertText({ page, text: 'http' });

const suggestionItem = await page.$(byTestId('autoCompleteSuggestionText'));
expect(await suggestionItem?.textContent()).toBe('"http" ');

await page.click(byTestId('euiFlyoutCloseButton'));
await page.click(byTestId('confirmModalConfirmButton'));
});

step('Open tls alert flyout', async () => {
await page.click(byTestId('createFirstAlertButton'));
await waitForLoadingToFinish({ page });
await page.click(byTestId('"xpack.uptime.alerts.tlsCertificate-SelectOption"'));
await waitForLoadingToFinish({ page });
await assertText({ page, text: 'has a certificate expiring within' });
});

step('Tls alert flyout has setting values', async () => {
await assertText({ page, text: '30 days' });
await assertText({ page, text: '730 days' });
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* 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 { journey, step, before } from '@elastic/synthetics';
import { assertText, byTestId, loginToKibana, waitForLoadingToFinish } from '../utils';

journey('TlsFlyoutInAlertingApp', async ({ page, params }) => {
before(async () => {
await waitForLoadingToFinish({ page });
});

const baseUrl = `${params.kibanaUrl}/app/management/insightsAndAlerting/triggersActions/rules`;

step('Go to Alerting app', async () => {
await page.goto(`${baseUrl}`, {
waitUntil: 'networkidle',
});
await loginToKibana({ page });
});

step('Open tls alert flyout', async () => {
await page.click(byTestId('createFirstAlertButton'));
await waitForLoadingToFinish({ page });
await page.click(byTestId('"xpack.uptime.alerts.tlsCertificate-SelectOption"'));
await waitForLoadingToFinish({ page });
await assertText({ page, text: 'has a certificate expiring within' });
});

step('Tls alert flyout has setting values', async () => {
await assertText({ page, text: '30 days' });
await assertText({ page, text: '730 days' });
});
});
1 change: 1 addition & 0 deletions x-pack/plugins/uptime/e2e/journeys/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
*/

export * from './uptime.journey';
export * from './alerts';
35 changes: 35 additions & 0 deletions x-pack/plugins/uptime/e2e/journeys/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* 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 { expect, Page } from '@elastic/synthetics';

export async function waitForLoadingToFinish({ page }: { page: Page }) {
while (true) {
if ((await page.$(byTestId('kbnLoadingMessage'))) === null) break;
await page.waitForTimeout(5 * 1000);
}
}

export async function loginToKibana({ page }: { page: Page }) {
await page.fill('[data-test-subj=loginUsername]', 'elastic', {
timeout: 60 * 1000,
});
await page.fill('[data-test-subj=loginPassword]', 'changeme');

await page.click('[data-test-subj=loginSubmit]');

await waitForLoadingToFinish({ page });
}

export const byTestId = (testId: string) => {
return `[data-test-subj=${testId}]`;
};

export const assertText = async ({ page, text }: { page: Page; text: string }) => {
await page.waitForSelector(`text=${text}`, { timeout: 60 * 1000 });
expect(await page.$(`text=${text}`)).toBeTruthy();
};
18 changes: 13 additions & 5 deletions x-pack/plugins/uptime/e2e/playwright_start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,30 @@ import { esArchiverLoad, esArchiverUnload } from './tasks/es_archiver';

import './journeys';

const listOfJourneys = ['uptime', 'TlsFlyoutInAlertingApp', 'StatusFlyoutInAlertingApp'] as const;

export function playwrightRunTests() {
return async ({ getService }: any) => {
const result = await playwrightStart(getService);

if (result && result.uptime.status !== 'succeeded') {
throw new Error('Tests failed');
}
listOfJourneys.forEach((journey) => {
if (result?.[journey] && result[journey].status !== 'succeeded') {
throw new Error('Tests failed');
}
});
};
}

async function playwrightStart(getService: any) {
console.log('Loading esArchiver...');
await esArchiverLoad('full_heartbeat');
const esArchiver = getService('esArchiver');

esArchiverLoad('full_heartbeat');

const config = getService('config');

await esArchiver.loadIfNeeded('x-pack/test/functional/es_archives/ml/farequote');

const kibanaUrl = Url.format({
protocol: config.get('servers.kibana.protocol'),
hostname: config.get('servers.kibana.hostname'),
Expand All @@ -41,7 +49,7 @@ async function playwrightStart(getService: any) {
});

console.log('Removing esArchiver...');
await esArchiverUnload('full_heartbeat');
esArchiverUnload('full_heartbeat');

return res;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
*/

import { useDispatch, useSelector } from 'react-redux';
import React, { useCallback } from 'react';
import React, { useCallback, useEffect } from 'react';
import { AlertTlsComponent } from '../alert_tls';
import { setAlertFlyoutVisible } from '../../../../state/actions';
import { selectDynamicSettings } from '../../../../state/selectors';
import { getDynamicSettings } from '../../../../state/actions/dynamic_settings';

export const AlertTls: React.FC<{}> = () => {
const dispatch = useDispatch();
Expand All @@ -18,6 +19,13 @@ export const AlertTls: React.FC<{}> = () => {
[dispatch]
);
const { settings } = useSelector(selectDynamicSettings);

useEffect(() => {
if (typeof settings === 'undefined') {
dispatch(getDynamicSettings());
}
}, [dispatch, settings]);

return (
<AlertTlsComponent
ageThreshold={settings?.certAgeThreshold}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ describe('AddFilterButton component', () => {
disabled={false}
flush="left"
iconType="plusInCircleFilled"
isLoading={false}
onClick={[Function]}
size="s"
>
Expand Down Expand Up @@ -90,6 +91,7 @@ describe('AddFilterButton component', () => {
disabled={false}
flush="left"
iconType="plusInCircleFilled"
isLoading={false}
onClick={[Function]}
size="s"
>
Expand Down Expand Up @@ -143,6 +145,7 @@ describe('AddFilterButton component', () => {
disabled={true}
flush="left"
iconType="plusInCircleFilled"
isLoading={false}
onClick={[Function]}
size="s"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import React, { useState } from 'react';
import { EuiButtonEmpty, EuiContextMenuItem, EuiContextMenuPanel, EuiPopover } from '@elastic/eui';
import * as labels from '../translations';
import { useIndexPattern } from '../../../../contexts/uptime_index_pattern_context';

interface Props {
newFilters: string[];
Expand All @@ -20,6 +21,8 @@ export const AddFilterButton: React.FC<Props> = ({ newFilters, onNewFilter, aler

const getSelectedItems = (fieldName: string) => alertFilters?.[fieldName] ?? [];

const indexPattern = useIndexPattern();

const onButtonClick = () => {
setPopover(!isPopoverOpen);
};
Expand Down Expand Up @@ -62,6 +65,7 @@ export const AddFilterButton: React.FC<Props> = ({ newFilters, onNewFilter, aler
onClick={onButtonClick}
size="s"
flush="left"
isLoading={!indexPattern}
>
{labels.ADD_FILTER}
</EuiButtonEmpty>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,18 @@
* 2.0.
*/

import React, { createContext, useContext, useEffect } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import React, { createContext, useContext } from 'react';
import { useFetcher } from '../../../observability/public';
import { DataPublicPluginStart, IndexPattern } from '../../../../../src/plugins/data/public';
import { indexStatusSelector, selectDynamicSettings } from '../state/selectors';
import { getDynamicSettings } from '../state/actions/dynamic_settings';
import { useHasData } from '../components/overview/empty_state/use_has_data';

export const UptimeIndexPatternContext = createContext({} as IndexPattern);

export const UptimeIndexPatternContextProvider: React.FC<{ data: DataPublicPluginStart }> = ({
children,
data: { indexPatterns },
}) => {
const { settings } = useSelector(selectDynamicSettings);
const { data: indexStatus } = useSelector(indexStatusSelector);

const dispatch = useDispatch();

useEffect(() => {
if (typeof settings === 'undefined') {
dispatch(getDynamicSettings());
}
}, [dispatch, settings]);
const { settings, data: indexStatus } = useHasData();

const heartbeatIndices = settings?.heartbeatIndices || '';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import { takeLatest, put, call } from 'redux-saga/effects';
import { takeLeading, put, call, takeLatest } from 'redux-saga/effects';
import { Action } from 'redux-actions';
import { i18n } from '@kbn/i18n';
import { fetchEffectFactory } from './fetch_effect';
Expand All @@ -25,7 +25,7 @@ import { DynamicSettings } from '../../../common/runtime_types';
import { kibanaService } from '../kibana_service';

export function* fetchDynamicSettingsEffect() {
yield takeLatest(
yield takeLeading(
String(getDynamicSettings),
fetchEffectFactory(getDynamicSettingsAPI, getDynamicSettingsSuccess, getDynamicSettingsFail)
);
Expand Down
Loading

0 comments on commit da6dbc5

Please sign in to comment.