Skip to content

Commit

Permalink
named parameters for configs + update warning message
Browse files Browse the repository at this point in the history
  • Loading branch information
Bamieh committed Jun 29, 2021
1 parent 9af1464 commit f83f9c1
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,9 @@ describe('startTrackingEventLoopDelaysUsage', () => {

it('initializes EventLoopDelaysCollector and starts timer', () => {
const collectionStartDelay = 1000;
startTrackingEventLoopDelaysUsage(
mockInternalRepository,
stopMonitoringEventLoop$,
collectionStartDelay
);
startTrackingEventLoopDelaysUsage(mockInternalRepository, stopMonitoringEventLoop$, {
collectionStartDelay,
});

expect(monitorEventLoopDelay).toBeCalledTimes(1);
expect(mockMonitorPercentile).toBeCalledTimes(0);
Expand All @@ -42,12 +40,10 @@ describe('startTrackingEventLoopDelaysUsage', () => {
it('stores event loop delays every collectionInterval duration', () => {
const collectionStartDelay = 100;
const collectionInterval = 1000;
startTrackingEventLoopDelaysUsage(
mockInternalRepository,
stopMonitoringEventLoop$,
startTrackingEventLoopDelaysUsage(mockInternalRepository, stopMonitoringEventLoop$, {
collectionStartDelay,
collectionInterval
);
collectionInterval,
});

expect(mockInternalRepository.create).toBeCalledTimes(0);
jest.advanceTimersByTime(collectionStartDelay);
Expand All @@ -62,13 +58,11 @@ describe('startTrackingEventLoopDelaysUsage', () => {
const collectionStartDelay = 0;
const collectionInterval = 1000;
const histogramReset = 5000;
startTrackingEventLoopDelaysUsage(
mockInternalRepository,
stopMonitoringEventLoop$,
startTrackingEventLoopDelaysUsage(mockInternalRepository, stopMonitoringEventLoop$, {
collectionStartDelay,
collectionInterval,
histogramReset
);
histogramReset,
});

expect(mockMonitorReset).toBeCalledTimes(0);
jest.advanceTimersByTime(collectionInterval * 5);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,21 @@ import { EventLoopDelaysCollector } from './event_loop_delays';
export function startTrackingEventLoopDelaysUsage(
internalRepository: ISavedObjectsRepository,
stopMonitoringEventLoop$: Observable<void>,
collectionStartDelay = MONITOR_EVENT_LOOP_DELAYS_START,
collectionInterval = MONITOR_EVENT_LOOP_DELAYS_INTERVAL,
histogramReset = MONITOR_EVENT_LOOP_DELAYS_RESET
configs: {
collectionStartDelay?: number;
collectionInterval?: number;
histogramReset?: number;
} = {}
) {
const eventLoopDelaysCollector = new EventLoopDelaysCollector();
const {
collectionStartDelay = MONITOR_EVENT_LOOP_DELAYS_START,
collectionInterval = MONITOR_EVENT_LOOP_DELAYS_INTERVAL,
histogramReset = MONITOR_EVENT_LOOP_DELAYS_RESET,
} = configs;

const eventLoopDelaysCollector = new EventLoopDelaysCollector();
const resetOnCount = Math.ceil(histogramReset / collectionInterval);

timer(collectionStartDelay, collectionInterval)
.pipe(
map((i) => (i + 1) % resetOnCount === 0),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,11 @@ describe('startTrackingEventLoopDelaysThreshold', () => {

it('initializes EventLoopDelaysCollector and starts timer', () => {
const collectionStartDelay = 1000;
const collectionWarnThreshold = 1000;
startTrackingEventLoopDelaysThreshold(
mockEventLoopCounter,
logger,
stopMonitoringEventLoop$,
collectionWarnThreshold,
collectionStartDelay
);
const warnThreshold = 1000;
startTrackingEventLoopDelaysThreshold(mockEventLoopCounter, logger, stopMonitoringEventLoop$, {
warnThreshold,
collectionStartDelay,
});

expect(monitorEventLoopDelay).toBeCalledTimes(1);
expect(mockMonitorPercentile).toBeCalledTimes(0);
Expand All @@ -46,16 +43,13 @@ describe('startTrackingEventLoopDelaysThreshold', () => {
it('logs a warning and increments usage counter when the mean delay exceeds the threshold', () => {
const collectionStartDelay = 100;
const collectionInterval = 1000;
const collectionWarnThreshold = 10;
const warnThreshold = 10;

startTrackingEventLoopDelaysThreshold(
mockEventLoopCounter,
logger,
stopMonitoringEventLoop$,
collectionWarnThreshold,
startTrackingEventLoopDelaysThreshold(mockEventLoopCounter, logger, stopMonitoringEventLoop$, {
warnThreshold,
collectionStartDelay,
collectionInterval
);
collectionInterval,
});

expect(logger.warn).toBeCalledTimes(0);
expect(mockEventLoopCounter.incrementCounter).toBeCalledTimes(0);
Expand All @@ -79,15 +73,12 @@ describe('startTrackingEventLoopDelaysThreshold', () => {

it('does not log warning or increment usage if threshold did not exceed mean delay', () => {
const collectionStartDelay = 100;
const collectionWarnThreshold = 15;
const warnThreshold = 15;

startTrackingEventLoopDelaysThreshold(
mockEventLoopCounter,
logger,
stopMonitoringEventLoop$,
collectionWarnThreshold,
collectionStartDelay
);
startTrackingEventLoopDelaysThreshold(mockEventLoopCounter, logger, stopMonitoringEventLoop$, {
warnThreshold,
collectionStartDelay,
});

expect(logger.warn).toBeCalledTimes(0);
expect(mockEventLoopCounter.incrementCounter).toBeCalledTimes(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,18 @@ export function startTrackingEventLoopDelaysThreshold(
eventLoopCounter: UsageCounter,
logger: Logger,
stopMonitoringEventLoop$: Observable<void>,
warnThreshold = MONITOR_EVENT_LOOP_WARN_THRESHOLD,
collectionStartDelay = MONITOR_EVENT_LOOP_THRESHOLD_START,
collectionInterval = MONITOR_EVENT_LOOP_THRESHOLD_INTERVAL
configs: {
warnThreshold?: number;
collectionStartDelay?: number;
collectionInterval?: number;
} = {}
) {
const {
warnThreshold = MONITOR_EVENT_LOOP_WARN_THRESHOLD,
collectionStartDelay = MONITOR_EVENT_LOOP_THRESHOLD_START,
collectionInterval = MONITOR_EVENT_LOOP_THRESHOLD_INTERVAL,
} = configs;

const eventLoopDelaysCollector = new EventLoopDelaysCollector();
timer(collectionStartDelay, collectionInterval)
.pipe(
Expand All @@ -47,7 +55,8 @@ export function startTrackingEventLoopDelaysThreshold(

if (meanDurationMs > warnThreshold) {
logger.warn(
`Average event loop delay threshold exceeded ${warnThreshold}ms. Received ${meanDurationMs}ms.`
`Average event loop delay threshold exceeded ${warnThreshold}ms. Received ${meanDurationMs}ms. ` +
`See https://ela.st/kibana-scaling-considerations for more information about scaling Kibana.`
);

eventLoopCounter.incrementCounter({
Expand Down

0 comments on commit f83f9c1

Please sign in to comment.