Skip to content

Commit

Permalink
[Discover] Add data view changed warning after alert rule created (el…
Browse files Browse the repository at this point in the history
…astic#134674)

* [Discover] add data view changed warn

* [Discover] add functional test

* [Discover] update snapshot

* [Discover] adjust comment

* [Discover] apply suggestions
  • Loading branch information
dimaanj authored and Vadim Yakhin committed Jul 5, 2022
1 parent b4e3a02 commit 8bbd0c8
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 5 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,17 @@ export const AddFilter = ({ onAddFilter }: AddFilterProps) => {
<EuiFieldText
fullWidth
value={filter}
data-test-subj="fieldFilterInput"
onChange={(e) => setFilter(e.target.value.trim())}
placeholder={sourcePlaceholder}
/>
</EuiFlexItem>
<EuiFlexItem>
<EuiButton isDisabled={filter.length === 0} onClick={onAddButtonClick}>
<EuiButton
data-test-subj="addFieldFilterButton"
isDisabled={filter.length === 0}
onClick={onAddButtonClick}
>
<FormattedMessage
id="indexPatternManagement.editIndexPattern.source.addButtonLabel"
defaultMessage="Add"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export function ViewAlertRoute() {
displayRuleChangedWarn,
displayPossibleDocsDiffInfoAlert,
showDataViewFetchError,
showDataViewUpdatedWarning,
} = getAlertUtils(toastNotifications, core, data);

const navigateToResults = async () => {
Expand All @@ -79,9 +80,12 @@ export function ViewAlertRoute() {
}

const calculatedChecksum = getCurrentChecksum(fetchedAlert.params);
// rule params changed
if (openActualAlert && calculatedChecksum !== queryParams.checksum) {
displayRuleChangedWarn();
} else if (openActualAlert && calculatedChecksum === queryParams.checksum) {
}
// documents might be updated or deleted
else if (openActualAlert && calculatedChecksum === queryParams.checksum) {
displayPossibleDocsDiffInfoAlert();
}

Expand All @@ -93,12 +97,24 @@ export function ViewAlertRoute() {

const dataView = fetchedSearchSource.getField('index');
const timeFieldName = dataView?.timeFieldName;
// data view fetch error
if (!dataView || !timeFieldName) {
showDataViewFetchError(fetchedAlert.id);
history.push(DISCOVER_MAIN_ROUTE);
return;
}

const dataViewSavedObject = await core.savedObjects.client.get('index-pattern', dataView.id!);
const alertUpdatedAt = fetchedAlert.updatedAt;
const dataViewUpdatedAt = dataViewSavedObject.updatedAt!;
// data view updated after the last update of the alert rule
if (
openActualAlert &&
new Date(dataViewUpdatedAt).valueOf() > new Date(alertUpdatedAt).valueOf()
) {
showDataViewUpdatedWarning();
}

const timeRange = openActualAlert
? { from: queryParams.from, to: queryParams.to }
: buildTimeRangeFilter(dataView, fetchedAlert, timeFieldName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,26 @@ export const getAlertUtils = (
}
};

const showDataViewUpdatedWarning = async () => {
const warnTitle = i18n.translate('discover.viewAlert.dataViewChangedWarnTitle', {
defaultMessage: 'Data View has changed',
});
const warnDescription = i18n.translate('discover.viewAlert.dataViewChangedWarnDescription', {
defaultMessage: `Data view has been updated after the last update of the alert rule.`,
});

toastNotifications.addWarning({
title: warnTitle,
text: toMountPoint(<MarkdownSimple>{warnDescription}</MarkdownSimple>),
});
};

return {
fetchAlert,
fetchSearchSource,
displayRuleChangedWarn,
displayPossibleDocsDiffInfoAlert,
showDataViewFetchError,
fetchAlert,
fetchSearchSource,
showDataViewUpdatedWarning,
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
const queryBar = getService('queryBar');
const security = getService('security');
const filterBar = getService('filterBar');
const find = getService('find');

const SOURCE_DATA_INDEX = 'search-source-alert';
const OUTPUT_DATA_INDEX = 'search-source-alert-output';
Expand Down Expand Up @@ -171,6 +172,14 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
return { message, title };
};

const getErrorToastTitle = async () => {
const toastList = await testSubjects.find('globalToastList');
const title = await (
await toastList.findByCssSelector('.euiToast--danger > .euiToastHeader')
).getVisibleText();
return title;
};

const openOutputIndex = async () => {
await PageObjects.common.navigateToApp('discover');
await PageObjects.header.waitUntilLoadingHasFinished();
Expand Down Expand Up @@ -327,6 +336,39 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
);
});

it('should display warning about recently updated data view', async () => {
await PageObjects.common.navigateToUrlWithBrowserHistory(
'management',
`/kibana/dataViews/dataView/${sourceDataViewId}`,
undefined
);
await PageObjects.header.waitUntilLoadingHasFinished();

await testSubjects.click('tab-sourceFilters');
await testSubjects.click('fieldFilterInput');

await PageObjects.common.sleep(15000);

const input = await find.activeElement();
await input.type('message');

await testSubjects.click('addFieldFilterButton');

await openOutputIndex();
await navigateToResults();

await openOutputIndex();
await navigateToResults();

const { message, title } = await getLastToast();

expect(await dataGrid.getDocCount()).to.be(1);
expect(title).to.be.equal('Data View has changed');
expect(message).to.be.equal(
'Data view has been updated after the last update of the alert rule.'
);
});

it('should display not found index error', async () => {
await openOutputIndex();
const link = await getResultsLink();
Expand All @@ -340,7 +382,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {

await navigateToDiscover(link);

const { title } = await getLastToast();
const title = await getErrorToastTitle();
expect(title).to.be.equal(
'No matching indices found: No indices match "search-source-alert"'
);
Expand Down
1 change: 1 addition & 0 deletions x-pack/test/functional_with_es_ssl/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ export default async function ({ readConfigFile }: FtrConfigProviderContext) {
stackAlerts: ['all'],
discover: ['all'],
advancedSettings: ['all'],
indexPatterns: ['all'],
},
spaces: ['*'],
},
Expand Down

0 comments on commit 8bbd0c8

Please sign in to comment.