[Infrastructure UI] Fix time range filter in alerts query (#153863)

## 📓 Summary

Closes #153741 

This PR fixes the time range filter by using the
`kibana.alert.time_range` field instead of `@timestamp`.

## 🧪 Testing

- Navigate to Hosts View
- Create an Inventory Alert that will trigger immediately
- Refresh the search until some alerts are triggered
- Play with relative time range (eg. 15 min ago -> 2 min ago) to verify
alerts appears correctly

---------

Co-authored-by: Marco Antonio Ghiani <marcoantonio.ghiani@elastic.co>
This commit is contained in:
Marco Antonio Ghiani 2023-04-03 11:20:51 +02:00 committed by GitHub
parent a1fccfd880
commit 77ce676518
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 2 deletions

View file

@ -7,7 +7,7 @@
import { useCallback, useMemo, useState } from 'react';
import createContainer from 'constate';
import { getTime } from '@kbn/data-plugin/common';
import { TIMESTAMP } from '@kbn/rule-data-utils';
import { ALERT_TIME_RANGE } from '@kbn/rule-data-utils';
import { BoolQuery, buildEsQuery, Filter } from '@kbn/es-query';
import { SnapshotNode } from '../../../../../common/http_api';
import { useUnifiedSearchContext } from './use_unified_search';
@ -77,7 +77,7 @@ const createAlertsEsQuery = ({
};
const createDateFilter = (date: HostsState['dateRange']) =>
getTime(undefined, date, { fieldName: TIMESTAMP });
getTime(undefined, date, { fieldName: ALERT_TIME_RANGE });
const createAlertStatusFilter = (status: AlertStatus = 'all'): Filter | null =>
ALERT_STATUS_QUERY[status] ? { query: ALERT_STATUS_QUERY[status], meta: {} } : null;

View file

@ -209,6 +209,10 @@
"system_status": {
"type": "keyword"
},
"time_range": {
"type": "date_range",
"format": "epoch_millis||strict_date_optional_time"
},
"uuid": {
"type": "keyword"
},
@ -484,6 +488,10 @@
"system_status": {
"type": "keyword"
},
"time_range": {
"type": "date_range",
"format": "epoch_millis||strict_date_optional_time"
},
"uuid": {
"type": "keyword"
},
@ -735,6 +743,10 @@
"system_status": {
"type": "keyword"
},
"time_range": {
"type": "date_range",
"format": "epoch_millis||strict_date_optional_time"
},
"uuid": {
"type": "keyword"
},