Skip to content
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

[7.x] revert PR 36804 (#42333) #42443

Merged
merged 1 commit into from
Aug 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ http: {
registerAuth: HttpServiceSetup['registerAuth'];
registerOnPostAuth: HttpServiceSetup['registerOnPostAuth'];
basePath: HttpServiceSetup['basePath'];
createNewServer: HttpServiceSetup['createNewServer'];
isTlsEnabled: HttpServiceSetup['isTlsEnabled'];
};
```
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ export interface CoreSetup
| Property | Type | Description |
| --- | --- | --- |
| [elasticsearch](./kibana-plugin-server.coresetup.elasticsearch.md) | <code>{</code><br/><code> adminClient$: Observable&lt;ClusterClient&gt;;</code><br/><code> dataClient$: Observable&lt;ClusterClient&gt;;</code><br/><code> createClient: (type: string, clientConfig?: Partial&lt;ElasticsearchClientConfig&gt;) =&gt; ClusterClient;</code><br/><code> }</code> | |
| [http](./kibana-plugin-server.coresetup.http.md) | <code>{</code><br/><code> createCookieSessionStorageFactory: HttpServiceSetup['createCookieSessionStorageFactory'];</code><br/><code> registerOnPreAuth: HttpServiceSetup['registerOnPreAuth'];</code><br/><code> registerAuth: HttpServiceSetup['registerAuth'];</code><br/><code> registerOnPostAuth: HttpServiceSetup['registerOnPostAuth'];</code><br/><code> basePath: HttpServiceSetup['basePath'];</code><br/><code> createNewServer: HttpServiceSetup['createNewServer'];</code><br/><code> isTlsEnabled: HttpServiceSetup['isTlsEnabled'];</code><br/><code> }</code> | |
| [http](./kibana-plugin-server.coresetup.http.md) | <code>{</code><br/><code> createCookieSessionStorageFactory: HttpServiceSetup['createCookieSessionStorageFactory'];</code><br/><code> registerOnPreAuth: HttpServiceSetup['registerOnPreAuth'];</code><br/><code> registerAuth: HttpServiceSetup['registerAuth'];</code><br/><code> registerOnPostAuth: HttpServiceSetup['registerOnPostAuth'];</code><br/><code> basePath: HttpServiceSetup['basePath'];</code><br/><code> isTlsEnabled: HttpServiceSetup['isTlsEnabled'];</code><br/><code> }</code> | |

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,11 @@

[Home](./index.md) &gt; [kibana-plugin-server](./kibana-plugin-server.md) &gt; [HttpServiceSetup](./kibana-plugin-server.httpservicesetup.md)

## HttpServiceSetup interface
## HttpServiceSetup type


<b>Signature:</b>

```typescript
export interface HttpServiceSetup extends HttpServerSetup
export declare type HttpServiceSetup = HttpServerSetup;
```

## Properties

| Property | Type | Description |
| --- | --- | --- |
| [createNewServer](./kibana-plugin-server.httpservicesetup.createnewserver.md) | <code>(cfg: Partial&lt;HttpConfig&gt;) =&gt; Promise&lt;HttpServerSetup&gt;</code> | |

2 changes: 1 addition & 1 deletion docs/development/core/server/kibana-plugin-server.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ The plugin integrates with the core system via lifecycle events: `setup`<!-- -->
| [ElasticsearchError](./kibana-plugin-server.elasticsearcherror.md) | |
| [ElasticsearchServiceSetup](./kibana-plugin-server.elasticsearchservicesetup.md) | |
| [FakeRequest](./kibana-plugin-server.fakerequest.md) | Fake request object created manually by Kibana plugins. |
| [HttpServiceSetup](./kibana-plugin-server.httpservicesetup.md) | |
| [HttpServiceStart](./kibana-plugin-server.httpservicestart.md) | |
| [InternalCoreStart](./kibana-plugin-server.internalcorestart.md) | |
| [KibanaRequestRoute](./kibana-plugin-server.kibanarequestroute.md) | Request specific route information exposed to a handler. |
Expand Down Expand Up @@ -80,6 +79,7 @@ The plugin integrates with the core system via lifecycle events: `setup`<!-- -->
| [ElasticsearchClientConfig](./kibana-plugin-server.elasticsearchclientconfig.md) | |
| [GetAuthHeaders](./kibana-plugin-server.getauthheaders.md) | Get headers to authenticate a user against Elasticsearch. |
| [Headers](./kibana-plugin-server.headers.md) | |
| [HttpServiceSetup](./kibana-plugin-server.httpservicesetup.md) | |
| [LegacyRequest](./kibana-plugin-server.legacyrequest.md) | Support Legacy platform request for the period of migration. |
| [OnPostAuthHandler](./kibana-plugin-server.onpostauthhandler.md) | |
| [OnPreAuthHandler](./kibana-plugin-server.onpreauthhandler.md) | |
Expand Down
3 changes: 0 additions & 3 deletions src/core/server/http/http_service.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

import { Server } from 'hapi';
import { HttpService } from './http_service';
import { HttpServerSetup } from './http_server';
import { HttpServiceSetup } from './http_service';
import { OnPreAuthToolkit } from './lifecycle/on_pre_auth';
import { AuthToolkit } from './lifecycle/auth';
Expand Down Expand Up @@ -52,10 +51,8 @@ const createSetupContractMock = () => {
isAuthenticated: jest.fn(),
getAuthHeaders: jest.fn(),
},
createNewServer: jest.fn(),
isTlsEnabled: false,
};
setupContract.createNewServer.mockResolvedValue({} as HttpServerSetup);
setupContract.createCookieSessionStorageFactory.mockResolvedValue(
sessionStorageMock.createFactory()
);
Expand Down
43 changes: 1 addition & 42 deletions src/core/server/http/http_service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,46 +133,6 @@ test('spins up notReady server until started if configured with `autoListen:true
expect(notReadyHapiServer.stop).toBeCalledTimes(1);
});

