-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into wrap-sequences
- Loading branch information
Showing
286 changed files
with
4,849 additions
and
2,575 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
/* | ||
* 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 { TestScheduler } from 'rxjs/testing'; | ||
import { ServiceStatus, ServiceStatusLevels } from './types'; | ||
import { getOverallStatusChanges } from './log_overall_status'; | ||
|
||
const getTestScheduler = () => | ||
new TestScheduler((actual, expected) => { | ||
expect(actual).toEqual(expected); | ||
}); | ||
|
||
const createStatus = (parts: Partial<ServiceStatus> = {}): ServiceStatus => ({ | ||
level: ServiceStatusLevels.available, | ||
summary: 'summary', | ||
...parts, | ||
}); | ||
|
||
describe('getOverallStatusChanges', () => { | ||
it('emits an initial message after first overall$ emission', () => { | ||
getTestScheduler().run(({ expectObservable, hot }) => { | ||
const overall$ = hot<ServiceStatus>('--a', { | ||
a: createStatus(), | ||
}); | ||
const stop$ = hot<void>(''); | ||
const expected = '--a'; | ||
|
||
expectObservable(getOverallStatusChanges(overall$, stop$)).toBe(expected, { | ||
a: 'Kibana is now available', | ||
}); | ||
}); | ||
}); | ||
|
||
it('emits a new message every time the status level changes', () => { | ||
getTestScheduler().run(({ expectObservable, hot }) => { | ||
const overall$ = hot<ServiceStatus>('--a--b', { | ||
a: createStatus({ | ||
level: ServiceStatusLevels.degraded, | ||
}), | ||
b: createStatus({ | ||
level: ServiceStatusLevels.available, | ||
}), | ||
}); | ||
const stop$ = hot<void>(''); | ||
const expected = '--a--b'; | ||
|
||
expectObservable(getOverallStatusChanges(overall$, stop$)).toBe(expected, { | ||
a: 'Kibana is now degraded', | ||
b: 'Kibana is now available (was degraded)', | ||
}); | ||
}); | ||
}); | ||
|
||
it('does not emit when the status stays the same', () => { | ||
getTestScheduler().run(({ expectObservable, hot }) => { | ||
const overall$ = hot<ServiceStatus>('--a--b--c', { | ||
a: createStatus({ | ||
level: ServiceStatusLevels.degraded, | ||
summary: 'summary 1', | ||
}), | ||
b: createStatus({ | ||
level: ServiceStatusLevels.degraded, | ||
summary: 'summary 2', | ||
}), | ||
c: createStatus({ | ||
level: ServiceStatusLevels.available, | ||
summary: 'summary 2', | ||
}), | ||
}); | ||
const stop$ = hot<void>(''); | ||
const expected = '--a-----b'; | ||
|
||
expectObservable(getOverallStatusChanges(overall$, stop$)).toBe(expected, { | ||
a: 'Kibana is now degraded', | ||
b: 'Kibana is now available (was degraded)', | ||
}); | ||
}); | ||
}); | ||
|
||
it('stops emitting once `stop$` emits', () => { | ||
getTestScheduler().run(({ expectObservable, hot }) => { | ||
const overall$ = hot<ServiceStatus>('--a--b', { | ||
a: createStatus({ | ||
level: ServiceStatusLevels.degraded, | ||
}), | ||
b: createStatus({ | ||
level: ServiceStatusLevels.available, | ||
}), | ||
}); | ||
const stop$ = hot<void>('----(s|)'); | ||
const expected = '--a-|'; | ||
|
||
expectObservable(getOverallStatusChanges(overall$, stop$)).toBe(expected, { | ||
a: 'Kibana is now degraded', | ||
}); | ||
}); | ||
}); | ||
}); |
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,31 @@ | ||
/* | ||
* 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 { Observable } from 'rxjs'; | ||
import { distinctUntilChanged, pairwise, startWith, takeUntil, map } from 'rxjs/operators'; | ||
import { ServiceStatus } from './types'; | ||
|
||
export const getOverallStatusChanges = ( | ||
overall$: Observable<ServiceStatus>, | ||
stop$: Observable<void> | ||
) => { | ||
return overall$.pipe( | ||
takeUntil(stop$), | ||
distinctUntilChanged((previous, next) => { | ||
return previous.level.toString() === next.level.toString(); | ||
}), | ||
startWith(undefined), | ||
pairwise(), | ||
map(([oldStatus, newStatus]) => { | ||
if (oldStatus) { | ||
return `Kibana is now ${newStatus!.level.toString()} (was ${oldStatus!.level.toString()})`; | ||
} | ||
return `Kibana is now ${newStatus!.level.toString()}`; | ||
}) | ||
); | ||
}; |
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
Oops, something went wrong.