forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Telemetry] track and warn event loop delays thresholds (elastic#103615)
- Loading branch information
1 parent
224c206
commit 355c769
Showing
11 changed files
with
342 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
src/plugins/kibana_usage_collection/server/collectors/event_loop_delays/track_delays.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { Subject } from 'rxjs'; | ||
|
||
import { | ||
mockMonitorPercentile, | ||
monitorEventLoopDelay, | ||
mockMonitorReset, | ||
mockMonitorDisable, | ||
} from './event_loop_delays.mocks'; | ||
import { savedObjectsRepositoryMock } from '../../../../../core/server/mocks'; | ||
import { startTrackingEventLoopDelaysUsage } from './track_delays'; | ||
|
||
describe('startTrackingEventLoopDelaysUsage', () => { | ||
const mockInternalRepository = savedObjectsRepositoryMock.create(); | ||
const stopMonitoringEventLoop$ = new Subject<void>(); | ||
|
||
beforeAll(() => jest.useFakeTimers('modern')); | ||
beforeEach(() => jest.clearAllMocks()); | ||
afterEach(() => stopMonitoringEventLoop$.next()); | ||
|
||
it('initializes EventLoopDelaysCollector and starts timer', () => { | ||
const collectionStartDelay = 1000; | ||
startTrackingEventLoopDelaysUsage(mockInternalRepository, stopMonitoringEventLoop$, { | ||
collectionStartDelay, | ||
}); | ||
|
||
expect(monitorEventLoopDelay).toBeCalledTimes(1); | ||
expect(mockMonitorPercentile).toBeCalledTimes(0); | ||
jest.advanceTimersByTime(collectionStartDelay); | ||
expect(mockMonitorPercentile).toBeCalled(); | ||
}); | ||
|
||
it('stores event loop delays every collectionInterval duration', () => { | ||
const collectionStartDelay = 100; | ||
const collectionInterval = 1000; | ||
startTrackingEventLoopDelaysUsage(mockInternalRepository, stopMonitoringEventLoop$, { | ||
collectionStartDelay, | ||
collectionInterval, | ||
}); | ||
|
||
expect(mockInternalRepository.create).toBeCalledTimes(0); | ||
jest.advanceTimersByTime(collectionStartDelay); | ||
expect(mockInternalRepository.create).toBeCalledTimes(1); | ||
jest.advanceTimersByTime(collectionInterval); | ||
expect(mockInternalRepository.create).toBeCalledTimes(2); | ||
jest.advanceTimersByTime(collectionInterval); | ||
expect(mockInternalRepository.create).toBeCalledTimes(3); | ||
}); | ||
|
||
it('resets histogram every histogramReset duration', () => { | ||
const collectionStartDelay = 0; | ||
const collectionInterval = 1000; | ||
const histogramReset = 5000; | ||
startTrackingEventLoopDelaysUsage(mockInternalRepository, stopMonitoringEventLoop$, { | ||
collectionStartDelay, | ||
collectionInterval, | ||
histogramReset, | ||
}); | ||
|
||
expect(mockMonitorReset).toBeCalledTimes(0); | ||
jest.advanceTimersByTime(collectionInterval * 5); | ||
expect(mockMonitorReset).toBeCalledTimes(1); | ||
jest.advanceTimersByTime(collectionInterval * 5); | ||
expect(mockMonitorReset).toBeCalledTimes(2); | ||
}); | ||
|
||
it('stops monitoring event loop delays once stopMonitoringEventLoop$.next is called', () => { | ||
startTrackingEventLoopDelaysUsage(mockInternalRepository, stopMonitoringEventLoop$); | ||
|
||
expect(mockMonitorDisable).toBeCalledTimes(0); | ||
stopMonitoringEventLoop$.next(); | ||
expect(mockMonitorDisable).toBeCalledTimes(1); | ||
}); | ||
}); |
56 changes: 56 additions & 0 deletions
56
src/plugins/kibana_usage_collection/server/collectors/event_loop_delays/track_delays.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { takeUntil, finalize, map } from 'rxjs/operators'; | ||
import { Observable, timer } from 'rxjs'; | ||
import type { ISavedObjectsRepository } from 'kibana/server'; | ||
import { | ||
MONITOR_EVENT_LOOP_DELAYS_START, | ||
MONITOR_EVENT_LOOP_DELAYS_INTERVAL, | ||
MONITOR_EVENT_LOOP_DELAYS_RESET, | ||
} from './constants'; | ||
import { storeHistogram } from './saved_objects'; | ||
import { EventLoopDelaysCollector } from './event_loop_delays'; | ||
|
||
/** | ||
* The monitoring of the event loop starts immediately. | ||
* The first collection of the histogram happens after 1 minute. | ||
* The daily histogram data is updated every 1 hour. | ||
*/ | ||
export function startTrackingEventLoopDelaysUsage( | ||
internalRepository: ISavedObjectsRepository, | ||
stopMonitoringEventLoop$: Observable<void>, | ||
configs: { | ||
collectionStartDelay?: number; | ||
collectionInterval?: number; | ||
histogramReset?: number; | ||
} = {} | ||
) { | ||
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), | ||
takeUntil(stopMonitoringEventLoop$), | ||
finalize(() => eventLoopDelaysCollector.stop()) | ||
) | ||
.subscribe(async (shouldReset) => { | ||
const histogram = eventLoopDelaysCollector.collect(); | ||
if (shouldReset) { | ||
eventLoopDelaysCollector.reset(); | ||
} | ||
await storeHistogram(histogram, internalRepository); | ||
}); | ||
} |
Oops, something went wrong.