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

Telemetry uses es client provided from start contract #67279

Closed
Closed
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 @@ -20,4 +20,5 @@ export interface CoreStart
| [elasticsearch](./kibana-plugin-core-server.corestart.elasticsearch.md) | <code>ElasticsearchServiceStart</code> | [ElasticsearchServiceStart](./kibana-plugin-core-server.elasticsearchservicestart.md) |
| [savedObjects](./kibana-plugin-core-server.corestart.savedobjects.md) | <code>SavedObjectsServiceStart</code> | [SavedObjectsServiceStart](./kibana-plugin-core-server.savedobjectsservicestart.md) |
| [uiSettings](./kibana-plugin-core-server.corestart.uisettings.md) | <code>UiSettingsServiceStart</code> | [UiSettingsServiceStart](./kibana-plugin-core-server.uisettingsservicestart.md) |
| [uuid](./kibana-plugin-core-server.corestart.uuid.md) | <code>UuidServiceStart</code> | [UuidServiceStart](./kibana-plugin-core-server.uuidservicestart.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-core-server](./kibana-plugin-core-server.md) &gt; [CoreStart](./kibana-plugin-core-server.corestart.md) &gt; [uuid](./kibana-plugin-core-server.corestart.uuid.md)

## CoreStart.uuid property

[UuidServiceStart](./kibana-plugin-core-server.uuidservicestart.md)

<b>Signature:</b>

```typescript
uuid: UuidServiceStart;
```
1 change: 1 addition & 0 deletions docs/development/core/server/kibana-plugin-core-server.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ The plugin integrates with the core system via lifecycle events: `setup`<!-- -->
| [URLMeaningfulParts](./kibana-plugin-core-server.urlmeaningfulparts.md) | We define our own typings because the current version of @<!-- -->types/node declares properties to be optional "hostname?: string". Although, parse call returns "hostname: null \| string". |
| [UserProvidedValues](./kibana-plugin-core-server.userprovidedvalues.md) | Describes the values explicitly set by user. |
| [UuidServiceSetup](./kibana-plugin-core-server.uuidservicesetup.md) | APIs to access the application's instance uuid. |
| [UuidServiceStart](./kibana-plugin-core-server.uuidservicestart.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-core-server](./kibana-plugin-core-server.md) &gt; [UuidServiceStart](./kibana-plugin-core-server.uuidservicestart.md) &gt; [getInstanceUuid](./kibana-plugin-core-server.uuidservicestart.getinstanceuuid.md)

## UuidServiceStart.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-core-server](./kibana-plugin-core-server.md) &gt; [UuidServiceStart](./kibana-plugin-core-server.uuidservicestart.md)

## UuidServiceStart interface

APIs to access the application's instance uuid.

<b>Signature:</b>

```typescript
export interface UuidServiceStart
```

## Methods

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

5 changes: 4 additions & 1 deletion src/core/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ import {
SavedObjectsServiceStart,
} from './saved_objects';
import { CapabilitiesSetup, CapabilitiesStart } from './capabilities';
import { UuidServiceSetup } from './uuid';
import { UuidServiceSetup, UuidServiceStart } from './uuid';
import { MetricsServiceSetup } from './metrics';
import { StatusServiceSetup } from './status';

Expand Down Expand Up @@ -425,6 +425,8 @@ export interface CoreStart {
savedObjects: SavedObjectsServiceStart;
/** {@link UiSettingsServiceStart} */
uiSettings: UiSettingsServiceStart;
/** {@link UuidServiceStart} */
uuid: UuidServiceStart;
}