// this is an integration test!
test('creates and sets up second http server', async () => {
const configService = createConfigService({
host: 'localhost',
port: 1234,
});
const { HttpServer } = jest.requireActual('./http_server');

mockHttpServer.mockImplementation((...args) => new HttpServer(...args));

const service = new HttpService({ configService, env, logger });
const serverSetup = await service.setup();
const cfg = { port: 2345 };
await serverSetup.createNewServer(cfg);
const server = await service.start();
expect(server.isListening()).toBeTruthy();
expect(server.isListening(cfg.port)).toBeTruthy();

try {
await serverSetup.createNewServer(cfg);
} catch (err) {
expect(err.message).toBe('port 2345 is already in use');
}

try {
await serverSetup.createNewServer({ port: 1234 });
} catch (err) {
expect(err.message).toBe('port 1234 is already in use');
}

try {
await serverSetup.createNewServer({ host: 'example.org' });
} catch (err) {
expect(err.message).toBe('port must be defined');
}
await service.stop();
expect(server.isListening()).toBeFalsy();
expect(server.isListening(cfg.port)).toBeFalsy();
});

test('logs error if already set up', async () => {
const configService = createConfigService();

Expand Down Expand Up @@ -273,8 +233,7 @@ test('returns http server contract on setup', async () => {
}));

const service = new HttpService({ configService, env, logger });
const { createNewServer, ...setupHttpServer } = await service.setup();
expect(createNewServer).toBeDefined();
const setupHttpServer = await service.setup();
expect(setupHttpServer).toEqual(httpServer);
});

Expand Down
50 changes: 4 additions & 46 deletions src/core/server/http/http_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,12 @@ import { LoggerFactory } from '../logging';
import { CoreService } from '../../types';
import { Logger } from '../logging';
import { CoreContext } from '../core_context';
import { HttpConfig, HttpConfigType, config as httpConfig } from './http_config';
import { HttpConfig, HttpConfigType } from './http_config';
import { HttpServer, HttpServerSetup } from './http_server';
import { HttpsRedirectServer } from './https_redirect_server';

/** @public */
export interface HttpServiceSetup extends HttpServerSetup {
createNewServer: (cfg: Partial<HttpConfig>) => Promise<HttpServerSetup>;
}
export type HttpServiceSetup = HttpServerSetup;
/** @public */
export interface HttpServiceStart {
/** Indicates if http server is listening on a given port */
Expand All @@ -42,7 +40,6 @@ export interface HttpServiceStart {
/** @internal */
export class HttpService implements CoreService<HttpServiceSetup, HttpServiceStart> {
private readonly httpServer: HttpServer;
private readonly secondaryServers: Map<number, HttpServer> = new Map();
private readonly httpsRedirectServer: HttpsRedirectServer;
private readonly config$: Observable<HttpConfig>;
private configSubscription?: Subscription;
Expand Down Expand Up @@ -77,17 +74,11 @@ export class HttpService implements CoreService<HttpServiceSetup, HttpServiceSta

const config = await this.config$.pipe(first()).toPromise();

const httpSetup = (this.httpServer.setup(config) || {}) as HttpServiceSetup;
const setup = {
...httpSetup,
createNewServer: this.createServer.bind(this),
};

if (this.shouldListen(config)) {
await this.runNotReadyServer(config);
}

return setup;
return this.httpServer.setup(config);
}

public async start() {
Expand All @@ -105,15 +96,10 @@ export class HttpService implements CoreService<HttpServiceSetup, HttpServiceSta
}

await this.httpServer.start();
await Promise.all([...this.secondaryServers.values()].map(server => server.start()));
}

return {
isListening: (port: number = 0) => {
const server = this.secondaryServers.get(port);
if (server) return server.isListening();
return this.httpServer.isListening();
},
isListening: () => this.httpServer.isListening(),
};
}

