From 9c0186850dee54c8cf7bfe8e0b49ba706f36b66e Mon Sep 17 00:00:00 2001 From: Walter Rafelsberger Date: Mon, 26 Sep 2022 15:27:59 +0200 Subject: [PATCH] Fix loading state for grouping. --- .../server/routes/explain_log_rate_spikes.ts | 53 ++++++++++++++----- 1 file changed, 39 insertions(+), 14 deletions(-) diff --git a/x-pack/plugins/aiops/server/routes/explain_log_rate_spikes.ts b/x-pack/plugins/aiops/server/routes/explain_log_rate_spikes.ts index 48ea2dbddb1c3..8a8a7372f80e2 100644 --- a/x-pack/plugins/aiops/server/routes/explain_log_rate_spikes.ts +++ b/x-pack/plugins/aiops/server/routes/explain_log_rate_spikes.ts @@ -52,8 +52,10 @@ import { // Overall progress is a float from 0 to 1. const LOADED_FIELD_CANDIDATES = 0.2; -const PROGRESS_STEP_P_VALUES = 0.6; -const PROGRESS_STEP_HISTOGRAMS = 0.2; +const PROGRESS_STEP_P_VALUES = 0.5; +const PROGRESS_STEP_GROUPING = 0.1; +const PROGRESS_STEP_HISTOGRAMS = 0.1; +const PROGRESS_STEP_HISTOGRAMS_GROUPS = 0.1; export const defineExplainLogRateSpikesRoute = ( router: IRouter, @@ -233,7 +235,35 @@ export const defineExplainLogRateSpikesRoute = ( undefined )) as [NumericChartData]; + function pushHistogramDataLoadingState() { + push( + updateLoadingStateAction({ + ccsWarning: false, + loaded, + loadingState: i18n.translate( + 'xpack.aiops.explainLogRateSpikes.loadingState.loadingHistogramData', + { + defaultMessage: 'Loading histogram data.', + } + ), + }) + ); + } + if (groupingEnabled) { + push( + updateLoadingStateAction({ + ccsWarning: false, + loaded, + loadingState: i18n.translate( + 'xpack.aiops.explainLogRateSpikes.loadingState.groupingResults', + { + defaultMessage: 'Transforming significant field/value pairs into groups.', + } + ), + }) + ); + // To optimize the `frequent_items` query, we identify duplicate change points by count attributes. // Note this is a compromise and not 100% accurate because there could be change points that // have the exact same counts but still don't co-occur. @@ -389,6 +419,10 @@ export const defineExplainLogRateSpikesRoute = ( push(addChangePointsGroupAction(changePointGroups)); } + loaded += PROGRESS_STEP_GROUPING; + + pushHistogramDataLoadingState(); + if (changePointGroups) { await asyncForEach(changePointGroups, async (cpg, index) => { const histogramQuery = { @@ -445,6 +479,8 @@ export const defineExplainLogRateSpikesRoute = ( } } + loaded += PROGRESS_STEP_HISTOGRAMS_GROUPS; + // time series filtered by fields if (changePoints) { await asyncForEach(changePoints, async (cp, index) => { @@ -496,18 +532,7 @@ export const defineExplainLogRateSpikesRoute = ( const { fieldName, fieldValue } = cp; loaded += (1 / changePoints.length) * PROGRESS_STEP_HISTOGRAMS; - push( - updateLoadingStateAction({ - ccsWarning: false, - loaded, - loadingState: i18n.translate( - 'xpack.aiops.explainLogRateSpikes.loadingState.loadingHistogramData', - { - defaultMessage: 'Loading histogram data.', - } - ), - }) - ); + pushHistogramDataLoadingState(); push( addChangePointsHistogramAction([ {