Skip to content

Commit

Permalink
run type check after refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Bamieh committed Nov 26, 2019
1 parent 7566a8a commit cd85bf5
Show file tree
Hide file tree
Showing 11 changed files with 22 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { i18nLoader } from '@kbn/i18n';
import { size } from 'lodash';
import { getIntegrityHashes, Integrities } from './file_integrity';
import { KIBANA_LOCALIZATION_STATS_TYPE } from '../../../common/constants';
import { PluginSetupContract as UsageCollectionPluginSetupContract } from '../../../../../../plugins/usage_collection/server';
import { UsageCollectionSetup } from '../../../../../../plugins/usage_collection/server';
export interface UsageStats {
locale: string;
integrities: Integrities;
Expand Down Expand Up @@ -53,7 +53,7 @@ export function createCollectorFetch(server: any) {
}

export function registerLocalizationUsageCollector(
usageCollection: UsageCollectionPluginSetupContract,
usageCollection: UsageCollectionSetup,
server: any
) {
const collector = usageCollection.makeUsageCollector({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import { TELEMETRY_STATS_TYPE } from '../../../common/constants';
import { getTelemetrySavedObject, TelemetrySavedObject } from '../../telemetry_repository';
import { getTelemetryOptIn, getTelemetrySendUsageFrom } from '../../telemetry_config';
import { PluginSetupContract as UsageCollectionPluginSetupContract } from '../../../../../../plugins/usage_collection/server';
import { UsageCollectionSetup } from '../../../../../../plugins/usage_collection/server';

export interface TelemetryUsageStats {
opt_in_status?: boolean | null;
Expand Down Expand Up @@ -64,7 +64,7 @@ export function createCollectorFetch(server: any) {
}

export function registerTelemetryPluginUsageCollector(
usageCollection: UsageCollectionPluginSetupContract,
usageCollection: UsageCollectionSetup,
server: any
) {
const collector = usageCollection.makeUsageCollector({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,9 @@
*/

import { UI_METRIC_USAGE_TYPE } from '../../../common/constants';
import { PluginSetupContract as UsageCollectionPluginSetupContract } from '../../../../../../plugins/usage_collection/server';
import { UsageCollectionSetup } from '../../../../../../plugins/usage_collection/server';

export function registerUiMetricUsageCollector(
usageCollection: UsageCollectionPluginSetupContract,
server: any
) {
export function registerUiMetricUsageCollector(usageCollection: UsageCollectionSetup, server: any) {
const collector = usageCollection.makeUsageCollector({
type: UI_METRIC_USAGE_TYPE,
fetch: async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,10 @@ import {
readTelemetryFile,
MAX_FILE_SIZE,
} from './telemetry_usage_collector';
import { PluginSetupContract as UsageCollectionPluginSetupContract } from '../../../../../../plugins/usage_collection/server';

const mockUsageCollector = () =>
(({
makeUsageCollector: jest.fn().mockImplementationOnce((arg: object) => arg),
} as any) as UsageCollectionPluginSetupContract);
const mockUsageCollector = () => ({
makeUsageCollector: jest.fn().mockImplementationOnce((arg: object) => arg),
});

const serverWithConfig = (configPath: string): Server => {
return {
Expand Down Expand Up @@ -134,7 +132,8 @@ describe('telemetry_usage_collector', () => {
const server: Server = serverWithConfig(tempFiles.unreadable);

// the `makeUsageCollector` is mocked above to return the argument passed to it
const collectorOptions = createTelemetryUsageCollector(mockUsageCollector(), server);
const usageCollector = mockUsageCollector() as any;
const collectorOptions = createTelemetryUsageCollector(usageCollector, server);

expect(collectorOptions.type).toBe('static_telemetry');
expect(await collectorOptions.fetch()).toEqual(expectedObject);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { dirname, join } from 'path';
// look for telemetry.yml in the same places we expect kibana.yml
import { ensureDeepObject } from './ensure_deep_object';
import { getXpackConfigWithDeprecated } from '../../../common/get_xpack_config_with_deprecated';
import { PluginSetupContract as UsageCollectionPluginSetupContract } from '../../../../../../plugins/usage_collection/server';
import { UsageCollectionSetup } from '../../../../../../plugins/usage_collection/server';

/**
* The maximum file size before we ignore it (note: this limit is arbitrary).
Expand Down Expand Up @@ -77,7 +77,7 @@ export async function readTelemetryFile(path: string): Promise<object | undefine
}

export function createTelemetryUsageCollector(
usageCollection: UsageCollectionPluginSetupContract,
usageCollection: UsageCollectionSetup,
server: Server
) {
return usageCollection.makeUsageCollector({
Expand All @@ -93,7 +93,7 @@ export function createTelemetryUsageCollector(
}

export function registerTelemetryUsageCollector(
usageCollection: UsageCollectionPluginSetupContract,
usageCollection: UsageCollectionSetup,
server: Server
) {
const collector = createTelemetryUsageCollector(usageCollection, server);
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/usage_collection/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class Plugin {
this.logger = this.initializerContext.logger.get();
}

public async setup(): Promise<PluginSetupContract> {
public async setup(): Promise<UsageCollectionSetup> {
const config = await this.initializerContext.config
.create<TypeOf<typeof ConfigSchema>>()
.pipe(first())
Expand Down
4 changes: 2 additions & 2 deletions x-pack/legacy/plugins/apm/server/lib/apm_telemetry/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
APM_SERVICES_TELEMETRY_SAVED_OBJECT_ID
} from '../../../common/apm_saved_object_constants';
import { APMLegacyServer } from '../../routes/typings';
import { PluginSetupContract as UsageCollector } from '../../../../../../../src/plugins/usage_collection/server';
import { UsageCollectionSetup } from '../../../../../../../src/plugins/usage_collection/server';

export function createApmTelementry(
agentNames: string[] = []
Expand Down Expand Up @@ -45,7 +45,7 @@ export async function storeApmServicesTelemetry(
}

export function makeApmUsageCollector(
usageCollector: UsageCollector,
usageCollector: UsageCollectionSetup,
server: APMLegacyServer
) {
const apmUsageCollector = usageCollector.makeUsageCollector({
Expand Down
2 changes: 1 addition & 1 deletion x-pack/legacy/plugins/canvas/server/shim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export async function createSetupShim(
// @ts-ignore: Missing from Legacy Server Type
addAppLinksToSampleDataset: server.addAppLinksToSampleDataset,
},
usageCollection: server.newPlatform.setup.plugins,
usageCollection: server.newPlatform.setup.plugins.usageCollection,
},
};
}
1 change: 0 additions & 1 deletion x-pack/legacy/plugins/lens/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import * as Joi from 'joi';
import { resolve } from 'path';
import { LegacyPluginInitializer } from 'src/legacy/types';
import KbnServer, { Server } from 'src/legacy/server/kbn_server';
import { UsageCollectionSetup } from 'src/plugins/usage_collection/server';
import mappings from './mappings.json';
import { PLUGIN_ID, getEditPath } from './common';
import { lensServerPlugin } from './server';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ describe('with a basic license', () => {
const { features, licensing, usageCollecion } = setup({
license: { isAvailable: true, type: 'basic' },
});
const { fetch: getSpacesUsage } = getSpacesUsageCollector(usageCollecion, {
const { fetch: getSpacesUsage } = getSpacesUsageCollector(usageCollecion as any, {
kibanaIndex: '.kibana',
features,
licensing,
Expand Down Expand Up @@ -106,7 +106,7 @@ describe('with no license', () => {
let usageStats: UsageStats;
beforeAll(async () => {
const { features, licensing, usageCollecion } = setup({ license: { isAvailable: false } });
const { fetch: getSpacesUsage } = getSpacesUsageCollector(usageCollecion, {
const { fetch: getSpacesUsage } = getSpacesUsageCollector(usageCollecion as any, {
kibanaIndex: '.kibana',
features,
licensing,
Expand Down
5 changes: 2 additions & 3 deletions x-pack/plugins/spaces/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
import { Observable } from 'rxjs';
import { take } from 'rxjs/operators';
import { CapabilitiesModifier } from 'src/legacy/server/capabilities';
import { PluginSetupContract as UsageCollectionPluginSetup } from 'src/plugins/usage_collection/server';
import { HomeServerPluginSetup } from 'src/plugins/home/server';
import { UsageCollectionSetup } from 'src/plugins/usage_collection/server';
import { HomeServerPluginSetup } from 'src/plugins/home/server';
import {
SavedObjectsLegacyService,
CoreSetup,
Expand Down Expand Up @@ -172,7 +171,7 @@ export class Plugin {
spacesService: SpacesServiceSetup,
featuresSetup: FeaturesPluginSetup,
licensingSetup: LicensingPluginSetup,
usageCollectionSetup?: UsageCollectionPluginSetup
usageCollectionSetup?: UsageCollectionSetup
) {
const legacyAPI = this.getLegacyAPI();
const { addScopedSavedObjectsClientWrapperFactory, types } = legacyAPI.savedObjects;
Expand Down

0 comments on commit cd85bf5

Please sign in to comment.