Skip to content

Commit

Permalink
Fix loading state for grouping.
Browse files Browse the repository at this point in the history
  • Loading branch information
walterra committed Sep 26, 2022
1 parent 7f4608b commit 9c01868
Showing 1 changed file with 39 additions and 14 deletions.
53 changes: 39 additions & 14 deletions x-pack/plugins/aiops/server/routes/explain_log_rate_spikes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<DataRequestHandlerContext>,
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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 = {
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -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([
{
Expand Down

0 comments on commit 9c01868

Please sign in to comment.