-
Notifications
You must be signed in to change notification settings - Fork 8.6k
add coreOverall$ to internal status contract
#113729
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
Changes from all commits
b4d9a6d
a9d892f
a39d976
a0f75b1
7577671
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,6 +30,7 @@ describe('StatusService', () => { | |
| }); | ||
|
|
||
| const delay = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms)); | ||
|
|
||
| const available: ServiceStatus<any> = { | ||
| level: ServiceStatusLevels.available, | ||
| summary: 'Available', | ||
|
|
@@ -38,6 +39,10 @@ describe('StatusService', () => { | |
| level: ServiceStatusLevels.degraded, | ||
| summary: 'This is degraded!', | ||
| }; | ||
| const critical: ServiceStatus<any> = { | ||
| level: ServiceStatusLevels.critical, | ||
| summary: 'This is critical!', | ||
| }; | ||
|
|
||
| type SetupDeps = Parameters<StatusService['setup']>[0]; | ||
| const setupDeps = (overrides: Partial<SetupDeps>): SetupDeps => { | ||
|
|
@@ -321,6 +326,177 @@ describe('StatusService', () => { | |
| }); | ||
| }); | ||
|
|
||
| describe('coreOverall$', () => { | ||
| it('exposes an overall summary of core services', async () => { | ||
| const setup = await service.setup( | ||
| setupDeps({ | ||
| elasticsearch: { | ||
| status$: of(degraded), | ||
| }, | ||
| savedObjects: { | ||
| status$: of(degraded), | ||
| }, | ||
| }) | ||
| ); | ||
| expect(await setup.coreOverall$.pipe(first()).toPromise()).toMatchObject({ | ||
| level: ServiceStatusLevels.degraded, | ||
| summary: '[2] services are degraded', | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That makes me think we should list the names of degraded services. To avoid unnecessary noise, we can trim the summary to a reasonable limit.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yea, that seems like a nice improvement. It may impact quite a few tests though, as we'll want to do the same for the global |
||
| }); | ||
| }); | ||
|
|
||
| it('computes the summary depending on the services status', async () => { | ||
| const setup = await service.setup( | ||
| setupDeps({ | ||
| elasticsearch: { | ||
| status$: of(degraded), | ||
| }, | ||
| savedObjects: { | ||
| status$: of(critical), | ||
| }, | ||
| }) | ||
| ); | ||
| expect(await setup.coreOverall$.pipe(first()).toPromise()).toMatchObject({ | ||
| level: ServiceStatusLevels.critical, | ||
| summary: '[savedObjects]: This is critical!', | ||
| }); | ||
| }); | ||
|
|
||
| it('replays last event', async () => { | ||
| const setup = await service.setup( | ||
| setupDeps({ | ||
| elasticsearch: { | ||
| status$: of(degraded), | ||
| }, | ||
| savedObjects: { | ||
| status$: of(degraded), | ||
| }, | ||
| }) | ||
| ); | ||
|
|
||
| const subResult1 = await setup.coreOverall$.pipe(first()).toPromise(); | ||
| const subResult2 = await setup.coreOverall$.pipe(first()).toPromise(); | ||
| const subResult3 = await setup.coreOverall$.pipe(first()).toPromise(); | ||
|
|
||
| expect(subResult1).toMatchObject({ | ||
| level: ServiceStatusLevels.degraded, | ||
| summary: '[2] services are degraded', | ||
| }); | ||
| expect(subResult2).toMatchObject({ | ||
| level: ServiceStatusLevels.degraded, | ||
| summary: '[2] services are degraded', | ||
| }); | ||
| expect(subResult3).toMatchObject({ | ||
| level: ServiceStatusLevels.degraded, | ||
| summary: '[2] services are degraded', | ||
| }); | ||
| }); | ||
|
|
||
| it('does not emit duplicate events', async () => { | ||
| const elasticsearch$ = new BehaviorSubject(available); | ||
| const savedObjects$ = new BehaviorSubject(degraded); | ||
| const setup = await service.setup( | ||
| setupDeps({ | ||
| elasticsearch: { | ||
| status$: elasticsearch$, | ||
| }, | ||
| savedObjects: { | ||
| status$: savedObjects$, | ||
| }, | ||
| }) | ||
| ); | ||
|
|
||
| const statusUpdates: ServiceStatus[] = []; | ||
| const subscription = setup.coreOverall$.subscribe((status) => statusUpdates.push(status)); | ||
|
|
||
| // Wait for timers to ensure that duplicate events are still filtered out regardless of debouncing. | ||
| elasticsearch$.next(available); | ||
| await delay(500); | ||
| elasticsearch$.next(available); | ||
| await delay(500); | ||
| elasticsearch$.next({ | ||
| level: ServiceStatusLevels.available, | ||
| summary: `Wow another summary`, | ||
| }); | ||
| await delay(500); | ||
| savedObjects$.next(degraded); | ||
| await delay(500); | ||
| savedObjects$.next(available); | ||
| await delay(500); | ||
| savedObjects$.next(available); | ||
| await delay(500); | ||
| subscription.unsubscribe(); | ||
|
|
||
| expect(statusUpdates).toMatchInlineSnapshot(` | ||
| Array [ | ||
| Object { | ||
| "detail": "See the status page for more information", | ||
| "level": degraded, | ||
| "meta": Object { | ||
| "affectedServices": Array [ | ||
| "savedObjects", | ||
| ], | ||
| }, | ||
| "summary": "[savedObjects]: This is degraded!", | ||
| }, | ||
| Object { | ||
| "level": available, | ||
| "summary": "All services are available", | ||
| }, | ||
| ] | ||
| `); | ||
| }); | ||
|
|
||
| it('debounces events in quick succession', async () => { | ||
| const savedObjects$ = new BehaviorSubject(available); | ||
| const setup = await service.setup( | ||
| setupDeps({ | ||
| elasticsearch: { | ||
| status$: new BehaviorSubject(available), | ||
| }, | ||
| savedObjects: { | ||
| status$: savedObjects$, | ||
| }, | ||
| }) | ||
| ); | ||
|
|
||
| const statusUpdates: ServiceStatus[] = []; | ||
| const subscription = setup.coreOverall$.subscribe((status) => statusUpdates.push(status)); | ||
|
|
||
| // All of these should debounced into a single `available` status | ||
| savedObjects$.next(degraded); | ||
| savedObjects$.next(available); | ||
| savedObjects$.next(degraded); | ||
| savedObjects$.next(available); | ||
| savedObjects$.next(degraded); | ||
| savedObjects$.next(available); | ||
| savedObjects$.next(degraded); | ||
| // Waiting for the debounce timeout should cut a new update | ||
| await delay(500); | ||
| savedObjects$.next(available); | ||
| await delay(500); | ||
| subscription.unsubscribe(); | ||
|
|
||
| expect(statusUpdates).toMatchInlineSnapshot(` | ||
| Array [ | ||
| Object { | ||
| "detail": "See the status page for more information", | ||
| "level": degraded, | ||
| "meta": Object { | ||
| "affectedServices": Array [ | ||
| "savedObjects", | ||
| ], | ||
| }, | ||
| "summary": "[savedObjects]: This is degraded!", | ||
| }, | ||
| Object { | ||
| "level": available, | ||
| "summary": "All services are available", | ||
| }, | ||
| ] | ||
| `); | ||
| }); | ||
| }); | ||
|
|
||
| describe('preboot status routes', () => { | ||
| let prebootRouterMock: RouterMock; | ||
| beforeEach(async () => { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.