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

[APM] License feature tracking for service maps #69455

Merged
merged 1 commit into from
Jun 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
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 })
Copy link
Contributor

Choose a reason for hiding this comment

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

it would be nice if we could have a mapped type for plugin setup and start contractions.

.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