From 91e99955f983b19e026d3aa16d5986198a867b7a Mon Sep 17 00:00:00 2001 From: Carlos Crespo Date: Thu, 19 Dec 2024 10:16:43 +0100 Subject: [PATCH] [APM] Replace security plugin authc with Kibana core (#203771) closes [#200700](https://github.com/elastic/kibana/issues/200700) ## Summary Replaces `authc` from `security` plugin with `core`'s as per https://docs.elastic.dev/kibana-dev-docs/api-meta/deprecated-api-list-by-plugin#apm Co-authored-by: Elastic Machine --- .../translations/translations/fr-FR.json | 3 +- .../translations/translations/ja-JP.json | 3 +- .../translations/translations/zh-CN.json | 3 +- .../get_apm_services_list.ts | 5 ++- .../apm/server/assistant_functions/index.ts | 8 ++-- .../lib/helpers/get_random_sampler/index.ts | 16 +++---- .../apm/server/plugin.ts | 2 +- .../apm/server/routes/agent_explorer/route.ts | 10 ++--- .../agent_keys/get_agent_keys_privileges.ts | 8 ++-- .../apm/server/routes/agent_keys/route.ts | 33 +++----------- .../index.ts | 6 ++- .../routes/assistant_functions/route.ts | 9 ++-- .../apm/server/routes/dependencies/route.ts | 16 +++---- .../apm/server/routes/fleet/is_superuser.ts | 9 ++-- .../apm/server/routes/fleet/route.ts | 16 +++---- .../routes/fleet/run_migration_check.ts | 8 +--- .../apm/server/routes/services/route.ts | 38 ++++++---------- .../server/routes/storage_explorer/route.ts | 43 ++++++------------- .../apm/server/routes/traces/route.ts | 10 ++--- 19 files changed, 83 insertions(+), 163 deletions(-) diff --git a/x-pack/platform/plugins/private/translations/translations/fr-FR.json b/x-pack/platform/plugins/private/translations/translations/fr-FR.json index 16a3d2d2071c4..98ea70111ef56 100644 --- a/x-pack/platform/plugins/private/translations/translations/fr-FR.json +++ b/x-pack/platform/plugins/private/translations/translations/fr-FR.json @@ -10631,7 +10631,6 @@ "xpack.apm.anomalyRuleType.anomalyDetector": "Types de détecteurs", "xpack.apm.anomalyRuleType.anomalyDetector.infoLabel": "Vous devez sélectionner au moins un détecteur", "xpack.apm.anomalyScore": "Anomalie {severity, select, minor {mineure} major {majeure} critical {critique} other {de sévérité inconnue}}", - "xpack.apm.api.apiKeys.securityRequired": "Le plug-in de sécurité est requis", "xpack.apm.api.fleet.cloud_apm_package_policy.requiredRoleOnCloud": "Opération autorisée uniquement pour les utilisateurs Elastic Cloud disposant du rôle de superutilisateur.", "xpack.apm.api.fleet.fleetSecurityRequired": "Les plug-ins Fleet et Security sont requis", "xpack.apm.api.storageExplorer.securityRequired": "Le plug-in de sécurité est requis", @@ -49608,4 +49607,4 @@ "xpack.watcher.watchEdit.thresholdWatchExpression.aggType.fieldIsRequiredValidationMessage": "Ce champ est requis.", "xpack.watcher.watcherDescription": "Détectez les modifications survenant dans vos données en créant, gérant et monitorant des alertes." } -} +} \ No newline at end of file diff --git a/x-pack/platform/plugins/private/translations/translations/ja-JP.json b/x-pack/platform/plugins/private/translations/translations/ja-JP.json index 80eaefdc765a9..06802ee2be796 100644 --- a/x-pack/platform/plugins/private/translations/translations/ja-JP.json +++ b/x-pack/platform/plugins/private/translations/translations/ja-JP.json @@ -10501,7 +10501,6 @@ "xpack.apm.anomalyRuleType.anomalyDetector": "検知器タイプ", "xpack.apm.anomalyRuleType.anomalyDetector.infoLabel": "検知器を最低1つ選択する必要があります", "xpack.apm.anomalyScore": "{severity, select, minor {軽微な} major {重要な} critical {重大な} other {不明な重要度の}}異常", - "xpack.apm.api.apiKeys.securityRequired": "セキュリティプラグインが必要です", "xpack.apm.api.fleet.cloud_apm_package_policy.requiredRoleOnCloud": "スーパーユーザーロールが付与されたElastic Cloudユーザーのみが操作できます。", "xpack.apm.api.fleet.fleetSecurityRequired": "FleetおよびSecurityプラグインが必要です", "xpack.apm.api.storageExplorer.securityRequired": "セキュリティプラグインが必要です", @@ -49457,4 +49456,4 @@ "xpack.watcher.watchEdit.thresholdWatchExpression.aggType.fieldIsRequiredValidationMessage": "フィールドを選択してください。", "xpack.watcher.watcherDescription": "アラートの作成、管理、監視によりデータへの変更を検知します。" } -} +} \ No newline at end of file diff --git a/x-pack/platform/plugins/private/translations/translations/zh-CN.json b/x-pack/platform/plugins/private/translations/translations/zh-CN.json index b76799b380d54..de40b51eca65e 100644 --- a/x-pack/platform/plugins/private/translations/translations/zh-CN.json +++ b/x-pack/platform/plugins/private/translations/translations/zh-CN.json @@ -10319,7 +10319,6 @@ "xpack.apm.anomalyRuleType.anomalyDetector": "检测工具类型", "xpack.apm.anomalyRuleType.anomalyDetector.infoLabel": "应至少选择一个检测工具", "xpack.apm.anomalyScore": "{severity, select, minor {轻微} major {重大} critical {严重} other {严重性未知}}异常", - "xpack.apm.api.apiKeys.securityRequired": "需要 Security 插件", "xpack.apm.api.fleet.cloud_apm_package_policy.requiredRoleOnCloud": "操作仅允许具有超级用户角色的 Elastic Cloud 用户执行。", "xpack.apm.api.fleet.fleetSecurityRequired": "需要 Fleet 和 Security 插件", "xpack.apm.api.storageExplorer.securityRequired": "需要 Security 插件", @@ -48728,4 +48727,4 @@ "xpack.watcher.watchEdit.thresholdWatchExpression.aggType.fieldIsRequiredValidationMessage": "此字段必填。", "xpack.watcher.watcherDescription": "通过创建、管理和监测警报来检测数据中的更改。" } -} +} \ No newline at end of file diff --git a/x-pack/plugins/observability_solution/apm/server/assistant_functions/get_apm_services_list.ts b/x-pack/plugins/observability_solution/apm/server/assistant_functions/get_apm_services_list.ts index b24c24425b413..20faf469a112e 100644 --- a/x-pack/plugins/observability_solution/apm/server/assistant_functions/get_apm_services_list.ts +++ b/x-pack/plugins/observability_solution/apm/server/assistant_functions/get_apm_services_list.ts @@ -63,12 +63,13 @@ export function registerGetApmServicesListFunction({ } as const, }, async ({ arguments: args }, signal) => { - const { logger } = resources; + const { logger, core } = resources; + const coreStart = await core.start(); const [apmAlertsClient, mlClient, randomSampler] = await Promise.all([ getApmAlertsClient(resources), getMlClient(resources), getRandomSampler({ - security: resources.plugins.security, + coreStart, probability: 1, request: resources.request, }), diff --git a/x-pack/plugins/observability_solution/apm/server/assistant_functions/index.ts b/x-pack/plugins/observability_solution/apm/server/assistant_functions/index.ts index 6a65e6126ff22..2354d85d5f958 100644 --- a/x-pack/plugins/observability_solution/apm/server/assistant_functions/index.ts +++ b/x-pack/plugins/observability_solution/apm/server/assistant_functions/index.ts @@ -80,14 +80,12 @@ export function registerAssistantFunctions({ }, }; - const { - request, - plugins: { security }, - } = apmRouteHandlerResources; + const { request, core } = apmRouteHandlerResources; + const coreStart = await core.start(); const [apmEventClient, randomSampler] = await Promise.all([ getApmEventClient(apmRouteHandlerResources), - getRandomSampler({ security, request, probability: 1 }), + getRandomSampler({ coreStart, request, probability: 1 }), ]); const hasData = await hasHistoricalAgentData(apmEventClient); diff --git a/x-pack/plugins/observability_solution/apm/server/lib/helpers/get_random_sampler/index.ts b/x-pack/plugins/observability_solution/apm/server/lib/helpers/get_random_sampler/index.ts index 5aadfde90045b..d00dbfbb55589 100644 --- a/x-pack/plugins/observability_solution/apm/server/lib/helpers/get_random_sampler/index.ts +++ b/x-pack/plugins/observability_solution/apm/server/lib/helpers/get_random_sampler/index.ts @@ -5,30 +5,26 @@ * 2.0. */ -import { KibanaRequest } from '@kbn/core/server'; +import { CoreStart, KibanaRequest } from '@kbn/core/server'; import seedrandom from 'seedrandom'; -import { APMRouteHandlerResources } from '../../../routes/apm_routes/register_apm_server_routes'; export type RandomSampler = Awaited>; export async function getRandomSampler({ - security, + coreStart, request, probability, }: { - security: APMRouteHandlerResources['plugins']['security']; + coreStart: CoreStart; request: KibanaRequest; probability: number; }) { let seed = 1; - if (security) { - const securityPluginStart = await security.start(); - const username = securityPluginStart.authc.getCurrentUser(request)?.username; + const username = coreStart.security.authc.getCurrentUser(request)?.username; - if (username) { - seed = Math.abs(seedrandom(username).int32()); - } + if (username) { + seed = Math.abs(seedrandom(username).int32()); } return { diff --git a/x-pack/plugins/observability_solution/apm/server/plugin.ts b/x-pack/plugins/observability_solution/apm/server/plugin.ts index 1142a5c69a51f..90a0cb175d6cb 100644 --- a/x-pack/plugins/observability_solution/apm/server/plugin.ts +++ b/x-pack/plugins/observability_solution/apm/server/plugin.ts @@ -224,7 +224,7 @@ export class APMPlugin ); plugins.observability.alertDetailsContextualInsightsService.registerHandler( - getAlertDetailsContextHandler(resourcePlugins, logger) + getAlertDetailsContextHandler(getCoreStart(), resourcePlugins, logger) ); registerDeprecations({ diff --git a/x-pack/plugins/observability_solution/apm/server/routes/agent_explorer/route.ts b/x-pack/plugins/observability_solution/apm/server/routes/agent_explorer/route.ts index 4f93304365744..870d6a3de11f2 100644 --- a/x-pack/plugins/observability_solution/apm/server/routes/agent_explorer/route.ts +++ b/x-pack/plugins/observability_solution/apm/server/routes/agent_explorer/route.ts @@ -33,18 +33,16 @@ const agentExplorerRoute = createApmServerRoute({ ]), }), async handler(resources): Promise { - const { - params, - request, - plugins: { security }, - } = resources; + const { params, request, core } = resources; const { environment, kuery, start, end, probability, serviceName, agentLanguage } = params.query; + const coreStart = await core.start(); + const [apmEventClient, randomSampler] = await Promise.all([ getApmEventClient(resources), - getRandomSampler({ security, request, probability }), + getRandomSampler({ coreStart, request, probability }), ]); return getAgents({ diff --git a/x-pack/plugins/observability_solution/apm/server/routes/agent_keys/get_agent_keys_privileges.ts b/x-pack/plugins/observability_solution/apm/server/routes/agent_keys/get_agent_keys_privileges.ts index b87efdafd302d..5c9a9b833b3d6 100644 --- a/x-pack/plugins/observability_solution/apm/server/routes/agent_keys/get_agent_keys_privileges.ts +++ b/x-pack/plugins/observability_solution/apm/server/routes/agent_keys/get_agent_keys_privileges.ts @@ -5,8 +5,8 @@ * 2.0. */ +import { CoreStart } from '@kbn/core/server'; import { ApmPluginRequestHandlerContext } from '../typings'; -import { APMPluginStartDependencies } from '../../types'; export interface AgentKeysPrivilegesResponse { areApiKeysEnabled: boolean; @@ -16,10 +16,10 @@ export interface AgentKeysPrivilegesResponse { export async function getAgentKeysPrivileges({ context, - securityPluginStart, + coreStart, }: { context: ApmPluginRequestHandlerContext; - securityPluginStart: NonNullable; + coreStart: CoreStart; }): Promise { const esClient = (await context.core).elasticsearch.client; const [securityHasPrivilegesResponse, areApiKeysEnabled] = await Promise.all([ @@ -28,7 +28,7 @@ export async function getAgentKeysPrivileges({ cluster: ['manage_security', 'manage_api_key', 'manage_own_api_key'], }, }), - securityPluginStart.authc.apiKeys.areAPIKeysEnabled(), + coreStart.security.authc.apiKeys.areAPIKeysEnabled(), ]); const { diff --git a/x-pack/plugins/observability_solution/apm/server/routes/agent_keys/route.ts b/x-pack/plugins/observability_solution/apm/server/routes/agent_keys/route.ts index 11d1131241b30..77fe8d6f50182 100644 --- a/x-pack/plugins/observability_solution/apm/server/routes/agent_keys/route.ts +++ b/x-pack/plugins/observability_solution/apm/server/routes/agent_keys/route.ts @@ -5,8 +5,6 @@ * 2.0. */ -import Boom from '@hapi/boom'; -import { i18n } from '@kbn/i18n'; import * as t from 'io-ts'; import { createApmServerRoute } from '../apm_routes/create_apm_server_route'; import { AgentKeysResponse, getAgentKeys } from './get_agent_keys'; @@ -33,19 +31,12 @@ const agentKeysPrivilegesRoute = createApmServerRoute({ endpoint: 'GET /internal/apm/agent_keys/privileges', security: { authz: { requiredPrivileges: ['apm'] } }, handler: async (resources): Promise => { - const { - plugins: { security }, - context, - } = resources; + const { context, core } = resources; - if (!security) { - throw Boom.internal(SECURITY_REQUIRED_MESSAGE); - } - - const securityPluginStart = await security.start(); + const coreStart = await core.start(); const agentKeysPrivileges = await getAgentKeysPrivileges({ context, - securityPluginStart, + coreStart, }); return agentKeysPrivileges; @@ -63,23 +54,15 @@ const invalidateAgentKeyRoute = createApmServerRoute({ body: t.type({ id: t.string }), }), handler: async (resources): Promise => { - const { - context, - params, - plugins: { security }, - } = resources; + const { context, params, core } = resources; const { body: { id }, } = params; - if (!security) { - throw Boom.internal(SECURITY_REQUIRED_MESSAGE); - } - - const securityPluginStart = await security.start(); + const coreStart = await core.start(); const { isAdmin } = await getAgentKeysPrivileges({ context, - securityPluginStart, + coreStart, }); const invalidatedKeys = await invalidateAgentKey({ @@ -126,7 +109,3 @@ export const agentKeysRouteRepository = { ...invalidateAgentKeyRoute, ...createAgentKeyRoute, }; - -const SECURITY_REQUIRED_MESSAGE = i18n.translate('xpack.apm.api.apiKeys.securityRequired', { - defaultMessage: 'Security plugin is required', -}); diff --git a/x-pack/plugins/observability_solution/apm/server/routes/assistant_functions/get_observability_alert_details_context/index.ts b/x-pack/plugins/observability_solution/apm/server/routes/assistant_functions/get_observability_alert_details_context/index.ts index 84e51675233c9..16a292d5478bc 100644 --- a/x-pack/plugins/observability_solution/apm/server/routes/assistant_functions/get_observability_alert_details_context/index.ts +++ b/x-pack/plugins/observability_solution/apm/server/routes/assistant_functions/get_observability_alert_details_context/index.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { Logger } from '@kbn/core/server'; +import { CoreStart, Logger } from '@kbn/core/server'; import type { AlertDetailsContextualInsight, AlertDetailsContextualInsightsHandler, @@ -32,6 +32,7 @@ import { APMRouteHandlerResources } from '../../apm_routes/register_apm_server_r import { getApmErrors } from './get_apm_errors'; export const getAlertDetailsContextHandler = ( + coreStartPromise: Promise, resourcePlugins: APMRouteHandlerResources['plugins'], logger: Logger ): AlertDetailsContextualInsightsHandler => { @@ -64,6 +65,7 @@ export const getAlertDetailsContextHandler = ( }, }; + const coreStart = await coreStartPromise; const [ apmEventClient, annotationsClient, @@ -81,7 +83,7 @@ export const getAlertDetailsContextHandler = ( requestContext.core, getMlClient(resources), getRandomSampler({ - security: resourcePlugins.security, + coreStart, probability: 1, request: requestContext.request, }), diff --git a/x-pack/plugins/observability_solution/apm/server/routes/assistant_functions/route.ts b/x-pack/plugins/observability_solution/apm/server/routes/assistant_functions/route.ts index 70f22e5fe5dbc..22cd7e3575b80 100644 --- a/x-pack/plugins/observability_solution/apm/server/routes/assistant_functions/route.ts +++ b/x-pack/plugins/observability_solution/apm/server/routes/assistant_functions/route.ts @@ -55,15 +55,12 @@ const getDownstreamDependenciesRoute = createApmServerRoute({ }), security: { authz: { requiredPrivileges: ['apm'] } }, handler: async (resources): Promise<{ content: APMDownstreamDependency[] }> => { - const { - params, - request, - plugins: { security }, - } = resources; + const { params, request, core } = resources; + const coreStart = await core.start(); const [apmEventClient, randomSampler] = await Promise.all([ getApmEventClient(resources), - getRandomSampler({ security, request, probability: 1 }), + getRandomSampler({ coreStart, request, probability: 1 }), ]); const { query } = params; diff --git a/x-pack/plugins/observability_solution/apm/server/routes/dependencies/route.ts b/x-pack/plugins/observability_solution/apm/server/routes/dependencies/route.ts index 0ff845e067bd0..5a744759a865e 100644 --- a/x-pack/plugins/observability_solution/apm/server/routes/dependencies/route.ts +++ b/x-pack/plugins/observability_solution/apm/server/routes/dependencies/route.ts @@ -49,14 +49,12 @@ const topDependenciesRoute = createApmServerRoute({ ]), security: { authz: { requiredPrivileges: ['apm'] } }, handler: async (resources): Promise => { - const { - request, - plugins: { security }, - } = resources; + const { request, core } = resources; + const coreStart = await core.start(); const [apmEventClient, randomSampler] = await Promise.all([ getApmEventClient(resources), - getRandomSampler({ security, request, probability: 1 }), + getRandomSampler({ coreStart, request, probability: 1 }), ]); const { environment, offset, numBuckets, kuery, start, end } = resources.params.query; @@ -89,14 +87,12 @@ const upstreamServicesForDependencyRoute = createApmServerRoute({ ]), security: { authz: { requiredPrivileges: ['apm'] } }, handler: async (resources): Promise => { - const { - request, - plugins: { security }, - } = resources; + const { request, core } = resources; + const coreStart = await core.start(); const [apmEventClient, randomSampler] = await Promise.all([ getApmEventClient(resources), - getRandomSampler({ security, request, probability: 1 }), + getRandomSampler({ coreStart, request, probability: 1 }), ]); const { diff --git a/x-pack/plugins/observability_solution/apm/server/routes/fleet/is_superuser.ts b/x-pack/plugins/observability_solution/apm/server/routes/fleet/is_superuser.ts index e36c0fd93d210..97a6bd92a88de 100644 --- a/x-pack/plugins/observability_solution/apm/server/routes/fleet/is_superuser.ts +++ b/x-pack/plugins/observability_solution/apm/server/routes/fleet/is_superuser.ts @@ -5,16 +5,15 @@ * 2.0. */ -import { KibanaRequest } from '@kbn/core/server'; -import { APMPluginStartDependencies } from '../../types'; +import { CoreStart, KibanaRequest } from '@kbn/core/server'; export function isSuperuser({ - securityPluginStart, + coreStart, request, }: { - securityPluginStart: NonNullable; + coreStart: CoreStart; request: KibanaRequest; }) { - const user = securityPluginStart.authc.getCurrentUser(request); + const user = coreStart.security.authc.getCurrentUser(request); return user?.roles.includes('superuser'); } diff --git a/x-pack/plugins/observability_solution/apm/server/routes/fleet/route.ts b/x-pack/plugins/observability_solution/apm/server/routes/fleet/route.ts index fa98472228e7c..ab74a48887f6a 100644 --- a/x-pack/plugins/observability_solution/apm/server/routes/fleet/route.ts +++ b/x-pack/plugins/observability_solution/apm/server/routes/fleet/route.ts @@ -149,19 +149,17 @@ const createCloudApmPackagePolicyRoute = createApmServerRoute({ throw Boom.internal(FLEET_SECURITY_REQUIRED_MESSAGE); } - const [savedObjectsClient, coreStart, fleetPluginStart, securityPluginStart, apmIndices] = - await Promise.all([ - (await context.core).savedObjects.client, - resources.core.start(), - plugins.fleet.start(), - plugins.security.start(), - resources.getApmIndices(), - ]); + const [savedObjectsClient, coreStart, fleetPluginStart, apmIndices] = await Promise.all([ + (await context.core).savedObjects.client, + resources.core.start(), + plugins.fleet.start(), + resources.getApmIndices(), + ]); const esClient = coreStart.elasticsearch.client.asScoped(resources.request).asCurrentUser; const cloudPluginSetup = plugins.cloud?.setup; - const hasRequiredRole = isSuperuser({ securityPluginStart, request }); + const hasRequiredRole = isSuperuser({ coreStart, request }); if (!hasRequiredRole || !cloudApmMigrationEnabled) { throw Boom.forbidden(CLOUD_SUPERUSER_REQUIRED_MESSAGE); } diff --git a/x-pack/plugins/observability_solution/apm/server/routes/fleet/run_migration_check.ts b/x-pack/plugins/observability_solution/apm/server/routes/fleet/run_migration_check.ts index 458383dca4934..ff4487c0684d9 100644 --- a/x-pack/plugins/observability_solution/apm/server/routes/fleet/run_migration_check.ts +++ b/x-pack/plugins/observability_solution/apm/server/routes/fleet/run_migration_check.ts @@ -34,12 +34,9 @@ export async function runMigrationCheck({ const cloudApmMigrationEnabled = config.agent.migrations.enabled; const savedObjectsClient = (await context.core).savedObjects.client; - const [fleetPluginStart, securityPluginStart] = await Promise.all([ - plugins.fleet.start(), - plugins.security.start(), - ]); + const [fleetPluginStart, coreStart] = await Promise.all([plugins.fleet.start(), core.start()]); - const hasRequiredRole = isSuperuser({ securityPluginStart, request }); + const hasRequiredRole = isSuperuser({ coreStart, request }); if (!hasRequiredRole) { return { has_cloud_agent_policy: false, @@ -58,7 +55,6 @@ export async function runMigrationCheck({ }) : undefined; const apmPackagePolicy = getApmPackagePolicy(cloudAgentPolicy); - const coreStart = await core.start(); const latestApmPackage = await getLatestApmPackage({ fleetPluginStart, request, diff --git a/x-pack/plugins/observability_solution/apm/server/routes/services/route.ts b/x-pack/plugins/observability_solution/apm/server/routes/services/route.ts index 71d570d2708f7..664706b8489b1 100644 --- a/x-pack/plugins/observability_solution/apm/server/routes/services/route.ts +++ b/x-pack/plugins/observability_solution/apm/server/routes/services/route.ts @@ -105,13 +105,7 @@ const servicesRoute = createApmServerRoute({ }), security: { authz: { requiredPrivileges: ['apm'] } }, async handler(resources): Promise { - const { - context, - params, - logger, - request, - plugins: { security }, - } = resources; + const { context, params, logger, request, core } = resources; const { searchQuery, @@ -127,6 +121,7 @@ const servicesRoute = createApmServerRoute({ } = params.query; const savedObjectsClient = (await context.core).savedObjects.client; + const coreStart = await core.start(); const [mlClient, apmEventClient, apmAlertsClient, serviceGroup, randomSampler] = await Promise.all([ getMlClient(resources), @@ -135,7 +130,7 @@ const servicesRoute = createApmServerRoute({ serviceGroupId ? getServiceGroup({ savedObjectsClient, serviceGroupId }) : Promise.resolve(null), - getRandomSampler({ security, request, probability }), + getRandomSampler({ coreStart, request, probability }), ]); return getServicesItems({ @@ -173,11 +168,7 @@ const servicesDetailedStatisticsRoute = createApmServerRoute({ }), security: { authz: { requiredPrivileges: ['apm'] } }, handler: async (resources): Promise => { - const { - params, - request, - plugins: { security }, - } = resources; + const { params, request, core } = resources; const { environment, @@ -193,9 +184,10 @@ const servicesDetailedStatisticsRoute = createApmServerRoute({ const { serviceNames } = params.body; + const coreStart = await core.start(); const [apmEventClient, randomSampler] = await Promise.all([ getApmEventClient(resources), - getRandomSampler({ security, request, probability }), + getRandomSampler({ coreStart, request, probability }), ]); if (!serviceNames.length) { @@ -786,15 +778,12 @@ export const serviceDependenciesRoute = createApmServerRoute({ }), security: { authz: { requiredPrivileges: ['apm'] } }, async handler(resources): Promise<{ serviceDependencies: ServiceDependenciesResponse }> { - const { - params, - request, - plugins: { security }, - } = resources; + const { params, request, core } = resources; + const coreStart = await core.start(); const [apmEventClient, randomSampler] = await Promise.all([ getApmEventClient(resources), - getRandomSampler({ security, request, probability: 1 }), + getRandomSampler({ coreStart, request, probability: 1 }), ]); const { serviceName } = params.path; @@ -829,15 +818,12 @@ export const serviceDependenciesBreakdownRoute = createApmServerRoute({ ): Promise<{ breakdown: ServiceDependenciesBreakdownResponse; }> => { - const { - params, - request, - plugins: { security }, - } = resources; + const { params, request, core } = resources; + const coreStart = await core.start(); const [apmEventClient, randomSampler] = await Promise.all([ getApmEventClient(resources), - getRandomSampler({ security, request, probability: 1 }), + getRandomSampler({ coreStart, request, probability: 1 }), ]); const { serviceName } = params.path; diff --git a/x-pack/plugins/observability_solution/apm/server/routes/storage_explorer/route.ts b/x-pack/plugins/observability_solution/apm/server/routes/storage_explorer/route.ts index 75f1e5168ac87..dfaf5dd8185ce 100644 --- a/x-pack/plugins/observability_solution/apm/server/routes/storage_explorer/route.ts +++ b/x-pack/plugins/observability_solution/apm/server/routes/storage_explorer/route.ts @@ -43,21 +43,16 @@ const storageExplorerRoute = createApmServerRoute({ ): Promise<{ serviceStatistics: StorageExplorerServiceStatisticsResponse; }> => { - const { - config, - params, - context, - request, - plugins: { security }, - } = resources; + const { config, params, context, request, core } = resources; const { query: { indexLifecyclePhase, probability, environment, kuery, start, end }, } = params; + const coreStart = await core.start(); const [apmEventClient, randomSampler] = await Promise.all([ getApmEventClient(resources), - getRandomSampler({ security, request, probability }), + getRandomSampler({ coreStart, request, probability }), ]); const searchAggregatedTransactions = await getSearchTransactionsEvents({ @@ -94,21 +89,17 @@ const storageExplorerServiceDetailsRoute = createApmServerRoute({ query: t.intersection([indexLifecyclePhaseRt, probabilityRt, environmentRt, kueryRt, rangeRt]), }), handler: async (resources): Promise => { - const { - params, - context, - request, - plugins: { security }, - } = resources; + const { params, context, request, core } = resources; const { path: { serviceName }, query: { indexLifecyclePhase, probability, environment, kuery, start, end }, } = params; + const coreStart = await core.start(); const [apmEventClient, randomSampler] = await Promise.all([ getApmEventClient(resources), - getRandomSampler({ security, request, probability }), + getRandomSampler({ coreStart, request, probability }), ]); return getStorageDetails({ @@ -136,21 +127,16 @@ const storageChartRoute = createApmServerRoute({ ): Promise<{ storageTimeSeries: SizeTimeseriesResponse; }> => { - const { - config, - params, - context, - request, - plugins: { security }, - } = resources; + const { config, params, context, request, core } = resources; const { query: { indexLifecyclePhase, probability, environment, kuery, start, end }, } = params; + const coreStart = await core.start(); const [apmEventClient, randomSampler] = await Promise.all([ getApmEventClient(resources), - getRandomSampler({ security, request, probability }), + getRandomSampler({ coreStart, request, probability }), ]); const searchAggregatedTransactions = await getSearchTransactionsEvents({ @@ -206,21 +192,16 @@ const storageExplorerSummaryStatsRoute = createApmServerRoute({ query: t.intersection([indexLifecyclePhaseRt, probabilityRt, environmentRt, kueryRt, rangeRt]), }), handler: async (resources): Promise => { - const { - config, - params, - context, - request, - plugins: { security }, - } = resources; + const { config, params, context, request, core } = resources; const { query: { indexLifecyclePhase, probability, environment, kuery, start, end }, } = params; + const coreStart = await core.start(); const [apmEventClient, randomSampler] = await Promise.all([ getApmEventClient(resources), - getRandomSampler({ security, request, probability }), + getRandomSampler({ coreStart, request, probability }), ]); const searchAggregatedTransactions = await getSearchTransactionsEvents({ diff --git a/x-pack/plugins/observability_solution/apm/server/routes/traces/route.ts b/x-pack/plugins/observability_solution/apm/server/routes/traces/route.ts index 804562c038051..f1a5dfdb25160 100644 --- a/x-pack/plugins/observability_solution/apm/server/routes/traces/route.ts +++ b/x-pack/plugins/observability_solution/apm/server/routes/traces/route.ts @@ -37,18 +37,14 @@ const tracesRoute = createApmServerRoute({ }), security: { authz: { requiredPrivileges: ['apm'] } }, handler: async (resources): Promise => { - const { - config, - params, - request, - plugins: { security }, - } = resources; + const { config, params, request, core } = resources; const { environment, kuery, start, end, probability } = params.query; + const coreStart = await core.start(); const [apmEventClient, randomSampler] = await Promise.all([ getApmEventClient(resources), - getRandomSampler({ security, request, probability }), + getRandomSampler({ coreStart, request, probability }), ]); const searchAggregatedTransactions = await getSearchTransactionsEvents({