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

[Discover] Add data view changed warning after alert rule created #134674

Merged
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
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

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,
dataViewUpdatedWarn,
dimaanj marked this conversation as resolved.
Show resolved Hide resolved
} = 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()
) {
dataViewUpdatedWarn();
}

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 dataViewUpdatedWarn = 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 {
displayRuleChangedWarn,
displayPossibleDocsDiffInfoAlert,
showDataViewFetchError,
fetchAlert,
fetchSearchSource,
dataViewUpdatedWarn,
};
};
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 @@ -127,6 +127,7 @@ export default async function ({ readConfigFile }: FtrConfigProviderContext) {
stackAlerts: ['all'],
discover: ['all'],
advancedSettings: ['all'],
indexPatterns: ['all'],
},
spaces: ['*'],
},
Expand Down