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

[Reporting] Use a shim for server config #62086

Merged
merged 20 commits into from
Apr 4, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion x-pack/legacy/plugins/reporting/server/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { ReportingConfig, ReportingConfigType } from './core';
export interface ReportingSetupDeps {
elasticsearch: ElasticsearchServiceSetup;
security: SecurityPluginSetup;
usageCollection: UsageCollectionSetup;
usageCollection?: UsageCollectionSetup;
Copy link
Member Author

Choose a reason for hiding this comment

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

cc @ @afharo - this commit is from your feedback on #61696

__LEGACY: LegacySetup;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
*/

import { get } from 'lodash';
import { XPackMainPlugin } from '../../../xpack_main/server/xpack_main';
import { ESCallCluster, ExportTypesRegistry } from '../../types';
import { ReportingConfig, ReportingSetupDeps } from '../types';
import { ReportingConfig } from '../types';
import { decorateRangeStats } from './decorate_range_stats';
import { getExportTypesHandler } from './get_export_type_handler';
import {
Expand All @@ -19,6 +20,8 @@ import {
RangeStats,
} from './types';

type XPackInfo = XPackMainPlugin['info'];

const JOB_TYPES_KEY = 'jobTypes';
const JOB_TYPES_FIELD = 'jobtype';
const LAYOUT_TYPES_KEY = 'layoutTypes';
Expand Down Expand Up @@ -100,7 +103,7 @@ async function handleResponse(response: AggregationResults): Promise<RangeStatSe

export async function getReportingUsage(
config: ReportingConfig,
plugins: ReportingSetupDeps,
xpackMainInfo: XPackInfo,
callCluster: ESCallCluster,
exportTypesRegistry: ExportTypesRegistry
) {
Expand Down Expand Up @@ -137,7 +140,6 @@ export async function getReportingUsage(
},
};

const { info: xpackMainInfo } = plugins.__LEGACY.plugins.xpack_main;
return callCluster('search', params)
.then((response: AggregationResults) => handleResponse(response))
.then((usage: RangeStatSets) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,12 @@ describe('license checks', () => {
beforeAll(async () => {
const plugins = getPluginsMock({ license: 'basic' });
const callClusterMock = jest.fn(() => Promise.resolve(getResponseMock()));
const { fetch } = getReportingUsageCollector(mockConfig, plugins, exportTypesRegistry);
const { fetch } = getReportingUsageCollector(
mockConfig,
plugins.usageCollection,
plugins.__LEGACY.plugins.xpack_main.info,
exportTypesRegistry
);
usageStats = await fetch(callClusterMock, exportTypesRegistry);
});

Expand All @@ -93,7 +98,12 @@ describe('license checks', () => {
beforeAll(async () => {
const plugins = getPluginsMock({ license: 'none' });
const callClusterMock = jest.fn(() => Promise.resolve(getResponseMock()));
const { fetch } = getReportingUsageCollector(mockConfig, plugins, exportTypesRegistry);
const { fetch } = getReportingUsageCollector(
mockConfig,
plugins.usageCollection,
plugins.__LEGACY.plugins.xpack_main.info,
exportTypesRegistry
);
usageStats = await fetch(callClusterMock, exportTypesRegistry);
});

Expand All @@ -115,7 +125,12 @@ describe('license checks', () => {
beforeAll(async () => {
const plugins = getPluginsMock({ license: 'platinum' });
const callClusterMock = jest.fn(() => Promise.resolve(getResponseMock()));
const { fetch } = getReportingUsageCollector(mockConfig, plugins, exportTypesRegistry);
const { fetch } = getReportingUsageCollector(
mockConfig,
plugins.usageCollection,
plugins.__LEGACY.plugins.xpack_main.info,
exportTypesRegistry
);
usageStats = await fetch(callClusterMock, exportTypesRegistry);
});

Expand All @@ -137,7 +152,12 @@ describe('license checks', () => {
beforeAll(async () => {
const plugins = getPluginsMock({ license: 'basic' });
const callClusterMock = jest.fn(() => Promise.resolve({}));
const { fetch } = getReportingUsageCollector(mockConfig, plugins, exportTypesRegistry);
const { fetch } = getReportingUsageCollector(
mockConfig,
plugins.usageCollection,
plugins.__LEGACY.plugins.xpack_main.info,
exportTypesRegistry
);
usageStats = await fetch(callClusterMock, exportTypesRegistry);
});

Expand All @@ -155,7 +175,12 @@ describe('data modeling', () => {
test('with normal looking usage data', async () => {
const mockConfig = getMockReportingConfig();
const plugins = getPluginsMock();
const { fetch } = getReportingUsageCollector(mockConfig, plugins, exportTypesRegistry);
const { fetch } = getReportingUsageCollector(
mockConfig,
plugins.usageCollection,
plugins.__LEGACY.plugins.xpack_main.info,
exportTypesRegistry
);
const callClusterMock = jest.fn(() =>
Promise.resolve(
getResponseMock({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { UsageCollectionSetup } from 'src/plugins/usage_collection/server';
import { XPackMainPlugin } from '../../../xpack_main/server/xpack_main';
import { KIBANA_REPORTING_TYPE } from '../../common/constants';
import { ReportingConfig, ReportingCore, ReportingSetupDeps } from '../../server/types';
import { ESCallCluster, ExportTypesRegistry } from '../../types';
import { getReportingUsage } from './get_reporting_usage';
import { RangeStats } from './types';

type XPackInfo = XPackMainPlugin['info'];

// places the reporting data as kibana stats
const METATYPE = 'kibana_stats';

Expand All @@ -18,15 +22,15 @@ const METATYPE = 'kibana_stats';
*/
export function getReportingUsageCollector(
config: ReportingConfig,
plugins: ReportingSetupDeps,
usageCollection: UsageCollectionSetup,
xpackMainInfo: XPackInfo,
exportTypesRegistry: ExportTypesRegistry,
isReady: () => Promise<boolean>
) {
const { usageCollection } = plugins;
return usageCollection.makeUsageCollector({
type: KIBANA_REPORTING_TYPE,
fetch: (callCluster: ESCallCluster) =>
getReportingUsage(config, plugins, callCluster, exportTypesRegistry),
getReportingUsage(config, xpackMainInfo, callCluster, exportTypesRegistry),
isReady,

/*
Expand All @@ -53,13 +57,19 @@ export function registerReportingUsageCollector(
reporting: ReportingCore,
plugins: ReportingSetupDeps
) {
if (!plugins.usageCollection) {
return;
}
const xpackMainInfo = plugins.__LEGACY.plugins.xpack_main.info;

const exportTypesRegistry = reporting.getExportTypesRegistry();
const collectionIsReady = reporting.pluginHasStarted.bind(reporting);
const config = reporting.getConfig();

const collector = getReportingUsageCollector(
config,
plugins,
plugins.usageCollection,
xpackMainInfo,
exportTypesRegistry,
collectionIsReady
);
Expand Down