Skip to content
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
732ccf2
move and migrate uuid code to new platform
pgayvallet Dec 2, 2019
bb7c5f0
create and wire uuid service
pgayvallet Dec 3, 2019
958b28e
handle legacy compatibility
pgayvallet Dec 3, 2019
3ed08c5
update generated docs
pgayvallet Dec 3, 2019
6964d1e
add `set` to LegacyConfig interface
pgayvallet Dec 6, 2019
88f9790
Fix types
pgayvallet Dec 6, 2019
c8a808d
fix config access
pgayvallet Dec 6, 2019
81a0dc0
Merge remote-tracking branch 'upstream/master' into kbn-48956-uuid-NP
pgayvallet Dec 9, 2019
7bbd025
Merge remote-tracking branch 'upstream/master' into kbn-48956-uuid-NP
pgayvallet Dec 11, 2019
b850444
Merge remote-tracking branch 'upstream/master' into kbn-48956-uuid-NP
pgayvallet Dec 12, 2019
a499ff1
respect naming conventions for uuid
pgayvallet Dec 12, 2019
afcdf9a
remove hardcoded config paths
pgayvallet Dec 12, 2019
6c0c880
rename manageInstanceUuid to resolveInstanceUuid
pgayvallet Dec 12, 2019
6139832
moves legacy config uuid set from uuid to legacy service
pgayvallet Dec 12, 2019
26719cb
log specific message depending on how uuid was resolved
pgayvallet Dec 12, 2019
1783d71
Merge remote-tracking branch 'upstream/master' into kbn-48956-uuid-NP
pgayvallet Dec 13, 2019
ba3a23f
Merge remote-tracking branch 'upstream/master' into kbn-48956-uuid-NP
pgayvallet Dec 13, 2019
8bcc718
resolve merge conflicts
pgayvallet Dec 13, 2019
f4b11d8
use fs.promises
pgayvallet Dec 13, 2019
fa6ea93
add forgotten @public in uuid contract
pgayvallet Dec 13, 2019
a6f5980
add explicit errors and tests
pgayvallet Dec 13, 2019
1844093
Merge remote-tracking branch 'upstream/master' into kbn-48956-uuid-NP
pgayvallet Dec 13, 2019
83eb19f
ensure uuid is valid in configuration
pgayvallet Dec 13, 2019
1b8e6b6
Merge remote-tracking branch 'upstream/master' into kbn-48956-uuid-NP
pgayvallet Dec 16, 2019
8767b73
fix read/write tests
pgayvallet Dec 16, 2019
9f27f5a
Merge remote-tracking branch 'upstream/master' into kbn-48956-uuid-NP
pgayvallet Dec 16, 2019
16e9a2f
Merge remote-tracking branch 'upstream/master' into kbn-48956-uuid-NP
pgayvallet Dec 17, 2019
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 @@ -22,4 +22,5 @@ export interface CoreSetup
| [http](./kibana-plugin-server.coresetup.http.md) | <code>HttpServiceSetup</code> | [HttpServiceSetup](./kibana-plugin-server.httpservicesetup.md) |
| [savedObjects](./kibana-plugin-server.coresetup.savedobjects.md) | <code>SavedObjectsServiceSetup</code> | [SavedObjectsServiceSetup](./kibana-plugin-server.savedobjectsservicesetup.md) |
| [uiSettings](./kibana-plugin-server.coresetup.uisettings.md) | <code>UiSettingsServiceSetup</code> | [UiSettingsServiceSetup](./kibana-plugin-server.uisettingsservicesetup.md) |
| [uuid](./kibana-plugin-server.coresetup.uuid.md) | <code>UuidServiceSetup</code> | [UuidServiceSetup](./kibana-plugin-server.uuidservicesetup.md) |

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-server](./kibana-plugin-server.md) &gt; [CoreSetup](./kibana-plugin-server.coresetup.md) &gt; [uuid](./kibana-plugin-server.coresetup.uuid.md)

## CoreSetup.uuid property

[UuidServiceSetup](./kibana-plugin-server.uuidservicesetup.md)

<b>Signature:</b>

