Skip to content

Commit

Permalink
Fix time filter in alerts table (#142377)
Browse files Browse the repository at this point in the history
  • Loading branch information
maryam-saeidi authored Oct 3, 2022
1 parent fe2210b commit bc65bc5
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 3 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 @@ -34,6 +34,13 @@ describe('buildEsQuery', () => {
timeRange: defaultTimeRange,
kuery: 'kibana.alert.status: "recovered" and kibana.alert.duration.us >= 120',
},
{
timeRange: {
from: 'now-15min',
to: 'now',
},
kuery: 'kibana.alert.status: "recovered"',
},
];

test.each(testData)('should generate correct es query for %j', ({ kuery, timeRange }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@

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

export function buildEsQuery(timeRange: TimeRange, kuery?: string) {
const timeFilter =
timeRange &&
getTime(undefined, timeRange, {
getRelativeTime(undefined, timeRange, {
fieldName: TIMESTAMP,
});
const filtersToUse = [...(timeFilter ? [timeFilter] : [])];
const filtersToUse = timeFilter ? [timeFilter] : [];
const queryToUse = kuery ? { query: kuery, language: 'kuery' } : [];

return kbnBuildEsQuery(undefined, queryToUse, filtersToUse);
Expand Down

0 comments on commit bc65bc5

Please sign in to comment.