-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
65 changed files
with
2,713 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,3 +37,4 @@ selenium | |
*.out | ||
ui_framework/doc_site/build/*.js* | ||
yarn.lock | ||
.vscode/ |
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,55 @@ | ||
# New platform | ||
|
||
## Dev setup | ||
|
||
``` | ||
npm run ts:start | ||
``` | ||
|
||
This builds the code into `./ts-tmp/` for now. | ||
|
||
(It will most likely show a couple type problems while building, but the files will still be built.) | ||
|
||
## VSCode | ||
|
||
If you want to see what it looks like with fantastic editor support. | ||
|
||
``` | ||
$ cat ~/dev/elastic/kibana/.vscode/settings.json | ||
// Place your settings in this file to overwrite default and user settings. | ||
{ | ||
"typescript.tsdk": "./node_modules/typescript/lib", | ||
"typescript.referencesCodeLens.enabled": true | ||
} | ||
``` | ||
|
||
## Running code | ||
|
||
(Make sure to build the code first, e.g. `npm run ts:build` or `npm run ts:start`) | ||
|
||
Just starts a server: | ||
|
||
``` | ||
node scripts/platform.js | ||
``` | ||
|
||
If you update `config/kibana.yml` to e.g. contain `pid.file: ./kibana.pid` | ||
you'll also see it write the PID file. (You can do this while running and just | ||
send a SIGHUP.) | ||
|
||
With failure: | ||
|
||
``` | ||
node scripts/platform.js -c ./config/kibana.dev.yml --port "test" | ||
``` | ||
|
||
## Running tests | ||
|
||
Run Jest: | ||
|
||
``` | ||
node scripts/jest.js | ||
``` | ||
|
||
(add `--watch` for re-running on change) | ||
|
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 @@ | ||
const configService = { | ||
start: jest.fn(), | ||
stop: jest.fn(), | ||
reloadConfig: jest.fn(), | ||
getConfig: jest.fn(() => []) | ||
}; | ||
|
||
const ConfigService = jest.fn(() => configService); | ||
|
||
const server = { | ||
start: jest.fn(), | ||
stop: jest.fn() | ||
}; | ||
const Server = jest.fn(() => server); | ||
|
||
const loggerService = { | ||
upgrade: jest.fn(), | ||
stop: jest.fn() | ||
}; | ||
|
||
const logger = { | ||
get: jest.fn().mockReturnValue({ | ||
info: jest.fn(), | ||
error: jest.fn() | ||
}) | ||
}; | ||
|
||
jest.mock('../../config', () => ({ ConfigService })); | ||
jest.mock('../../server', () => ({ Server })); | ||
jest.mock('../../logger', () => ({ logger, loggerService })); | ||
|
||
import { App } from '../'; | ||
import { Env } from '../../env'; | ||
|
||
test('starts services on "start"', () => { | ||
const env = new Env('.'); | ||
const argv = { foo: 'bar' }; | ||
|
||
const app = new App(argv, env); | ||
|
||
expect(configService.start).toHaveBeenCalledTimes(0); | ||
expect(loggerService.upgrade).toHaveBeenCalledTimes(0); | ||
expect(server.start).toHaveBeenCalledTimes(0); | ||
|
||
app.start(); | ||
|
||
expect(configService.start).toHaveBeenCalledTimes(1); | ||
expect(loggerService.upgrade).toHaveBeenCalledTimes(1); | ||
expect(server.start).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
test('reloads config', () => { | ||
const env = new Env('.'); | ||
const argv = { foo: 'bar' }; | ||
|
||
const app = new App(argv, env); | ||
|
||
expect(configService.reloadConfig).toHaveBeenCalledTimes(0); | ||
|
||
app.reloadConfig(); | ||
|
||
expect(configService.reloadConfig).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
test('stops services on "shutdown"', () => { | ||
const env = new Env('.'); | ||
const argv = { foo: 'bar' }; | ||
|
||
const app = new App(argv, env); | ||
app.start(); | ||
|
||
expect(configService.stop).toHaveBeenCalledTimes(0); | ||
expect(loggerService.stop).toHaveBeenCalledTimes(0); | ||
expect(server.stop).toHaveBeenCalledTimes(0); | ||
|
||
app.shutdown(); | ||
|
||
expect(configService.stop).toHaveBeenCalledTimes(1); | ||
expect(loggerService.stop).toHaveBeenCalledTimes(1); | ||
expect(server.stop).toHaveBeenCalledTimes(1); | ||
}); |
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,55 @@ | ||
import { BehaviorSubject } from 'rxjs'; | ||
|
||
import { Server } from '../server'; | ||
import { Env } from '../env'; | ||
import { ConfigService } from '../config'; | ||
import { loggerService, logger, LoggerConfig } from '../logger'; | ||
|
||
const log = logger.get('app'); | ||
|
||
// Top-level entry point to kick off the app | ||
|
||
export class App { | ||
configService: ConfigService; | ||
server?: Server; | ||
|
||
constructor( | ||
argv: {[key: string]: any}, | ||
private readonly env: Env | ||
) { | ||
this.configService = new ConfigService(argv, env); | ||
} | ||
|
||
start() { | ||
this.configService.start(); | ||
|
||
// In general we should try to do as _little_ as possible before we | ||
// configure the logger, so beware of adding features before we kick it | ||
// off below. | ||
|
||
const config$ = this.configService.getConfig(); | ||
|
||
const loggingConfig$ = config$ | ||
.map(config => new LoggerConfig(config.atPath('logging'))); | ||
|
||
loggerService.upgrade(loggingConfig$); | ||
|
||
log.info('starting the server'); | ||
|
||
this.server = new Server(this.env, config$); | ||
this.server.start(); | ||
} | ||
|
||
reloadConfig() { | ||
this.configService.reloadConfig(); | ||
} | ||
|
||
shutdown() { | ||
log.info('commencing shutdown sequence :boom:'); | ||
if (this.server !== undefined) { | ||
this.server.stop(); | ||
} | ||
this.configService.stop(); | ||
loggerService.stop(); | ||
} | ||
} |
Oops, something went wrong.