```typescript
uuid: UuidServiceSetup;
```
1 change: 1 addition & 0 deletions docs/development/core/server/kibana-plugin-server.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ The plugin integrates with the core system via lifecycle events: `setup`<!-- -->
| [UiSettingsParams](./kibana-plugin-server.uisettingsparams.md) | UiSettings parameters defined by the plugins. |
| [UiSettingsServiceSetup](./kibana-plugin-server.uisettingsservicesetup.md) | |
| [UserProvidedValues](./kibana-plugin-server.userprovidedvalues.md) | Describes the values explicitly set by user. |
| [UuidServiceSetup](./kibana-plugin-server.uuidservicesetup.md) | APIs to access the application's instance uuid. |

## Variables

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-server](./kibana-plugin-server.md) &gt; [UuidServiceSetup](./kibana-plugin-server.uuidservicesetup.md) &gt; [getInstanceUuid](./kibana-plugin-server.uuidservicesetup.getinstanceuuid.md)

## UuidServiceSetup.getInstanceUuid() method

Retrieve the Kibana instance uuid.

<b>Signature:</b>

```typescript
getInstanceUuid(): string;
```
<b>Returns:</b>

`string`

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

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

## UuidServiceSetup interface

APIs to access the application's instance uuid.

<b>Signature:</b>

```typescript
export interface UuidServiceSetup
```

## Methods

| Method | Description |
| --- | --- |
| [getInstanceUuid()](./kibana-plugin-server.uuidservicesetup.getinstanceuuid.md) | Retrieve the Kibana instance uuid. |

1 change: 1 addition & 0 deletions src/core/server/http/http_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ export const config = {
)
),
}),
uuid: schema.maybe(schema.string()),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like having to add this here, as the server config namespace is now more like only the http config, However the current property is server.uuid, so I don't really see another way.

