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 { isOfQueryType, 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 @@ -96,6 +95,14 @@ export const initializeSwimLaneDataFetcher = (

const { viewBy, swimlaneType, perPage, fromPage } = input;

let isEmptyQuery = true;

if (isOfQueryType(query)) {
isEmptyQuery = !query.query;
} else {
isEmptyQuery = !query?.esql;
}
rbrtj marked this conversation as resolved.
Show resolved Hide resolved

Copy link
Contributor

Choose a reason for hiding this comment

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

what if the query provides enough results for several pages, and the user wants to page further?

Copy link
Contributor

Choose a reason for hiding this comment

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

I reckon we should approach it differently. When query changes , we need to update swimLaneInput$ observable, resetting the pagination.

Copy link
Contributor

Choose a reason for hiding this comment

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

You can check the AnomalyTimelineStateService as an example

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed in: 868dd88

let appliedFilters: estypes.QueryDslQueryContainer;
try {
if (filters || query) {
Expand All @@ -114,12 +121,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 All @@ -129,7 +131,7 @@ export const initializeSwimLaneDataFetcher = (
viewBy!,
swimLaneLimit,
perPage!,
fromPage,
isEmptyQuery ? fromPage : 1,
undefined,
appliedFilters,
bucketInterval
Expand Down