Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ML] Fix Anomaly Swim Lane Embeddable not updating properly on query change #195090

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 @@ -23,13 +23,14 @@ import {
startWith,
switchMap,
tap,
distinctUntilChanged,
merge,
} from 'rxjs';
import {
ANOMALY_SWIM_LANE_HARD_LIMIT,
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 @@ -62,7 +63,14 @@ export const initializeSwimLaneDataFetcher = (
swimlaneType: swimLaneApi.swimlaneType,
viewBy: swimLaneApi.viewBy,
perPage: swimLaneApi.perPage,
fromPage: swimLaneApi.fromPage,
fromPage: merge(
query$.pipe(map(() => 1)),
swimLaneApi.fromPage,
filters$.pipe(map(() => 1))
).pipe(
distinctUntilChanged(),
tap((fromPage) => swimLaneApi.updatePagination({ fromPage }))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realized we should also reset the pagination on time filter changes. In the Anomaly Explorer page, we listen to filter, query and time range, and form a ES query. Then the pagination observable listens for the ES query change and reset pagination accordingly.
And looking at this side effect I wonder if fromPage update should happen inside of initializeSwimLaneControls instead 🤔 In that case the swim lane fetcher logic only get the latest fromPage value, and the controls code is directly responsible for resetting it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, updated in: 5a95ba0
I think it should be more convenient now

),
});

const bucketInterval$ = combineLatest([selectedJobs$, chartWidth$, appliedTimeRange$]).pipe(
Expand Down Expand Up @@ -114,12 +122,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