Skip to content

Commit

Permalink
Merge branch 'master' into search/error-alignment
Browse files Browse the repository at this point in the history
  • Loading branch information
elasticmachine authored Sep 25, 2020
2 parents a9b9b7f + 341c1ac commit 23f1603
Show file tree
Hide file tree
Showing 81 changed files with 1,098 additions and 885 deletions.
1 change: 1 addition & 0 deletions src/plugins/data/server/server.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import { DeleteDocumentParams } from 'elasticsearch';
import { DeleteScriptParams } from 'elasticsearch';
import { DeleteTemplateParams } from 'elasticsearch';
import { Duration } from 'moment';
import { ElasticsearchClient as ElasticsearchClient_2 } from 'kibana/server';
import { Ensure } from '@kbn/utility-types';
import { EnvironmentMode } from '@kbn/config';
import { ErrorToastOptions } from 'src/core/public/notifications';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@
* under the License.
*/

import { savedObjectsRepositoryMock, loggingSystemMock } from '../../../../../core/server/mocks';
import {
savedObjectsRepositoryMock,
loggingSystemMock,
elasticsearchServiceMock,
} from '../../../../../core/server/mocks';
import {
CollectorOptions,
createUsageCollectionSetupMock,
Expand Down Expand Up @@ -50,6 +54,7 @@ describe('telemetry_application_usage', () => {
const getUsageCollector = jest.fn();
const registerType = jest.fn();
const callCluster = jest.fn();
const esClient = elasticsearchServiceMock.createClusterClient().asInternalUser;

beforeAll(() =>
registerApplicationUsageCollector(logger, usageCollectionMock, registerType, getUsageCollector)
Expand All @@ -62,7 +67,7 @@ describe('telemetry_application_usage', () => {

test('if no savedObjectClient initialised, return undefined', async () => {
expect(collector.isReady()).toBe(false);
expect(await collector.fetch(callCluster)).toBeUndefined();
expect(await collector.fetch(callCluster, esClient)).toBeUndefined();
jest.runTimersToTime(ROLL_INDICES_START);
});

Expand All @@ -80,7 +85,7 @@ describe('telemetry_application_usage', () => {
jest.runTimersToTime(ROLL_TOTAL_INDICES_INTERVAL); // Force rollTotals to run

expect(collector.isReady()).toBe(true);
expect(await collector.fetch(callCluster)).toStrictEqual({});
expect(await collector.fetch(callCluster, esClient)).toStrictEqual({});
expect(savedObjectClient.bulkCreate).not.toHaveBeenCalled();
});

Expand Down Expand Up @@ -137,7 +142,7 @@ describe('telemetry_application_usage', () => {

jest.runTimersToTime(ROLL_TOTAL_INDICES_INTERVAL); // Force rollTotals to run

expect(await collector.fetch(callCluster)).toStrictEqual({
expect(await collector.fetch(callCluster, esClient)).toStrictEqual({
appId: {
clicks_total: total + 1 + 10,
clicks_7_days: total + 1,
Expand Down Expand Up @@ -197,7 +202,7 @@ describe('telemetry_application_usage', () => {

getUsageCollector.mockImplementation(() => savedObjectClient);

expect(await collector.fetch(callCluster)).toStrictEqual({
expect(await collector.fetch(callCluster, esClient)).toStrictEqual({
appId: {
clicks_total: 1,
clicks_7_days: 0,
Expand Down
17 changes: 10 additions & 7 deletions src/plugins/telemetry/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {
SavedObjectsClient,
Plugin,
Logger,
IClusterClient,
} from '../../../core/server';
import { registerRoutes } from './routes';
import { registerCollection } from './telemetry_collection';
Expand Down Expand Up @@ -83,6 +84,7 @@ export class TelemetryPlugin implements Plugin<TelemetryPluginSetup, TelemetryPl
private readonly fetcherTask: FetcherTask;
private savedObjectsClient?: ISavedObjectsRepository;
private uiSettingsClient?: IUiSettingsClient;
private elasticsearchClient?: IClusterClient;

constructor(initializerContext: PluginInitializerContext<TelemetryConfigType>) {
this.logger = initializerContext.logger.get();
Expand All @@ -102,8 +104,11 @@ export class TelemetryPlugin implements Plugin<TelemetryPluginSetup, TelemetryPl
const currentKibanaVersion = this.currentKibanaVersion;
const config$ = this.config$;
const isDev = this.isDev;

registerCollection(telemetryCollectionManager, elasticsearch.legacy.client);
registerCollection(
telemetryCollectionManager,
elasticsearch.legacy.client,
() => this.elasticsearchClient
);
const router = http.createRouter();

registerRoutes({
Expand All @@ -126,14 +131,12 @@ export class TelemetryPlugin implements Plugin<TelemetryPluginSetup, TelemetryPl
};
}

public async start(
core: CoreStart,
{ telemetryCollectionManager }: TelemetryPluginsDepsStart
): Promise<TelemetryPluginStart> {
const { savedObjects, uiSettings } = core;
public async start(core: CoreStart, { telemetryCollectionManager }: TelemetryPluginsDepsStart) {
const { savedObjects, uiSettings, elasticsearch } = core;
this.savedObjectsClient = savedObjects.createInternalRepository();
const savedObjectsClient = new SavedObjectsClient(this.savedObjectsClient);
this.uiSettingsClient = uiSettings.asScopedToClient(savedObjectsClient);
this.elasticsearchClient = elasticsearch.client;

try {
await handleOldSettings(savedObjectsClient, this.uiSettingsClient);
Expand Down

This file was deleted.

This file was deleted.

Loading

0 comments on commit 23f1603

Please sign in to comment.