We could deprecates/rename that once the config deprecation PR lands if we want to.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a note to the config refactoring issue just so we don't forget?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the legacy config, we validated this as a valid guid. Can we add that validation here as well? Should be able to specify a custom validate option to schema.string()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh good catch, totally forgot about that

},
{
validate: rawConfig => {
Expand Down
4 changes: 4 additions & 0 deletions src/core/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import { IUiSettingsClient, UiSettingsServiceSetup } from './ui_settings';
import { SavedObjectsClientContract } from './saved_objects/types';
import { SavedObjectsServiceSetup, SavedObjectsServiceStart } from './saved_objects';
import { CapabilitiesSetup, CapabilitiesStart } from './capabilities';
import { UuidServiceSetup } from './uuid';

export { bootstrap } from './bootstrap';
export { Capabilities, CapabilitiesProvider, CapabilitiesSwitcher } from './capabilities';
Expand Down Expand Up @@ -268,6 +269,8 @@ export interface CoreSetup {
savedObjects: SavedObjectsServiceSetup;
/** {@link UiSettingsServiceSetup} */
uiSettings: UiSettingsServiceSetup;
/** {@link UuidServiceSetup} */
uuid: UuidServiceSetup;
}

/**
Expand All @@ -289,4 +292,5 @@ export {
PluginsServiceSetup,
PluginsServiceStart,
PluginOpaqueId,
UuidServiceSetup,
};
2 changes: 2 additions & 0 deletions src/core/server/internal_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
InternalSavedObjectsServiceSetup,
} from './saved_objects';
import { CapabilitiesSetup, CapabilitiesStart } from './capabilities';
import { UuidServiceSetup } from './uuid';

/** @internal */
export interface InternalCoreSetup {
Expand All @@ -35,6 +36,7 @@ export interface InternalCoreSetup {
elasticsearch: InternalElasticsearchServiceSetup;
uiSettings: InternalUiSettingsServiceSetup;
savedObjects: InternalSavedObjectsServiceSetup;
uuid: UuidServiceSetup;
}

/**
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export class LegacyObjectToConfigAdapter extends ObjectToConfigAdapter {
keepaliveTimeout: configValue.keepaliveTimeout,
socketTimeout: configValue.socketTimeout,
compression: configValue.compression,
uuid: configValue.uuid,
};
}

Expand Down
2 changes: 2 additions & 0 deletions src/core/server/legacy/config/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
export interface LegacyConfig {
get<T>(key?: string): T;
has(key: string): boolean;
set(key: string, value: any): void;
set(config: Record<string, any>): void;
}

/**
Expand Down
39 changes: 39 additions & 0 deletions src/core/server/legacy/legacy_service.mock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import { LegacyServiceDiscoverPlugins } from './legacy_service';

const createDiscoverMock = () => {
const setupContract: DeeplyMockedKeys<LegacyServiceDiscoverPlugins> = {
pluginSpecs: [],
disabledPluginSpecs: [],
uiExports: {} as any,
settings: {},
pluginExtendedConfig: {
get: jest.fn(),
has: jest.fn(),
set: jest.fn(),
} as any,
};
return setupContract;
};

export const legacyServiceMock = {
createDiscover: createDiscoverMock,
};
34 changes: 34 additions & 0 deletions src/core/server/legacy/legacy_service.test.mocks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

export const findLegacyPluginSpecsMock = jest
.fn()
.mockImplementation((settings: Record<string, any>) => ({
pluginSpecs: [],
pluginExtendedConfig: {
has: jest.fn(),
get: jest.fn(() => settings),
set: jest.fn(),
},
disabledPluginSpecs: [],
uiExports: [],
}));
jest.doMock('./plugins/find_legacy_plugin_specs.ts', () => ({
findLegacyPluginSpecs: findLegacyPluginSpecsMock,
}));
81 changes: 58 additions & 23 deletions src/core/server/legacy/legacy_service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,36 +17,34 @@
* under the License.
*/

import { BehaviorSubject, throwError } from 'rxjs';

jest.mock('../../../legacy/server/kbn_server');
jest.mock('../../../cli/cluster/cluster_manager');
jest.mock('./plugins/find_legacy_plugin_specs');
jest.mock('./config/legacy_deprecation_adapters', () => ({
convertLegacyDeprecationProvider: (provider: any) => Promise.resolve(provider),
}));
import { findLegacyPluginSpecsMock } from './legacy_service.test.mocks';

import { BehaviorSubject, throwError } from 'rxjs';
import { LegacyService, LegacyServiceSetupDeps, LegacyServiceStartDeps } from '.';
// @ts-ignore: implicit any for JS file
import MockClusterManager from '../../../cli/cluster/cluster_manager';
import KbnServer from '../../../legacy/server/kbn_server';
import { Config, Env, ObjectToConfigAdapter } from '../config';
import { contextServiceMock } from '../context/context_service.mock';
import { getEnvOptions } from '../config/__mocks__/env';
import { configServiceMock } from '../config/config_service.mock';

import { BasePathProxyServer } from '../http';
import { loggingServiceMock } from '../logging/logging_service.mock';
import { DiscoveredPlugin } from '../plugins';
import { findLegacyPluginSpecs } from './plugins/find_legacy_plugin_specs';

import { configServiceMock } from '../config/config_service.mock';
import { loggingServiceMock } from '../logging/logging_service.mock';
import { contextServiceMock } from '../context/context_service.mock';
import { httpServiceMock } from '../http/http_service.mock';
import { uiSettingsServiceMock } from '../ui_settings/ui_settings_service.mock';
import { savedObjectsServiceMock } from '../saved_objects/saved_objects_service.mock';
import { capabilitiesServiceMock } from '../capabilities/capabilities_service.mock';
import { findLegacyPluginSpecs } from './plugins/find_legacy_plugin_specs';
import { uuidServiceMock } from '../uuid/uuid_service.mock';

const MockKbnServer: jest.Mock<KbnServer> = KbnServer as any;
const findLegacyPluginSpecsMock: jest.Mock<typeof findLegacyPluginSpecs> = findLegacyPluginSpecs as any;

let coreId: symbol;
let env: Env;
Expand All @@ -58,23 +56,17 @@ let startDeps: LegacyServiceStartDeps;

const logger = loggingServiceMock.create();
let configService: ReturnType<typeof configServiceMock.create>;
let uuidSetup: ReturnType<typeof uuidServiceMock.createSetupContract>;

beforeEach(() => {
coreId = Symbol();
env = Env.createDefault(getEnvOptions());
configService = configServiceMock.create();
uuidSetup = uuidServiceMock.createSetupContract();

findLegacyPluginSpecsMock.mockImplementation(
settings =>
Promise.resolve({
pluginSpecs: [],
pluginExtendedConfig: settings,
disabledPluginSpecs: [],
uiExports: [],
}) as any
);

findLegacyPluginSpecsMock.mockClear();
MockKbnServer.prototype.ready = jest.fn().mockReturnValue(Promise.resolve());
MockKbnServer.prototype.listen = jest.fn();

setupDeps = {
core: {
Expand All @@ -97,6 +89,7 @@ beforeEach(() => {
browserConfigs: new Map(),
},
},
uuid: uuidSetup,
},
plugins: { 'plugin-id': 'plugin-value' },
};
Expand All @@ -123,7 +116,6 @@ beforeEach(() => {

afterEach(() => {
jest.clearAllMocks();
findLegacyPluginSpecsMock.mockReset();
});

describe('once LegacyService is set up with connection info', () => {
Expand All @@ -142,11 +134,15 @@ describe('once LegacyService is set up with connection info', () => {

expect(MockKbnServer).toHaveBeenCalledTimes(1);
expect(MockKbnServer).toHaveBeenCalledWith(
{ path: { autoListen: true }, server: { autoListen: true } },
{ path: { autoListen: true }, server: { autoListen: true } }, // Because of the mock, path also gets the value
expect.objectContaining({ get: expect.any(Function) }),
expect.any(Object),
{ disabledPluginSpecs: [], pluginSpecs: [], uiExports: [] }
);
expect(MockKbnServer.mock.calls[0][1].get()).toEqual({
path: { autoListen: true },
server: { autoListen: true },
});

const [mockKbnServer] = MockKbnServer.mock.instances;
expect(mockKbnServer.listen).toHaveBeenCalledTimes(1);
Expand All @@ -169,10 +165,14 @@ describe('once LegacyService is set up with connection info', () => {
expect(MockKbnServer).toHaveBeenCalledTimes(1);
expect(MockKbnServer).toHaveBeenCalledWith(
{ path: { autoListen: false }, server: { autoListen: true } },
{ path: { autoListen: false }, server: { autoListen: true } },
expect.objectContaining({ get: expect.any(Function) }),
expect.any(Object),
{ disabledPluginSpecs: [], pluginSpecs: [], uiExports: [] }
);
expect(MockKbnServer.mock.calls[0][1].get()).toEqual({
path: { autoListen: false },
server: { autoListen: true },
});

const [mockKbnServer] = MockKbnServer.mock.instances;
expect(mockKbnServer.ready).toHaveBeenCalledTimes(1);
Expand Down Expand Up @@ -306,10 +306,14 @@ describe('once LegacyService is set up without connection info', () => {
expect(MockKbnServer).toHaveBeenCalledTimes(1);
expect(MockKbnServer).toHaveBeenCalledWith(
{ path: {}, server: { autoListen: true } },
{ path: {}, server: { autoListen: true } },
expect.objectContaining({ get: expect.any(Function) }),
expect.any(Object),
{ disabledPluginSpecs: [], pluginSpecs: [], uiExports: [] }
);
expect(MockKbnServer.mock.calls[0][1].get()).toEqual({
path: {},
server: { autoListen: true },
});
});

test('reconfigures logging configuration if new config is received.', async () => {
Expand Down Expand Up @@ -440,3 +444,34 @@ describe('#discoverPlugins()', () => {
expect(configService.addDeprecationProvider).toHaveBeenCalledWith('', 'providerB');
});
});

test('Sets the server.uuid property on the legacy configuration', async () => {
configService.atPath.mockReturnValue(new BehaviorSubject({ autoListen: true }));
const legacyService = new LegacyService({
coreId,
env,
logger,
configService: configService as any,
});

uuidSetup.getInstanceUuid.mockImplementation(() => 'UUID_FROM_SERVICE');

const configSetMock = jest.fn();

findLegacyPluginSpecsMock.mockImplementation((settings: Record<string, any>) => ({
pluginSpecs: [],
pluginExtendedConfig: {
has: jest.fn(),
get: jest.fn(() => settings),
set: configSetMock,
},
disabledPluginSpecs: [],
uiExports: [],
}));

await legacyService.discoverPlugins();
await legacyService.setup(setupDeps);

expect(configSetMock).toHaveBeenCalledTimes(1);
expect(configSetMock).toHaveBeenCalledWith('server.uuid', 'UUID_FROM_SERVICE');
});
Loading