Skip to content

Commit

Permalink
[APM] Use licensing from context (elastic#70118)
Browse files Browse the repository at this point in the history
* [APM] Use licensing from context

We added the usage of `featureUsage.notifyUsage` from the licensing plugin in elastic#69455.

This required us to use `getStartServices to add `licensing` to `context.plugins`.

In elastic#69838 `featureUsage` was added to `context.licensing`, so we don't need to add it to `context.plugins`.
  • Loading branch information
smith committed Jun 29, 2020
1 parent 2c48a90 commit 820a08c
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 45 deletions.
64 changes: 28 additions & 36 deletions x-pack/plugins/apm/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,46 +4,42 @@
* you may not use this file except in compliance with the Elastic License.
*/
import { i18n } from '@kbn/i18n';
import { combineLatest, Observable } from 'rxjs';
import { map, take } from 'rxjs/operators';
import {
PluginInitializerContext,
Plugin,
CoreSetup,
CoreStart,
Logger,
Plugin,
PluginInitializerContext,
} from 'src/core/server';
import { Observable, combineLatest } from 'rxjs';
import { map, take } from 'rxjs/operators';
import { ObservabilityPluginSetup } from '../../observability/server';
import { SecurityPluginSetup } from '../../security/server';
import { UsageCollectionSetup } from '../../../../src/plugins/usage_collection/server';
import { TaskManagerSetupContract } from '../../task_manager/server';
import { AlertingPlugin } from '../../alerts/server';
import { ActionsPlugin } from '../../actions/server';
import { APMConfig, APMXPackConfig, mergeConfigs } from '.';
import { APMOSSPluginSetup } from '../../../../src/plugins/apm_oss/server';
import { createApmAgentConfigurationIndex } from './lib/settings/agent_configuration/create_agent_config_index';
import { createApmCustomLinkIndex } from './lib/settings/custom_link/create_custom_link_index';
import { createApmApi } from './routes/create_apm_api';
import { getApmIndices } from './lib/settings/apm_indices/get_apm_indices';
import { APMConfig, mergeConfigs, APMXPackConfig } from '.';
import { HomeServerPluginSetup } from '../../../../src/plugins/home/server';
import { UsageCollectionSetup } from '../../../../src/plugins/usage_collection/server';
import { ActionsPlugin } from '../../actions/server';
import { AlertingPlugin } from '../../alerts/server';
import { CloudSetup } from '../../cloud/server';
import { getInternalSavedObjectsClient } from './lib/helpers/get_internal_saved_objects_client';
import {
LicensingPluginSetup,
LicensingPluginStart,
} from '../../licensing/server';
import { registerApmAlerts } from './lib/alerts/register_apm_alerts';
import { createApmTelemetry } from './lib/apm_telemetry';

import { PluginSetupContract as FeaturesPluginSetup } from '../../features/server';
import { LicensingPluginSetup } from '../../licensing/server';
import { MlPluginSetup } from '../../ml/server';
import { ObservabilityPluginSetup } from '../../observability/server';
import { SecurityPluginSetup } from '../../security/server';
import { TaskManagerSetupContract } from '../../task_manager/server';
import {
APM_FEATURE,
APM_SERVICE_MAPS_FEATURE_NAME,
APM_SERVICE_MAPS_LICENSE_TYPE,
} from './feature';
import { registerApmAlerts } from './lib/alerts/register_apm_alerts';
import { createApmTelemetry } from './lib/apm_telemetry';
import { getInternalSavedObjectsClient } from './lib/helpers/get_internal_saved_objects_client';
import { createApmAgentConfigurationIndex } from './lib/settings/agent_configuration/create_agent_config_index';
import { getApmIndices } from './lib/settings/apm_indices/get_apm_indices';
import { createApmCustomLinkIndex } from './lib/settings/custom_link/create_custom_link_index';
import { createApmApi } from './routes/create_apm_api';
import { apmIndices, apmTelemetry } from './saved_objects';
import { createElasticCloudInstructions } from './tutorial/elastic_cloud';
import { MlPluginSetup } from '../../ml/server';

export interface APMPluginSetup {
config$: Observable<APMConfig>;
Expand Down Expand Up @@ -135,18 +131,14 @@ export class APMPlugin implements Plugin<APMPluginSetup> {
APM_SERVICE_MAPS_LICENSE_TYPE
);

core.getStartServices().then(([_coreStart, pluginsStart]) => {
createApmApi().init(core, {
config$: mergedConfig$,
logger: this.logger!,
plugins: {
licensing: (pluginsStart as { licensing: LicensingPluginStart })
.licensing,
observability: plugins.observability,
security: plugins.security,
ml: plugins.ml,
},
});
createApmApi().init(core, {
config$: mergedConfig$,
logger: this.logger!,
plugins: {
observability: plugins.observability,
security: plugins.security,
ml: plugins.ml,
},
});

return {
Expand Down
3 changes: 1 addition & 2 deletions x-pack/plugins/apm/server/routes/create_api/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { CoreSetup, Logger } from 'src/core/server';
import { Params } from '../typings';
import { BehaviorSubject } from 'rxjs';
import { APMConfig } from '../..';
import { LicensingPluginStart } from '../../../../licensing/server';

const getCoreMock = () => {
const get = jest.fn();
Expand Down Expand Up @@ -41,7 +40,7 @@ const getCoreMock = () => {
logger: ({
error: jest.fn(),
} as unknown) as Logger,
plugins: { licensing: {} as LicensingPluginStart },
plugins: {},
},
};
};
Expand Down
5 changes: 1 addition & 4 deletions x-pack/plugins/apm/server/routes/service_map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,7 @@ export const serviceMapRoute = createRoute(() => ({
if (!isValidPlatinumLicense(context.licensing.license)) {
throw Boom.forbidden(invalidLicenseMessage);
}

context.plugins.licensing.featureUsage.notifyUsage(
APM_SERVICE_MAPS_FEATURE_NAME
);
context.licensing.featureUsage.notifyUsage(APM_SERVICE_MAPS_FEATURE_NAME);

const setup = await setupRequest(context, request);
const {
Expand Down
3 changes: 0 additions & 3 deletions x-pack/plugins/apm/server/routes/typings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
import { PickByValue, Optional } from 'utility-types';
import { Observable } from 'rxjs';
import { Server } from 'hapi';
import { LicensingPluginStart } from '../../../licensing/server';
import { ObservabilityPluginSetup } from '../../../observability/server';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { FetchOptions } from '../../public/services/rest/callApi';
Expand Down Expand Up @@ -67,7 +66,6 @@ export type APMRequestHandlerContext<
config: APMConfig;
logger: Logger;
plugins: {
licensing: LicensingPluginStart;
observability?: ObservabilityPluginSetup;
security?: SecurityPluginSetup;
ml?: MlPluginSetup;
Expand Down Expand Up @@ -116,7 +114,6 @@ export interface ServerAPI<TRouteState extends RouteState> {
config$: Observable<APMConfig>;
logger: Logger;
plugins: {
licensing: LicensingPluginStart;
observability?: ObservabilityPluginSetup;
security?: SecurityPluginSetup;
ml?: MlPluginSetup;
Expand Down

0 comments on commit 820a08c

Please sign in to comment.