Skip to content

Commit

Permalink
[8.7] [AO] Fix time range filter in alerts table (#153648) (#155739)
Browse files Browse the repository at this point in the history
# Backport

This will backport the following commits from `main` to `8.7`:
- [[AO] Fix time range filter in alerts table
(#153648)](#153648)

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

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

<!--BACKPORT [{"author":{"name":"Maryam
Saeidi","email":"[email protected]"},"sourceCommit":{"committedDate":"2023-03-25T10:31:51Z","message":"[AO]
Fix time range filter in alerts table (#153648)\n\nFixes
#153284\r\n\r\n## Summary\r\n\r\nThis PR fixes the time range filter by
using the `ALERT_TIME_RANGE`\r\ninstead of `TIMESTAMP`\r\ncc @tonyghiani
\r\n\r\n\r\n\r\nhttps://user-images.githubusercontent.com/12370520/227532946-087c85c5-1390-47eb-bf0a-bd7319a000a7.mov","sha":"62827b1aabb7db6d5f8b7987b492c768169d291e","branchLabelMapping":{"^v8.8.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","Team:
Actionable
Observability","backport:prev-minor","v8.8.0"],"number":153648,"url":"https://github.com/elastic/kibana/pull/153648","mergeCommit":{"message":"[AO]
Fix time range filter in alerts table (#153648)\n\nFixes
#153284\r\n\r\n## Summary\r\n\r\nThis PR fixes the time range filter by
using the `ALERT_TIME_RANGE`\r\ninstead of `TIMESTAMP`\r\ncc @tonyghiani
\r\n\r\n\r\n\r\nhttps://user-images.githubusercontent.com/12370520/227532946-087c85c5-1390-47eb-bf0a-bd7319a000a7.mov","sha":"62827b1aabb7db6d5f8b7987b492c768169d291e"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v8.8.0","labelRegex":"^v8.8.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/153648","number":153648,"mergeCommit":{"message":"[AO]
Fix time range filter in alerts table (#153648)\n\nFixes
#153284\r\n\r\n## Summary\r\n\r\nThis PR fixes the time range filter by
using the `ALERT_TIME_RANGE`\r\ninstead of `TIMESTAMP`\r\ncc @tonyghiani
\r\n\r\n\r\n\r\nhttps://user-images.githubusercontent.com/12370520/227532946-087c85c5-1390-47eb-bf0a-bd7319a000a7.mov","sha":"62827b1aabb7db6d5f8b7987b492c768169d291e"}}]}]
BACKPORT-->
  • Loading branch information
maryam-saeidi authored Apr 26, 2023
1 parent 1dce8b2 commit e7fd103
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ describe('ObservabilityAlertSearchBar', () => {
},
{
range: {
'@timestamp': expect.objectContaining({
'kibana.alert.time_range': expect.objectContaining({
format: 'strict_date_optional_time',
gte: mockedFrom,
lte: mockedTo,
Expand Down Expand Up @@ -138,7 +138,7 @@ describe('ObservabilityAlertSearchBar', () => {
},
{
range: {
'@timestamp': expect.objectContaining({
'kibana.alert.time_range': expect.objectContaining({
format: 'strict_date_optional_time',
gte: mockedFrom,
lte: mockedTo,
Expand Down

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 @@ -6,14 +6,14 @@
*/

import { buildEsQuery as kbnBuildEsQuery, TimeRange, Query } from '@kbn/es-query';
import { TIMESTAMP } from '@kbn/rule-data-utils';
import { ALERT_TIME_RANGE } from '@kbn/rule-data-utils';
import { getTime } from '@kbn/data-plugin/common';

export function buildEsQuery(timeRange: TimeRange, kuery?: string, queries: Query[] = []) {
const timeFilter =
timeRange &&
getTime(undefined, timeRange, {
fieldName: TIMESTAMP,
fieldName: ALERT_TIME_RANGE,
});
const filtersToUse = timeFilter ? [timeFilter] : [];
const kueryFilter = kuery ? [{ query: kuery, language: 'kuery' }] : [];
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,10 @@
"system_status": {
"type": "keyword"
},
"time_range": {
"type": "date_range",
"format": "epoch_millis||strict_date_optional_time"
},
"uuid": {
"type": "keyword"
},
Expand Down Expand Up @@ -470,6 +474,10 @@
"system_status": {
"type": "keyword"
},
"time_range": {
"type": "date_range",
"format": "epoch_millis||strict_date_optional_time"
},
"uuid": {
"type": "keyword"
},
Expand Down Expand Up @@ -714,6 +722,10 @@
"system_status": {
"type": "keyword"
},
"time_range": {
"type": "date_range",
"format": "epoch_millis||strict_date_optional_time"
},
"uuid": {
"type": "keyword"
},
Expand Down Expand Up @@ -752,4 +764,4 @@
}
}
}
}
}
15 changes: 15 additions & 0 deletions x-pack/test/functional/services/observability/overview/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ const DATE_WITH_DATA = {
rangeTo: '2021-10-20T13:36:22.109Z',
};

const DATE_WITHOUT_DATA = {
rangeFrom: '2021-09-18T13:36:22.109Z',
rangeTo: '2021-09-20T13:36:22.109Z',
};

const ALERTS_TITLE = 'Alerts';
const ALERTS_ACCORDION_SELECTOR = `accordion-${ALERTS_TITLE}`;
const ALERTS_SECTION_BUTTON_CSS_SELECTOR = `[data-test-subj=${ALERTS_ACCORDION_SELECTOR}] button.euiAccordion__button`;
Expand All @@ -38,6 +43,15 @@ export function ObservabilityOverviewCommonProvider({
);
};

const navigateToOverviewPageWithoutAlerts = async () => {
return await pageObjects.common.navigateToUrlWithBrowserHistory(
'observability',
'/overview',
`?rangeFrom=${DATE_WITHOUT_DATA.rangeFrom}&rangeTo=${DATE_WITHOUT_DATA.rangeTo}`,
{ ensureCurrentUrl: false }
);
};

const navigateToOverviewPage = async () => {
await pageObjects.common.navigateToUrlWithBrowserHistory(
'observability',
Expand Down Expand Up @@ -81,6 +95,7 @@ export function ObservabilityOverviewCommonProvider({
return {
getAlertsTableNoDataOrFail,
navigateToOverviewPageWithAlerts,
navigateToOverviewPageWithoutAlerts,
navigateToOverviewPage,
openAlertsSectionAndWaitToAppear,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default ({ getService, getPageObjects }: FtrProviderContext) => {
const observability = getService('observability');
const retry = getService('retry');

describe('Observability alerts / Add to case', function () {
describe('Observability alerts / Add to case >', function () {
this.tags('includeFirefox');

before(async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const RECOVERED_ALERTS = 30;
export default ({ getService }: FtrProviderContext) => {
const esArchiver = getService('esArchiver');

describe('alert status filter', function () {
describe('Alert status filter >', function () {
this.tags('includeFirefox');

const observability = getService('observability');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

import expect from '@kbn/expect';
import { ALERT_STATUS_RECOVERED } from '@kbn/rule-data-utils';
import { FtrProviderContext } from '../../../../ftr_provider_context';
import { asyncForEach } from '../../helpers';

Expand All @@ -20,7 +21,7 @@ export default ({ getService }: FtrProviderContext) => {
const esArchiver = getService('esArchiver');
const find = getService('find');

describe('Observability alerts', function () {
describe('Observability alerts >', function () {
this.tags('includeFirefox');

const testSubjects = getService('testSubjects');
Expand Down Expand Up @@ -49,12 +50,12 @@ export default ({ getService }: FtrProviderContext) => {

describe('Alerts table', () => {
before(async () => {
await esArchiver.load('x-pack/test/functional/es_archives/infra/metrics_and_logs');
await esArchiver.load('x-pack/test/functional/es_archives/infra/simple_logs');
await observability.alerts.common.navigateToTimeWithData();
});

after(async () => {
await esArchiver.unload('x-pack/test/functional/es_archives/infra/metrics_and_logs');
await esArchiver.unload('x-pack/test/functional/es_archives/infra/simple_logs');
});

it('Renders the table', async () => {
Expand Down Expand Up @@ -113,8 +114,9 @@ export default ({ getService }: FtrProviderContext) => {

it('Correctly applies date picker selections', async () => {
await retry.try(async () => {
await observability.alerts.common.setAlertStatusFilter(ALERT_STATUS_RECOVERED);
await (await testSubjects.find('superDatePickerToggleQuickMenuButton')).click();
// We shouldn't expect any data for the last 15 minutes
// We shouldn't expect any recovered alert for the last 15 minutes
await (await testSubjects.find('superDatePickerCommonlyUsed_Last_15 minutes')).click();
await observability.alerts.common.getNoDataStateOrFail();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const ALL_ALERTS = 10;
export default ({ getService }: FtrProviderContext) => {
const esArchiver = getService('esArchiver');

describe('Observability overview', function () {
describe('Observability overview >', function () {
this.tags('includeFirefox');

const observability = getService('observability');
Expand All @@ -29,7 +29,7 @@ export default ({ getService }: FtrProviderContext) => {

describe('Without alerts', function () {
it('navigate and open alerts section', async () => {
await observability.overview.common.navigateToOverviewPage();
await observability.overview.common.navigateToOverviewPageWithoutAlerts();
await observability.overview.common.openAlertsSectionAndWaitToAppear();
});

Expand Down

0 comments on commit e7fd103

Please sign in to comment.