export {
Expand All @@ -436,6 +438,7 @@ export {
PluginsServiceStart,
PluginOpaqueId,
UuidServiceSetup,
UuidServiceStart,
};

/**
Expand Down
3 changes: 2 additions & 1 deletion src/core/server/internal_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {
InternalSavedObjectsServiceStart,
} from './saved_objects';
import { InternalUiSettingsServiceSetup, InternalUiSettingsServiceStart } from './ui_settings';
import { UuidServiceSetup } from './uuid';
import { UuidServiceSetup, UuidServiceStart } from './uuid';
import { InternalMetricsServiceSetup } from './metrics';
import { InternalRenderingServiceSetup } from './rendering';
import { InternalHttpResourcesSetup } from './http_resources';
Expand Down Expand Up @@ -58,6 +58,7 @@ export interface InternalCoreStart {
elasticsearch: ElasticsearchServiceStart;
savedObjects: InternalSavedObjectsServiceStart;
uiSettings: InternalUiSettingsServiceStart;
uuid: UuidServiceStart;
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/core/server/legacy/legacy_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ export class LegacyService implements CoreService {
getTypeRegistry: startDeps.core.savedObjects.getTypeRegistry,
},
uiSettings: { asScopedToClient: startDeps.core.uiSettings.asScopedToClient },
uuid: startDeps.core.uuid,
};

const router = setupDeps.core.http.createRouter('', this.legacyId);
Expand Down
2 changes: 2 additions & 0 deletions src/core/server/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ function createCoreStartMock() {
elasticsearch: elasticsearchServiceMock.createStart(),
savedObjects: savedObjectsServiceMock.createStartContract(),
uiSettings: uiSettingsServiceMock.createStartContract(),
uuid: uuidServiceMock.createStartContract(),
};

return mock;
Expand Down Expand Up @@ -188,6 +189,7 @@ function createInternalCoreStartMock() {
elasticsearch: elasticsearchServiceMock.createStart(),
savedObjects: savedObjectsServiceMock.createInternalStartContract(),
uiSettings: uiSettingsServiceMock.createStartContract(),
uuid: uuidServiceMock.createStartContract(),
};
return startDeps;
}
Expand Down
1 change: 1 addition & 0 deletions src/core/server/plugins/plugin_context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,5 +223,6 @@ export function createPluginStartContext<TPlugin, TPluginDependencies>(
uiSettings: {
asScopedToClient: deps.uiSettings.asScopedToClient,
},
uuid: deps.uuid,
};
}
7 changes: 7 additions & 0 deletions src/core/server/server.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,8 @@ export interface CoreStart {
savedObjects: SavedObjectsServiceStart;
// (undocumented)
uiSettings: UiSettingsServiceStart;
// (undocumented)
uuid: UuidServiceStart;
}

// @public
Expand Down Expand Up @@ -2535,6 +2537,11 @@ export interface UuidServiceSetup {
getInstanceUuid(): string;
}

// @public
export interface UuidServiceStart {
getInstanceUuid(): string;
}

// @public
export const validBodyOutput: readonly ["data", "stream"];

Expand Down
2 changes: 2 additions & 0 deletions src/core/server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,14 @@ export class Server {
const capabilitiesStart = this.capabilities.start();
const uiSettingsStart = await this.uiSettings.start();
const elasticsearchStart = await this.elasticsearch.start();
const uuidStart = await this.uuid.start();

this.coreStart = {
capabilities: capabilitiesStart,
elasticsearch: elasticsearchStart,
savedObjects: savedObjectsStart,
uiSettings: uiSettingsStart,
uuid: uuidStart,
};

const pluginsStart = await this.plugins.start(this.coreStart);
Expand Down
2 changes: 1 addition & 1 deletion src/core/server/uuid/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
* under the License.
*/

export { UuidService, UuidServiceSetup } from './uuid_service';
export { UuidService, UuidServiceSetup, UuidServiceStart } from './uuid_service';
11 changes: 10 additions & 1 deletion src/core/server/uuid/uuid_service.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { UuidService, UuidServiceSetup } from './uuid_service';
import { UuidService, UuidServiceSetup, UuidServiceStart } from './uuid_service';

const createSetupContractMock = () => {
const setupContract: jest.Mocked<UuidServiceSetup> = {
Expand All @@ -26,10 +26,18 @@ const createSetupContractMock = () => {
return setupContract;
};

const createStartContractMock = () => {
const startContract: jest.Mocked<UuidServiceStart> = {
getInstanceUuid: jest.fn().mockImplementation(() => 'uuid'),
};
return startContract;
};

type UuidServiceContract = PublicMethodsOf<UuidService>;
const createMock = () => {
const mocked: jest.Mocked<UuidServiceContract> = {
setup: jest.fn(),
start: jest.fn(),
};
mocked.setup.mockResolvedValue(createSetupContractMock());
return mocked;
Expand All @@ -38,4 +46,5 @@ const createMock = () => {
export const uuidServiceMock = {
create: createMock,
createSetupContract: createSetupContractMock,
createStartContract: createStartContractMock,
};
8 changes: 8 additions & 0 deletions src/core/server/uuid/uuid_service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,12 @@ describe('UuidService', () => {
expect(setup.getInstanceUuid()).toEqual('SOME_UUID');
});
});
describe('#start()', () => {
it('returns the uuid resolved from resolveInstanceUuid', async () => {
const service = new UuidService(coreContext);
await service.setup();
const start = await service.start();
expect(start.getInstanceUuid()).toEqual('SOME_UUID');
});
});
});
18 changes: 18 additions & 0 deletions src/core/server/uuid/uuid_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,18 @@ export interface UuidServiceSetup {
getInstanceUuid(): string;
}

/**
* APIs to access the application's instance uuid.
*
* @public
*/
export interface UuidServiceStart {
/**
* Retrieve the Kibana instance uuid.
*/
getInstanceUuid(): string;
}

/** @internal */
export class UuidService {
private readonly log: Logger;
Expand All @@ -58,4 +70,10 @@ export class UuidService {
getInstanceUuid: () => this.uuid,
};
}

public start() {
return {
getInstanceUuid: () => this.uuid,
};
}
}
2 changes: 1 addition & 1 deletion src/plugins/telemetry/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ export class TelemetryPlugin implements Plugin {
const config$ = this.config$;
const isDev = this.isDev;

registerCollection(telemetryCollectionManager, elasticsearch.dataClient);
const router = http.createRouter();

registerRoutes({
Expand All @@ -109,6 +108,7 @@ export class TelemetryPlugin implements Plugin {
this.logger.warn('Unable to update legacy telemetry configs.');
}

registerCollection(telemetryCollectionManager, core.elasticsearch.legacy.client);
this.fetcherTask.start(core, { telemetryCollectionManager });
}

Expand Down
2 changes: 1 addition & 1 deletion src/plugins/usage_collection/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import { PluginInitializerContext } from 'kibana/server';
import { UsageCollectionPlugin } from './plugin';

export { UsageCollectionSetup } from './plugin';
export { UsageCollectionSetup, UsageCollectionStart } from './plugin';
export { config } from './config';
export const plugin = (initializerContext: PluginInitializerContext) =>
new UsageCollectionPlugin(initializerContext);
9 changes: 6 additions & 3 deletions src/plugins/usage_collection/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ import { CollectorSet } from './collector';
import { setupRoutes } from './routes';

export type UsageCollectionSetup = CollectorSet;
export class UsageCollectionPlugin implements Plugin<CollectorSet> {
export type UsageCollectionStart = CollectorSet;
export class UsageCollectionPlugin implements Plugin<UsageCollectionSetup, UsageCollectionStart> {
private readonly logger: Logger;
private savedObjects?: ISavedObjectsRepository;
private collectorSet?: CollectorSet;
constructor(private readonly initializerContext: PluginInitializerContext) {
this.logger = this.initializerContext.logger.get();
}
Expand All @@ -44,20 +46,21 @@ export class UsageCollectionPlugin implements Plugin<CollectorSet> {
.pipe(first())
.toPromise();

const collectorSet = new CollectorSet({
this.collectorSet = new CollectorSet({
logger: this.logger.get('collector-set'),
maximumWaitTimeForAllCollectorsInS: config.maximumWaitTimeForAllCollectorsInS,
});

const router = core.http.createRouter();
setupRoutes(router, () => this.savedObjects);

return collectorSet;
return this.collectorSet;
}

public start({ savedObjects }: CoreStart) {
this.logger.debug('Starting plugin');
this.savedObjects = savedObjects.createInternalRepository();
return this.collectorSet!;
}

public stop() {
Expand Down
Loading