Skip to content

Commit 97521ea

Browse files
authored
[APM] Use licensing from context (#70118) (#70194)
* [APM] Use licensing from context We added the usage of `featureUsage.notifyUsage` from the licensing plugin in #69455. This required us to use `getStartServices to add `licensing` to `context.plugins`. In #69838 `featureUsage` was added to `context.licensing`, so we don't need to add it to `context.plugins`.
1 parent 4fc922b commit 97521ea

File tree

4 files changed

+30
-45
lines changed

4 files changed

+30
-45
lines changed

x-pack/plugins/apm/server/plugin.ts

Lines changed: 28 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4,46 +4,42 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66
import { i18n } from '@kbn/i18n';
7+
import { combineLatest, Observable } from 'rxjs';
8+
import { map, take } from 'rxjs/operators';
79
import {
8-
PluginInitializerContext,
9-
Plugin,
1010
CoreSetup,
1111
CoreStart,
1212
Logger,
13+
Plugin,
14+
PluginInitializerContext,
1315
} from 'src/core/server';
14-
import { Observable, combineLatest } from 'rxjs';
15-
import { map, take } from 'rxjs/operators';
16-
import { ObservabilityPluginSetup } from '../../observability/server';
17-
import { SecurityPluginSetup } from '../../security/server';
18-
import { UsageCollectionSetup } from '../../../../src/plugins/usage_collection/server';
19-
import { TaskManagerSetupContract } from '../../task_manager/server';
20-
import { AlertingPlugin } from '../../alerts/server';
21-
import { ActionsPlugin } from '../../actions/server';
16+
import { APMConfig, APMXPackConfig, mergeConfigs } from '.';
2217
import { APMOSSPluginSetup } from '../../../../src/plugins/apm_oss/server';
23-
import { createApmAgentConfigurationIndex } from './lib/settings/agent_configuration/create_agent_config_index';
24-
import { createApmCustomLinkIndex } from './lib/settings/custom_link/create_custom_link_index';
25-
import { createApmApi } from './routes/create_apm_api';
26-
import { getApmIndices } from './lib/settings/apm_indices/get_apm_indices';
27-
import { APMConfig, mergeConfigs, APMXPackConfig } from '.';
2818
import { HomeServerPluginSetup } from '../../../../src/plugins/home/server';
19+
import { UsageCollectionSetup } from '../../../../src/plugins/usage_collection/server';
20+
import { ActionsPlugin } from '../../actions/server';
21+
import { AlertingPlugin } from '../../alerts/server';
2922
import { CloudSetup } from '../../cloud/server';
30-
import { getInternalSavedObjectsClient } from './lib/helpers/get_internal_saved_objects_client';
31-
import {
32-
LicensingPluginSetup,
33-
LicensingPluginStart,
34-
} from '../../licensing/server';
35-
import { registerApmAlerts } from './lib/alerts/register_apm_alerts';
36-
import { createApmTelemetry } from './lib/apm_telemetry';
37-
3823
import { PluginSetupContract as FeaturesPluginSetup } from '../../features/server';
24+
import { LicensingPluginSetup } from '../../licensing/server';
25+
import { MlPluginSetup } from '../../ml/server';
26+
import { ObservabilityPluginSetup } from '../../observability/server';
27+
import { SecurityPluginSetup } from '../../security/server';
28+
import { TaskManagerSetupContract } from '../../task_manager/server';
3929
import {
4030
APM_FEATURE,
4131
APM_SERVICE_MAPS_FEATURE_NAME,
4232
APM_SERVICE_MAPS_LICENSE_TYPE,
4333
} from './feature';
34+
import { registerApmAlerts } from './lib/alerts/register_apm_alerts';
35+
import { createApmTelemetry } from './lib/apm_telemetry';
36+
import { getInternalSavedObjectsClient } from './lib/helpers/get_internal_saved_objects_client';
37+
import { createApmAgentConfigurationIndex } from './lib/settings/agent_configuration/create_agent_config_index';
38+
import { getApmIndices } from './lib/settings/apm_indices/get_apm_indices';
39+
import { createApmCustomLinkIndex } from './lib/settings/custom_link/create_custom_link_index';
40+
import { createApmApi } from './routes/create_apm_api';
4441
import { apmIndices, apmTelemetry } from './saved_objects';
4542
import { createElasticCloudInstructions } from './tutorial/elastic_cloud';
46-
import { MlPluginSetup } from '../../ml/server';
4743

4844
export interface APMPluginSetup {
4945
config$: Observable<APMConfig>;
@@ -135,18 +131,14 @@ export class APMPlugin implements Plugin<APMPluginSetup> {
135131
APM_SERVICE_MAPS_LICENSE_TYPE
136132
);
137133

138-
core.getStartServices().then(([_coreStart, pluginsStart]) => {
139-
createApmApi().init(core, {
140-
config$: mergedConfig$,
141-
logger: this.logger!,
142-
plugins: {
143-
licensing: (pluginsStart as { licensing: LicensingPluginStart })
144-
.licensing,
145-
observability: plugins.observability,
146-
security: plugins.security,
147-
ml: plugins.ml,
148-
},
149-
});
134+
createApmApi().init(core, {
135+
config$: mergedConfig$,
136+
logger: this.logger!,
137+
plugins: {
138+
observability: plugins.observability,
139+
security: plugins.security,
140+
ml: plugins.ml,
141+
},
150142
});
151143

152144
return {

x-pack/plugins/apm/server/routes/create_api/index.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import { CoreSetup, Logger } from 'src/core/server';
99
import { Params } from '../typings';
1010
import { BehaviorSubject } from 'rxjs';
1111
import { APMConfig } from '../..';
12-
import { LicensingPluginStart } from '../../../../licensing/server';
1312

1413
const getCoreMock = () => {
1514
const get = jest.fn();
@@ -41,7 +40,7 @@ const getCoreMock = () => {
4140
logger: ({
4241
error: jest.fn(),
4342
} as unknown) as Logger,
44-
plugins: { licensing: {} as LicensingPluginStart },
43+
plugins: {},
4544
},
4645
};
4746
};

x-pack/plugins/apm/server/routes/service_map.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,7 @@ export const serviceMapRoute = createRoute(() => ({
3535
if (!isValidPlatinumLicense(context.licensing.license)) {
3636
throw Boom.forbidden(invalidLicenseMessage);
3737
}
38-
39-
context.plugins.licensing.featureUsage.notifyUsage(
40-
APM_SERVICE_MAPS_FEATURE_NAME
41-
);
38+
context.licensing.featureUsage.notifyUsage(APM_SERVICE_MAPS_FEATURE_NAME);
4239

4340
const setup = await setupRequest(context, request);
4441
const {

x-pack/plugins/apm/server/routes/typings.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import {
1414
import { PickByValue, Optional } from 'utility-types';
1515
import { Observable } from 'rxjs';
1616
import { Server } from 'hapi';
17-
import { LicensingPluginStart } from '../../../licensing/server';
1817
import { ObservabilityPluginSetup } from '../../../observability/server';
1918
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
2019
import { FetchOptions } from '../../public/services/rest/callApi';
@@ -67,7 +66,6 @@ export type APMRequestHandlerContext<
6766
config: APMConfig;
6867
logger: Logger;
6968
plugins: {
70-
licensing: LicensingPluginStart;
7169
observability?: ObservabilityPluginSetup;
7270
security?: SecurityPluginSetup;
7371
ml?: MlPluginSetup;
@@ -116,7 +114,6 @@ export interface ServerAPI<TRouteState extends RouteState> {
116114
config$: Observable<APMConfig>;
117115
logger: Logger;
118116
plugins: {
119-
licensing: LicensingPluginStart;
120117
observability?: ObservabilityPluginSetup;
121118
security?: SecurityPluginSetup;
122119
ml?: MlPluginSetup;

0 commit comments

Comments
 (0)