forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Monitoring] Add KQL filter bar to alerts (elastic#111663)
* [Monitoring] Add KQL filter bar to alerts * Finish adding filters to UI * Adding filterQuery to all the backend alert functions * removing unused translations * fixing types * Moving alerting code to async imports Co-authored-by: Kibana Machine <[email protected]>
- Loading branch information
1 parent
ef8518d
commit a29fdf5
Showing
79 changed files
with
1,208 additions
and
120 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
...gins/monitoring/public/alerts/components/param_details_form/use_derived_index_pattern.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { useEffect, useState } from 'react'; | ||
import { DataPublicPluginStart, IFieldType, IIndexPattern } from 'src/plugins/data/public'; | ||
import { | ||
INDEX_PATTERN_BEATS, | ||
INDEX_PATTERN_ELASTICSEARCH, | ||
INDEX_PATTERN_KIBANA, | ||
INDEX_PATTERN_LOGSTASH, | ||
} from '../../../../common/constants'; | ||
import { prefixIndexPattern } from '../../../../common/ccs_utils'; | ||
import { MonitoringConfig } from '../../../types'; | ||
|
||
const INDEX_PATTERNS = `${INDEX_PATTERN_ELASTICSEARCH},${INDEX_PATTERN_KIBANA},${INDEX_PATTERN_LOGSTASH},${INDEX_PATTERN_BEATS}`; | ||
|
||
export const useDerivedIndexPattern = ( | ||
data: DataPublicPluginStart, | ||
config?: MonitoringConfig | ||
): { loading: boolean; derivedIndexPattern: IIndexPattern } => { | ||
const indexPattern = prefixIndexPattern(config || ({} as MonitoringConfig), INDEX_PATTERNS, '*'); | ||
const [loading, setLoading] = useState<boolean>(true); | ||
const [fields, setFields] = useState<IFieldType[]>([]); | ||
useEffect(() => { | ||
(async function fetchData() { | ||
const result = await data.indexPatterns.getFieldsForWildcard({ | ||
pattern: indexPattern, | ||
}); | ||
setFields(result); | ||
setLoading(false); | ||
})(); | ||
}, [indexPattern, data.indexPatterns]); | ||
return { | ||
loading, | ||
derivedIndexPattern: { | ||
title: indexPattern, | ||
fields, | ||
}, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
x-pack/plugins/monitoring/public/alerts/legacy_alert/expression.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
import React, { useCallback } from 'react'; | ||
import { debounce } from 'lodash'; | ||
import { EuiSpacer, EuiForm, EuiFormRow } from '@elastic/eui'; | ||
import { i18n } from '@kbn/i18n'; | ||
import { useDerivedIndexPattern } from '../components/param_details_form/use_derived_index_pattern'; | ||
import { convertKueryToElasticSearchQuery } from '../../lib/kuery'; | ||
import { KueryBar } from '../../components/kuery_bar'; | ||
import { Props } from '../components/param_details_form/expression'; | ||
|
||
const FILTER_TYPING_DEBOUNCE_MS = 500; | ||
|
||
export const Expression = ({ alertParams, config, setAlertParams, data }: Props) => { | ||
const { derivedIndexPattern } = useDerivedIndexPattern(data, config); | ||
const onFilterChange = useCallback( | ||
(filter: string) => { | ||
setAlertParams('filterQueryText', filter); | ||
setAlertParams( | ||
'filterQuery', | ||
convertKueryToElasticSearchQuery(filter, derivedIndexPattern) || '' | ||
); | ||
}, | ||
[setAlertParams, derivedIndexPattern] | ||
); | ||
|
||
/* eslint-disable-next-line react-hooks/exhaustive-deps */ | ||
const debouncedOnFilterChange = useCallback(debounce(onFilterChange, FILTER_TYPING_DEBOUNCE_MS), [ | ||
onFilterChange, | ||
]); | ||
return ( | ||
<EuiForm component="form"> | ||
<EuiFormRow | ||
fullWidth | ||
label={i18n.translate('xpack.monitoring.alerts.filterLable', { | ||
defaultMessage: 'Filter', | ||
})} | ||
helpText={i18n.translate('xpack.monitoring.alerts.filterHelpText', { | ||
defaultMessage: 'Use a KQL expression to limit the scope of your alert trigger.', | ||
})} | ||
> | ||
<KueryBar | ||
value={alertParams.filterQueryText} | ||
derivedIndexPattern={derivedIndexPattern} | ||
onSubmit={onFilterChange} | ||
onChange={debouncedOnFilterChange} | ||
/> | ||
</EuiFormRow> | ||
<EuiSpacer /> | ||
</EuiForm> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.