Skip to content
/ kibana Public
forked from elastic/kibana

Commit

Permalink
[APM] License feature tracking for service maps (elastic#69455)
Browse files Browse the repository at this point in the history
Use the license feature API to register the service maps feature and track its usage when the API endpoint is accessed.

Fixes elastic#64850.
  • Loading branch information
smith committed Jun 18, 2020
1 parent ffae603 commit 3855239
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 13 deletions.
3 changes: 3 additions & 0 deletions x-pack/plugins/apm/server/feature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,6 @@ export const APM_FEATURE = {
},
},
};

export const APM_SERVICE_MAPS_FEATURE_NAME = 'APM service maps';
export const APM_SERVICE_MAPS_LICENSE_TYPE = 'platinum';
39 changes: 28 additions & 11 deletions x-pack/plugins/apm/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
import { Observable, combineLatest } from 'rxjs';
import { map, take } from 'rxjs/operators';
import { ObservabilityPluginSetup } from '../../observability/server';
import { SecurityPluginSetup } from '../../security/public';
import { SecurityPluginSetup } from '../../security/server';
import { UsageCollectionSetup } from '../../../../src/plugins/usage_collection/server';
import { TaskManagerSetupContract } from '../../task_manager/server';
import { AlertingPlugin } from '../../alerts/server';
Expand All @@ -28,11 +28,19 @@ import { APMConfig, mergeConfigs, APMXPackConfig } from '.';
import { HomeServerPluginSetup } from '../../../../src/plugins/home/server';
import { CloudSetup } from '../../cloud/server';
import { getInternalSavedObjectsClient } from './lib/helpers/get_internal_saved_objects_client';
import { LicensingPluginSetup } from '../../licensing/public';
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 { APM_FEATURE } from './feature';
import {
APM_FEATURE,
APM_SERVICE_MAPS_FEATURE_NAME,
APM_SERVICE_MAPS_LICENSE_TYPE,
} from './feature';
import { apmIndices, apmTelemetry } from './saved_objects';
import { createElasticCloudInstructions } from './tutorial/elastic_cloud';
import { MlPluginSetup } from '../../ml/server';
Expand Down Expand Up @@ -120,16 +128,25 @@ export class APMPlugin implements Plugin<APMPluginSetup> {
elasticCloud: createElasticCloudInstructions(plugins.cloud),
};
});

plugins.features.registerFeature(APM_FEATURE);
plugins.licensing.featureUsage.register(
APM_SERVICE_MAPS_FEATURE_NAME,
APM_SERVICE_MAPS_LICENSE_TYPE
);

createApmApi().init(core, {
config$: mergedConfig$,
logger: this.logger!,
plugins: {
observability: plugins.observability,
security: plugins.security,
ml: plugins.ml,
},
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,
},
});
});

return {
Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugins/apm/server/routes/create_api/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ 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 @@ -40,7 +41,7 @@ const getCoreMock = () => {
logger: ({
error: jest.fn(),
} as unknown) as Logger,
plugins: {},
plugins: { licensing: {} as LicensingPluginStart },
},
};
};
Expand Down
5 changes: 5 additions & 0 deletions x-pack/plugins/apm/server/routes/service_map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { getServiceMap } from '../lib/service_map/get_service_map';
import { getServiceMapServiceNodeInfo } from '../lib/service_map/get_service_map_service_node_info';
import { createRoute } from './create_route';
import { rangeRt } from './default_api_types';
import { APM_SERVICE_MAPS_FEATURE_NAME } from '../feature';

export const serviceMapRoute = createRoute(() => ({
path: '/api/apm/service-map',
Expand All @@ -35,6 +36,10 @@ export const serviceMapRoute = createRoute(() => ({
throw Boom.forbidden(invalidLicenseMessage);
}

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

const setup = await setupRequest(context, request);
const {
query: { serviceName, environment },
Expand Down
5 changes: 4 additions & 1 deletion x-pack/plugins/apm/server/routes/typings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ 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';
import { SecurityPluginSetup } from '../../../security/public';
import { SecurityPluginSetup } from '../../../security/server';
import { MlPluginSetup } from '../../../ml/server';
import { APMConfig } from '..';

Expand Down Expand Up @@ -66,6 +67,7 @@ export type APMRequestHandlerContext<
config: APMConfig;
logger: Logger;
plugins: {
licensing: LicensingPluginStart;
observability?: ObservabilityPluginSetup;
security?: SecurityPluginSetup;
ml?: MlPluginSetup;
Expand Down Expand Up @@ -114,6 +116,7 @@ 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 3855239

Please sign in to comment.