From e8832954d5152d329c9d642bd3aaf51e6fa4bb22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B8ren=20Louv-Jansen?= Date: Thu, 1 Aug 2019 14:18:57 +0200 Subject: [PATCH] Migrate remaining routes --- .../app/ServiceOverview/ServiceList/index.tsx | 2 +- .../Settings/AddSettings/AddSettingFlyout.tsx | 2 +- .../components/app/Settings/SettingsList.tsx | 4 +- .../waterfall_helpers/waterfall_helpers.ts | 2 +- .../components/shared/DatePicker/index.tsx | 42 ++++ .../{settings.ts => agent_configuration.ts} | 24 +- .../apm/public/services/rest/apm/services.ts | 22 +- .../apm/public/services/rest/apm/traces.ts | 13 +- .../public/services/rest/apm/ui_filters.ts | 6 +- .../apm/server/lib/helpers/setup_request.ts | 2 +- .../lib/services/get_service_agent_name.ts | 4 - .../services/get_service_transaction_types.ts | 4 - .../get_services/get_services_items.ts | 2 - .../server/lib/services/get_services/index.ts | 2 - .../create_configuration.ts | 6 +- ...ation.ts => delete_agent_configuration.ts} | 2 +- ...ons.ts => get_agent_configuration_list.ts} | 6 +- .../get_environments/index.ts | 5 - .../agent_configuration/get_service_names.ts | 4 - .../settings/agent_configuration/search.ts | 6 +- .../update_configuration.ts | 6 +- .../apm/server/lib/traces/get_trace.ts | 2 - .../lib/transactions/get_transaction/index.ts | 2 - .../server/lib/ui_filters/get_environments.ts | 4 - .../plugins/apm/server/new-platform/plugin.ts | 8 +- .../routes/__test__/routeFailures.test.ts | 4 +- .../agent_configuration_list_route.ts | 35 +++ .../agent_configuration_payload_validation.ts | 21 ++ .../create_agent_configuration_route.ts | 33 +++ .../delete_agent_configuration_route.ts | 30 +++ .../agent_configuration/environments_route.ts | 30 +++ .../server/routes/agent_configuration/init.ts | 39 ++++ .../search_agent_configurations_route.ts | 49 ++++ .../service_names_route.ts | 28 +++ .../update_agent_configuration_route.ts | 35 +++ .../plugins/apm/server/routes/services.ts | 73 ------ .../apm/server/routes/services/init.ts | 17 ++ .../services/service_agent_name_route.ts | 30 +++ .../routes/services/service_list_route.ts | 46 ++++ .../service_transaction_types_routes.ts | 29 +++ .../plugins/apm/server/routes/settings.ts | 216 ------------------ .../plugins/apm/server/routes/traces.ts | 48 ---- .../plugins/apm/server/routes/traces/init.ts | 19 ++ .../server/routes/traces/trace_list_route.ts | 28 +++ .../apm/server/routes/traces/trace_route.ts | 31 +++ .../plugins/apm/server/routes/ui_filters.ts | 34 --- .../routes/ui_filters/environments_route.ts | 34 +++ .../apm/server/routes/ui_filters/init.ts | 13 ++ 48 files changed, 640 insertions(+), 464 deletions(-) rename x-pack/legacy/plugins/apm/public/services/rest/apm/{settings.ts => agent_configuration.ts} (59%) rename x-pack/legacy/plugins/apm/server/lib/settings/agent_configuration/{delete_configuration.ts => delete_agent_configuration.ts} (92%) rename x-pack/legacy/plugins/apm/server/lib/settings/agent_configuration/{list_configurations.ts => get_agent_configuration_list.ts} (73%) create mode 100644 x-pack/legacy/plugins/apm/server/routes/agent_configuration/agent_configuration_list_route.ts create mode 100644 x-pack/legacy/plugins/apm/server/routes/agent_configuration/agent_configuration_payload_validation.ts create mode 100644 x-pack/legacy/plugins/apm/server/routes/agent_configuration/create_agent_configuration_route.ts create mode 100644 x-pack/legacy/plugins/apm/server/routes/agent_configuration/delete_agent_configuration_route.ts create mode 100644 x-pack/legacy/plugins/apm/server/routes/agent_configuration/environments_route.ts create mode 100644 x-pack/legacy/plugins/apm/server/routes/agent_configuration/init.ts create mode 100644 x-pack/legacy/plugins/apm/server/routes/agent_configuration/search_agent_configurations_route.ts create mode 100644 x-pack/legacy/plugins/apm/server/routes/agent_configuration/service_names_route.ts create mode 100644 x-pack/legacy/plugins/apm/server/routes/agent_configuration/update_agent_configuration_route.ts delete mode 100644 x-pack/legacy/plugins/apm/server/routes/services.ts create mode 100644 x-pack/legacy/plugins/apm/server/routes/services/init.ts create mode 100644 x-pack/legacy/plugins/apm/server/routes/services/service_agent_name_route.ts create mode 100644 x-pack/legacy/plugins/apm/server/routes/services/service_list_route.ts create mode 100644 x-pack/legacy/plugins/apm/server/routes/services/service_transaction_types_routes.ts delete mode 100644 x-pack/legacy/plugins/apm/server/routes/settings.ts delete mode 100644 x-pack/legacy/plugins/apm/server/routes/traces.ts create mode 100644 x-pack/legacy/plugins/apm/server/routes/traces/init.ts create mode 100644 x-pack/legacy/plugins/apm/server/routes/traces/trace_list_route.ts create mode 100644 x-pack/legacy/plugins/apm/server/routes/traces/trace_route.ts delete mode 100644 x-pack/legacy/plugins/apm/server/routes/ui_filters.ts create mode 100644 x-pack/legacy/plugins/apm/server/routes/ui_filters/environments_route.ts create mode 100644 x-pack/legacy/plugins/apm/server/routes/ui_filters/init.ts diff --git a/x-pack/legacy/plugins/apm/public/components/app/ServiceOverview/ServiceList/index.tsx b/x-pack/legacy/plugins/apm/public/components/app/ServiceOverview/ServiceList/index.tsx index 31e05379928ecb0..310038e64e2413b 100644 --- a/x-pack/legacy/plugins/apm/public/components/app/ServiceOverview/ServiceList/index.tsx +++ b/x-pack/legacy/plugins/apm/public/components/app/ServiceOverview/ServiceList/index.tsx @@ -8,8 +8,8 @@ import { EuiToolTip } from '@elastic/eui'; import { i18n } from '@kbn/i18n'; import React from 'react'; import styled from 'styled-components'; -import { ServiceListAPIResponse } from '../../../../../server/lib/services/get_services'; import { NOT_AVAILABLE_LABEL } from '../../../../../common/i18n'; +import { ServiceListAPIResponse } from '../../../../../server/routes/services/service_list_route'; import { fontSizes, truncate } from '../../../../style/variables'; import { asDecimal, asMillis } from '../../../../utils/formatters'; import { APMLink } from '../../../shared/Links/apm/APMLink'; diff --git a/x-pack/legacy/plugins/apm/public/components/app/Settings/AddSettings/AddSettingFlyout.tsx b/x-pack/legacy/plugins/apm/public/components/app/Settings/AddSettings/AddSettingFlyout.tsx index 1726c2233d40466..ae641558c470f98 100644 --- a/x-pack/legacy/plugins/apm/public/components/app/Settings/AddSettings/AddSettingFlyout.tsx +++ b/x-pack/legacy/plugins/apm/public/components/app/Settings/AddSettings/AddSettingFlyout.tsx @@ -31,7 +31,7 @@ import { deleteAgentConfiguration, updateAgentConfiguration, createAgentConfiguration -} from '../../../../services/rest/apm/settings'; +} from '../../../../services/rest/apm/agent_configuration'; import { ENVIRONMENT_NOT_DEFINED } from '../../../../../common/environment_filter_values'; interface Props { diff --git a/x-pack/legacy/plugins/apm/public/components/app/Settings/SettingsList.tsx b/x-pack/legacy/plugins/apm/public/components/app/Settings/SettingsList.tsx index aff6dcfeef37514..fee21439f4033de 100644 --- a/x-pack/legacy/plugins/apm/public/components/app/Settings/SettingsList.tsx +++ b/x-pack/legacy/plugins/apm/public/components/app/Settings/SettingsList.tsx @@ -22,13 +22,13 @@ import { EuiLink } from '@elastic/eui'; import { isEmpty } from 'lodash'; -import { loadAgentConfigurationList } from '../../../services/rest/apm/settings'; +import { loadAgentConfigurationList } from '../../../services/rest/apm/agent_configuration'; import { useFetcher } from '../../../hooks/useFetcher'; import { ITableColumn, ManagedTable } from '../../shared/ManagedTable'; -import { AgentConfigurationListAPIResponse } from '../../../../server/lib/settings/agent_configuration/list_configurations'; import { AddSettingsFlyout } from './AddSettings/AddSettingFlyout'; import { APMLink } from '../../shared/Links/apm/APMLink'; import { LoadingStatePrompt } from '../../shared/LoadingStatePrompt'; +import { AgentConfigurationListAPIResponse } from '../../../../server/routes/agent_configuration/agent_configuration_list_route'; export type Config = AgentConfigurationListAPIResponse[0]; diff --git a/x-pack/legacy/plugins/apm/public/components/app/TransactionDetails/Transaction/WaterfallContainer/Waterfall/waterfall_helpers/waterfall_helpers.ts b/x-pack/legacy/plugins/apm/public/components/app/TransactionDetails/Transaction/WaterfallContainer/Waterfall/waterfall_helpers/waterfall_helpers.ts index 80a8474c293052a..f63d6ab9539f433 100644 --- a/x-pack/legacy/plugins/apm/public/components/app/TransactionDetails/Transaction/WaterfallContainer/Waterfall/waterfall_helpers/waterfall_helpers.ts +++ b/x-pack/legacy/plugins/apm/public/components/app/TransactionDetails/Transaction/WaterfallContainer/Waterfall/waterfall_helpers/waterfall_helpers.ts @@ -16,10 +16,10 @@ import { zipObject } from 'lodash'; import { idx } from '@kbn/elastic-idx'; -import { TraceAPIResponse } from '../../../../../../../../server/lib/traces/get_trace'; import { StringMap } from '../../../../../../../../typings/common'; import { Span } from '../../../../../../../../typings/es_schemas/ui/Span'; import { Transaction } from '../../../../../../../../typings/es_schemas/ui/Transaction'; +import { TraceAPIResponse } from '../../../../../../../../server/routes/traces/trace_route'; interface IWaterfallIndex { [key: string]: IWaterfallItem; diff --git a/x-pack/legacy/plugins/apm/public/components/shared/DatePicker/index.tsx b/x-pack/legacy/plugins/apm/public/components/shared/DatePicker/index.tsx index 911e63c69734f1d..308a46b9db73502 100644 --- a/x-pack/legacy/plugins/apm/public/components/shared/DatePicker/index.tsx +++ b/x-pack/legacy/plugins/apm/public/components/shared/DatePicker/index.tsx @@ -48,6 +48,48 @@ export function DatePicker() { return ( ({ + return callApmApi({ pathname: `/api/apm/settings/agent-configuration/services` }); } @@ -23,7 +23,7 @@ export async function loadAgentConfigurationEnvironments({ }: { serviceName: string; }) { - return callApi({ + return callApmApi({ pathname: `/api/apm/settings/agent-configuration/services/${serviceName}/environments` }); } @@ -31,7 +31,7 @@ export async function loadAgentConfigurationEnvironments({ export async function createAgentConfiguration( configuration: AgentConfigurationIntake ) { - return callApi({ + return callApmApi({ pathname: `/api/apm/settings/agent-configuration/new`, method: 'POST', body: JSON.stringify(configuration) @@ -42,7 +42,7 @@ export async function updateAgentConfiguration( configurationId: string, configuration: AgentConfigurationIntake ) { - return callApi({ + return callApmApi({ pathname: `/api/apm/settings/agent-configuration/${configurationId}`, method: 'PUT', body: JSON.stringify(configuration) @@ -50,14 +50,14 @@ export async function updateAgentConfiguration( } export async function deleteAgentConfiguration(configId: string) { - return callApi({ + return callApmApi({ pathname: `/api/apm/settings/agent-configuration/${configId}`, method: 'DELETE' }); } export async function loadAgentConfigurationList() { - return callApi({ + return callApmApi({ pathname: `/api/apm/settings/agent-configuration` }); } diff --git a/x-pack/legacy/plugins/apm/public/services/rest/apm/services.ts b/x-pack/legacy/plugins/apm/public/services/rest/apm/services.ts index 045993d4fbeae67..ba4017a665a6c24 100644 --- a/x-pack/legacy/plugins/apm/public/services/rest/apm/services.ts +++ b/x-pack/legacy/plugins/apm/public/services/rest/apm/services.ts @@ -4,11 +4,11 @@ * you may not use this file except in compliance with the Elastic License. */ -import { ServiceAgentNameAPIResponse } from '../../../../server/lib/services/get_service_agent_name'; -import { ServiceListAPIResponse } from '../../../../server/lib/services/get_services'; -import { callApi } from '../callApi'; +import { callApmApi } from '../callApi'; import { UIFilters } from '../../../../typings/ui-filters'; -import { ServiceTransactionTypesAPIResponse } from '../../../../server/lib/services/get_service_transaction_types'; +import { serviceListRoute } from '../../../../server/routes/services/service_list_route'; +import { serviceAgentNameRoute } from '../../../../server/routes/services/service_agent_name_route'; +import { serviceTransactionTypesRoute } from '../../../../server/routes/services/service_transaction_types_routes'; export async function loadServiceList({ start, @@ -19,7 +19,7 @@ export async function loadServiceList({ end: string; uiFilters: UIFilters; }) { - return callApi({ + return callApmApi({ pathname: `/api/apm/services`, query: { start, @@ -38,11 +38,12 @@ export async function loadServiceAgentName({ start: string; end: string; }) { - const { agentName } = await callApi({ + const { agentName } = await callApmApi({ pathname: `/api/apm/services/${serviceName}/agent_name`, query: { start, - end + end, + uiFilters: undefined // TODO: should uiFilters be required like this? } }); @@ -58,13 +59,14 @@ export async function loadServiceTransactionTypes({ start: string; end: string; }) { - const { transactionTypes } = await callApi< - ServiceTransactionTypesAPIResponse + const { transactionTypes } = await callApmApi< + typeof serviceTransactionTypesRoute >({ pathname: `/api/apm/services/${serviceName}/transaction_types`, query: { start, - end + end, + uiFilters: undefined // TODO: should uiFilters be required like this? } }); return transactionTypes; diff --git a/x-pack/legacy/plugins/apm/public/services/rest/apm/traces.ts b/x-pack/legacy/plugins/apm/public/services/rest/apm/traces.ts index a1bccb9f4e9f783..889be2fa3abdeee 100644 --- a/x-pack/legacy/plugins/apm/public/services/rest/apm/traces.ts +++ b/x-pack/legacy/plugins/apm/public/services/rest/apm/traces.ts @@ -4,10 +4,10 @@ * you may not use this file except in compliance with the Elastic License. */ -import { TraceAPIResponse } from '../../../../server/lib/traces/get_trace'; -import { callApi } from '../callApi'; +import { callApmApi } from '../callApi'; import { UIFilters } from '../../../../typings/ui-filters'; -import { TransactionGroupListAPIResponse } from '../../../../server/routes/transaction_groups/transaction_group_list_route'; +import { traceListRoute } from '../../../../server/routes/traces/trace_list_route'; +import { traceRoute } from '../../../../server/routes/traces/trace_route'; export async function loadTrace({ traceId, @@ -18,11 +18,12 @@ export async function loadTrace({ start: string; end: string; }) { - return callApi({ + return callApmApi({ pathname: `/api/apm/traces/${traceId}`, query: { start, - end + end, + uiFilters: undefined // TODO: should uiFilters be required like this? } }); } @@ -36,7 +37,7 @@ export async function loadTraceList({ end: string; uiFilters: UIFilters; }) { - return callApi({ + return callApmApi({ pathname: '/api/apm/traces', query: { start, diff --git a/x-pack/legacy/plugins/apm/public/services/rest/apm/ui_filters.ts b/x-pack/legacy/plugins/apm/public/services/rest/apm/ui_filters.ts index c8c76292202e4c8..3afe30e5492da95 100644 --- a/x-pack/legacy/plugins/apm/public/services/rest/apm/ui_filters.ts +++ b/x-pack/legacy/plugins/apm/public/services/rest/apm/ui_filters.ts @@ -4,8 +4,8 @@ * you may not use this file except in compliance with the Elastic License. */ -import { EnvironmentUIFilterAPIResponse } from '../../../../server/lib/ui_filters/get_environments'; -import { callApi } from '../callApi'; +import { callApmApi } from '../callApi'; +import { environmentsRoute } from '../../../../server/routes/ui_filters/environments_route'; export async function loadEnvironmentsFilter({ serviceName, @@ -16,7 +16,7 @@ export async function loadEnvironmentsFilter({ start: string; end: string; }) { - return callApi({ + return callApmApi({ pathname: '/api/apm/ui_filters/environments', query: { start, diff --git a/x-pack/legacy/plugins/apm/server/lib/helpers/setup_request.ts b/x-pack/legacy/plugins/apm/server/lib/helpers/setup_request.ts index 715793e55e4e349..797997fc03b6a17 100644 --- a/x-pack/legacy/plugins/apm/server/lib/helpers/setup_request.ts +++ b/x-pack/legacy/plugins/apm/server/lib/helpers/setup_request.ts @@ -27,7 +27,7 @@ export type APMRequest | unknown> = { export interface DefaultQueryParams { start: string; end: string; - uiFilters: string; + uiFilters: string | undefined; } interface APMRequestQuery { diff --git a/x-pack/legacy/plugins/apm/server/lib/services/get_service_agent_name.ts b/x-pack/legacy/plugins/apm/server/lib/services/get_service_agent_name.ts index ebe0ba9827b5343..c9d434cfe283817 100644 --- a/x-pack/legacy/plugins/apm/server/lib/services/get_service_agent_name.ts +++ b/x-pack/legacy/plugins/apm/server/lib/services/get_service_agent_name.ts @@ -9,13 +9,9 @@ import { SERVICE_AGENT_NAME, SERVICE_NAME } from '../../../common/elasticsearch_fieldnames'; -import { PromiseReturnType } from '../../../typings/common'; import { rangeFilter } from '../helpers/range_filter'; import { Setup } from '../helpers/setup_request'; -export type ServiceAgentNameAPIResponse = PromiseReturnType< - typeof getServiceAgentName ->; export async function getServiceAgentName(serviceName: string, setup: Setup) { const { start, end, client, config } = setup; diff --git a/x-pack/legacy/plugins/apm/server/lib/services/get_service_transaction_types.ts b/x-pack/legacy/plugins/apm/server/lib/services/get_service_transaction_types.ts index c8053c57776db84..a1f035da9dc1ac7 100644 --- a/x-pack/legacy/plugins/apm/server/lib/services/get_service_transaction_types.ts +++ b/x-pack/legacy/plugins/apm/server/lib/services/get_service_transaction_types.ts @@ -9,13 +9,9 @@ import { SERVICE_NAME, TRANSACTION_TYPE } from '../../../common/elasticsearch_fieldnames'; -import { PromiseReturnType } from '../../../typings/common'; import { rangeFilter } from '../helpers/range_filter'; import { Setup } from '../helpers/setup_request'; -export type ServiceTransactionTypesAPIResponse = PromiseReturnType< - typeof getServiceTransactionTypes ->; export async function getServiceTransactionTypes( serviceName: string, setup: Setup diff --git a/x-pack/legacy/plugins/apm/server/lib/services/get_services/get_services_items.ts b/x-pack/legacy/plugins/apm/server/lib/services/get_services/get_services_items.ts index 75410b70e013921..bf2c6a713aac08f 100644 --- a/x-pack/legacy/plugins/apm/server/lib/services/get_services/get_services_items.ts +++ b/x-pack/legacy/plugins/apm/server/lib/services/get_services/get_services_items.ts @@ -12,11 +12,9 @@ import { SERVICE_NAME, TRANSACTION_DURATION } from '../../../../common/elasticsearch_fieldnames'; -import { PromiseReturnType } from '../../../../typings/common'; import { rangeFilter } from '../../helpers/range_filter'; import { Setup } from '../../helpers/setup_request'; -export type ServiceListAPIResponse = PromiseReturnType; export async function getServicesItems(setup: Setup) { const { start, end, uiFiltersES, client, config } = setup; diff --git a/x-pack/legacy/plugins/apm/server/lib/services/get_services/index.ts b/x-pack/legacy/plugins/apm/server/lib/services/get_services/index.ts index bd3437f6991c35c..0ef720e96287f15 100644 --- a/x-pack/legacy/plugins/apm/server/lib/services/get_services/index.ts +++ b/x-pack/legacy/plugins/apm/server/lib/services/get_services/index.ts @@ -5,13 +5,11 @@ */ import { isEmpty } from 'lodash'; -import { PromiseReturnType } from '../../../../typings/common'; import { Setup } from '../../helpers/setup_request'; import { getAgentStatus } from './get_agent_status'; import { getLegacyDataStatus } from './get_legacy_data_status'; import { getServicesItems } from './get_services_items'; -export type ServiceListAPIResponse = PromiseReturnType; export async function getServices(setup: Setup) { const items = await getServicesItems(setup); const hasLegacyData = await getLegacyDataStatus(setup); diff --git a/x-pack/legacy/plugins/apm/server/lib/settings/agent_configuration/create_configuration.ts b/x-pack/legacy/plugins/apm/server/lib/settings/agent_configuration/create_configuration.ts index 42d324dda82f25f..6d3cd9beb7870d6 100644 --- a/x-pack/legacy/plugins/apm/server/lib/settings/agent_configuration/create_configuration.ts +++ b/x-pack/legacy/plugins/apm/server/lib/settings/agent_configuration/create_configuration.ts @@ -5,13 +5,9 @@ */ import { Setup } from '../../helpers/setup_request'; -import { PromiseReturnType } from '../../../../typings/common'; import { AgentConfigurationIntake } from './configuration_types'; -export type CreateAgentConfigurationAPIResponse = PromiseReturnType< - typeof createConfiguration ->; -export async function createConfiguration({ +export async function createAgentConfiguration({ configuration, setup }: { diff --git a/x-pack/legacy/plugins/apm/server/lib/settings/agent_configuration/delete_configuration.ts b/x-pack/legacy/plugins/apm/server/lib/settings/agent_configuration/delete_agent_configuration.ts similarity index 92% rename from x-pack/legacy/plugins/apm/server/lib/settings/agent_configuration/delete_configuration.ts rename to x-pack/legacy/plugins/apm/server/lib/settings/agent_configuration/delete_agent_configuration.ts index 82b192125a5cffc..3f91578b4b3da65 100644 --- a/x-pack/legacy/plugins/apm/server/lib/settings/agent_configuration/delete_configuration.ts +++ b/x-pack/legacy/plugins/apm/server/lib/settings/agent_configuration/delete_agent_configuration.ts @@ -6,7 +6,7 @@ import { Setup } from '../../helpers/setup_request'; -export async function deleteConfiguration({ +export async function deleteAgentConfiguration({ configurationId, setup }: { diff --git a/x-pack/legacy/plugins/apm/server/lib/settings/agent_configuration/list_configurations.ts b/x-pack/legacy/plugins/apm/server/lib/settings/agent_configuration/get_agent_configuration_list.ts similarity index 73% rename from x-pack/legacy/plugins/apm/server/lib/settings/agent_configuration/list_configurations.ts rename to x-pack/legacy/plugins/apm/server/lib/settings/agent_configuration/get_agent_configuration_list.ts index 9edceb86dda8db6..92f7230d5cf8001 100644 --- a/x-pack/legacy/plugins/apm/server/lib/settings/agent_configuration/list_configurations.ts +++ b/x-pack/legacy/plugins/apm/server/lib/settings/agent_configuration/get_agent_configuration_list.ts @@ -4,14 +4,10 @@ * you may not use this file except in compliance with the Elastic License. */ -import { PromiseReturnType } from '../../../../typings/common'; import { Setup } from '../../helpers/setup_request'; import { AgentConfiguration } from './configuration_types'; -export type AgentConfigurationListAPIResponse = PromiseReturnType< - typeof listConfigurations ->; -export async function listConfigurations({ setup }: { setup: Setup }) { +export async function getAgentConfigurationList({ setup }: { setup: Setup }) { const { client, config } = setup; const params = { diff --git a/x-pack/legacy/plugins/apm/server/lib/settings/agent_configuration/get_environments/index.ts b/x-pack/legacy/plugins/apm/server/lib/settings/agent_configuration/get_environments/index.ts index e4f986ed4184ced..39e8a7de3ce9595 100644 --- a/x-pack/legacy/plugins/apm/server/lib/settings/agent_configuration/get_environments/index.ts +++ b/x-pack/legacy/plugins/apm/server/lib/settings/agent_configuration/get_environments/index.ts @@ -6,13 +6,8 @@ import { getAllEnvironments } from './get_all_environments'; import { Setup } from '../../../helpers/setup_request'; -import { PromiseReturnType } from '../../../../../typings/common'; import { getUnavailableEnvironments } from './get_unavailable_environments'; -export type AgentConfigurationEnvironmentsAPIResponse = PromiseReturnType< - typeof getEnvironments ->; - export async function getEnvironments({ serviceName, setup diff --git a/x-pack/legacy/plugins/apm/server/lib/settings/agent_configuration/get_service_names.ts b/x-pack/legacy/plugins/apm/server/lib/settings/agent_configuration/get_service_names.ts index 3c8db74890d05b6..3e15123fdc21e62 100644 --- a/x-pack/legacy/plugins/apm/server/lib/settings/agent_configuration/get_service_names.ts +++ b/x-pack/legacy/plugins/apm/server/lib/settings/agent_configuration/get_service_names.ts @@ -5,15 +5,11 @@ */ import { Setup } from '../../helpers/setup_request'; -import { PromiseReturnType } from '../../../../typings/common'; import { PROCESSOR_EVENT, SERVICE_NAME } from '../../../../common/elasticsearch_fieldnames'; -export type AgentConfigurationServicesAPIResponse = PromiseReturnType< - typeof getServiceNames ->; export async function getServiceNames({ setup }: { setup: Setup }) { const { client, config } = setup; diff --git a/x-pack/legacy/plugins/apm/server/lib/settings/agent_configuration/search.ts b/x-pack/legacy/plugins/apm/server/lib/settings/agent_configuration/search.ts index 0cf6987112b0f2a..b08c568cf598869 100644 --- a/x-pack/legacy/plugins/apm/server/lib/settings/agent_configuration/search.ts +++ b/x-pack/legacy/plugins/apm/server/lib/settings/agent_configuration/search.ts @@ -5,7 +5,6 @@ */ import { ESFilter } from 'elasticsearch'; -import { PromiseReturnType } from '../../../../typings/common'; import { SERVICE_NAME, SERVICE_ENVIRONMENT @@ -13,10 +12,7 @@ import { import { Setup } from '../../helpers/setup_request'; import { AgentConfiguration } from './configuration_types'; -export type SearchAgentConfigurationsAPIResponse = PromiseReturnType< - typeof searchConfigurations ->; -export async function searchConfigurations({ +export async function searchAgentConfigurations({ serviceName, environment, setup diff --git a/x-pack/legacy/plugins/apm/server/lib/settings/agent_configuration/update_configuration.ts b/x-pack/legacy/plugins/apm/server/lib/settings/agent_configuration/update_configuration.ts index ad7c789efa94cdb..3417b2a06aea0a0 100644 --- a/x-pack/legacy/plugins/apm/server/lib/settings/agent_configuration/update_configuration.ts +++ b/x-pack/legacy/plugins/apm/server/lib/settings/agent_configuration/update_configuration.ts @@ -5,13 +5,9 @@ */ import { Setup } from '../../helpers/setup_request'; -import { PromiseReturnType } from '../../../../typings/common'; import { AgentConfigurationIntake } from './configuration_types'; -export type UpdateAgentConfigurationAPIResponse = PromiseReturnType< - typeof updateConfiguration ->; -export async function updateConfiguration({ +export async function updateAgentConfiguration({ configurationId, configuration, setup diff --git a/x-pack/legacy/plugins/apm/server/lib/traces/get_trace.ts b/x-pack/legacy/plugins/apm/server/lib/traces/get_trace.ts index a296bcbdecccf49..66c62d714e24774 100644 --- a/x-pack/legacy/plugins/apm/server/lib/traces/get_trace.ts +++ b/x-pack/legacy/plugins/apm/server/lib/traces/get_trace.ts @@ -4,12 +4,10 @@ * you may not use this file except in compliance with the Elastic License. */ -import { PromiseReturnType } from '../../../typings/common'; import { getTraceErrorsPerTransaction } from '../errors/get_trace_errors_per_transaction'; import { Setup } from '../helpers/setup_request'; import { getTraceItems } from './get_trace_items'; -export type TraceAPIResponse = PromiseReturnType; export async function getTrace(traceId: string, setup: Setup) { const [trace, errorsPerTransaction] = await Promise.all([ getTraceItems(traceId, setup), diff --git a/x-pack/legacy/plugins/apm/server/lib/transactions/get_transaction/index.ts b/x-pack/legacy/plugins/apm/server/lib/transactions/get_transaction/index.ts index 60d9a38b5e662e3..cdaddc3af3e9563 100644 --- a/x-pack/legacy/plugins/apm/server/lib/transactions/get_transaction/index.ts +++ b/x-pack/legacy/plugins/apm/server/lib/transactions/get_transaction/index.ts @@ -10,12 +10,10 @@ import { TRACE_ID, TRANSACTION_ID } from '../../../../common/elasticsearch_fieldnames'; -import { PromiseReturnType } from '../../../../typings/common'; import { Transaction } from '../../../../typings/es_schemas/ui/Transaction'; import { rangeFilter } from '../../helpers/range_filter'; import { Setup } from '../../helpers/setup_request'; -export type TransactionAPIResponse = PromiseReturnType; export async function getTransaction( transactionId: string, traceId: string, diff --git a/x-pack/legacy/plugins/apm/server/lib/ui_filters/get_environments.ts b/x-pack/legacy/plugins/apm/server/lib/ui_filters/get_environments.ts index 93a82bf6db85bdc..3b48bfc7a98697e 100644 --- a/x-pack/legacy/plugins/apm/server/lib/ui_filters/get_environments.ts +++ b/x-pack/legacy/plugins/apm/server/lib/ui_filters/get_environments.ts @@ -11,14 +11,10 @@ import { SERVICE_ENVIRONMENT, SERVICE_NAME } from '../../../common/elasticsearch_fieldnames'; -import { PromiseReturnType } from '../../../typings/common'; import { rangeFilter } from '../helpers/range_filter'; import { Setup } from '../helpers/setup_request'; import { ENVIRONMENT_NOT_DEFINED } from '../../../common/environment_filter_values'; -export type EnvironmentUIFilterAPIResponse = PromiseReturnType< - typeof getEnvironments ->; export async function getEnvironments(setup: Setup, serviceName?: string) { const { start, end, client, config } = setup; diff --git a/x-pack/legacy/plugins/apm/server/new-platform/plugin.ts b/x-pack/legacy/plugins/apm/server/new-platform/plugin.ts index 72ef149d8c9ce54..f683c0cd1f9fa98 100644 --- a/x-pack/legacy/plugins/apm/server/new-platform/plugin.ts +++ b/x-pack/legacy/plugins/apm/server/new-platform/plugin.ts @@ -9,12 +9,12 @@ import { makeApmUsageCollector } from '../lib/apm_telemetry'; import { CoreSetupWithUsageCollector } from '../lib/apm_telemetry/make_apm_usage_collector'; import { initErrorsApi } from '../routes/errors/init'; import { initMetricsApi } from '../routes/metrics/init'; -import { initServicesApi } from '../routes/services'; -import { initTracesApi } from '../routes/traces'; +import { initServicesApi } from '../routes/services/init'; +import { initTracesApi } from '../routes/traces/init'; import { initTransactionGroupsApi } from '../routes/transaction_groups/init'; -import { initUIFiltersApi } from '../routes/ui_filters'; +import { initUIFiltersApi } from '../routes/ui_filters/init'; import { initIndexPatternApi } from '../routes/index_patterns/index_pattern'; -import { initSettingsApi } from '../routes/settings'; +import { initSettingsApi } from '../routes/agent_configuration/init'; export class Plugin { public setup(core: InternalCoreSetup) { diff --git a/x-pack/legacy/plugins/apm/server/routes/__test__/routeFailures.test.ts b/x-pack/legacy/plugins/apm/server/routes/__test__/routeFailures.test.ts index 4bf6ff3003a7648..7a9dac13a5301b4 100644 --- a/x-pack/legacy/plugins/apm/server/routes/__test__/routeFailures.test.ts +++ b/x-pack/legacy/plugins/apm/server/routes/__test__/routeFailures.test.ts @@ -7,8 +7,8 @@ import { flatten } from 'lodash'; import { InternalCoreSetup } from 'src/core/server'; import { initErrorsApi } from '../errors/init'; -import { initServicesApi } from '../services'; -import { initTracesApi } from '../traces'; +import { initServicesApi } from '../services/init'; +import { initTracesApi } from '../traces/init'; describe('route handlers should fail with a Boom error', () => { let consoleErrorSpy: any; diff --git a/x-pack/legacy/plugins/apm/server/routes/agent_configuration/agent_configuration_list_route.ts b/x-pack/legacy/plugins/apm/server/routes/agent_configuration/agent_configuration_list_route.ts new file mode 100644 index 000000000000000..454bad1415b0cd7 --- /dev/null +++ b/x-pack/legacy/plugins/apm/server/routes/agent_configuration/agent_configuration_list_route.ts @@ -0,0 +1,35 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import Joi from 'joi'; +import { APMRequest, setupRequest } from '../../lib/helpers/setup_request'; +import { createApmAgentConfigurationIndex } from '../../lib/settings/agent_configuration/create_agent_config_index'; +import { getAgentConfigurationList } from '../../lib/settings/agent_configuration/get_agent_configuration_list'; +import { PromiseReturnType } from '../../../typings/common'; + +export type AgentConfigurationListAPIResponse = PromiseReturnType< + typeof agentConfigurationListRoute['handler'] +>; +export const agentConfigurationListRoute = { + method: 'GET', + path: '/api/apm/settings/agent-configuration', + options: { + validate: { + query: { + _debug: Joi.bool() + } + }, + tags: ['access:apm'] + }, + handler: async (req: APMRequest) => { + await createApmAgentConfigurationIndex(req.server); + + const setup = await setupRequest(req); + return await getAgentConfigurationList({ + setup + }); + } +}; diff --git a/x-pack/legacy/plugins/apm/server/routes/agent_configuration/agent_configuration_payload_validation.ts b/x-pack/legacy/plugins/apm/server/routes/agent_configuration/agent_configuration_payload_validation.ts new file mode 100644 index 000000000000000..d6a9c2445a70fc7 --- /dev/null +++ b/x-pack/legacy/plugins/apm/server/routes/agent_configuration/agent_configuration_payload_validation.ts @@ -0,0 +1,21 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ +import Joi from 'joi'; + +export const agentConfigPayloadValidation = { + settings: Joi.object({ + transaction_sample_rate: Joi.number() + .min(0) + .max(1) + .precision(3) + .required() + .options({ convert: false }) + }), + service: Joi.object({ + name: Joi.string().required(), + environment: Joi.string() + }) +}; diff --git a/x-pack/legacy/plugins/apm/server/routes/agent_configuration/create_agent_configuration_route.ts b/x-pack/legacy/plugins/apm/server/routes/agent_configuration/create_agent_configuration_route.ts new file mode 100644 index 000000000000000..c5a035789229710 --- /dev/null +++ b/x-pack/legacy/plugins/apm/server/routes/agent_configuration/create_agent_configuration_route.ts @@ -0,0 +1,33 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import Joi from 'joi'; +import { APMRequest, setupRequest } from '../../lib/helpers/setup_request'; +import { createAgentConfiguration } from '../../lib/settings/agent_configuration/create_configuration'; +import { AgentConfigurationIntake } from '../../lib/settings/agent_configuration/configuration_types'; +import { agentConfigPayloadValidation } from './agent_configuration_payload_validation'; + +export const createAgentConfigurationRoute = { + method: 'POST', + path: `/api/apm/settings/agent-configuration/new`, + options: { + validate: { + query: { + _debug: Joi.bool() + }, + payload: agentConfigPayloadValidation + }, + tags: ['access:apm'] + }, + handler: async (req: APMRequest) => { + const setup = await setupRequest(req); + const configuration = req.payload as AgentConfigurationIntake; // TODO: this should be typed as well + return await createAgentConfiguration({ + configuration, + setup + }); + } +}; diff --git a/x-pack/legacy/plugins/apm/server/routes/agent_configuration/delete_agent_configuration_route.ts b/x-pack/legacy/plugins/apm/server/routes/agent_configuration/delete_agent_configuration_route.ts new file mode 100644 index 000000000000000..eb02aedda94776e --- /dev/null +++ b/x-pack/legacy/plugins/apm/server/routes/agent_configuration/delete_agent_configuration_route.ts @@ -0,0 +1,30 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import Joi from 'joi'; +import { deleteAgentConfiguration } from '../../lib/settings/agent_configuration/delete_agent_configuration'; +import { APMRequest, setupRequest } from '../../lib/helpers/setup_request'; + +export const deleteAgentConfigurationRoute = { + method: 'DELETE', + path: `/api/apm/settings/agent-configuration/{configurationId}`, + options: { + validate: { + query: { + _debug: Joi.bool() + } + }, + tags: ['access:apm'] + }, + handler: async (req: APMRequest) => { + const setup = await setupRequest(req); + const { configurationId } = req.params; + return await deleteAgentConfiguration({ + configurationId, + setup + }); + } +}; diff --git a/x-pack/legacy/plugins/apm/server/routes/agent_configuration/environments_route.ts b/x-pack/legacy/plugins/apm/server/routes/agent_configuration/environments_route.ts new file mode 100644 index 000000000000000..7af95b79dcfe54b --- /dev/null +++ b/x-pack/legacy/plugins/apm/server/routes/agent_configuration/environments_route.ts @@ -0,0 +1,30 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import Joi from 'joi'; +import { APMRequest, setupRequest } from '../../lib/helpers/setup_request'; +import { getEnvironments } from '../../lib/settings/agent_configuration/get_environments'; + +export const environmentsRoute = { + method: 'GET', + path: `/api/apm/settings/agent-configuration/services/{serviceName}/environments`, + options: { + validate: { + query: { + _debug: Joi.bool() + } + }, + tags: ['access:apm'] + }, + handler: async (req: APMRequest) => { + const setup = await setupRequest(req); + const { serviceName } = req.params; + return await getEnvironments({ + serviceName, + setup + }); + } +}; diff --git a/x-pack/legacy/plugins/apm/server/routes/agent_configuration/init.ts b/x-pack/legacy/plugins/apm/server/routes/agent_configuration/init.ts new file mode 100644 index 000000000000000..d8e662c63bf3dca --- /dev/null +++ b/x-pack/legacy/plugins/apm/server/routes/agent_configuration/init.ts @@ -0,0 +1,39 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { InternalCoreSetup } from 'src/core/server'; +import { agentConfigurationListRoute } from './agent_configuration_list_route'; +import { deleteAgentConfigurationRoute } from './delete_agent_configuration_route'; +import { serviceNamesRoute } from './service_names_route'; +import { environmentsRoute } from './environments_route'; +import { createAgentConfigurationRoute } from './create_agent_configuration_route'; +import { updateAgentConfigurationRoute } from './update_agent_configuration_route'; +import { searchAgentConfigurationsRoute } from './search_agent_configurations_route'; + +export function initSettingsApi(core: InternalCoreSetup) { + const { server } = core.http; + + // get list of configurations + server.route(agentConfigurationListRoute); + + // delete configuration + server.route(deleteAgentConfigurationRoute); + + // get list of services + server.route(serviceNamesRoute); + + // get environments for service + server.route(environmentsRoute); + + // create configuration + server.route(createAgentConfigurationRoute); + + // update configuration + server.route(updateAgentConfigurationRoute); + + // Lookup single configuration (used by APM Server) + server.route(searchAgentConfigurationsRoute); +} diff --git a/x-pack/legacy/plugins/apm/server/routes/agent_configuration/search_agent_configurations_route.ts b/x-pack/legacy/plugins/apm/server/routes/agent_configuration/search_agent_configurations_route.ts new file mode 100644 index 000000000000000..7c1c5887b17f821 --- /dev/null +++ b/x-pack/legacy/plugins/apm/server/routes/agent_configuration/search_agent_configurations_route.ts @@ -0,0 +1,49 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import Joi from 'joi'; +import { ServerRoute } from 'hapi'; +import { setupRequest } from '../../lib/helpers/setup_request'; +import { createApmAgentConfigurationIndex } from '../../lib/settings/agent_configuration/create_agent_config_index'; +import { searchAgentConfigurations } from '../../lib/settings/agent_configuration/search'; + +interface Payload { + service: { + name: string; + environment?: string; + }; +} + +export const searchAgentConfigurationsRoute: ServerRoute = { + method: 'POST', + path: '/api/apm/settings/agent-configuration/search', + options: { + validate: { + query: { + _debug: Joi.bool() + } + }, + tags: ['access:apm'] + }, + handler: async (req, h) => { + await createApmAgentConfigurationIndex(req.server); + const setup = await setupRequest(req); + const payload = req.payload as Payload; + const serviceName = payload.service.name; + const environment = payload.service.environment; + const config = await searchAgentConfigurations({ + serviceName, + environment, + setup + }); + + if (!config) { + return h.response().code(404); + } + + return config; + } +}; diff --git a/x-pack/legacy/plugins/apm/server/routes/agent_configuration/service_names_route.ts b/x-pack/legacy/plugins/apm/server/routes/agent_configuration/service_names_route.ts new file mode 100644 index 000000000000000..3651351817acb76 --- /dev/null +++ b/x-pack/legacy/plugins/apm/server/routes/agent_configuration/service_names_route.ts @@ -0,0 +1,28 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import Joi from 'joi'; +import { APMRequest, setupRequest } from '../../lib/helpers/setup_request'; +import { getServiceNames } from '../../lib/settings/agent_configuration/get_service_names'; + +export const serviceNamesRoute = { + method: 'GET', + path: `/api/apm/settings/agent-configuration/services`, + options: { + validate: { + query: { + _debug: Joi.bool() + } + }, + tags: ['access:apm'] + }, + handler: async (req: APMRequest) => { + const setup = await setupRequest(req); + return await getServiceNames({ + setup + }); + } +}; diff --git a/x-pack/legacy/plugins/apm/server/routes/agent_configuration/update_agent_configuration_route.ts b/x-pack/legacy/plugins/apm/server/routes/agent_configuration/update_agent_configuration_route.ts new file mode 100644 index 000000000000000..54c2df274a9fc5d --- /dev/null +++ b/x-pack/legacy/plugins/apm/server/routes/agent_configuration/update_agent_configuration_route.ts @@ -0,0 +1,35 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import Joi from 'joi'; +import { APMRequest, setupRequest } from '../../lib/helpers/setup_request'; +import { updateAgentConfiguration } from '../../lib/settings/agent_configuration/update_configuration'; +import { agentConfigPayloadValidation } from './agent_configuration_payload_validation'; +import { AgentConfigurationIntake } from '../../lib/settings/agent_configuration/configuration_types'; + +export const updateAgentConfigurationRoute = { + method: 'PUT', + path: `/api/apm/settings/agent-configuration/{configurationId}`, + options: { + validate: { + query: { + _debug: Joi.bool() + }, + payload: agentConfigPayloadValidation + }, + tags: ['access:apm'] + }, + handler: async (req: APMRequest) => { + const setup = await setupRequest(req); + const { configurationId } = req.params; + const configuration = req.payload as AgentConfigurationIntake; + return await updateAgentConfiguration({ + configurationId, + configuration, + setup + }); + } +}; diff --git a/x-pack/legacy/plugins/apm/server/routes/services.ts b/x-pack/legacy/plugins/apm/server/routes/services.ts deleted file mode 100644 index f5f242e4a93c1ec..000000000000000 --- a/x-pack/legacy/plugins/apm/server/routes/services.ts +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - -import { InternalCoreSetup } from 'src/core/server'; -import { AgentName } from '../../typings/es_schemas/ui/fields/Agent'; -import { createApmTelementry, storeApmTelemetry } from '../lib/apm_telemetry'; -import { withDefaultQueryParamValidators } from '../lib/helpers/input_validation'; -import { setupRequest } from '../lib/helpers/setup_request'; -import { getServiceAgentName } from '../lib/services/get_service_agent_name'; -import { getServices } from '../lib/services/get_services'; -import { getServiceTransactionTypes } from '../lib/services/get_service_transaction_types'; - -export function initServicesApi(core: InternalCoreSetup) { - const { server } = core.http; - server.route({ - method: 'GET', - path: '/api/apm/services', - options: { - validate: { - query: withDefaultQueryParamValidators() - }, - tags: ['access:apm'] - }, - handler: async req => { - const setup = await setupRequest(req); - const services = await getServices(setup); - - // Store telemetry data derived from services - const agentNames = services.items.map( - ({ agentName }) => agentName as AgentName - ); - const apmTelemetry = createApmTelementry(agentNames); - storeApmTelemetry(server, apmTelemetry); - - return services; - } - }); - - server.route({ - method: 'GET', - path: `/api/apm/services/{serviceName}/agent_name`, - options: { - validate: { - query: withDefaultQueryParamValidators() - }, - tags: ['access:apm'] - }, - handler: async req => { - const setup = await setupRequest(req); - const { serviceName } = req.params; - return getServiceAgentName(serviceName, setup); - } - }); - - server.route({ - method: 'GET', - path: `/api/apm/services/{serviceName}/transaction_types`, - options: { - validate: { - query: withDefaultQueryParamValidators() - }, - tags: ['access:apm'] - }, - handler: async req => { - const setup = await setupRequest(req); - const { serviceName } = req.params; - return getServiceTransactionTypes(serviceName, setup); - } - }); -} diff --git a/x-pack/legacy/plugins/apm/server/routes/services/init.ts b/x-pack/legacy/plugins/apm/server/routes/services/init.ts new file mode 100644 index 000000000000000..922f9977abf1818 --- /dev/null +++ b/x-pack/legacy/plugins/apm/server/routes/services/init.ts @@ -0,0 +1,17 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { InternalCoreSetup } from 'src/core/server'; +import { serviceListRoute } from './service_list_route'; +import { serviceAgentNameRoute } from './service_agent_name_route'; +import { serviceTransactionTypesRoute } from './service_transaction_types_routes'; + +export function initServicesApi(core: InternalCoreSetup) { + const { server } = core.http; + server.route(serviceListRoute); + server.route(serviceAgentNameRoute); + server.route(serviceTransactionTypesRoute); +} diff --git a/x-pack/legacy/plugins/apm/server/routes/services/service_agent_name_route.ts b/x-pack/legacy/plugins/apm/server/routes/services/service_agent_name_route.ts new file mode 100644 index 000000000000000..9b8d7f14750fb1d --- /dev/null +++ b/x-pack/legacy/plugins/apm/server/routes/services/service_agent_name_route.ts @@ -0,0 +1,30 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { getServiceAgentName } from '../../lib/services/get_service_agent_name'; +import { withDefaultQueryParamValidators } from '../../lib/helpers/input_validation'; +import { + DefaultQueryParams, + APMRequest, + setupRequest +} from '../../lib/helpers/setup_request'; + +export const serviceAgentNameRoute = { + method: 'GET', + path: `/api/apm/services/{serviceName}/agent_name`, + options: { + validate: { + query: withDefaultQueryParamValidators() + }, + tags: ['access:apm'] + }, + handler: async (req: APMRequest) => { + const setup = await setupRequest(req); + const { serviceName } = req.params; + + return getServiceAgentName(serviceName, setup); + } +}; diff --git a/x-pack/legacy/plugins/apm/server/routes/services/service_list_route.ts b/x-pack/legacy/plugins/apm/server/routes/services/service_list_route.ts new file mode 100644 index 000000000000000..e39319736502e5f --- /dev/null +++ b/x-pack/legacy/plugins/apm/server/routes/services/service_list_route.ts @@ -0,0 +1,46 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { AgentName } from '../../../typings/es_schemas/ui/fields/Agent'; +import { + createApmTelementry, + storeApmTelemetry +} from '../../lib/apm_telemetry'; +import { getServices } from '../../lib/services/get_services'; +import { withDefaultQueryParamValidators } from '../../lib/helpers/input_validation'; +import { + DefaultQueryParams, + APMRequest, + setupRequest +} from '../../lib/helpers/setup_request'; +import { PromiseReturnType } from '../../../typings/common'; + +export type ServiceListAPIResponse = PromiseReturnType< + typeof serviceListRoute['handler'] +>; +export const serviceListRoute = { + method: 'GET', + path: '/api/apm/services', + options: { + validate: { + query: withDefaultQueryParamValidators() + }, + tags: ['access:apm'] + }, + handler: async (req: APMRequest) => { + const setup = await setupRequest(req); + const services = await getServices(setup); + + // Store telemetry data derived from services + const agentNames = services.items.map( + ({ agentName }) => agentName as AgentName + ); + const apmTelemetry = createApmTelementry(agentNames); + storeApmTelemetry(req.server, apmTelemetry); + + return services; + } +}; diff --git a/x-pack/legacy/plugins/apm/server/routes/services/service_transaction_types_routes.ts b/x-pack/legacy/plugins/apm/server/routes/services/service_transaction_types_routes.ts new file mode 100644 index 000000000000000..d3c1267091b1c5e --- /dev/null +++ b/x-pack/legacy/plugins/apm/server/routes/services/service_transaction_types_routes.ts @@ -0,0 +1,29 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { getServiceTransactionTypes } from '../../lib/services/get_service_transaction_types'; +import { withDefaultQueryParamValidators } from '../../lib/helpers/input_validation'; +import { + DefaultQueryParams, + APMRequest, + setupRequest +} from '../../lib/helpers/setup_request'; + +export const serviceTransactionTypesRoute = { + method: 'GET', + path: `/api/apm/services/{serviceName}/transaction_types`, + options: { + validate: { + query: withDefaultQueryParamValidators() + }, + tags: ['access:apm'] + }, + handler: async (req: APMRequest) => { + const setup = await setupRequest(req); + const { serviceName } = req.params; + return getServiceTransactionTypes(serviceName, setup); + } +}; diff --git a/x-pack/legacy/plugins/apm/server/routes/settings.ts b/x-pack/legacy/plugins/apm/server/routes/settings.ts deleted file mode 100644 index 89df32430eab69d..000000000000000 --- a/x-pack/legacy/plugins/apm/server/routes/settings.ts +++ /dev/null @@ -1,216 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - -import { InternalCoreSetup } from 'src/core/server'; -import Joi from 'joi'; -import { setupRequest } from '../lib/helpers/setup_request'; -import { getServiceNames } from '../lib/settings/agent_configuration/get_service_names'; -import { createConfiguration } from '../lib/settings/agent_configuration/create_configuration'; -import { updateConfiguration } from '../lib/settings/agent_configuration/update_configuration'; -import { AgentConfigurationIntake } from '../lib/settings/agent_configuration/configuration_types'; -import { searchConfigurations } from '../lib/settings/agent_configuration/search'; -import { listConfigurations } from '../lib/settings/agent_configuration/list_configurations'; -import { getEnvironments } from '../lib/settings/agent_configuration/get_environments'; -import { deleteConfiguration } from '../lib/settings/agent_configuration/delete_configuration'; -import { createApmAgentConfigurationIndex } from '../lib/settings/agent_configuration/create_agent_config_index'; - -export function initSettingsApi(core: InternalCoreSetup) { - const { server } = core.http; - - // get list of configurations - server.route({ - method: 'GET', - path: '/api/apm/settings/agent-configuration', - options: { - validate: { - query: { - _debug: Joi.bool() - } - }, - tags: ['access:apm'] - }, - handler: async req => { - await createApmAgentConfigurationIndex(server); - - const setup = await setupRequest(req); - return await listConfigurations({ - setup - }); - } - }); - - // delete configuration - server.route({ - method: 'DELETE', - path: `/api/apm/settings/agent-configuration/{configurationId}`, - options: { - validate: { - query: { - _debug: Joi.bool() - } - }, - tags: ['access:apm'] - }, - handler: async req => { - const setup = await setupRequest(req); - const { configurationId } = req.params; - return await deleteConfiguration({ - configurationId, - setup - }); - } - }); - - // get list of services - server.route({ - method: 'GET', - path: `/api/apm/settings/agent-configuration/services`, - options: { - validate: { - query: { - _debug: Joi.bool() - } - }, - tags: ['access:apm'] - }, - handler: async req => { - const setup = await setupRequest(req); - return await getServiceNames({ - setup - }); - } - }); - - // get environments for service - server.route({ - method: 'GET', - path: `/api/apm/settings/agent-configuration/services/{serviceName}/environments`, - options: { - validate: { - query: { - _debug: Joi.bool() - } - }, - tags: ['access:apm'] - }, - handler: async req => { - const setup = await setupRequest(req); - const { serviceName } = req.params; - return await getEnvironments({ - serviceName, - setup - }); - } - }); - - const agentConfigPayloadValidation = { - settings: Joi.object({ - transaction_sample_rate: Joi.number() - .min(0) - .max(1) - .precision(3) - .required() - .options({ convert: false }) - }), - service: Joi.object({ - name: Joi.string().required(), - environment: Joi.string() - }) - }; - - // create configuration - server.route({ - method: 'POST', - path: `/api/apm/settings/agent-configuration/new`, - options: { - validate: { - query: { - _debug: Joi.bool() - }, - payload: agentConfigPayloadValidation - }, - tags: ['access:apm'] - }, - handler: async req => { - const setup = await setupRequest(req); - const configuration = req.payload as AgentConfigurationIntake; - return await createConfiguration({ - configuration, - setup - }); - } - }); - - // update configuration - server.route({ - method: 'PUT', - path: `/api/apm/settings/agent-configuration/{configurationId}`, - options: { - validate: { - query: { - _debug: Joi.bool() - }, - payload: agentConfigPayloadValidation - }, - tags: ['access:apm'] - }, - handler: async req => { - const setup = await setupRequest(req); - const { configurationId } = req.params; - const configuration = req.payload as AgentConfigurationIntake; - return await updateConfiguration({ - configurationId, - configuration, - setup - }); - } - }); - - // Lookup single configuration - [ - '/api/apm/settings/agent-configuration/search', - '/api/apm/settings/cm/search' // backward compatible api route for apm-server - ].forEach(path => { - server.route({ - method: 'POST', - path, - options: { - validate: { - query: { - _debug: Joi.bool() - } - }, - tags: ['access:apm'] - }, - handler: async (req, h) => { - interface Payload { - service: { - name: string; - environment?: string; - }; - } - - await createApmAgentConfigurationIndex(server); - - const setup = await setupRequest(req); - const payload = req.payload as Payload; - const serviceName = payload.service.name; - const environment = payload.service.environment; - const config = await searchConfigurations({ - serviceName, - environment, - setup - }); - - if (!config) { - return h.response().code(404); - } - - return config; - } - }); - }); -} diff --git a/x-pack/legacy/plugins/apm/server/routes/traces.ts b/x-pack/legacy/plugins/apm/server/routes/traces.ts deleted file mode 100644 index c1df35729777331..000000000000000 --- a/x-pack/legacy/plugins/apm/server/routes/traces.ts +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - -import { InternalCoreSetup } from 'src/core/server'; -import { withDefaultQueryParamValidators } from '../lib/helpers/input_validation'; -import { setupRequest } from '../lib/helpers/setup_request'; -import { getTrace } from '../lib/traces/get_trace'; -import { getTransactionGroupList } from '../lib/transaction_groups'; - -export function initTracesApi(core: InternalCoreSetup) { - const { server } = core.http; - - // Get trace list - server.route({ - method: 'GET', - path: '/api/apm/traces', - options: { - validate: { - query: withDefaultQueryParamValidators() - }, - tags: ['access:apm'] - }, - handler: async req => { - const setup = await setupRequest(req); - return getTransactionGroupList({ type: 'top_traces' }, setup); - } - }); - - // Get individual trace - server.route({ - method: 'GET', - path: `/api/apm/traces/{traceId}`, - options: { - validate: { - query: withDefaultQueryParamValidators() - }, - tags: ['access:apm'] - }, - handler: async req => { - const { traceId } = req.params; - const setup = await setupRequest(req); - return getTrace(traceId, setup); - } - }); -} diff --git a/x-pack/legacy/plugins/apm/server/routes/traces/init.ts b/x-pack/legacy/plugins/apm/server/routes/traces/init.ts new file mode 100644 index 000000000000000..3cbd30982e098a1 --- /dev/null +++ b/x-pack/legacy/plugins/apm/server/routes/traces/init.ts @@ -0,0 +1,19 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { InternalCoreSetup } from 'src/core/server'; +import { traceListRoute } from './trace_list_route'; +import { traceRoute } from './trace_route'; + +export function initTracesApi(core: InternalCoreSetup) { + const { server } = core.http; + + // Get trace list + server.route(traceListRoute); + + // Get individual trace + server.route(traceRoute); +} diff --git a/x-pack/legacy/plugins/apm/server/routes/traces/trace_list_route.ts b/x-pack/legacy/plugins/apm/server/routes/traces/trace_list_route.ts new file mode 100644 index 000000000000000..ab6252e4908823a --- /dev/null +++ b/x-pack/legacy/plugins/apm/server/routes/traces/trace_list_route.ts @@ -0,0 +1,28 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { withDefaultQueryParamValidators } from '../../lib/helpers/input_validation'; +import { + DefaultQueryParams, + APMRequest, + setupRequest +} from '../../lib/helpers/setup_request'; +import { getTransactionGroupList } from '../../lib/transaction_groups'; + +export const traceListRoute = { + method: 'GET', + path: '/api/apm/traces', + options: { + validate: { + query: withDefaultQueryParamValidators() + }, + tags: ['access:apm'] + }, + handler: async (req: APMRequest) => { + const setup = await setupRequest(req); + return getTransactionGroupList({ type: 'top_traces' }, setup); + } +}; diff --git a/x-pack/legacy/plugins/apm/server/routes/traces/trace_route.ts b/x-pack/legacy/plugins/apm/server/routes/traces/trace_route.ts new file mode 100644 index 000000000000000..ddca038820d1e1e --- /dev/null +++ b/x-pack/legacy/plugins/apm/server/routes/traces/trace_route.ts @@ -0,0 +1,31 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { withDefaultQueryParamValidators } from '../../lib/helpers/input_validation'; +import { + APMRequest, + setupRequest, + DefaultQueryParams +} from '../../lib/helpers/setup_request'; +import { getTrace } from '../../lib/traces/get_trace'; +import { PromiseReturnType } from '../../../typings/common'; + +export type TraceAPIResponse = PromiseReturnType; +export const traceRoute = { + method: 'GET', + path: `/api/apm/traces/{traceId}`, + options: { + validate: { + query: withDefaultQueryParamValidators() + }, + tags: ['access:apm'] + }, + handler: async (req: APMRequest) => { + const { traceId } = req.params; + const setup = await setupRequest(req); + return getTrace(traceId, setup); + } +}; diff --git a/x-pack/legacy/plugins/apm/server/routes/ui_filters.ts b/x-pack/legacy/plugins/apm/server/routes/ui_filters.ts deleted file mode 100644 index 411e6bbc66fd836..000000000000000 --- a/x-pack/legacy/plugins/apm/server/routes/ui_filters.ts +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - -import Joi from 'joi'; -import { InternalCoreSetup } from 'src/core/server'; -import { withDefaultQueryParamValidators } from '../lib/helpers/input_validation'; -import { setupRequest } from '../lib/helpers/setup_request'; -import { getEnvironments } from '../lib/ui_filters/get_environments'; - -export function initUIFiltersApi(core: InternalCoreSetup) { - const { server } = core.http; - server.route({ - method: 'GET', - path: '/api/apm/ui_filters/environments', - options: { - validate: { - query: withDefaultQueryParamValidators({ - serviceName: Joi.string() - }) - }, - tags: ['access:apm'] - }, - handler: async req => { - const setup = await setupRequest(req); - const { serviceName } = req.query as { - serviceName?: string; - }; - return getEnvironments(setup, serviceName); - } - }); -} diff --git a/x-pack/legacy/plugins/apm/server/routes/ui_filters/environments_route.ts b/x-pack/legacy/plugins/apm/server/routes/ui_filters/environments_route.ts new file mode 100644 index 000000000000000..cbf2facd1241bbf --- /dev/null +++ b/x-pack/legacy/plugins/apm/server/routes/ui_filters/environments_route.ts @@ -0,0 +1,34 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ +import Joi from 'joi'; +import { withDefaultQueryParamValidators } from '../../lib/helpers/input_validation'; +import { getEnvironments } from '../../lib/ui_filters/get_environments'; +import { APMRequest, setupRequest } from '../../lib/helpers/setup_request'; + +interface Query { + _debug?: string; + start?: string; + end?: string; + serviceName?: string; +} + +export const environmentsRoute = { + method: 'GET', + path: '/api/apm/ui_filters/environments', + options: { + validate: { + query: withDefaultQueryParamValidators({ + serviceName: Joi.string() + }) + }, + tags: ['access:apm'] + }, + handler: async (req: APMRequest) => { + const setup = await setupRequest(req); + const { serviceName } = req.query; + return getEnvironments(setup, serviceName); + } +}; diff --git a/x-pack/legacy/plugins/apm/server/routes/ui_filters/init.ts b/x-pack/legacy/plugins/apm/server/routes/ui_filters/init.ts new file mode 100644 index 000000000000000..8294bdd331ea1fe --- /dev/null +++ b/x-pack/legacy/plugins/apm/server/routes/ui_filters/init.ts @@ -0,0 +1,13 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { InternalCoreSetup } from 'src/core/server'; +import { environmentsRoute } from './environments_route'; + +export function initUIFiltersApi(core: InternalCoreSetup) { + const { server } = core.http; + server.route(environmentsRoute); +}