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

ensure workload agg doesnt run until next interval when it fails #83632

Merged
merged 2 commits into from
Nov 20, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -477,6 +477,41 @@ describe('Workload Statistics Aggregator', () => {
}, reject);
});
});

test('recovery after errors occurrs at the next interval', async () => {
const refreshInterval = 1000;

const taskStore = taskStoreMock.create({});
const logger = loggingSystemMock.create().get();
const workloadAggregator = createWorkloadAggregator(
taskStore,
of(true),
refreshInterval,
3000,
logger
);

return new Promise((resolve, reject) => {
let errorWasThrowAt = 0;
taskStore.aggregate.mockImplementation(async () => {
if (errorWasThrowAt === 0) {
errorWasThrowAt = Date.now();
throw new Error(`Elasticsearch has gone poof`);
} else if (Date.now() - errorWasThrowAt < refreshInterval) {
reject(new Error(`Elasticsearch is still poof`));
}

return setTaskTypeCount(mockAggregatedResult(), 'alerting_telemetry', {
idle: 2,
});
});

workloadAggregator.pipe(take(2), bufferCount(2)).subscribe((results) => {
gmmorris marked this conversation as resolved.
Show resolved Hide resolved
expect(results.length).toEqual(2);
resolve();
}, reject);
});
});
});

describe('estimateRecurringTaskScheduling', () => {
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@
*/

import { combineLatest, Observable, timer } from 'rxjs';
import { mergeMap, map, filter, catchError } from 'rxjs/operators';
import { mergeMap, map, filter, switchMap, catchError } from 'rxjs/operators';
import { Logger } from 'src/core/server';
import { JsonObject } from 'src/plugins/kibana_utils/common';
import { keyBy, mapValues } from 'lodash';
@@ -222,8 +222,8 @@ export function createWorkloadAggregator(
}),
catchError((ex: Error, caught) => {
logger.error(`[WorkloadAggregator]: ${ex}`);
// continue to pull values from the same observable
return caught;
// continue to pull values from the same observable but only on the next refreshInterval
return timer(refreshInterval).pipe(switchMap(() => caught));
})
);
}