Skip to content

Commit

Permalink
[8.15] [ML] Fix Anomaly Swim Lane Embeddable not updating properly on…
Browse files Browse the repository at this point in the history
… query change (#195090) (#195723)

# Backport

This will backport the following commits from `main` to `8.15`:
- [[ML] Fix Anomaly Swim Lane Embeddable not updating properly on query
change (#195090)](#195090)

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

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

<!--BACKPORT [{"author":{"name":"Robert
Jaszczurek","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-10-10T09:19:28Z","message":"[ML]
Fix Anomaly Swim Lane Embeddable not updating properly on query change
(#195090)\n\n## Summary\r\n\r\nFix for:
[#194579](https://github.com/elastic/kibana/issues/194579)\r\nIn Anomaly
Explorer, we do not limit the query size, as it is based on
a\r\nconstant value of `1000`.\r\nHowever, we did limit the query for
the embeddable by setting the size\r\nto the value of the previous query
cardinality.\r\nAfter discussing with @darnautov, we couldn't identify
any potential\r\nregressions from removing this check.\r\nIncludes fix
for issue mentioned
in:\r\n[#2397303538](https://github.com/elastic/kibana/pull/195090#issuecomment-2397303538)\r\nWhen
querying from a pagination page other than page 1, we didn’t
reset\r\nthe `fromPage` value, which prevented the query from returning
results.\r\nBefore:\r\n\r\n\r\nhttps://github.com/user-attachments/assets/80476a0c-8fcc-40f7-8cac-04ecfb01d614\r\n\r\nAfter:\r\n\r\n\r\nhttps://github.com/user-attachments/assets/f55e20fd-b1a4-446e-b16a-b1a6069bf63c\r\n\r\n\r\n\r\nhttps://github.com/user-attachments/assets/d31cb47d-cd13-4b3c-b6f9-c0ee60d3a370","sha":"d44d3543fb71858de5b09e04f3a538bd8cb0bf5b","branchLabelMapping":{"^v9.0.0$":"main","^v8.16.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix",":ml","Feature:Anomaly
Detection","v9.0.0","Team:ML","v8.16.0","backport:version","v8.15.3"],"title":"[ML]
Fix Anomaly Swim Lane Embeddable not updating properly on query
change","number":195090,"url":"https://github.com/elastic/kibana/pull/195090","mergeCommit":{"message":"[ML]
Fix Anomaly Swim Lane Embeddable not updating properly on query change
(#195090)\n\n## Summary\r\n\r\nFix for:
[#194579](https://github.com/elastic/kibana/issues/194579)\r\nIn Anomaly
Explorer, we do not limit the query size, as it is based on
a\r\nconstant value of `1000`.\r\nHowever, we did limit the query for
the embeddable by setting the size\r\nto the value of the previous query
cardinality.\r\nAfter discussing with @darnautov, we couldn't identify
any potential\r\nregressions from removing this check.\r\nIncludes fix
for issue mentioned
in:\r\n[#2397303538](https://github.com/elastic/kibana/pull/195090#issuecomment-2397303538)\r\nWhen
querying from a pagination page other than page 1, we didn’t
reset\r\nthe `fromPage` value, which prevented the query from returning
results.\r\nBefore:\r\n\r\n\r\nhttps://github.com/user-attachments/assets/80476a0c-8fcc-40f7-8cac-04ecfb01d614\r\n\r\nAfter:\r\n\r\n\r\nhttps://github.com/user-attachments/assets/f55e20fd-b1a4-446e-b16a-b1a6069bf63c\r\n\r\n\r\n\r\nhttps://github.com/user-attachments/assets/d31cb47d-cd13-4b3c-b6f9-c0ee60d3a370","sha":"d44d3543fb71858de5b09e04f3a538bd8cb0bf5b"}},"sourceBranch":"main","suggestedTargetBranches":["8.x","8.15"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/195090","number":195090,"mergeCommit":{"message":"[ML]
Fix Anomaly Swim Lane Embeddable not updating properly on query change
(#195090)\n\n## Summary\r\n\r\nFix for:
[#194579](https://github.com/elastic/kibana/issues/194579)\r\nIn Anomaly
Explorer, we do not limit the query size, as it is based on
a\r\nconstant value of `1000`.\r\nHowever, we did limit the query for
the embeddable by setting the size\r\nto the value of the previous query
cardinality.\r\nAfter discussing with @darnautov, we couldn't identify
any potential\r\nregressions from removing this check.\r\nIncludes fix
for issue mentioned
in:\r\n[#2397303538](https://github.com/elastic/kibana/pull/195090#issuecomment-2397303538)\r\nWhen
querying from a pagination page other than page 1, we didn’t
reset\r\nthe `fromPage` value, which prevented the query from returning
results.\r\nBefore:\r\n\r\n\r\nhttps://github.com/user-attachments/assets/80476a0c-8fcc-40f7-8cac-04ecfb01d614\r\n\r\nAfter:\r\n\r\n\r\nhttps://github.com/user-attachments/assets/f55e20fd-b1a4-446e-b16a-b1a6069bf63c\r\n\r\n\r\n\r\nhttps://github.com/user-attachments/assets/d31cb47d-cd13-4b3c-b6f9-c0ee60d3a370","sha":"d44d3543fb71858de5b09e04f3a538bd8cb0bf5b"}},{"branch":"8.x","label":"v8.16.0","branchLabelMappingKey":"^v8.16.0$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.15","label":"v8.15.3","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Robert Jaszczurek <[email protected]>
  • Loading branch information
kibanamachine and rbrtj authored Oct 10, 2024
1 parent 2372820 commit 99f139c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
apiHasExecutionContext,
apiHasParentApi,
apiPublishesTimeRange,
fetch$,
initializeTimeRange,
initializeTitles,
useBatchedPublishingSubjects,
Expand All @@ -26,7 +27,8 @@ import { KibanaRenderContextProvider } from '@kbn/react-kibana-context-render';
import React, { useCallback, useState } from 'react';
import useUnmount from 'react-use/lib/useUnmount';
import type { Observable } from 'rxjs';
import { BehaviorSubject, combineLatest, map, of, Subscription } from 'rxjs';
import { BehaviorSubject, combineLatest, distinctUntilChanged, map, of, Subscription } from 'rxjs';
import fastIsEqual from 'fast-deep-equal';
import type { AnomalySwimlaneEmbeddableServices } from '..';
import { ANOMALY_SWIMLANE_EMBEDDABLE_TYPE } from '..';
import type { MlDependencies } from '../../application/app';
Expand Down Expand Up @@ -235,6 +237,21 @@ export const getAnomalySwimLaneEmbeddableFactory = (
anomalySwimLaneServices
);

subscriptions.add(
fetch$(api)
.pipe(
map((fetchContext) => ({
query: fetchContext.query,
filters: fetchContext.filters,
timeRange: fetchContext.timeRange,
})),
distinctUntilChanged(fastIsEqual)
)
.subscribe(() => {
api.updatePagination({ fromPage: 1 });
})
);

const onRenderComplete = () => {};

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import type { estypes } from '@elastic/elasticsearch';
import type { TimeRange } from '@kbn/es-query';
import { type TimeRange } from '@kbn/es-query';
import type { PublishesUnifiedSearch } from '@kbn/presentation-publishing';
import {
BehaviorSubject,
Expand All @@ -29,7 +29,6 @@ import {
SWIMLANE_TYPE,
} from '../../application/explorer/explorer_constants';
import type { OverallSwimlaneData } from '../../application/explorer/explorer_utils';
import { isViewBySwimLaneData } from '../../application/explorer/swimlane_container';
import { CONTROLLED_BY_SWIM_LANE_FILTER } from '../../ui_actions/constants';
import { getJobsObservable } from '../common/get_jobs_observable';
import { processFilters } from '../common/process_filters';
Expand Down Expand Up @@ -114,12 +113,7 @@ export const initializeSwimLaneDataFetcher = (
const { earliest, latest } = overallSwimlaneData;

if (overallSwimlaneData && swimlaneType === SWIMLANE_TYPE.VIEW_BY) {
const swimlaneData = swimLaneData$.value;

let swimLaneLimit = ANOMALY_SWIM_LANE_HARD_LIMIT;
if (isViewBySwimLaneData(swimlaneData) && viewBy === swimlaneData.fieldName) {
swimLaneLimit = swimlaneData.cardinality;
}
const swimLaneLimit = ANOMALY_SWIM_LANE_HARD_LIMIT;

return from(
anomalyTimelineService.loadViewBySwimlane(
Expand Down

0 comments on commit 99f139c

Please sign in to comment.