[8.7] [ML] Change point detection: fix applying filters and query to the charts (#154707) (#154712)

# Backport

This will backport the following commits from `main` to `8.7`:
- [[ML] Change point detection: fix applying filters and query to the
charts (#154707)](https://github.com/elastic/kibana/pull/154707)

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

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

<!--BACKPORT [{"author":{"name":"Dima
Arnautov","email":"dmitrii.arnautov@elastic.co"},"sourceCommit":{"committedDate":"2023-04-11T10:15:40Z","message":"[ML]
Change point detection: fix applying filters and query to the charts
(#154707)","sha":"7db297bec59f6ac8527487baf7783ed8f44280e6","branchLabelMapping":{"^v8.8.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix",":ml","Team:ML","Feature:ML/AIOps","v8.8.0","v8.7.1"],"number":154707,"url":"https://github.com/elastic/kibana/pull/154707","mergeCommit":{"message":"[ML]
Change point detection: fix applying filters and query to the charts
(#154707)","sha":"7db297bec59f6ac8527487baf7783ed8f44280e6"}},"sourceBranch":"main","suggestedTargetBranches":["8.7"],"targetPullRequestStates":[{"branch":"main","label":"v8.8.0","labelRegex":"^v8.8.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/154707","number":154707,"mergeCommit":{"message":"[ML]
Change point detection: fix applying filters and query to the charts
(#154707)","sha":"7db297bec59f6ac8527487baf7783ed8f44280e6"}},{"branch":"8.7","label":"v8.7.1","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Dima Arnautov <dmitrii.arnautov@elastic.co>
This commit is contained in:
Kibana Machine 2023-04-11 08:39:59 -04:00 committed by GitHub
parent 30c920e1dd
commit e0fc37bdfa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -31,35 +31,39 @@ export const ChartComponent: FC<ChartComponentProps> = React.memo(({ annotation
const timeRange = useTimeRangeUpdates();
const { dataView } = useDataSource();
const { requestParams, bucketInterval } = useChangePointDetectionContext();
const { requestParams, bucketInterval, resultQuery, resultFilters } =
useChangePointDetectionContext();
const filters = useMemo(() => {
return annotation.group
? [
{
meta: {
index: dataView.id!,
alias: null,
negate: false,
disabled: false,
type: 'phrase',
key: annotation.group.name,
params: {
query: annotation.group.value,
return [
...resultFilters,
...(annotation.group
? [
{
meta: {
index: dataView.id!,
alias: null,
negate: false,
disabled: false,
type: 'phrase',
key: annotation.group.name,
params: {
query: annotation.group.value,
},
},
query: {
match_phrase: {
[annotation.group.name]: annotation.group.value,
},
},
$state: {
store: FilterStateStore.APP_STATE,
},
},
query: {
match_phrase: {
[annotation.group.name]: annotation.group.value,
},
},
$state: {
store: FilterStateStore.APP_STATE,
},
},
]
: [];
}, [dataView.id, annotation.group]);
]
: []),
];
}, [dataView.id, annotation.group, resultFilters]);
// @ts-ignore incorrect types for attributes
const attributes = useMemo<TypedLensByValueInput['attributes']>(() => {
@ -151,10 +155,7 @@ export const ChartComponent: FC<ChartComponentProps> = React.memo(({ annotation
: []),
],
},
query: {
query: '',
language: 'kuery',
},
query: resultQuery,
filters,
datasourceStates: {
formBased: {
@ -202,13 +203,26 @@ export const ChartComponent: FC<ChartComponentProps> = React.memo(({ annotation
adHocDataViews: {},
},
};
}, [dataView.id, dataView.timeFieldName, annotation, requestParams, filters, bucketInterval]);
}, [
annotation.group?.value,
annotation.timestamp,
annotation.label,
dataView.id,
dataView.timeFieldName,
resultQuery,
filters,
bucketInterval.expression,
requestParams.fn,
requestParams.metricField,
]);
return (
<EmbeddableComponent
id={`changePointChart_${annotation.group ? annotation.group.value : annotation.label}`}
style={{ height: 350 }}
timeRange={timeRange}
query={resultQuery}
filters={filters}
attributes={attributes}
renderMode={'view'}
executionContext={{