Expand All @@ -129,32 +115,6 @@ export class HttpService implements CoreService<HttpServiceSetup, HttpServiceSta
return !this.coreContext.env.isDevClusterMaster && config.autoListen;
}

private async createServer(cfg: Partial<HttpConfig>) {
const { port } = cfg;
const config = await this.config$.pipe(first()).toPromise();

if (!port) {
throw new Error('port must be defined');
}

// verify that main server and none of the secondary servers are already using this port
if (this.secondaryServers.has(port) || config.port === port) {
throw new Error(`port ${port} is already in use`);
}

for (const [key, val] of Object.entries(cfg)) {
httpConfig.schema.validateKey(key, val);
}

const baseConfig = await this.config$.pipe(first()).toPromise();
const finalConfig = { ...baseConfig, ...cfg };

const httpServer = new HttpServer(this.logger, `secondary server:${port}`);
const httpSetup = await httpServer.setup(finalConfig);
this.secondaryServers.set(port, httpServer);
return httpSetup;
}

public async stop() {
if (this.configSubscription === undefined) {
return;
Expand All @@ -168,8 +128,6 @@ export class HttpService implements CoreService<HttpServiceSetup, HttpServiceSta
}
await this.httpServer.stop();
await this.httpsRedirectServer.stop();
await Promise.all([...this.secondaryServers.values()].map(s => s.stop()));
this.secondaryServers.clear();
}

private async runNotReadyServer(config: HttpConfig) {
Expand Down
1 change: 0 additions & 1 deletion src/core/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ export interface CoreSetup {
registerAuth: HttpServiceSetup['registerAuth'];
registerOnPostAuth: HttpServiceSetup['registerOnPostAuth'];
basePath: HttpServiceSetup['basePath'];
createNewServer: HttpServiceSetup['createNewServer'];
isTlsEnabled: HttpServiceSetup['isTlsEnabled'];
};
}
Expand Down
1 change: 0 additions & 1 deletion src/core/server/plugins/plugin_context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ export function createPluginSetupContext<TPlugin, TPluginDependencies>(
registerAuth: deps.http.registerAuth,
registerOnPostAuth: deps.http.registerOnPostAuth,
basePath: deps.http.basePath,
createNewServer: deps.http.createNewServer,
isTlsEnabled: deps.http.isTlsEnabled,
},
};
Expand Down
9 changes: 1 addition & 8 deletions src/core/server/server.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
```ts

import Boom from 'boom';
import { ByteSizeValue } from '@kbn/config-schema';
import { CallCluster } from 'src/legacy/core_plugins/elasticsearch';
import { ConfigOptions } from 'elasticsearch';
import { Duration } from 'moment';
Expand Down Expand Up @@ -100,7 +99,6 @@ export interface CoreSetup {
registerAuth: HttpServiceSetup['registerAuth'];
registerOnPostAuth: HttpServiceSetup['registerOnPostAuth'];
basePath: HttpServiceSetup['basePath'];
createNewServer: HttpServiceSetup['createNewServer'];
isTlsEnabled: HttpServiceSetup['isTlsEnabled'];
};
}
Expand Down Expand Up @@ -170,12 +168,7 @@ export type Headers = Record<string, string | string[] | undefined>;
// Warning: (ae-forgotten-export) The symbol "HttpServerSetup" needs to be exported by the entry point index.d.ts
//
// @public (undocumented)
export interface HttpServiceSetup extends HttpServerSetup {
// Warning: (ae-forgotten-export) The symbol "HttpConfig" needs to be exported by the entry point index.d.ts
//
// (undocumented)
createNewServer: (cfg: Partial<HttpConfig>) => Promise<HttpServerSetup>;
}
export type HttpServiceSetup = HttpServerSetup;

// @public (undocumented)
export interface HttpServiceStart {
Expand Down