From 922edc5e982d1387899d90775c05814d94001dd6 Mon Sep 17 00:00:00 2001 From: Carlos Crespo Date: Wed, 11 Dec 2024 12:55:16 +0100 Subject: [PATCH] Replace security plugin authc with Kibana core --- .../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 031904320bf99..57b385d68f8b7 100644 --- a/x-pack/platform/plugins/private/translations/translations/fr-FR.json +++ b/x-pack/platform/plugins/private/translations/translations/fr-FR.json @@ -10700,7 +10700,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", @@ -49761,4 +49760,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 90eeb4cc57b12..62ebb2e26b8f2 100644 --- a/x-pack/platform/plugins/private/translations/translations/ja-JP.json +++ b/x-pack/platform/plugins/private/translations/translations/ja-JP.json @@ -10570,7 +10570,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": "セキュリティプラグインが必要です", @@ -49610,4 +49609,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 a4a6f117857e1..6532e3737dbe6 100644 --- a/x-pack/platform/plugins/private/translations/translations/zh-CN.json +++ b/x-pack/platform/plugins/private/translations/translations/zh-CN.json @@ -10385,7 +10385,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 插件", @@ -48877,4 +48876,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 6f0fcc7dceb3c..d560b25dd5f10 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 d8c2cd70768c4..5defc5ca9027f 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'; @@ -34,19 +32,12 @@ const agentKeysPrivilegesRoute = createApmServerRoute({ options: { tags: ['access: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; @@ -60,23 +51,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({ @@ -118,7 +101,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 5fc89e00fcc8b..7c6572169b037 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({ tags: ['access: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 4459a127ea13e..39b62b0f4f610 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 @@ -51,14 +51,12 @@ const topDependenciesRoute = createApmServerRoute({ tags: ['access: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; @@ -93,14 +91,12 @@ const upstreamServicesForDependencyRoute = createApmServerRoute({ tags: ['access: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 05b74b3fc9c42..c44d283a5a3d5 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 @@ -141,19 +141,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 da2a506e3ae3f..eb6005dc2c1a8 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 @@ -106,13 +106,7 @@ const servicesRoute = createApmServerRoute({ }), options: { tags: ['access:apm'] }, async handler(resources): Promise { - const { - context, - params, - logger, - request, - plugins: { security }, - } = resources; + const { context, params, logger, request, core } = resources; const { searchQuery, @@ -128,6 +122,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), @@ -136,7 +131,7 @@ const servicesRoute = createApmServerRoute({ serviceGroupId ? getServiceGroup({ savedObjectsClient, serviceGroupId }) : Promise.resolve(null), - getRandomSampler({ security, request, probability }), + getRandomSampler({ coreStart, request, probability }), ]); return getServicesItems({ @@ -174,11 +169,7 @@ const servicesDetailedStatisticsRoute = createApmServerRoute({ }), options: { tags: ['access:apm'] }, handler: async (resources): Promise => { - const { - params, - request, - plugins: { security }, - } = resources; + const { params, request, core } = resources; const { environment, @@ -194,9 +185,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) { @@ -784,15 +776,12 @@ export const serviceDependenciesRoute = createApmServerRoute({ tags: ['access: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 6592e86297046..d2255fdd13835 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 0814bcdc5738f..018cc1acc10fb 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({ }), options: { tags: ['access: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({