Skip to content

Commit

Permalink
[8.x] [OBX-UX-MGMT][ALERTING] Fix APM rule error msg when KQL filter …
Browse files Browse the repository at this point in the history
…is invalid (elastic#203096) (elastic#203134)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[OBX-UX-MGMT][ALERTING] Fix APM rule error msg when KQL filter is
invalid (elastic#203096)](elastic#203096)

<!--- Backport version: 9.4.3 -->

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

<!--BACKPORT [{"author":{"name":"Faisal
Kanout","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-12-05T16:07:58Z","message":"[OBX-UX-MGMT][ALERTING]
Fix APM rule error msg when KQL filter is invalid (elastic#203096)\n\n##
Summary\r\n\r\nIt fixes elastic#199273
by validating\r\nthe query before passing it to the preview
chart","sha":"f1109cfccedfd386263a00207df81c766cfaf6e4","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["bug","release_note:fix","v9.0.0","backport:prev-minor","ci:project-deploy-observability","Team:obs-ux-infra_services","Team:obs-ux-management"],"title":"[OBX-UX-MGMT][ALERTING]
Fix APM rule error msg when KQL filter is
invalid","number":203096,"url":"https://github.com/elastic/kibana/pull/203096","mergeCommit":{"message":"[OBX-UX-MGMT][ALERTING]
Fix APM rule error msg when KQL filter is invalid (elastic#203096)\n\n##
Summary\r\n\r\nIt fixes elastic#199273
by validating\r\nthe query before passing it to the preview
chart","sha":"f1109cfccedfd386263a00207df81c766cfaf6e4"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/203096","number":203096,"mergeCommit":{"message":"[OBX-UX-MGMT][ALERTING]
Fix APM rule error msg when KQL filter is invalid (elastic#203096)\n\n##
Summary\r\n\r\nIt fixes elastic#199273
by validating\r\nthe query before passing it to the preview
chart","sha":"f1109cfccedfd386263a00207df81c766cfaf6e4"}}]}] BACKPORT-->

Co-authored-by: Faisal Kanout <[email protected]>
  • Loading branch information
kibanamachine and fkanout authored Dec 5, 2024
1 parent 627d84b commit a70bdf0
Showing 1 changed file with 33 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
*/
import React from 'react';
import { i18n } from '@kbn/i18n';
import { Query } from '@kbn/es-query';
import { EuiFormErrorText } from '@elastic/eui';
import { Query, fromKueryExpression } from '@kbn/es-query';
import { useKibana } from '@kbn/kibana-react-plugin/public';
import { ApmPluginStartDeps } from '../../../plugin';
import { useAdHocApmDataView } from '../../../hooks/use_adhoc_apm_data_view';
Expand All @@ -26,7 +27,7 @@ export function ApmRuleUnifiedSearchBar({
setRuleParams: (key: string, value: any) => void;
}) {
const { services } = useKibana<ApmPluginStartDeps>();

const [queryError, setQueryError] = React.useState<string>();
const {
unifiedSearch: {
ui: { SearchBar },
Expand All @@ -38,27 +39,38 @@ export function ApmRuleUnifiedSearchBar({

const handleSubmit = (payload: { query?: Query }) => {
const { query } = payload;
setRuleParams('searchConfiguration', { query });
try {
setQueryError(undefined);
fromKueryExpression(query?.query as string);
setRuleParams('searchConfiguration', { query });
} catch (e) {
setQueryError(e.message);
}
};

return (
<SearchBar
appName={i18n.translate('xpack.apm.appName', {
defaultMessage: 'APM',
})}
iconType="search"
placeholder={placeholder || searchbarPlaceholder}
indexPatterns={dataView ? [dataView] : undefined}
showQueryInput={true}
showQueryMenu={false}
showFilterBar={false}
showDatePicker={false}
showSubmitButton={false}
displayStyle="inPage"
onQueryChange={handleSubmit}
onQuerySubmit={handleSubmit}
dataTestSubj="apmRuleUnifiedSearchBar"
query={ruleParams.searchConfiguration?.query}
/>
<>
<SearchBar
appName={i18n.translate('xpack.apm.appName', {
defaultMessage: 'APM',
})}
iconType="search"
placeholder={placeholder || searchbarPlaceholder}
indexPatterns={dataView ? [dataView] : undefined}
showQueryInput={true}
showQueryMenu={false}
showFilterBar={false}
showDatePicker={false}
showSubmitButton={false}
displayStyle="inPage"
onQueryChange={handleSubmit}
onQuerySubmit={handleSubmit}
dataTestSubj="apmRuleUnifiedSearchBar"
query={ruleParams.searchConfiguration?.query}
/>
{queryError && (
<EuiFormErrorText data-test-subj="apmSearchBarErrorCallout">{queryError}</EuiFormErrorText>
)}
</>
);
}

0 comments on commit a70bdf0

Please sign in to comment.