diff --git a/x-pack/plugins/observability_solution/apm/server/plugin.ts b/x-pack/plugins/observability_solution/apm/server/plugin.ts index 2c2392b845415..7e93a5f3c3324 100644 --- a/x-pack/plugins/observability_solution/apm/server/plugin.ts +++ b/x-pack/plugins/observability_solution/apm/server/plugin.ts @@ -40,7 +40,7 @@ import { createApmSourceMapIndexTemplate } from './routes/source_maps/create_apm import { addApiKeysToEveryPackagePolicyIfMissing } from './routes/fleet/api_keys/add_api_keys_to_policies_if_missing'; import { apmTutorialCustomIntegration } from '../common/tutorial/tutorials'; import { registerAssistantFunctions } from './assistant_functions'; -import { getAlertDetailsContextHandler } from './routes/assistant_functions/get_observability_alert_details_context/get_alert_details_context_handler'; +import { getAlertDetailsContextHandler } from './routes/assistant_functions/get_observability_alert_details_context'; export class APMPlugin implements Plugin diff --git a/x-pack/plugins/observability_solution/apm/server/routes/assistant_functions/get_changepoints/index.ts b/x-pack/plugins/observability_solution/apm/server/routes/assistant_functions/get_changepoints/index.ts index 2ffbdc30a1c52..99ea7ec691dab 100644 --- a/x-pack/plugins/observability_solution/apm/server/routes/assistant_functions/get_changepoints/index.ts +++ b/x-pack/plugins/observability_solution/apm/server/routes/assistant_functions/get_changepoints/index.ts @@ -5,7 +5,6 @@ * 2.0. */ -import moment from 'moment'; import { LatencyAggregationType } from '../../../../common/latency_aggregation_types'; import { APMEventClient } from '../../../lib/helpers/create_es_client/create_apm_event_client'; import { ApmTimeseriesType, getApmTimeseries, TimeseriesChangePoint } from '../get_apm_timeseries'; @@ -18,14 +17,16 @@ export interface ChangePointGrouping { export async function getServiceChangePoints({ apmEventClient, - alertStartedAt, + start, + end, serviceName, serviceEnvironment, transactionType, transactionName, }: { apmEventClient: APMEventClient; - alertStartedAt: string; + start: string; + end: string; serviceName: string | undefined; serviceEnvironment: string | undefined; transactionType: string | undefined; @@ -38,8 +39,8 @@ export async function getServiceChangePoints({ const res = await getApmTimeseries({ apmEventClient, arguments: { - start: moment(alertStartedAt).subtract(12, 'hours').toISOString(), - end: alertStartedAt, + start, + end, stats: [ { title: 'Latency', @@ -95,12 +96,14 @@ export async function getServiceChangePoints({ export async function getExitSpanChangePoints({ apmEventClient, - alertStartedAt, + start, + end, serviceName, serviceEnvironment, }: { apmEventClient: APMEventClient; - alertStartedAt: string; + start: string; + end: string; serviceName: string | undefined; serviceEnvironment: string | undefined; }): Promise { @@ -111,8 +114,8 @@ export async function getExitSpanChangePoints({ const res = await getApmTimeseries({ apmEventClient, arguments: { - start: moment(alertStartedAt).subtract(30, 'minute').toISOString(), - end: alertStartedAt, + start, + end, stats: [ { title: 'Exit span latency', diff --git a/x-pack/plugins/observability_solution/apm/server/routes/assistant_functions/get_log_categories/index.ts b/x-pack/plugins/observability_solution/apm/server/routes/assistant_functions/get_log_categories/index.ts index 990b63f412f76..e3e570c05e13e 100644 --- a/x-pack/plugins/observability_solution/apm/server/routes/assistant_functions/get_log_categories/index.ts +++ b/x-pack/plugins/observability_solution/apm/server/routes/assistant_functions/get_log_categories/index.ts @@ -17,13 +17,11 @@ import { } from '../../../../common/es_fields/apm'; import { getTypedSearch } from '../../../utils/create_typed_es_client'; -export type LogCategories = - | Array<{ - errorCategory: string; - docCount: number; - sampleMessage: string; - }> - | undefined; +export interface LogCategory { + errorCategory: string; + docCount: number; + sampleMessage: string; +} export async function getLogCategories({ esClient, @@ -40,7 +38,7 @@ export async function getLogCategories({ 'container.id'?: string; 'kubernetes.pod.name'?: string; }; -}): Promise { +}): Promise { const start = datemath.parse(args.start)?.valueOf()!; const end = datemath.parse(args.end)?.valueOf()!; diff --git a/x-pack/plugins/observability_solution/apm/server/routes/assistant_functions/get_observability_alert_details_context/get_alert_details_context_handler.ts b/x-pack/plugins/observability_solution/apm/server/routes/assistant_functions/get_observability_alert_details_context/get_alert_details_context_handler.ts deleted file mode 100644 index cd1a56d56f45e..0000000000000 --- a/x-pack/plugins/observability_solution/apm/server/routes/assistant_functions/get_observability_alert_details_context/get_alert_details_context_handler.ts +++ /dev/null @@ -1,85 +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 - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { Logger } from '@kbn/core/server'; -import { - AlertDetailsContextualInsightsHandlerQuery, - AlertDetailsContextualInsightsRequestContext, -} from '@kbn/observability-plugin/server/services'; -import { getApmAlertsClient } from '../../../lib/helpers/get_apm_alerts_client'; -import { getApmEventClient } from '../../../lib/helpers/get_apm_event_client'; -import { getMlClient } from '../../../lib/helpers/get_ml_client'; -import { getRandomSampler } from '../../../lib/helpers/get_random_sampler'; -import { getObservabilityAlertDetailsContext } from '.'; -import { APMRouteHandlerResources } from '../../apm_routes/register_apm_server_routes'; - -export const getAlertDetailsContextHandler = ( - resourcePlugins: APMRouteHandlerResources['plugins'], - logger: Logger -) => { - return async ( - requestContext: AlertDetailsContextualInsightsRequestContext, - query: AlertDetailsContextualInsightsHandlerQuery - ) => { - const resources = { - getApmIndices: async () => { - const coreContext = await requestContext.core; - return resourcePlugins.apmDataAccess.setup.getApmIndices(coreContext.savedObjects.client); - }, - request: requestContext.request, - params: { query: { _inspect: false } }, - plugins: resourcePlugins, - context: { - core: requestContext.core, - licensing: requestContext.licensing, - alerting: resourcePlugins.alerting!.start().then((startContract) => { - return { - getRulesClient() { - return startContract.getRulesClientWithRequest(requestContext.request); - }, - }; - }), - rac: resourcePlugins.ruleRegistry.start().then((startContract) => { - return { - getAlertsClient() { - return startContract.getRacClientWithRequest(requestContext.request); - }, - }; - }), - }, - }; - - const [apmEventClient, annotationsClient, apmAlertsClient, coreContext, mlClient] = - await Promise.all([ - getApmEventClient(resources), - resourcePlugins.observability.setup.getScopedAnnotationsClient( - resources.context, - requestContext.request - ), - getApmAlertsClient(resources), - requestContext.core, - getMlClient(resources), - getRandomSampler({ - security: resourcePlugins.security, - probability: 1, - request: requestContext.request, - }), - ]); - const esClient = coreContext.elasticsearch.client.asCurrentUser; - - return getObservabilityAlertDetailsContext({ - coreContext, - apmEventClient, - annotationsClient, - apmAlertsClient, - mlClient, - esClient, - query, - logger, - }); - }; -}; diff --git a/x-pack/plugins/observability_solution/apm/server/routes/assistant_functions/get_observability_alert_details_context/get_apm_alert_details_context_prompt.ts b/x-pack/plugins/observability_solution/apm/server/routes/assistant_functions/get_observability_alert_details_context/get_apm_alert_details_context_prompt.ts deleted file mode 100644 index 4a28a0460ebbd..0000000000000 --- a/x-pack/plugins/observability_solution/apm/server/routes/assistant_functions/get_observability_alert_details_context/get_apm_alert_details_context_prompt.ts +++ /dev/null @@ -1,85 +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 - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { isEmpty } from 'lodash'; -import { AlertDetailsContextualInsight } from '@kbn/observability-plugin/server/services'; -import { APMDownstreamDependency } from '../get_apm_downstream_dependencies'; -import { ServiceSummary } from '../get_apm_service_summary'; -import { LogCategories } from '../get_log_categories'; -import { ApmAnomalies } from '../get_apm_service_summary/get_anomalies'; -import { ChangePointGrouping } from '../get_changepoints'; - -export function getApmAlertDetailsContextPrompt({ - serviceName, - serviceEnvironment, - serviceSummary, - downstreamDependencies, - logCategories, - serviceChangePoints, - exitSpanChangePoints, - anomalies, -}: { - serviceName?: string; - serviceEnvironment?: string; - serviceSummary?: ServiceSummary; - downstreamDependencies?: APMDownstreamDependency[]; - logCategories: LogCategories; - serviceChangePoints?: ChangePointGrouping[]; - exitSpanChangePoints?: ChangePointGrouping[]; - anomalies?: ApmAnomalies; -}): AlertDetailsContextualInsight[] { - const prompt: AlertDetailsContextualInsight[] = []; - if (!isEmpty(serviceSummary)) { - prompt.push({ - key: 'serviceSummary', - description: 'Metadata for the service where the alert occurred', - data: serviceSummary, - }); - } - - if (!isEmpty(downstreamDependencies)) { - prompt.push({ - key: 'downstreamDependencies', - description: `Downstream dependencies from the service "${serviceName}". Problems in these services can negatively affect the performance of "${serviceName}"`, - data: downstreamDependencies, - }); - } - - if (!isEmpty(serviceChangePoints)) { - prompt.push({ - key: 'serviceChangePoints', - description: `Significant change points for "${serviceName}". Use this to spot dips and spikes in throughput, latency and failure rate`, - data: serviceChangePoints, - }); - } - - if (!isEmpty(exitSpanChangePoints)) { - prompt.push({ - key: 'exitSpanChangePoints', - description: `Significant change points for the dependencies of "${serviceName}". Use this to spot dips or spikes in throughput, latency and failure rate for downstream dependencies`, - data: exitSpanChangePoints, - }); - } - - if (!isEmpty(logCategories)) { - prompt.push({ - key: 'logCategories', - description: `Log events occurring around the time of the alert`, - data: logCategories, - }); - } - - if (!isEmpty(anomalies)) { - prompt.push({ - key: 'anomalies', - description: `Anomalies for services running in the environment "${serviceEnvironment}"`, - data: anomalies, - }); - } - - return prompt; -} diff --git a/x-pack/plugins/observability_solution/apm/server/routes/assistant_functions/get_observability_alert_details_context/get_container_id_from_signals.ts b/x-pack/plugins/observability_solution/apm/server/routes/assistant_functions/get_observability_alert_details_context/get_container_id_from_signals.ts index 22679dd55ded0..638903e813545 100644 --- a/x-pack/plugins/observability_solution/apm/server/routes/assistant_functions/get_observability_alert_details_context/get_container_id_from_signals.ts +++ b/x-pack/plugins/observability_solution/apm/server/routes/assistant_functions/get_observability_alert_details_context/get_container_id_from_signals.ts @@ -12,7 +12,7 @@ import { rangeQuery, typedSearch } from '@kbn/observability-plugin/server/utils/ import * as t from 'io-ts'; import moment from 'moment'; import { ESSearchRequest } from '@kbn/es-types'; -import { observabilityAlertDetailsContextRt } from '@kbn/observability-plugin/server/services'; +import { alertDetailsContextRt } from '@kbn/observability-plugin/server/services'; import { ApmDocumentType } from '../../../../common/document_type'; import { APMEventClient, @@ -26,7 +26,7 @@ export async function getContainerIdFromSignals({ coreContext, apmEventClient, }: { - query: t.TypeOf; + query: t.TypeOf; esClient: ElasticsearchClient; coreContext: Pick; apmEventClient: APMEventClient; diff --git a/x-pack/plugins/observability_solution/apm/server/routes/assistant_functions/get_observability_alert_details_context/get_service_name_from_signals.ts b/x-pack/plugins/observability_solution/apm/server/routes/assistant_functions/get_observability_alert_details_context/get_service_name_from_signals.ts index bd62b998bee99..284c286766c76 100644 --- a/x-pack/plugins/observability_solution/apm/server/routes/assistant_functions/get_observability_alert_details_context/get_service_name_from_signals.ts +++ b/x-pack/plugins/observability_solution/apm/server/routes/assistant_functions/get_observability_alert_details_context/get_service_name_from_signals.ts @@ -12,7 +12,7 @@ import { rangeQuery, termQuery, typedSearch } from '@kbn/observability-plugin/se import * as t from 'io-ts'; import moment from 'moment'; import { ESSearchRequest } from '@kbn/es-types'; -import { observabilityAlertDetailsContextRt } from '@kbn/observability-plugin/server/services'; +import { alertDetailsContextRt } from '@kbn/observability-plugin/server/services'; import { ApmDocumentType } from '../../../../common/document_type'; import { APMEventClient, @@ -26,7 +26,7 @@ export async function getServiceNameFromSignals({ coreContext, apmEventClient, }: { - query: t.TypeOf; + query: t.TypeOf; esClient: ElasticsearchClient; coreContext: Pick; apmEventClient: APMEventClient; 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 d6022876c9f3b..85032b2f05b53 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,176 +5,236 @@ * 2.0. */ -import type { ScopedAnnotationsClient } from '@kbn/observability-plugin/server'; -import type { ElasticsearchClient } from '@kbn/core-elasticsearch-server'; -import type { CoreRequestHandlerContext, Logger } from '@kbn/core/server'; +import { Logger } from '@kbn/core/server'; import { - AlertDetailsContextualInsight, AlertDetailsContextualInsightsHandlerQuery, + AlertDetailsContextualInsightsRequestContext, } from '@kbn/observability-plugin/server/services'; import moment from 'moment'; -import type { MlClient } from '../../../lib/helpers/get_ml_client'; -import type { APMEventClient } from '../../../lib/helpers/create_es_client/create_apm_event_client'; -import type { ApmAlertsClient } from '../../../lib/helpers/get_apm_alerts_client'; +import { isEmpty } from 'lodash'; +import { getApmAlertsClient } from '../../../lib/helpers/get_apm_alerts_client'; +import { getApmEventClient } from '../../../lib/helpers/get_apm_event_client'; +import { getMlClient } from '../../../lib/helpers/get_ml_client'; +import { getRandomSampler } from '../../../lib/helpers/get_random_sampler'; import { getApmServiceSummary } from '../get_apm_service_summary'; import { getAssistantDownstreamDependencies } from '../get_apm_downstream_dependencies'; import { getLogCategories } from '../get_log_categories'; import { getAnomalies } from '../get_apm_service_summary/get_anomalies'; import { getServiceNameFromSignals } from './get_service_name_from_signals'; import { getContainerIdFromSignals } from './get_container_id_from_signals'; -import { getApmAlertDetailsContextPrompt } from './get_apm_alert_details_context_prompt'; import { getExitSpanChangePoints, getServiceChangePoints } from '../get_changepoints'; +import { APMRouteHandlerResources } from '../../apm_routes/register_apm_server_routes'; -export async function getObservabilityAlertDetailsContext({ - coreContext, - annotationsClient, - apmAlertsClient, - apmEventClient, - esClient, - logger, - mlClient, - query, -}: { - coreContext: Pick; - annotationsClient?: ScopedAnnotationsClient; - apmAlertsClient: ApmAlertsClient; - apmEventClient: APMEventClient; - esClient: ElasticsearchClient; - logger: Logger; - mlClient?: MlClient; - query: AlertDetailsContextualInsightsHandlerQuery; -}): Promise { - const alertStartedAt = query.alert_started_at; - const serviceEnvironment = query['service.environment']; - const hostName = query['host.name']; - const kubernetesPodName = query['kubernetes.pod.name']; - const [serviceName, containerId] = await Promise.all([ - getServiceNameFromSignals({ - query, - esClient, - coreContext, - apmEventClient, - }), - getContainerIdFromSignals({ - query, - esClient, - coreContext, - apmEventClient, - }), - ]); +export const getAlertDetailsContextHandler = ( + resourcePlugins: APMRouteHandlerResources['plugins'], + logger: Logger +) => { + return async ( + requestContext: AlertDetailsContextualInsightsRequestContext, + query: AlertDetailsContextualInsightsHandlerQuery + ) => { + const resources = { + getApmIndices: async () => { + const coreContext = await requestContext.core; + return resourcePlugins.apmDataAccess.setup.getApmIndices(coreContext.savedObjects.client); + }, + request: requestContext.request, + params: { query: { _inspect: false } }, + plugins: resourcePlugins, + context: { + core: requestContext.core, + licensing: requestContext.licensing, + alerting: resourcePlugins.alerting!.start().then((startContract) => { + return { + getRulesClient() { + return startContract.getRulesClientWithRequest(requestContext.request); + }, + }; + }), + rac: resourcePlugins.ruleRegistry.start().then((startContract) => { + return { + getAlertsClient() { + return startContract.getRacClientWithRequest(requestContext.request); + }, + }; + }), + }, + }; + + const [apmEventClient, annotationsClient, apmAlertsClient, coreContext, mlClient] = + await Promise.all([ + getApmEventClient(resources), + resourcePlugins.observability.setup.getScopedAnnotationsClient( + resources.context, + requestContext.request + ), + getApmAlertsClient(resources), + requestContext.core, + getMlClient(resources), + getRandomSampler({ + security: resourcePlugins.security, + probability: 1, + request: requestContext.request, + }), + ]); + const esClient = coreContext.elasticsearch.client.asCurrentUser; + + const alertStartedAt = query.alert_started_at; + const serviceEnvironment = query['service.environment']; + const hostName = query['host.name']; + const kubernetesPodName = query['kubernetes.pod.name']; + const [serviceName, containerId] = await Promise.all([ + getServiceNameFromSignals({ + query, + esClient, + coreContext, + apmEventClient, + }), + getContainerIdFromSignals({ + query, + esClient, + coreContext, + apmEventClient, + }), + ]); - async function handleError(cb: () => Promise): Promise { - try { - return await cb(); - } catch (error) { - logger.error('Error while fetching observability alert details context'); - logger.error(error); - return; + async function handleError(cb: () => Promise): Promise { + try { + return await cb(); + } catch (error) { + logger.error('Error while fetching observability alert details context'); + logger.error(error); + return; + } } - } - const serviceSummaryPromise = serviceName - ? handleError(() => - getApmServiceSummary({ - apmEventClient, - annotationsClient, - esClient, - apmAlertsClient, - mlClient, - logger, - arguments: { - 'service.name': serviceName, - 'service.environment': serviceEnvironment, - start: moment(alertStartedAt).subtract(5, 'minute').toISOString(), - end: alertStartedAt, - }, - }) - ) - : undefined; + const serviceSummaryPromise = serviceName + ? handleError(() => + getApmServiceSummary({ + apmEventClient, + annotationsClient, + esClient, + apmAlertsClient, + mlClient, + logger, + arguments: { + 'service.name': serviceName, + 'service.environment': serviceEnvironment, + start: moment(alertStartedAt).subtract(5, 'minute').toISOString(), + end: alertStartedAt, + }, + }) + ) + : undefined; - const downstreamDependenciesPromise = serviceName - ? handleError(() => - getAssistantDownstreamDependencies({ - apmEventClient, - arguments: { - 'service.name': serviceName, - 'service.environment': serviceEnvironment, - start: moment(alertStartedAt).subtract(5, 'minute').toISOString(), - end: alertStartedAt, - }, - }) - ) - : undefined; + const downstreamDependenciesPromise = serviceName + ? handleError(() => + getAssistantDownstreamDependencies({ + apmEventClient, + arguments: { + 'service.name': serviceName, + 'service.environment': serviceEnvironment, + start: moment(alertStartedAt).subtract(15, 'minute').toISOString(), + end: alertStartedAt, + }, + }) + ) + : undefined; - const logCategoriesPromise = handleError(() => - getLogCategories({ - esClient, - coreContext, - arguments: { - start: moment(alertStartedAt).subtract(5, 'minute').toISOString(), - end: alertStartedAt, - 'service.name': serviceName, - 'host.name': hostName, - 'container.id': containerId, - 'kubernetes.pod.name': kubernetesPodName, - }, - }) - ); + const logCategoriesPromise = handleError(() => + getLogCategories({ + esClient, + coreContext, + arguments: { + start: moment(alertStartedAt).subtract(15, 'minute').toISOString(), + end: alertStartedAt, + 'service.name': serviceName, + 'host.name': hostName, + 'container.id': containerId, + 'kubernetes.pod.name': kubernetesPodName, + }, + }) + ); - const serviceChangePointsPromise = handleError(() => - getServiceChangePoints({ - apmEventClient, - alertStartedAt, - serviceName, - serviceEnvironment, - transactionType: query['transaction.type'], - transactionName: query['transaction.name'], - }) - ); + const serviceChangePointsPromise = handleError(() => + getServiceChangePoints({ + apmEventClient, + start: moment(alertStartedAt).subtract(6, 'hours').toISOString(), + end: alertStartedAt, + serviceName, + serviceEnvironment, + transactionType: query['transaction.type'], + transactionName: query['transaction.name'], + }) + ); - const exitSpanChangePointsPromise = handleError(() => - getExitSpanChangePoints({ - apmEventClient, - alertStartedAt, - serviceName, - serviceEnvironment, - }) - ); + const exitSpanChangePointsPromise = handleError(() => + getExitSpanChangePoints({ + apmEventClient, + start: moment(alertStartedAt).subtract(6, 'hours').toISOString(), + end: alertStartedAt, + serviceName, + serviceEnvironment, + }) + ); - const anomaliesPromise = handleError(() => - getAnomalies({ - start: moment(alertStartedAt).subtract(1, 'hour').valueOf(), - end: moment(alertStartedAt).valueOf(), - environment: serviceEnvironment, - mlClient, - logger, - }) - ); + const anomaliesPromise = handleError(() => + getAnomalies({ + start: moment(alertStartedAt).subtract(1, 'hour').valueOf(), + end: moment(alertStartedAt).valueOf(), + environment: serviceEnvironment, + mlClient, + logger, + }) + ); - const [ - serviceSummary, - downstreamDependencies, - logCategories, - serviceChangePoints, - exitSpanChangePoints, - anomalies, - ] = await Promise.all([ - serviceSummaryPromise, - downstreamDependenciesPromise, - logCategoriesPromise, - serviceChangePointsPromise, - exitSpanChangePointsPromise, - anomaliesPromise, - ]); + const [ + serviceSummary, + downstreamDependencies, + logCategories, + serviceChangePoints, + exitSpanChangePoints, + anomalies, + ] = await Promise.all([ + serviceSummaryPromise, + downstreamDependenciesPromise, + logCategoriesPromise, + serviceChangePointsPromise, + exitSpanChangePointsPromise, + anomaliesPromise, + ]); - return getApmAlertDetailsContextPrompt({ - serviceName, - serviceEnvironment, - serviceSummary, - downstreamDependencies, - logCategories, - serviceChangePoints, - exitSpanChangePoints, - anomalies, - }); -} + return [ + { + key: 'serviceSummary', + description: 'Metadata for the service where the alert occurred', + data: serviceSummary, + }, + { + key: 'downstreamDependencies', + description: `Downstream dependencies from the service "${serviceName}". Problems in these services can negatively affect the performance of "${serviceName}"`, + data: downstreamDependencies, + }, + { + key: 'serviceChangePoints', + description: `Significant change points for "${serviceName}". Use this to spot dips and spikes in throughput, latency and failure rate`, + data: serviceChangePoints, + }, + { + key: 'exitSpanChangePoints', + description: `Significant change points for the dependencies of "${serviceName}". Use this to spot dips or spikes in throughput, latency and failure rate for downstream dependencies`, + data: exitSpanChangePoints, + }, + { + key: 'logCategories', + description: `Log events occurring around the time of the alert`, + data: logCategories, + }, + { + key: 'anomalies', + description: `Anomalies for services running in the environment "${serviceEnvironment}"`, + data: anomalies, + }, + ].filter(({ data }) => !isEmpty(data)); + }; +}; 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 af3dfac613bd5..68b7362f85d85 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 @@ -6,16 +6,8 @@ */ import * as t from 'io-ts'; import { omit } from 'lodash'; -import { - AlertDetailsContextualInsight, - observabilityAlertDetailsContextRt, -} from '@kbn/observability-plugin/server/services'; -import { getApmAlertsClient } from '../../lib/helpers/get_apm_alerts_client'; import { getApmEventClient } from '../../lib/helpers/get_apm_event_client'; -import { getMlClient } from '../../lib/helpers/get_ml_client'; -import { getRandomSampler } from '../../lib/helpers/get_random_sampler'; import { createApmServerRoute } from '../apm_routes/create_apm_server_route'; -import { getObservabilityAlertDetailsContext } from './get_observability_alert_details_context'; import { downstreamDependenciesRouteRt, @@ -24,49 +16,6 @@ import { } from './get_apm_downstream_dependencies'; import { getApmTimeseries, getApmTimeseriesRt, type ApmTimeseries } from './get_apm_timeseries'; -const getObservabilityAlertDetailsContextRoute = createApmServerRoute({ - endpoint: 'GET /internal/apm/assistant/alert_details_contextual_insights', - options: { - tags: ['access:apm'], - }, - - params: t.type({ - query: observabilityAlertDetailsContextRt, - }), - handler: async (resources): Promise<{ context: AlertDetailsContextualInsight[] }> => { - const { context, request, plugins, logger, params } = resources; - const { query } = params; - - const [apmEventClient, annotationsClient, coreContext, apmAlertsClient, mlClient] = - await Promise.all([ - getApmEventClient(resources), - plugins.observability.setup.getScopedAnnotationsClient(context, request), - context.core, - getApmAlertsClient(resources), - getMlClient(resources), - getRandomSampler({ - security: resources.plugins.security, - probability: 1, - request: resources.request, - }), - ]); - const esClient = coreContext.elasticsearch.client.asCurrentUser; - - const obsAlertContext = await getObservabilityAlertDetailsContext({ - coreContext, - annotationsClient, - apmAlertsClient, - apmEventClient, - esClient, - logger, - mlClient, - query, - }); - - return { context: obsAlertContext }; - }, -}); - const getApmTimeSeriesRoute = createApmServerRoute({ endpoint: 'POST /internal/apm/assistant/get_apm_timeseries', options: { @@ -120,6 +69,5 @@ const getDownstreamDependenciesRoute = createApmServerRoute({ export const assistantRouteRepository = { ...getApmTimeSeriesRoute, - ...getObservabilityAlertDetailsContextRoute, ...getDownstreamDependenciesRoute, }; diff --git a/x-pack/plugins/observability_solution/observability/public/pages/alert_details/alert_details_contextual_insights.tsx b/x-pack/plugins/observability_solution/observability/public/pages/alert_details/alert_details_contextual_insights.tsx index 1de4b4a136919..7754badbf121d 100644 --- a/x-pack/plugins/observability_solution/observability/public/pages/alert_details/alert_details_contextual_insights.tsx +++ b/x-pack/plugins/observability_solution/observability/public/pages/alert_details/alert_details_contextual_insights.tsx @@ -10,6 +10,7 @@ import { EuiFlexGroup, EuiFlexItem } from '@elastic/eui'; import React, { useCallback } from 'react'; import { i18n } from '@kbn/i18n'; import dedent from 'dedent'; +import { type AlertDetailsContextualInsight } from '../../../server/services'; import { useKibana } from '../../utils/kibana_react'; import { AlertData } from '../../hooks/use_fetch_alert_detail'; @@ -21,16 +22,16 @@ export function AlertDetailContextualInsights({ alert }: { alert: AlertData | nu const ObservabilityAIAssistantContextualInsight = observabilityAIAssistant?.ObservabilityAIAssistantContextualInsight; - const getPromptMessages = useCallback(async () => { + const getAlertContextMessages = useCallback(async () => { const fields = alert?.formatted.fields as Record | undefined; if (!observabilityAIAssistant || !fields || !alert) { return []; } try { - const { context } = await http.get<{ - context: Array<{ description: string; data: unknown }>; - }>('/internal/apm/assistant/alert_details_contextual_insights', { + const { alertContext } = await http.get<{ + alertContext: AlertDetailsContextualInsight[]; + }>('/internal/observability/assistant/alert_details_contextual_insights', { query: { alert_started_at: new Date(alert.formatted.start).toISOString(), @@ -47,26 +48,28 @@ export function AlertDetailContextualInsights({ alert }: { alert: AlertData | nu }, }); - const obsAlertContext = context + const obsAlertContext = alertContext .map(({ description, data }) => `${description}:\n${JSON.stringify(data, null, 2)}`) .join('\n\n'); return observabilityAIAssistant.getContextualInsightMessages({ message: `I'm looking at an alert and trying to understand why it was triggered`, instructions: dedent( - `I'm an SRE. I am looking at an alert that was triggered. I want to understand why it was triggered, what it means, and what I should do next. + `I'm an SRE. I am looking at an alert that was triggered. I want to understand why it was triggered, what it means, and what I should do next. - The following contextual information is available to help me understand the alert: + The following contextual information is available to help you understand the alert: ${obsAlertContext} Be brief and to the point. Do not list the alert details as bullet points. Refer to the contextual information provided above when relevant. - Pay specific attention to why the alert happened and what may have contributed to it. + Pay special attention to regressions in downstream dependencies like big increases or decreases in throughput, latency or failure rate + Suggest reasons why the alert happened and what may have contributed to it. ` ), }); } catch (e) { + console.error('An error occurred while fetching alert context', e); return observabilityAIAssistant.getContextualInsightMessages({ message: `I'm looking at an alert and trying to understand why it was triggered`, instructions: dedent( @@ -88,7 +91,7 @@ export function AlertDetailContextualInsights({ alert }: { alert: AlertData | nu 'xpack.observability.alertDetailContextualInsights.InsightButtonLabel', { defaultMessage: 'Help me understand this alert' } )} - messages={getPromptMessages} + messages={getAlertContextMessages} /> diff --git a/x-pack/plugins/observability_solution/observability/server/routes/assistant/route.ts b/x-pack/plugins/observability_solution/observability/server/routes/assistant/route.ts new file mode 100644 index 0000000000000..e6e04704971d2 --- /dev/null +++ b/x-pack/plugins/observability_solution/observability/server/routes/assistant/route.ts @@ -0,0 +1,37 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import * as t from 'io-ts'; +import { alertDetailsContextRt } from '../../services'; +import { createObservabilityServerRoute } from '../create_observability_server_route'; + +const getObservabilityAlertDetailsContextRoute = createObservabilityServerRoute({ + endpoint: 'GET /internal/observability/assistant/alert_details_contextual_insights', + options: { + tags: [], + }, + params: t.type({ + query: alertDetailsContextRt, + }), + handler: async ({ dependencies, params, context, request }) => { + const alertContext = + await dependencies.assistant.alertDetailsContextualInsightsService.getAlertDetailsContext( + { + core: context.core, + licensing: context.licensing, + request, + }, + params.query + ); + + return { alertContext }; + }, +}); + +export const aiAssistantRouteRepository = { + ...getObservabilityAlertDetailsContextRoute, +}; diff --git a/x-pack/plugins/observability_solution/observability/server/routes/get_global_observability_server_route_repository.ts b/x-pack/plugins/observability_solution/observability/server/routes/get_global_observability_server_route_repository.ts index 78c4a2614b528..1516c42f86fd1 100644 --- a/x-pack/plugins/observability_solution/observability/server/routes/get_global_observability_server_route_repository.ts +++ b/x-pack/plugins/observability_solution/observability/server/routes/get_global_observability_server_route_repository.ts @@ -5,11 +5,14 @@ * 2.0. */ +import { EndpointOf } from '@kbn/server-route-repository'; import { ObservabilityConfig } from '..'; +import { aiAssistantRouteRepository } from './assistant/route'; import { rulesRouteRepository } from './rules/route'; export function getObservabilityServerRouteRepository(config: ObservabilityConfig) { const repository = { + ...aiAssistantRouteRepository, ...rulesRouteRepository, }; return repository; @@ -18,3 +21,5 @@ export function getObservabilityServerRouteRepository(config: ObservabilityConfi export type ObservabilityServerRouteRepository = ReturnType< typeof getObservabilityServerRouteRepository >; + +export type APIEndpoint = EndpointOf; diff --git a/x-pack/plugins/observability_solution/observability/server/routes/types.ts b/x-pack/plugins/observability_solution/observability/server/routes/types.ts index a0ef6ee6c0c74..3940253137640 100644 --- a/x-pack/plugins/observability_solution/observability/server/routes/types.ts +++ b/x-pack/plugins/observability_solution/observability/server/routes/types.ts @@ -7,12 +7,15 @@ import type { EndpointOf, ReturnOf, ServerRouteRepository } from '@kbn/server-route-repository'; import { KibanaRequest, Logger } from '@kbn/core/server'; -import { ObservabilityServerRouteRepository } from './get_global_observability_server_route_repository'; +import { + ObservabilityServerRouteRepository, + APIEndpoint, +} from './get_global_observability_server_route_repository'; import { ObservabilityRequestHandlerContext } from '../types'; import { RegisterRoutesDependencies } from './register_routes'; import { ObservabilityConfig } from '..'; -export type { ObservabilityServerRouteRepository }; +export type { ObservabilityServerRouteRepository, APIEndpoint }; export interface ObservabilityRouteHandlerResources { context: ObservabilityRequestHandlerContext; diff --git a/x-pack/plugins/observability_solution/observability/server/services/index.ts b/x-pack/plugins/observability_solution/observability/server/services/index.ts index 7c20d191440d6..840bac95ee48b 100644 --- a/x-pack/plugins/observability_solution/observability/server/services/index.ts +++ b/x-pack/plugins/observability_solution/observability/server/services/index.ts @@ -13,9 +13,9 @@ import { SavedObjectsClientContract, } from '@kbn/core/server'; import { LicensingApiRequestHandlerContext } from '@kbn/licensing-plugin/server'; -import { concat } from 'lodash'; +import { flatten } from 'lodash'; -export const observabilityAlertDetailsContextRt = t.intersection([ +export const alertDetailsContextRt = t.intersection([ t.type({ alert_started_at: t.string, }), @@ -33,9 +33,7 @@ export const observabilityAlertDetailsContextRt = t.intersection([ }), ]); -export type AlertDetailsContextualInsightsHandlerQuery = t.TypeOf< - typeof observabilityAlertDetailsContextRt ->; +export type AlertDetailsContextualInsightsHandlerQuery = t.TypeOf; export interface AlertDetailsContextualInsight { key: string; @@ -77,11 +75,21 @@ export class AlertDetailsContextualInsightsService { context: AlertDetailsContextualInsightsRequestContext, query: AlertDetailsContextualInsightsHandlerQuery ): Promise { - if (this.handlers.length === 0) return []; + if (this.handlers.length === 0) { + return []; + } - return Promise.all(this.handlers.map((handler) => handler(context, query))).then((results) => { - const [head, ...rest] = results; - return concat(head, ...rest); - }); + const results = await Promise.all( + this.handlers.map(async (handler) => { + try { + return await handler(context, query); + } catch (error) { + console.error(`Error: Could not get alert context from handler`, error); + return []; + } + }) + ); + + return flatten(results); } } diff --git a/x-pack/plugins/observability_solution/observability/server/types.ts b/x-pack/plugins/observability_solution/observability/server/types.ts index 76a209f318078..8c298d239a53d 100644 --- a/x-pack/plugins/observability_solution/observability/server/types.ts +++ b/x-pack/plugins/observability_solution/observability/server/types.ts @@ -19,6 +19,7 @@ export type { ObservabilityRouteHandlerResources, AbstractObservabilityServerRouteRepository, ObservabilityServerRouteRepository, + APIEndpoint, ObservabilityAPIReturnType, } from './routes/types'; diff --git a/x-pack/test/apm_api_integration/common/config.ts b/x-pack/test/apm_api_integration/common/config.ts index a4f02524b98cf..c22fb0325288b 100644 --- a/x-pack/test/apm_api_integration/common/config.ts +++ b/x-pack/test/apm_api_integration/common/config.ts @@ -75,7 +75,7 @@ export interface CreateTest { logSynthtraceEsClient: ( context: InheritedFtrProviderContext ) => Promise; - synthtraceEsClient: (context: InheritedFtrProviderContext) => Promise; + apmSynthtraceEsClient: (context: InheritedFtrProviderContext) => Promise; synthtraceKibanaClient: ( context: InheritedFtrProviderContext ) => Promise; @@ -112,7 +112,7 @@ export function createTestConfig( ...services, apmFtrConfig: () => config, registry: RegistryProvider, - synthtraceEsClient: (context: InheritedFtrProviderContext) => { + apmSynthtraceEsClient: (context: InheritedFtrProviderContext) => { return bootstrapApmSynthtrace(context, synthtraceKibanaClient); }, logSynthtraceEsClient: (context: InheritedFtrProviderContext) => diff --git a/x-pack/test/apm_api_integration/tests/agent_explorer/agent_explorer.spec.ts b/x-pack/test/apm_api_integration/tests/agent_explorer/agent_explorer.spec.ts index 7fea0939d41ee..95e71167aaab4 100644 --- a/x-pack/test/apm_api_integration/tests/agent_explorer/agent_explorer.spec.ts +++ b/x-pack/test/apm_api_integration/tests/agent_explorer/agent_explorer.spec.ts @@ -14,7 +14,7 @@ import { FtrProviderContext } from '../../common/ftr_provider_context'; export default function ApiTest({ getService }: FtrProviderContext) { const registry = getService('registry'); const apmApiClient = getService('apmApiClient'); - const synthtraceEsClient = getService('synthtraceEsClient'); + const apmSynthtraceEsClient = getService('apmSynthtraceEsClient'); const start = new Date('2021-01-01T00:00:00.000Z').getTime(); const end = new Date('2021-01-01T00:15:00.000Z').getTime() - 1; @@ -103,7 +103,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { 'service.language.name': 'javascript', }); - await synthtraceEsClient.index([ + await apmSynthtraceEsClient.index([ timerange(start, end) .interval('5m') .rate(1) @@ -143,7 +143,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { ]); }); - after(() => synthtraceEsClient.clean()); + after(() => apmSynthtraceEsClient.clean()); it('labels.telemetry_auto_version takes precedence over agent.version for otelAgets', async () => { const { status, body } = await callApi(); diff --git a/x-pack/test/apm_api_integration/tests/alerts/anomaly_alert.spec.ts b/x-pack/test/apm_api_integration/tests/alerts/anomaly_alert.spec.ts index f98a82a6cd30c..033d64e8f12e8 100644 --- a/x-pack/test/apm_api_integration/tests/alerts/anomaly_alert.spec.ts +++ b/x-pack/test/apm_api_integration/tests/alerts/anomaly_alert.spec.ts @@ -26,7 +26,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { const es = getService('es'); const logger = getService('log'); - const synthtraceEsClient = getService('synthtraceEsClient'); + const apmSynthtraceEsClient = getService('apmSynthtraceEsClient'); registry.when( 'fetching service anomalies with a trial license', { config: 'trial', archives: [] }, @@ -62,7 +62,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { ]; }); - await synthtraceEsClient.index(events); + await apmSynthtraceEsClient.index(events); await createAndRunApmMlJobs({ es, ml, environments: ['production'], logger }); }); @@ -72,7 +72,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { }); async function cleanup() { - await synthtraceEsClient.clean(); + await apmSynthtraceEsClient.clean(); await cleanupRuleAndAlertState({ es, supertest, logger }); await ml.cleanMlIndices(); } diff --git a/x-pack/test/apm_api_integration/tests/alerts/error_count_threshold.spec.ts b/x-pack/test/apm_api_integration/tests/alerts/error_count_threshold.spec.ts index 545706af43107..46d62449de475 100644 --- a/x-pack/test/apm_api_integration/tests/alerts/error_count_threshold.spec.ts +++ b/x-pack/test/apm_api_integration/tests/alerts/error_count_threshold.spec.ts @@ -31,7 +31,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { const es = getService('es'); const logger = getService('log'); const apmApiClient = getService('apmApiClient'); - const synthtraceEsClient = getService('synthtraceEsClient'); + const apmSynthtraceEsClient = getService('apmSynthtraceEsClient'); registry.when('error count threshold alert', { config: 'basic', archives: [] }, () => { const javaErrorMessage = 'a java error'; @@ -96,10 +96,13 @@ export default function ApiTest({ getService }: FtrProviderContext) { ]; }); - return Promise.all([synthtraceEsClient.index(events), synthtraceEsClient.index(phpEvents)]); + return Promise.all([ + apmSynthtraceEsClient.index(events), + apmSynthtraceEsClient.index(phpEvents), + ]); }); - after(() => synthtraceEsClient.clean()); + after(() => apmSynthtraceEsClient.clean()); // FLAKY: https://github.com/elastic/kibana/issues/176948 describe('create rule without kql filter', () => { diff --git a/x-pack/test/apm_api_integration/tests/alerts/generate_data.ts b/x-pack/test/apm_api_integration/tests/alerts/generate_data.ts index 2765c0a1e265b..79fd804aea1cd 100644 --- a/x-pack/test/apm_api_integration/tests/alerts/generate_data.ts +++ b/x-pack/test/apm_api_integration/tests/alerts/generate_data.ts @@ -21,12 +21,12 @@ export const config = { }; export async function generateLatencyData({ - synthtraceEsClient, + apmSynthtraceEsClient, serviceName, start, end, }: { - synthtraceEsClient: ApmSynthtraceEsClient; + apmSynthtraceEsClient: ApmSynthtraceEsClient; serviceName: string; start: number; end: number; @@ -58,16 +58,16 @@ export async function generateLatencyData({ ), ]; - await synthtraceEsClient.index(documents); + await apmSynthtraceEsClient.index(documents); } export async function generateErrorData({ - synthtraceEsClient, + apmSynthtraceEsClient, serviceName, start, end, }: { - synthtraceEsClient: ApmSynthtraceEsClient; + apmSynthtraceEsClient: ApmSynthtraceEsClient; serviceName: string; start: number; end: number; @@ -110,5 +110,5 @@ export async function generateErrorData({ ]; }); - await synthtraceEsClient.index(documents); + await apmSynthtraceEsClient.index(documents); } diff --git a/x-pack/test/apm_api_integration/tests/alerts/preview_chart_error_count.spec.ts b/x-pack/test/apm_api_integration/tests/alerts/preview_chart_error_count.spec.ts index c1b2243c1373d..897f446734444 100644 --- a/x-pack/test/apm_api_integration/tests/alerts/preview_chart_error_count.spec.ts +++ b/x-pack/test/apm_api_integration/tests/alerts/preview_chart_error_count.spec.ts @@ -19,7 +19,7 @@ import { generateErrorData } from './generate_data'; export default function ApiTest({ getService }: FtrProviderContext) { const registry = getService('registry'); const apmApiClient = getService('apmApiClient'); - const synthtraceEsClient = getService('synthtraceEsClient'); + const apmSynthtraceEsClient = getService('apmSynthtraceEsClient'); const start = new Date('2021-01-01T00:00:00.000Z').getTime(); const end = new Date('2021-01-01T00:15:00.000Z').getTime() - 1; @@ -72,11 +72,11 @@ export default function ApiTest({ getService }: FtrProviderContext) { // FLAKY: https://github.com/elastic/kibana/issues/172769 describe('error_count', () => { beforeEach(async () => { - await generateErrorData({ serviceName: 'synth-go', start, end, synthtraceEsClient }); - await generateErrorData({ serviceName: 'synth-java', start, end, synthtraceEsClient }); + await generateErrorData({ serviceName: 'synth-go', start, end, apmSynthtraceEsClient }); + await generateErrorData({ serviceName: 'synth-java', start, end, apmSynthtraceEsClient }); }); - afterEach(() => synthtraceEsClient.clean()); + afterEach(() => apmSynthtraceEsClient.clean()); it('with data', async () => { const options = getOptions(); @@ -308,11 +308,11 @@ export default function ApiTest({ getService }: FtrProviderContext) { // FLAKY: https://github.com/elastic/kibana/issues/176975 describe('error_count', () => { before(async () => { - await generateErrorData({ serviceName: 'synth-go', start, end, synthtraceEsClient }); - await generateErrorData({ serviceName: 'synth-java', start, end, synthtraceEsClient }); + await generateErrorData({ serviceName: 'synth-go', start, end, apmSynthtraceEsClient }); + await generateErrorData({ serviceName: 'synth-java', start, end, apmSynthtraceEsClient }); }); - after(() => synthtraceEsClient.clean()); + after(() => apmSynthtraceEsClient.clean()); it('with data', async () => { const options = getOptionsWithFilterQuery(); diff --git a/x-pack/test/apm_api_integration/tests/alerts/preview_chart_error_rate.spec.ts b/x-pack/test/apm_api_integration/tests/alerts/preview_chart_error_rate.spec.ts index 2a3479bcffea0..bc11d1cb68fd9 100644 --- a/x-pack/test/apm_api_integration/tests/alerts/preview_chart_error_rate.spec.ts +++ b/x-pack/test/apm_api_integration/tests/alerts/preview_chart_error_rate.spec.ts @@ -19,7 +19,7 @@ import { generateErrorData } from './generate_data'; export default function ApiTest({ getService }: FtrProviderContext) { const registry = getService('registry'); const apmApiClient = getService('apmApiClient'); - const synthtraceEsClient = getService('synthtraceEsClient'); + const apmSynthtraceEsClient = getService('apmSynthtraceEsClient'); const start = new Date('2021-01-01T00:00:00.000Z').getTime(); const end = new Date('2021-01-01T00:15:00.000Z').getTime() - 1; @@ -73,11 +73,11 @@ export default function ApiTest({ getService }: FtrProviderContext) { // FLAKY: https://github.com/elastic/kibana/issues/176977 describe('transaction_error_rate', () => { before(async () => { - await generateErrorData({ serviceName: 'synth-go', start, end, synthtraceEsClient }); - await generateErrorData({ serviceName: 'synth-java', start, end, synthtraceEsClient }); + await generateErrorData({ serviceName: 'synth-go', start, end, apmSynthtraceEsClient }); + await generateErrorData({ serviceName: 'synth-java', start, end, apmSynthtraceEsClient }); }); - after(() => synthtraceEsClient.clean()); + after(() => apmSynthtraceEsClient.clean()); it('with data', async () => { const options = getOptions(); @@ -332,11 +332,11 @@ export default function ApiTest({ getService }: FtrProviderContext) { // FLAKY: https://github.com/elastic/kibana/issues/176983 describe('transaction_error_rate', () => { before(async () => { - await generateErrorData({ serviceName: 'synth-go', start, end, synthtraceEsClient }); - await generateErrorData({ serviceName: 'synth-java', start, end, synthtraceEsClient }); + await generateErrorData({ serviceName: 'synth-go', start, end, apmSynthtraceEsClient }); + await generateErrorData({ serviceName: 'synth-java', start, end, apmSynthtraceEsClient }); }); - after(() => synthtraceEsClient.clean()); + after(() => apmSynthtraceEsClient.clean()); it('with data', async () => { const options = getOptionsWithFilterQuery(); diff --git a/x-pack/test/apm_api_integration/tests/alerts/preview_chart_transaction_duration.spec.ts b/x-pack/test/apm_api_integration/tests/alerts/preview_chart_transaction_duration.spec.ts index 3c149458ce222..4bae66ed9e66b 100644 --- a/x-pack/test/apm_api_integration/tests/alerts/preview_chart_transaction_duration.spec.ts +++ b/x-pack/test/apm_api_integration/tests/alerts/preview_chart_transaction_duration.spec.ts @@ -19,7 +19,7 @@ import { generateLatencyData } from './generate_data'; export default function ApiTest({ getService }: FtrProviderContext) { const registry = getService('registry'); const apmApiClient = getService('apmApiClient'); - const synthtraceEsClient = getService('synthtraceEsClient'); + const apmSynthtraceEsClient = getService('apmSynthtraceEsClient'); const start = new Date('2021-01-01T00:00:00.000Z').getTime(); const end = new Date('2021-01-01T00:15:00.000Z').getTime() - 1; @@ -76,11 +76,11 @@ export default function ApiTest({ getService }: FtrProviderContext) { // Failing: See https://github.com/elastic/kibana/issues/176989 describe('transaction_duration', () => { before(async () => { - await generateLatencyData({ serviceName: 'synth-go', start, end, synthtraceEsClient }); - await generateLatencyData({ serviceName: 'synth-java', start, end, synthtraceEsClient }); + await generateLatencyData({ serviceName: 'synth-go', start, end, apmSynthtraceEsClient }); + await generateLatencyData({ serviceName: 'synth-java', start, end, apmSynthtraceEsClient }); }); - after(() => synthtraceEsClient.clean()); + after(() => apmSynthtraceEsClient.clean()); it('with data', async () => { const options = getOptions(); @@ -304,11 +304,11 @@ export default function ApiTest({ getService }: FtrProviderContext) { registry.when(`with data loaded and using KQL filter`, { config: 'basic', archives: [] }, () => { describe('transaction_duration', () => { before(async () => { - await generateLatencyData({ serviceName: 'synth-go', start, end, synthtraceEsClient }); - await generateLatencyData({ serviceName: 'synth-java', start, end, synthtraceEsClient }); + await generateLatencyData({ serviceName: 'synth-go', start, end, apmSynthtraceEsClient }); + await generateLatencyData({ serviceName: 'synth-java', start, end, apmSynthtraceEsClient }); }); - after(() => synthtraceEsClient.clean()); + after(() => apmSynthtraceEsClient.clean()); it('with data', async () => { const options = getOptionsWithFilterQuery(); diff --git a/x-pack/test/apm_api_integration/tests/alerts/transaction_duration.spec.ts b/x-pack/test/apm_api_integration/tests/alerts/transaction_duration.spec.ts index 5eab7e772a4cd..7d4ec54fa52fb 100644 --- a/x-pack/test/apm_api_integration/tests/alerts/transaction_duration.spec.ts +++ b/x-pack/test/apm_api_integration/tests/alerts/transaction_duration.spec.ts @@ -31,7 +31,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { const es = getService('es'); const logger = getService('log'); const apmApiClient = getService('apmApiClient'); - const synthtraceEsClient = getService('synthtraceEsClient'); + const apmSynthtraceEsClient = getService('apmSynthtraceEsClient'); const ruleParams = { threshold: 3000, @@ -68,11 +68,11 @@ export default function ApiTest({ getService }: FtrProviderContext) { .success(), ]; }); - return synthtraceEsClient.index(events); + return apmSynthtraceEsClient.index(events); }); after(async () => { - await synthtraceEsClient.clean(); + await apmSynthtraceEsClient.clean(); }); // FLAKY: https://github.com/elastic/kibana/issues/176996 diff --git a/x-pack/test/apm_api_integration/tests/alerts/transaction_error_rate.spec.ts b/x-pack/test/apm_api_integration/tests/alerts/transaction_error_rate.spec.ts index ec66b7aaf67ec..6416337c3bfc9 100644 --- a/x-pack/test/apm_api_integration/tests/alerts/transaction_error_rate.spec.ts +++ b/x-pack/test/apm_api_integration/tests/alerts/transaction_error_rate.spec.ts @@ -30,7 +30,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { const es = getService('es'); const logger = getService('log'); const apmApiClient = getService('apmApiClient'); - const synthtraceEsClient = getService('synthtraceEsClient'); + const apmSynthtraceEsClient = getService('apmSynthtraceEsClient'); registry.when('transaction error rate alert', { config: 'basic', archives: [] }, () => { before(() => { @@ -66,11 +66,11 @@ export default function ApiTest({ getService }: FtrProviderContext) { .success(), ]; }); - return synthtraceEsClient.index(events); + return apmSynthtraceEsClient.index(events); }); after(async () => { - await synthtraceEsClient.clean(); + await apmSynthtraceEsClient.clean(); }); // FLAKY: https://github.com/elastic/kibana/issues/177104 diff --git a/x-pack/test/apm_api_integration/tests/anomalies/anomaly_charts.spec.ts b/x-pack/test/apm_api_integration/tests/anomalies/anomaly_charts.spec.ts index 93effd3984daf..1ba02adbade97 100644 --- a/x-pack/test/apm_api_integration/tests/anomalies/anomaly_charts.spec.ts +++ b/x-pack/test/apm_api_integration/tests/anomalies/anomaly_charts.spec.ts @@ -22,7 +22,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { const ml = getService('ml'); const es = getService('es'); const logger = getService('log'); - const synthtraceEsClient = getService('synthtraceEsClient'); + const apmSynthtraceEsClient = getService('apmSynthtraceEsClient'); const start = moment().subtract(2, 'days'); const end = moment(); @@ -128,7 +128,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { ]; }); - await synthtraceEsClient.index(events); + await apmSynthtraceEsClient.index(events); }); afterEach(async () => { @@ -136,7 +136,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { }); async function cleanup() { - await synthtraceEsClient.clean(); + await apmSynthtraceEsClient.clean(); await ml.cleanMlIndices(); } diff --git a/x-pack/test/apm_api_integration/tests/assistant/obs_alert_details_context.spec.ts b/x-pack/test/apm_api_integration/tests/assistant/obs_alert_details_context.spec.ts deleted file mode 100644 index 5a98ec708bcf3..0000000000000 --- a/x-pack/test/apm_api_integration/tests/assistant/obs_alert_details_context.spec.ts +++ /dev/null @@ -1,507 +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 - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import moment from 'moment'; -import { log, apm, generateShortId, timerange } from '@kbn/apm-synthtrace-client'; -import expect from '@kbn/expect'; -import { LogCategories } from '@kbn/apm-plugin/server/routes/assistant_functions/get_log_categories'; -import { FtrProviderContext } from '../../common/ftr_provider_context'; -import { SupertestReturnType } from '../../common/apm_api_supertest'; - -export default function ApiTest({ getService }: FtrProviderContext) { - const registry = getService('registry'); - const apmApiClient = getService('apmApiClient'); - const apmSynthtraceClient = getService('synthtraceEsClient'); - const logSynthtraceClient = getService('logSynthtraceEsClient'); - - registry.when( - 'fetching observability alerts details context for AI assistant contextual insights', - { config: 'trial', archives: [] }, - () => { - const start = moment().subtract(10, 'minutes').valueOf(); - const end = moment().valueOf(); - const range = timerange(start, end); - - describe('when no traces or logs are available', async () => { - let response: SupertestReturnType<'GET /internal/apm/assistant/alert_details_contextual_insights'>; - before(async () => { - response = await apmApiClient.writeUser({ - endpoint: 'GET /internal/apm/assistant/alert_details_contextual_insights', - params: { - query: { - alert_started_at: new Date(end).toISOString(), - }, - }, - }); - }); - - it('returns nothing', () => { - expect(response.body.context).to.eql([]); - }); - }); - - describe('when traces and logs are ingested and logs are not annotated with service.name', async () => { - before(async () => { - await ingestTraces({ 'service.name': 'Backend', 'container.id': 'my-container-a' }); - await ingestLogs({ - 'container.id': 'my-container-a', - 'kubernetes.pod.name': 'pod-a', - }); - }); - - after(async () => { - await cleanup(); - }); - - describe('when no params are specified', async () => { - let response: SupertestReturnType<'GET /internal/apm/assistant/alert_details_contextual_insights'>; - before(async () => { - response = await apmApiClient.writeUser({ - endpoint: 'GET /internal/apm/assistant/alert_details_contextual_insights', - params: { - query: { - alert_started_at: new Date(end).toISOString(), - }, - }, - }); - }); - - it('returns only 1 log category', async () => { - expect(response.body.context).to.have.length(1); - expect( - (response.body.context[0]?.data as LogCategories)?.map( - ({ errorCategory }: { errorCategory: string }) => errorCategory - ) - ).to.eql(['Error message from container my-container-a']); - }); - }); - - describe('when service name is specified', async () => { - let response: SupertestReturnType<'GET /internal/apm/assistant/alert_details_contextual_insights'>; - before(async () => { - response = await apmApiClient.writeUser({ - endpoint: 'GET /internal/apm/assistant/alert_details_contextual_insights', - params: { - query: { - alert_started_at: new Date(end).toISOString(), - 'service.name': 'Backend', - }, - }, - }); - }); - - it('returns service summary', () => { - const serviceSummary = response.body.context.find( - ({ key }) => key === 'serviceSummary' - ); - expect(serviceSummary?.data).to.eql({ - 'service.name': 'Backend', - 'service.environment': ['production'], - 'agent.name': 'java', - 'service.version': ['1.0.0'], - 'language.name': 'java', - instances: 1, - anomalies: [], - alerts: [], - deployments: [], - }); - }); - - it('returns downstream dependencies', async () => { - const downstreamDependencies = response.body.context.find( - ({ key }) => key === 'downstreamDependencies' - ); - expect(downstreamDependencies?.data).to.eql([ - { - 'span.destination.service.resource': 'elasticsearch', - 'span.type': 'db', - 'span.subtype': 'elasticsearch', - }, - ]); - }); - - it('returns log categories', () => { - const logCategories = response.body.context.find(({ key }) => key === 'logCategories'); - expect(logCategories?.data).to.have.length(1); - - const logCategory = (logCategories?.data as LogCategories)?.[0]; - expect(logCategory?.sampleMessage).to.match( - /Error message #\d{16} from container my-container-a/ - ); - expect(logCategory?.docCount).to.be.greaterThan(0); - expect(logCategory?.errorCategory).to.be('Error message from container my-container-a'); - }); - }); - - describe('when container id is specified', async () => { - let response: SupertestReturnType<'GET /internal/apm/assistant/alert_details_contextual_insights'>; - before(async () => { - response = await apmApiClient.writeUser({ - endpoint: 'GET /internal/apm/assistant/alert_details_contextual_insights', - params: { - query: { - alert_started_at: new Date(end).toISOString(), - 'container.id': 'my-container-a', - }, - }, - }); - }); - - it('returns service summary', () => { - const serviceSummary = response.body.context.find( - ({ key }) => key === 'serviceSummary' - ); - expect(serviceSummary?.data).to.eql({ - 'service.name': 'Backend', - 'service.environment': ['production'], - 'agent.name': 'java', - 'service.version': ['1.0.0'], - 'language.name': 'java', - instances: 1, - anomalies: [], - alerts: [], - deployments: [], - }); - }); - - it('returns downstream dependencies', async () => { - const downstreamDependencies = response.body.context.find( - ({ key }) => key === 'downstreamDependencies' - ); - expect(downstreamDependencies?.data).to.eql([ - { - 'span.destination.service.resource': 'elasticsearch', - 'span.type': 'db', - 'span.subtype': 'elasticsearch', - }, - ]); - }); - - it('returns log categories', () => { - const logCategories = response.body.context.find(({ key }) => key === 'logCategories'); - expect(logCategories?.data).to.have.length(1); - - const logCategory = (logCategories?.data as LogCategories)?.[0]; - expect(logCategory?.sampleMessage).to.match( - /Error message #\d{16} from container my-container-a/ - ); - expect(logCategory?.docCount).to.be.greaterThan(0); - expect(logCategory?.errorCategory).to.be('Error message from container my-container-a'); - }); - }); - - describe('when non-existing container id is specified', async () => { - let response: SupertestReturnType<'GET /internal/apm/assistant/alert_details_contextual_insights'>; - before(async () => { - response = await apmApiClient.writeUser({ - endpoint: 'GET /internal/apm/assistant/alert_details_contextual_insights', - params: { - query: { - alert_started_at: new Date(end).toISOString(), - 'container.id': 'non-existing-container', - }, - }, - }); - }); - - it('returns nothing', () => { - expect(response.body.context).to.eql([]); - }); - }); - - describe('when non-existing service.name is specified', async () => { - let response: SupertestReturnType<'GET /internal/apm/assistant/alert_details_contextual_insights'>; - before(async () => { - response = await apmApiClient.writeUser({ - endpoint: 'GET /internal/apm/assistant/alert_details_contextual_insights', - params: { - query: { - alert_started_at: new Date(end).toISOString(), - 'service.name': 'non-existing-service', - }, - }, - }); - }); - - it('returns empty service summary', () => { - const serviceSummary = response.body.context.find( - ({ key }) => key === 'serviceSummary' - ); - expect(serviceSummary?.data).to.eql({ - 'service.name': 'non-existing-service', - 'service.environment': [], - instances: 1, - anomalies: [], - alerts: [], - deployments: [], - }); - }); - - it('returns no downstream dependencies', async () => { - const downstreamDependencies = response.body.context.find( - ({ key }) => key === 'downstreamDependencies' - ); - expect(downstreamDependencies).to.eql(undefined); - }); - - it('returns log categories', () => { - const logCategories = response.body.context.find(({ key }) => key === 'logCategories'); - expect(logCategories?.data).to.have.length(1); - }); - }); - }); - - describe('when traces and logs are ingested and logs are annotated with service.name', async () => { - before(async () => { - await ingestTraces({ 'service.name': 'Backend', 'container.id': 'my-container-a' }); - await ingestLogs({ - 'service.name': 'Backend', - 'container.id': 'my-container-a', - 'kubernetes.pod.name': 'pod-a', - }); - - // also ingest unrelated Frontend traces and logs that should not show up in the response when fetching "Backend"-related things - await ingestTraces({ 'service.name': 'Frontend', 'container.id': 'my-container-b' }); - await ingestLogs({ - 'service.name': 'Frontend', - 'container.id': 'my-container-b', - 'kubernetes.pod.name': 'pod-b', - }); - - // also ingest logs that are not annotated with service.name - await ingestLogs({ - 'container.id': 'my-container-c', - 'kubernetes.pod.name': 'pod-c', - }); - }); - - after(async () => { - await cleanup(); - }); - - describe('when no params are specified', async () => { - let response: SupertestReturnType<'GET /internal/apm/assistant/alert_details_contextual_insights'>; - before(async () => { - response = await apmApiClient.writeUser({ - endpoint: 'GET /internal/apm/assistant/alert_details_contextual_insights', - params: { - query: { - alert_started_at: new Date(end).toISOString(), - }, - }, - }); - }); - - it('returns no service summary', async () => { - const serviceSummary = response.body.context.find( - ({ key }) => key === 'serviceSummary' - ); - expect(serviceSummary).to.be(undefined); - }); - - it('returns 1 log category', async () => { - const logCategories = response.body.context.find(({ key }) => key === 'logCategories'); - expect( - (logCategories?.data as LogCategories)?.map( - ({ errorCategory }: { errorCategory: string }) => errorCategory - ) - ).to.eql(['Error message from service', 'Error message from container my-container-c']); - }); - }); - - describe('when service name is specified', async () => { - let response: SupertestReturnType<'GET /internal/apm/assistant/alert_details_contextual_insights'>; - before(async () => { - response = await apmApiClient.writeUser({ - endpoint: 'GET /internal/apm/assistant/alert_details_contextual_insights', - params: { - query: { - alert_started_at: new Date(end).toISOString(), - 'service.name': 'Backend', - }, - }, - }); - }); - - it('returns log categories', () => { - const logCategories = response.body.context.find(({ key }) => key === 'logCategories'); - expect(logCategories?.data).to.have.length(1); - - const logCategory = (logCategories?.data as LogCategories)?.[0]; - expect(logCategory?.sampleMessage).to.match( - /Error message #\d{16} from service Backend/ - ); - expect(logCategory?.docCount).to.be.greaterThan(0); - expect(logCategory?.errorCategory).to.be('Error message from service Backend'); - }); - }); - - describe('when container id is specified', async () => { - let response: SupertestReturnType<'GET /internal/apm/assistant/alert_details_contextual_insights'>; - before(async () => { - response = await apmApiClient.writeUser({ - endpoint: 'GET /internal/apm/assistant/alert_details_contextual_insights', - params: { - query: { - alert_started_at: new Date(end).toISOString(), - 'container.id': 'my-container-a', - }, - }, - }); - }); - - it('returns log categories', () => { - const logCategories = response.body.context.find(({ key }) => key === 'logCategories'); - expect(logCategories?.data).to.have.length(1); - - const logCategory = (logCategories?.data as LogCategories)?.[0]; - expect(logCategory?.sampleMessage).to.match( - /Error message #\d{16} from service Backend/ - ); - expect(logCategory?.docCount).to.be.greaterThan(0); - expect(logCategory?.errorCategory).to.be('Error message from service Backend'); - }); - }); - - describe('when non-existing service.name is specified', async () => { - let response: SupertestReturnType<'GET /internal/apm/assistant/alert_details_contextual_insights'>; - before(async () => { - response = await apmApiClient.writeUser({ - endpoint: 'GET /internal/apm/assistant/alert_details_contextual_insights', - params: { - query: { - alert_started_at: new Date(end).toISOString(), - 'service.name': 'non-existing-service', - }, - }, - }); - }); - - it('returns empty service summary', () => { - const serviceSummary = response.body.context.find( - ({ key }) => key === 'serviceSummary' - ); - expect(serviceSummary?.data).to.eql({ - 'service.name': 'non-existing-service', - 'service.environment': [], - instances: 1, - anomalies: [], - alerts: [], - deployments: [], - }); - }); - - it('does not return log categories', () => { - const logCategories = response.body.context.find(({ key }) => key === 'logCategories'); - expect(logCategories?.data).to.have.length(1); - - expect( - (logCategories?.data as LogCategories)?.map( - ({ errorCategory }: { errorCategory: string }) => errorCategory - ) - ).to.eql(['Error message from container my-container-c']); - }); - }); - }); - - async function ingestTraces(eventMetadata: { - 'service.name': string; - 'container.id'?: string; - 'host.name'?: string; - 'kubernetes.pod.name'?: string; - }) { - const serviceInstance = apm - .service({ - name: eventMetadata['service.name'], - environment: 'production', - agentName: 'java', - }) - .instance('my-instance'); - - const events = range - .interval('1m') - .rate(1) - .generator((timestamp) => { - return serviceInstance - .transaction({ transactionName: 'tx' }) - .timestamp(timestamp) - .duration(10000) - .defaults({ 'service.version': '1.0.0', ...eventMetadata }) - .outcome('success') - .children( - serviceInstance - .span({ - spanName: 'GET apm-*/_search', - spanType: 'db', - spanSubtype: 'elasticsearch', - }) - .duration(1000) - .success() - .destination('elasticsearch') - .timestamp(timestamp) - ); - }); - - await apmSynthtraceClient.index(events); - } - - function ingestLogs(eventMetadata: { - 'service.name'?: string; - 'container.id'?: string; - 'kubernetes.pod.name'?: string; - 'host.name'?: string; - }) { - const getMessage = () => { - const msgPrefix = `Error message #${generateShortId()}`; - - if (eventMetadata['service.name']) { - return `${msgPrefix} from service ${eventMetadata['service.name']}`; - } - - if (eventMetadata['container.id']) { - return `${msgPrefix} from container ${eventMetadata['container.id']}`; - } - - if (eventMetadata['kubernetes.pod.name']) { - return `${msgPrefix} from pod ${eventMetadata['kubernetes.pod.name']}`; - } - - if (eventMetadata['host.name']) { - return `${msgPrefix} from host ${eventMetadata['host.name']}`; - } - - return msgPrefix; - }; - - const events = range - .interval('1m') - .rate(1) - .generator((timestamp) => { - return [ - log - .create() - .message(getMessage()) - .logLevel('error') - .defaults({ - 'trace.id': generateShortId(), - 'agent.name': 'synth-agent', - ...eventMetadata, - }) - .timestamp(timestamp), - ]; - }); - - return logSynthtraceClient.index(events); - } - - async function cleanup() { - await apmSynthtraceClient.clean(); - await logSynthtraceClient.clean(); - } - } - ); -} diff --git a/x-pack/test/apm_api_integration/tests/cold_start/cold_start.spec.ts b/x-pack/test/apm_api_integration/tests/cold_start/cold_start.spec.ts index 5d4eb4e1585c0..7d0b2f6d8a625 100644 --- a/x-pack/test/apm_api_integration/tests/cold_start/cold_start.spec.ts +++ b/x-pack/test/apm_api_integration/tests/cold_start/cold_start.spec.ts @@ -22,7 +22,7 @@ type ColdStartRate = export default function ApiTest({ getService }: FtrProviderContext) { const registry = getService('registry'); const apmApiClient = getService('apmApiClient'); - const synthtraceEsClient = getService('synthtraceEsClient'); + const apmSynthtraceEsClient = getService('apmSynthtraceEsClient'); const { serviceName } = dataConfig; const start = new Date('2021-01-01T00:00:00.000Z').getTime(); @@ -74,7 +74,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { before(async () => { await generateData({ - synthtraceEsClient, + apmSynthtraceEsClient, start, end, coldStartRate: 10, @@ -85,7 +85,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { status = response.status; }); - after(() => synthtraceEsClient.clean()); + after(() => apmSynthtraceEsClient.clean()); it('returns correct HTTP status', () => { expect(status).to.be(200); @@ -121,14 +121,14 @@ export default function ApiTest({ getService }: FtrProviderContext) { const comparisonEndDate = moment(start).add(3, 'minutes'); await generateData({ - synthtraceEsClient, + apmSynthtraceEsClient, start: startDate.valueOf(), end: endDate.valueOf(), coldStartRate: 10, warmStartRate: 30, }); await generateData({ - synthtraceEsClient, + apmSynthtraceEsClient, start: comparisonStartDate.getTime(), end: comparisonEndDate.valueOf(), coldStartRate: 20, @@ -146,7 +146,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { status = response.status; }); - after(() => synthtraceEsClient.clean()); + after(() => apmSynthtraceEsClient.clean()); it('returns correct HTTP status', () => { expect(status).to.be(200); diff --git a/x-pack/test/apm_api_integration/tests/cold_start/cold_start_by_transaction_name/cold_start_by_transaction_name.spec.ts b/x-pack/test/apm_api_integration/tests/cold_start/cold_start_by_transaction_name/cold_start_by_transaction_name.spec.ts index 4078aaa08e793..7019735a05498 100644 --- a/x-pack/test/apm_api_integration/tests/cold_start/cold_start_by_transaction_name/cold_start_by_transaction_name.spec.ts +++ b/x-pack/test/apm_api_integration/tests/cold_start/cold_start_by_transaction_name/cold_start_by_transaction_name.spec.ts @@ -22,7 +22,7 @@ type ColdStartRate = export default function ApiTest({ getService }: FtrProviderContext) { const registry = getService('registry'); const apmApiClient = getService('apmApiClient'); - const synthtraceEsClient = getService('synthtraceEsClient'); + const apmSynthtraceEsClient = getService('apmSynthtraceEsClient'); const { serviceName, transactionName } = dataConfig; const start = new Date('2021-01-01T00:00:00.000Z').getTime(); @@ -79,7 +79,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { before(async () => { await generateData({ - synthtraceEsClient, + apmSynthtraceEsClient, start, end, coldStartRate: 10, @@ -90,7 +90,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { status = response.status; }); - after(() => synthtraceEsClient.clean()); + after(() => apmSynthtraceEsClient.clean()); it('returns correct HTTP status', () => { expect(status).to.be(200); @@ -126,14 +126,14 @@ export default function ApiTest({ getService }: FtrProviderContext) { const comparisonEndDate = moment(start).add(3, 'minutes'); await generateData({ - synthtraceEsClient, + apmSynthtraceEsClient, start: startDate.valueOf(), end: endDate.valueOf(), coldStartRate: 10, warmStartRate: 30, }); await generateData({ - synthtraceEsClient, + apmSynthtraceEsClient, start: comparisonStartDate.getTime(), end: comparisonEndDate.valueOf(), coldStartRate: 20, @@ -151,7 +151,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { status = response.status; }); - after(() => synthtraceEsClient.clean()); + after(() => apmSynthtraceEsClient.clean()); it('returns correct HTTP status', () => { expect(status).to.be(200); diff --git a/x-pack/test/apm_api_integration/tests/cold_start/cold_start_by_transaction_name/generate_data.ts b/x-pack/test/apm_api_integration/tests/cold_start/cold_start_by_transaction_name/generate_data.ts index 407e115d473b7..ff4d725a3d017 100644 --- a/x-pack/test/apm_api_integration/tests/cold_start/cold_start_by_transaction_name/generate_data.ts +++ b/x-pack/test/apm_api_integration/tests/cold_start/cold_start_by_transaction_name/generate_data.ts @@ -14,13 +14,13 @@ export const dataConfig = { }; export async function generateData({ - synthtraceEsClient, + apmSynthtraceEsClient, start, end, coldStartRate, warmStartRate, }: { - synthtraceEsClient: ApmSynthtraceEsClient; + apmSynthtraceEsClient: ApmSynthtraceEsClient; start: number; end: number; coldStartRate: number; @@ -60,5 +60,5 @@ export async function generateData({ ), ]; - await synthtraceEsClient.index(traceEvents); + await apmSynthtraceEsClient.index(traceEvents); } diff --git a/x-pack/test/apm_api_integration/tests/cold_start/generate_data.ts b/x-pack/test/apm_api_integration/tests/cold_start/generate_data.ts index ecbba07e3b498..9c36e53e82632 100644 --- a/x-pack/test/apm_api_integration/tests/cold_start/generate_data.ts +++ b/x-pack/test/apm_api_integration/tests/cold_start/generate_data.ts @@ -20,13 +20,13 @@ export const dataConfig = { }; export async function generateData({ - synthtraceEsClient, + apmSynthtraceEsClient, start, end, coldStartRate, warmStartRate, }: { - synthtraceEsClient: ApmSynthtraceEsClient; + apmSynthtraceEsClient: ApmSynthtraceEsClient; start: number; end: number; coldStartRate: number; @@ -66,5 +66,5 @@ export async function generateData({ ), ]; - await synthtraceEsClient.index(traceEvents); + await apmSynthtraceEsClient.index(traceEvents); } diff --git a/x-pack/test/apm_api_integration/tests/custom_dashboards/custom_dashboards.spec.ts b/x-pack/test/apm_api_integration/tests/custom_dashboards/custom_dashboards.spec.ts index 3dcd39df10bb8..46903bf1b5e6b 100644 --- a/x-pack/test/apm_api_integration/tests/custom_dashboards/custom_dashboards.spec.ts +++ b/x-pack/test/apm_api_integration/tests/custom_dashboards/custom_dashboards.spec.ts @@ -17,7 +17,7 @@ import { export default function ApiTest({ getService }: FtrProviderContext) { const registry = getService('registry'); const apmApiClient = getService('apmApiClient'); - const synthtrace = getService('synthtraceEsClient'); + const synthtrace = getService('apmSynthtraceEsClient'); const start = '2023-08-22T00:00:00.000Z'; const end = '2023-08-22T00:15:00.000Z'; diff --git a/x-pack/test/apm_api_integration/tests/data_view/static.spec.ts b/x-pack/test/apm_api_integration/tests/data_view/static.spec.ts index dbe7db5830f93..56b310f8f2fe6 100644 --- a/x-pack/test/apm_api_integration/tests/data_view/static.spec.ts +++ b/x-pack/test/apm_api_integration/tests/data_view/static.spec.ts @@ -19,7 +19,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { const registry = getService('registry'); const apmApiClient = getService('apmApiClient'); const supertest = getService('supertest'); - const synthtrace = getService('synthtraceEsClient'); + const synthtrace = getService('apmSynthtraceEsClient'); const logger = getService('log'); const dataViewPattern = 'traces-apm*,apm-*,logs-apm*,apm-*,metrics-apm*,apm-*'; diff --git a/x-pack/test/apm_api_integration/tests/dependencies/dependency_metrics.spec.ts b/x-pack/test/apm_api_integration/tests/dependencies/dependency_metrics.spec.ts index 40b0120a3d96f..c9cb6aea71306 100644 --- a/x-pack/test/apm_api_integration/tests/dependencies/dependency_metrics.spec.ts +++ b/x-pack/test/apm_api_integration/tests/dependencies/dependency_metrics.spec.ts @@ -27,7 +27,7 @@ const { export default function ApiTest({ getService }: FtrProviderContext) { const registry = getService('registry'); const apmApiClient = getService('apmApiClient'); - const synthtraceEsClient = getService('synthtraceEsClient'); + const apmSynthtraceEsClient = getService('apmSynthtraceEsClient'); const start = new Date('2021-01-01T00:00:00.000Z').getTime(); const end = new Date('2021-01-01T00:15:00.000Z').getTime() - 1; @@ -98,7 +98,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { registry.when('Dependency metrics when data is loaded', { config: 'basic', archives: [] }, () => { before(async () => { await generateOperationData({ - synthtraceEsClient, + apmSynthtraceEsClient, start, end, }); @@ -299,6 +299,6 @@ export default function ApiTest({ getService }: FtrProviderContext) { }); }); - after(() => synthtraceEsClient.clean()); + after(() => apmSynthtraceEsClient.clean()); }); } diff --git a/x-pack/test/apm_api_integration/tests/dependencies/generate_data.ts b/x-pack/test/apm_api_integration/tests/dependencies/generate_data.ts index fad21e46f6070..58b708f0ab253 100644 --- a/x-pack/test/apm_api_integration/tests/dependencies/generate_data.ts +++ b/x-pack/test/apm_api_integration/tests/dependencies/generate_data.ts @@ -22,11 +22,11 @@ export const dataConfig = { }; export async function generateData({ - synthtraceEsClient, + apmSynthtraceEsClient, start, end, }: { - synthtraceEsClient: ApmSynthtraceEsClient; + apmSynthtraceEsClient: ApmSynthtraceEsClient; start: number; end: number; }) { @@ -35,7 +35,7 @@ export async function generateData({ .instance('instance-a'); const { rate, transaction, span } = dataConfig; - await synthtraceEsClient.index( + await apmSynthtraceEsClient.index( timerange(start, end) .interval('1m') .rate(rate) diff --git a/x-pack/test/apm_api_integration/tests/dependencies/generate_operation_data.ts b/x-pack/test/apm_api_integration/tests/dependencies/generate_operation_data.ts index d68183960ca5a..97d7c35e23733 100644 --- a/x-pack/test/apm_api_integration/tests/dependencies/generate_operation_data.ts +++ b/x-pack/test/apm_api_integration/tests/dependencies/generate_operation_data.ts @@ -21,11 +21,11 @@ export const generateOperationDataConfig = { export async function generateOperationData({ start, end, - synthtraceEsClient, + apmSynthtraceEsClient, }: { start: number; end: number; - synthtraceEsClient: ApmSynthtraceEsClient; + apmSynthtraceEsClient: ApmSynthtraceEsClient; }) { const synthGoInstance = apm .service({ name: 'synth-go', environment: 'production', agentName: 'go' }) @@ -36,7 +36,7 @@ export async function generateOperationData({ const interval = timerange(start, end).interval('1m'); - return await synthtraceEsClient.index([ + return await apmSynthtraceEsClient.index([ interval .rate(generateOperationDataConfig.ES_SEARCH_UNKNOWN_RATE) .generator((timestamp) => diff --git a/x-pack/test/apm_api_integration/tests/dependencies/metadata.spec.ts b/x-pack/test/apm_api_integration/tests/dependencies/metadata.spec.ts index 62fb3c7958845..33b81c8599111 100644 --- a/x-pack/test/apm_api_integration/tests/dependencies/metadata.spec.ts +++ b/x-pack/test/apm_api_integration/tests/dependencies/metadata.spec.ts @@ -11,7 +11,7 @@ import { dataConfig, generateData } from './generate_data'; export default function ApiTest({ getService }: FtrProviderContext) { const registry = getService('registry'); const apmApiClient = getService('apmApiClient'); - const synthtraceEsClient = getService('synthtraceEsClient'); + const apmSynthtraceEsClient = getService('apmSynthtraceEsClient'); const start = new Date('2021-01-01T00:00:00.000Z').getTime(); const end = new Date('2021-01-01T00:15:00.000Z').getTime() - 1; @@ -47,10 +47,10 @@ export default function ApiTest({ getService }: FtrProviderContext) { 'Dependency metadata when data is generated', { config: 'basic', archives: [] }, () => { - after(() => synthtraceEsClient.clean()); + after(() => apmSynthtraceEsClient.clean()); it('returns correct metadata for the dependency', async () => { - await generateData({ synthtraceEsClient, start, end }); + await generateData({ apmSynthtraceEsClient, start, end }); const { status, body } = await callApi(); const { span } = dataConfig; @@ -59,7 +59,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { expect(body.metadata.spanType).to.equal(span.type); expect(body.metadata.spanSubtype).to.equal(span.subType); - await synthtraceEsClient.clean(); + await apmSynthtraceEsClient.clean(); }); } ); diff --git a/x-pack/test/apm_api_integration/tests/dependencies/service_dependencies.spec.ts b/x-pack/test/apm_api_integration/tests/dependencies/service_dependencies.spec.ts index 3ac094dc9e540..ab9563169fe9b 100644 --- a/x-pack/test/apm_api_integration/tests/dependencies/service_dependencies.spec.ts +++ b/x-pack/test/apm_api_integration/tests/dependencies/service_dependencies.spec.ts @@ -11,7 +11,7 @@ import { generateData } from './generate_data'; export default function ApiTest({ getService }: FtrProviderContext) { const apmApiClient = getService('apmApiClient'); - const synthtraceEsClient = getService('synthtraceEsClient'); + const apmSynthtraceEsClient = getService('apmSynthtraceEsClient'); const registry = getService('registry'); const start = new Date('2021-01-01T00:00:00.000Z').getTime(); const end = new Date('2021-01-01T00:15:00.000Z').getTime() - 1; @@ -51,9 +51,9 @@ export default function ApiTest({ getService }: FtrProviderContext) { registry.when('Dependency for services', { config: 'basic', archives: [] }, () => { describe('when data is loaded', () => { before(async () => { - await generateData({ synthtraceEsClient, start, end }); + await generateData({ apmSynthtraceEsClient, start, end }); }); - after(() => synthtraceEsClient.clean()); + after(() => apmSynthtraceEsClient.clean()); it('returns a list of dependencies for a service', async () => { const { status, body } = await callApi(); @@ -89,9 +89,9 @@ export default function ApiTest({ getService }: FtrProviderContext) { registry.when('Dependency for services breakdown', { config: 'basic', archives: [] }, () => { describe('when data is loaded', () => { before(async () => { - await generateData({ synthtraceEsClient, start, end }); + await generateData({ apmSynthtraceEsClient, start, end }); }); - after(() => synthtraceEsClient.clean()); + after(() => apmSynthtraceEsClient.clean()); it('returns a list of dependencies for a service', async () => { const { status, body } = await callApi(); diff --git a/x-pack/test/apm_api_integration/tests/dependencies/top_dependencies.spec.ts b/x-pack/test/apm_api_integration/tests/dependencies/top_dependencies.spec.ts index d08b96ab2e57f..acdea5a3d54de 100644 --- a/x-pack/test/apm_api_integration/tests/dependencies/top_dependencies.spec.ts +++ b/x-pack/test/apm_api_integration/tests/dependencies/top_dependencies.spec.ts @@ -16,7 +16,7 @@ type TopDependencies = APIReturnType<'GET /internal/apm/dependencies/top_depende export default function ApiTest({ getService }: FtrProviderContext) { const registry = getService('registry'); const apmApiClient = getService('apmApiClient'); - const synthtraceEsClient = getService('synthtraceEsClient'); + const apmSynthtraceEsClient = getService('apmSynthtraceEsClient'); const start = new Date('2021-01-01T00:00:00.000Z').getTime(); const end = new Date('2021-01-01T00:15:00.000Z').getTime() - 1; @@ -55,12 +55,12 @@ export default function ApiTest({ getService }: FtrProviderContext) { let topDependencies: TopDependencies; before(async () => { - await generateData({ synthtraceEsClient, start, end }); + await generateData({ apmSynthtraceEsClient, start, end }); const response = await callApi(); topDependencies = response.body; }); - after(() => synthtraceEsClient.clean()); + after(() => apmSynthtraceEsClient.clean()); it('returns an array of dependencies', () => { expect(topDependencies).to.have.property('dependencies'); diff --git a/x-pack/test/apm_api_integration/tests/dependencies/top_operations.spec.ts b/x-pack/test/apm_api_integration/tests/dependencies/top_operations.spec.ts index 353c32a263eb1..20a38369bcd5d 100644 --- a/x-pack/test/apm_api_integration/tests/dependencies/top_operations.spec.ts +++ b/x-pack/test/apm_api_integration/tests/dependencies/top_operations.spec.ts @@ -30,7 +30,7 @@ const { export default function ApiTest({ getService }: FtrProviderContext) { const registry = getService('registry'); const apmApiClient = getService('apmApiClient'); - const synthtraceEsClient = getService('synthtraceEsClient'); + const apmSynthtraceEsClient = getService('apmSynthtraceEsClient'); const start = new Date('2021-01-01T00:00:00.000Z').getTime(); const end = new Date('2021-01-01T00:15:00.000Z').getTime() - 1; @@ -74,13 +74,13 @@ export default function ApiTest({ getService }: FtrProviderContext) { registry.when('Top operations when data is generated', { config: 'basic', archives: [] }, () => { before(() => generateOperationData({ - synthtraceEsClient, + apmSynthtraceEsClient, start, end, }) ); - after(() => synthtraceEsClient.clean()); + after(() => apmSynthtraceEsClient.clean()); describe('requested for elasticsearch', () => { let response: TopOperations; diff --git a/x-pack/test/apm_api_integration/tests/dependencies/top_spans.spec.ts b/x-pack/test/apm_api_integration/tests/dependencies/top_spans.spec.ts index 1f6cae4f8393b..b07c7c323ed9c 100644 --- a/x-pack/test/apm_api_integration/tests/dependencies/top_spans.spec.ts +++ b/x-pack/test/apm_api_integration/tests/dependencies/top_spans.spec.ts @@ -13,7 +13,7 @@ import { FtrProviderContext } from '../../common/ftr_provider_context'; export default function ApiTest({ getService }: FtrProviderContext) { const registry = getService('registry'); const apmApiClient = getService('apmApiClient'); - const synthtraceEsClient = getService('synthtraceEsClient'); + const apmSynthtraceEsClient = getService('apmSynthtraceEsClient'); const start = new Date('2021-01-01T00:00:00.000Z').getTime(); const end = new Date('2021-01-01T00:15:00.000Z').getTime() - 1; @@ -80,7 +80,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { .instance('instance-a'); before(async () => { - await synthtraceEsClient.index([ + await apmSynthtraceEsClient.index([ timerange(start, end) .interval('1m') .rate(1) @@ -239,7 +239,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { }); }); - after(() => synthtraceEsClient.clean()); + after(() => apmSynthtraceEsClient.clean()); } ); } diff --git a/x-pack/test/apm_api_integration/tests/dependencies/upstream_services.spec.ts b/x-pack/test/apm_api_integration/tests/dependencies/upstream_services.spec.ts index 7a44acaf5f9e9..1a7e958881d96 100644 --- a/x-pack/test/apm_api_integration/tests/dependencies/upstream_services.spec.ts +++ b/x-pack/test/apm_api_integration/tests/dependencies/upstream_services.spec.ts @@ -11,7 +11,7 @@ import { generateData } from './generate_data'; export default function ApiTest({ getService }: FtrProviderContext) { const apmApiClient = getService('apmApiClient'); - const synthtraceEsClient = getService('synthtraceEsClient'); + const apmSynthtraceEsClient = getService('apmSynthtraceEsClient'); const registry = getService('registry'); const start = new Date('2021-01-01T00:00:00.000Z').getTime(); const end = new Date('2021-01-01T00:15:00.000Z').getTime() - 1; @@ -51,9 +51,9 @@ export default function ApiTest({ getService }: FtrProviderContext) { registry.when('Dependency upstream services', { config: 'basic', archives: [] }, () => { describe('when data is loaded', () => { before(async () => { - await generateData({ synthtraceEsClient, start, end }); + await generateData({ apmSynthtraceEsClient, start, end }); }); - after(() => synthtraceEsClient.clean()); + after(() => apmSynthtraceEsClient.clean()); it('returns a list of upstream services for the dependency', async () => { const { status, body } = await callApi(); diff --git a/x-pack/test/apm_api_integration/tests/diagnostics/apm_events.spec.ts b/x-pack/test/apm_api_integration/tests/diagnostics/apm_events.spec.ts index d30cc24e80179..870f339ddf602 100644 --- a/x-pack/test/apm_api_integration/tests/diagnostics/apm_events.spec.ts +++ b/x-pack/test/apm_api_integration/tests/diagnostics/apm_events.spec.ts @@ -15,7 +15,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { const registry = getService('registry'); const apmApiClient = getService('apmApiClient'); const es = getService('es'); - const synthtraceEsClient = getService('synthtraceEsClient'); + const apmSynthtraceEsClient = getService('apmSynthtraceEsClient'); const start = new Date('2021-01-01T00:00:00.000Z').getTime(); const end = new Date('2021-01-01T00:15:00.000Z').getTime() - 1; @@ -43,7 +43,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { .service({ name: 'synth-go', environment: 'production', agentName: 'go' }) .instance('instance-a'); - await synthtraceEsClient.index( + await apmSynthtraceEsClient.index( timerange(start, end) .interval('1m') .rate(30) @@ -57,7 +57,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { ); }); - after(() => synthtraceEsClient.clean()); + after(() => apmSynthtraceEsClient.clean()); it('returns zero doc_counts when no time range is specified', async () => { const { body } = await apmApiClient.readUser({ diff --git a/x-pack/test/apm_api_integration/tests/diagnostics/data_streams.spec.ts b/x-pack/test/apm_api_integration/tests/diagnostics/data_streams.spec.ts index cd94fe5d60418..969ce9fabd5a6 100644 --- a/x-pack/test/apm_api_integration/tests/diagnostics/data_streams.spec.ts +++ b/x-pack/test/apm_api_integration/tests/diagnostics/data_streams.spec.ts @@ -13,7 +13,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { const registry = getService('registry'); const apmApiClient = getService('apmApiClient'); const es = getService('es'); - const synthtraceEsClient = getService('synthtraceEsClient'); + const apmSynthtraceEsClient = getService('apmSynthtraceEsClient'); const synthtraceKibanaClient = getService('synthtraceKibanaClient'); const start = new Date('2021-01-01T00:00:00.000Z').getTime(); @@ -53,7 +53,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { .service({ name: 'synth-go', environment: 'production', agentName: 'go' }) .instance('instance-a'); - await synthtraceEsClient.index( + await apmSynthtraceEsClient.index( timerange(start, end) .interval('1m') .rate(30) @@ -67,7 +67,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { ); }); - after(() => synthtraceEsClient.clean()); + after(() => apmSynthtraceEsClient.clean()); it('returns 5 data streams', async () => { const { status, body } = await apmApiClient.adminUser({ diff --git a/x-pack/test/apm_api_integration/tests/diagnostics/index_pattern_settings.ts b/x-pack/test/apm_api_integration/tests/diagnostics/index_pattern_settings.ts index 675145ab8673b..64749066a2e04 100644 --- a/x-pack/test/apm_api_integration/tests/diagnostics/index_pattern_settings.ts +++ b/x-pack/test/apm_api_integration/tests/diagnostics/index_pattern_settings.ts @@ -14,7 +14,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { const registry = getService('registry'); const apmApiClient = getService('apmApiClient'); const es = getService('es'); - const synthtraceEsClient = getService('synthtraceEsClient'); + const apmSynthtraceEsClient = getService('apmSynthtraceEsClient'); const synthtraceKibanaClient = getService('synthtraceKibanaClient'); const start = new Date('2021-01-01T00:00:00.000Z').getTime(); @@ -49,7 +49,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { const instance = apm .service({ name: 'synth-go', environment: 'production', agentName: 'go' }) .instance('instance-a'); - await synthtraceEsClient.index( + await apmSynthtraceEsClient.index( timerange(start, end) .interval('1m') .rate(30) @@ -63,7 +63,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { ); }); - after(() => synthtraceEsClient.clean()); + after(() => apmSynthtraceEsClient.clean()); it('returns APM index templates', async () => { const { status, body } = await apmApiClient.adminUser({ diff --git a/x-pack/test/apm_api_integration/tests/diagnostics/index_templates.spec.ts b/x-pack/test/apm_api_integration/tests/diagnostics/index_templates.spec.ts index fcde133347ee3..2ece2835b5944 100644 --- a/x-pack/test/apm_api_integration/tests/diagnostics/index_templates.spec.ts +++ b/x-pack/test/apm_api_integration/tests/diagnostics/index_templates.spec.ts @@ -14,7 +14,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { const registry = getService('registry'); const apmApiClient = getService('apmApiClient'); const es = getService('es'); - const synthtraceEsClient = getService('synthtraceEsClient'); + const apmSynthtraceEsClient = getService('apmSynthtraceEsClient'); const synthtraceKibanaClient = getService('synthtraceKibanaClient'); const start = new Date('2021-01-01T00:00:00.000Z').getTime(); @@ -47,7 +47,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { const instance = apm .service({ name: 'synth-go', environment: 'production', agentName: 'go' }) .instance('instance-a'); - await synthtraceEsClient.index( + await apmSynthtraceEsClient.index( timerange(start, end) .interval('1m') .rate(30) @@ -61,7 +61,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { ); }); - after(() => synthtraceEsClient.clean()); + after(() => apmSynthtraceEsClient.clean()); it('verifies that all the default APM index templates exist', async () => { const { status, body } = await apmApiClient.adminUser({ diff --git a/x-pack/test/apm_api_integration/tests/diagnostics/indices.spec.ts b/x-pack/test/apm_api_integration/tests/diagnostics/indices.spec.ts index 4f7507e74e2f3..477824524b48c 100644 --- a/x-pack/test/apm_api_integration/tests/diagnostics/indices.spec.ts +++ b/x-pack/test/apm_api_integration/tests/diagnostics/indices.spec.ts @@ -13,7 +13,7 @@ import { FtrProviderContext } from '../../common/ftr_provider_context'; export default function ApiTest({ getService }: FtrProviderContext) { const registry = getService('registry'); const apmApiClient = getService('apmApiClient'); - const synthtraceEsClient = getService('synthtraceEsClient'); + const apmSynthtraceEsClient = getService('apmSynthtraceEsClient'); const es = getService('es'); const synthtraceKibanaClient = getService('synthtraceKibanaClient'); @@ -40,7 +40,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { .service({ name: 'synth-go', environment: 'production', agentName: 'go' }) .instance('instance-a'); - await synthtraceEsClient.index( + await apmSynthtraceEsClient.index( timerange(start, end) .interval('1m') .rate(30) @@ -54,7 +54,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { ); }); - after(() => synthtraceEsClient.clean()); + after(() => apmSynthtraceEsClient.clean()); it('returns empty response', async () => { const { status, body } = await apmApiClient.adminUser({ @@ -76,7 +76,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { .service({ name: 'synth-go', environment: 'production', agentName: 'go' }) .instance('instance-a'); - await synthtraceEsClient.index( + await apmSynthtraceEsClient.index( timerange(start, end) .interval('1m') .rate(30) @@ -94,7 +94,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { await es.indices.delete({ index: 'traces-apm-default' }); const latestVersion = await synthtraceKibanaClient.fetchLatestApmPackageVersion(); await synthtraceKibanaClient.installApmPackage(latestVersion); - await synthtraceEsClient.clean(); + await apmSynthtraceEsClient.clean(); }); it('returns a list of items with mapping issues', async () => { @@ -121,7 +121,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { .service({ name: 'synth-go', environment: 'production', agentName: 'go' }) .instance('instance-a'); - await synthtraceEsClient.index( + await apmSynthtraceEsClient.index( timerange(start, end) .interval('1m') .rate(30) @@ -138,7 +138,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { after(async () => { const latestVersion = await synthtraceKibanaClient.fetchLatestApmPackageVersion(); await synthtraceKibanaClient.installApmPackage(latestVersion); - await synthtraceEsClient.clean(); + await apmSynthtraceEsClient.clean(); }); describe.skip('an ingest pipeline is removed', () => { diff --git a/x-pack/test/apm_api_integration/tests/environment/generate_data.ts b/x-pack/test/apm_api_integration/tests/environment/generate_data.ts index 6e9ae2831e6be..af71533bf3e0d 100644 --- a/x-pack/test/apm_api_integration/tests/environment/generate_data.ts +++ b/x-pack/test/apm_api_integration/tests/environment/generate_data.ts @@ -10,11 +10,11 @@ import type { ApmSynthtraceEsClient } from '@kbn/apm-synthtrace'; // Generate synthetic data for the environment test suite export async function generateData({ - synthtraceEsClient, + apmSynthtraceEsClient, start, end, }: { - synthtraceEsClient: ApmSynthtraceEsClient; + apmSynthtraceEsClient: ApmSynthtraceEsClient; start: number; end: number; }) { @@ -63,5 +63,5 @@ export async function generateData({ return [...loopGeneratedDocs, customDoc]; }); - await synthtraceEsClient.index(docs); + await apmSynthtraceEsClient.index(docs); } diff --git a/x-pack/test/apm_api_integration/tests/environment/get_environment.spec.ts b/x-pack/test/apm_api_integration/tests/environment/get_environment.spec.ts index bdb24342c8653..8a717e735b0f2 100644 --- a/x-pack/test/apm_api_integration/tests/environment/get_environment.spec.ts +++ b/x-pack/test/apm_api_integration/tests/environment/get_environment.spec.ts @@ -17,19 +17,19 @@ const end = new Date(endNumber).toISOString(); export default function environmentsAPITests({ getService }: FtrProviderContext) { const registry = getService('registry'); const apmApiClient = getService('apmApiClient'); - const synthtraceEsClient = getService('synthtraceEsClient'); + const apmSynthtraceEsClient = getService('apmSynthtraceEsClient'); // FLAKY: https://github.com/elastic/kibana/issues/177305 registry.when('environments when data is loaded', { config: 'basic', archives: [] }, async () => { before(async () => { await generateData({ - synthtraceEsClient, + apmSynthtraceEsClient, start: startNumber, end: endNumber, }); }); - after(() => synthtraceEsClient.clean()); + after(() => apmSynthtraceEsClient.clean()); describe('get environments', () => { describe('when service name is not specified', () => { diff --git a/x-pack/test/apm_api_integration/tests/error_rate/service_apis.spec.ts b/x-pack/test/apm_api_integration/tests/error_rate/service_apis.spec.ts index 9a0ba400e13da..2ab6b1bb97a5e 100644 --- a/x-pack/test/apm_api_integration/tests/error_rate/service_apis.spec.ts +++ b/x-pack/test/apm_api_integration/tests/error_rate/service_apis.spec.ts @@ -17,7 +17,7 @@ import { FtrProviderContext } from '../../common/ftr_provider_context'; export default function ApiTest({ getService }: FtrProviderContext) { const registry = getService('registry'); const apmApiClient = getService('apmApiClient'); - const synthtraceEsClient = getService('synthtraceEsClient'); + const apmSynthtraceEsClient = getService('apmSynthtraceEsClient'); const serviceName = 'synth-go'; const start = new Date('2021-01-01T00:00:00.000Z').getTime(); @@ -166,7 +166,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { const transactionNameProductList = 'GET /api/product/list'; const transactionNameProductId = 'GET /api/product/:id'; - await synthtraceEsClient.index([ + await apmSynthtraceEsClient.index([ timerange(start, end) .interval('1m') .rate(GO_PROD_LIST_RATE) @@ -210,7 +210,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { ]); }); - after(() => synthtraceEsClient.clean()); + after(() => apmSynthtraceEsClient.clean()); describe('compare error rate value between service inventory, error rate chart, service inventory and transactions apis', () => { before(async () => { diff --git a/x-pack/test/apm_api_integration/tests/error_rate/service_maps.spec.ts b/x-pack/test/apm_api_integration/tests/error_rate/service_maps.spec.ts index fa4b3f7074352..aa7d635b977cc 100644 --- a/x-pack/test/apm_api_integration/tests/error_rate/service_maps.spec.ts +++ b/x-pack/test/apm_api_integration/tests/error_rate/service_maps.spec.ts @@ -15,7 +15,7 @@ import { FtrProviderContext } from '../../common/ftr_provider_context'; export default function ApiTest({ getService }: FtrProviderContext) { const registry = getService('registry'); const apmApiClient = getService('apmApiClient'); - const synthtraceEsClient = getService('synthtraceEsClient'); + const apmSynthtraceEsClient = getService('apmSynthtraceEsClient'); const serviceName = 'synth-go'; const start = new Date('2021-01-01T00:00:00.000Z').getTime(); @@ -88,7 +88,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { const transactionNameProductList = 'GET /api/product/list'; const transactionNameProductId = 'GET /api/product/:id'; - return synthtraceEsClient.index([ + return apmSynthtraceEsClient.index([ timerange(start, end) .interval('1m') .rate(GO_PROD_LIST_RATE) @@ -138,7 +138,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { ]); }); - after(() => synthtraceEsClient.clean()); + after(() => apmSynthtraceEsClient.clean()); // FLAKY: https://github.com/elastic/kibana/issues/172772 describe('compare latency value between service inventory and service maps', () => { diff --git a/x-pack/test/apm_api_integration/tests/errors/distribution.spec.ts b/x-pack/test/apm_api_integration/tests/errors/distribution.spec.ts index 2b30dca5db80a..544ca97817af0 100644 --- a/x-pack/test/apm_api_integration/tests/errors/distribution.spec.ts +++ b/x-pack/test/apm_api_integration/tests/errors/distribution.spec.ts @@ -21,7 +21,7 @@ type ErrorsDistribution = export default function ApiTest({ getService }: FtrProviderContext) { const registry = getService('registry'); const apmApiClient = getService('apmApiClient'); - const synthtraceEsClient = getService('synthtraceEsClient'); + const apmSynthtraceEsClient = getService('apmSynthtraceEsClient'); const serviceName = 'synth-go'; const start = new Date('2021-01-01T00:00:00.000Z').getTime(); @@ -65,10 +65,10 @@ export default function ApiTest({ getService }: FtrProviderContext) { describe('errors distribution', () => { const { appleTransaction, bananaTransaction } = config; before(async () => { - await generateData({ serviceName, start, end, synthtraceEsClient }); + await generateData({ serviceName, start, end, apmSynthtraceEsClient }); }); - after(() => synthtraceEsClient.clean()); + after(() => apmSynthtraceEsClient.clean()); describe('without comparison', () => { let errorsDistribution: ErrorsDistribution; diff --git a/x-pack/test/apm_api_integration/tests/errors/error_group_list.spec.ts b/x-pack/test/apm_api_integration/tests/errors/error_group_list.spec.ts index bac97c76a3f36..fd01833cb4f50 100644 --- a/x-pack/test/apm_api_integration/tests/errors/error_group_list.spec.ts +++ b/x-pack/test/apm_api_integration/tests/errors/error_group_list.spec.ts @@ -19,7 +19,7 @@ type ErrorGroups = export default function ApiTest({ getService }: FtrProviderContext) { const registry = getService('registry'); const apmApiClient = getService('apmApiClient'); - const synthtraceEsClient = getService('synthtraceEsClient'); + const apmSynthtraceEsClient = getService('apmSynthtraceEsClient'); const serviceName = 'synth-go'; const start = new Date('2021-01-01T00:00:00.000Z').getTime(); @@ -73,7 +73,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { .service({ name: serviceName, environment: 'production', agentName: 'go' }) .instance('instance-a'); - await synthtraceEsClient.index([ + await apmSynthtraceEsClient.index([ timerange(start, end) .interval('1m') .rate(appleTransaction.successRate) @@ -123,7 +123,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { ]); }); - after(() => synthtraceEsClient.clean()); + after(() => apmSynthtraceEsClient.clean()); describe('returns the correct data', () => { let errorGroups: ErrorGroups; diff --git a/x-pack/test/apm_api_integration/tests/errors/generate_data.ts b/x-pack/test/apm_api_integration/tests/errors/generate_data.ts index 1ecc0f02e3f39..a7e627a048e05 100644 --- a/x-pack/test/apm_api_integration/tests/errors/generate_data.ts +++ b/x-pack/test/apm_api_integration/tests/errors/generate_data.ts @@ -21,12 +21,12 @@ export const config = { }; export async function generateData({ - synthtraceEsClient, + apmSynthtraceEsClient, serviceName, start, end, }: { - synthtraceEsClient: ApmSynthtraceEsClient; + apmSynthtraceEsClient: ApmSynthtraceEsClient; serviceName: string; start: number; end: number; @@ -69,5 +69,5 @@ export async function generateData({ ]; }); - await synthtraceEsClient.index(documents); + await apmSynthtraceEsClient.index(documents); } diff --git a/x-pack/test/apm_api_integration/tests/errors/group_id_samples.spec.ts b/x-pack/test/apm_api_integration/tests/errors/group_id_samples.spec.ts index 165fb81e3c643..004f853b6c56a 100644 --- a/x-pack/test/apm_api_integration/tests/errors/group_id_samples.spec.ts +++ b/x-pack/test/apm_api_integration/tests/errors/group_id_samples.spec.ts @@ -22,7 +22,7 @@ type ErrorSampleDetails = export default function ApiTest({ getService }: FtrProviderContext) { const registry = getService('registry'); const apmApiClient = getService('apmApiClient'); - const synthtraceEsClient = getService('synthtraceEsClient'); + const apmSynthtraceEsClient = getService('apmSynthtraceEsClient'); const serviceName = 'synth-go'; const start = new Date('2021-01-01T00:00:00.000Z').getTime(); @@ -80,10 +80,10 @@ export default function ApiTest({ getService }: FtrProviderContext) { const { bananaTransaction } = config; describe('error group id', () => { before(async () => { - await generateData({ serviceName, start, end, synthtraceEsClient }); + await generateData({ serviceName, start, end, apmSynthtraceEsClient }); }); - after(() => synthtraceEsClient.clean()); + after(() => apmSynthtraceEsClient.clean()); describe('return correct data', () => { let errorsSamplesResponse: ErrorGroupSamples; @@ -108,10 +108,10 @@ export default function ApiTest({ getService }: FtrProviderContext) { registry.when('when error sample data is loaded', { config: 'basic', archives: [] }, () => { describe('error sample id', () => { before(async () => { - await generateData({ serviceName, start, end, synthtraceEsClient }); + await generateData({ serviceName, start, end, apmSynthtraceEsClient }); }); - after(() => synthtraceEsClient.clean()); + after(() => apmSynthtraceEsClient.clean()); describe('return correct data', () => { let errorSampleDetailsResponse: ErrorSampleDetails; @@ -146,7 +146,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { const errorMessage = 'Error 1'; const groupId = getErrorGroupingKey(errorMessage); - await synthtraceEsClient.index([ + await apmSynthtraceEsClient.index([ timerange(start, end) .interval('15m') .rate(1) @@ -174,7 +174,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { errorGroupSamplesResponse = (await callErrorGroupSamplesApi({ groupId })).body; }); - after(() => synthtraceEsClient.clean()); + after(() => apmSynthtraceEsClient.clean()); it('returns the errors in the correct order (sampled first, then unsampled)', () => { const idsOfErrors = errorGroupSamplesResponse.errorSampleIds.map((id) => parseInt(id, 10)); diff --git a/x-pack/test/apm_api_integration/tests/errors/top_erroneous_transactions/generate_data.ts b/x-pack/test/apm_api_integration/tests/errors/top_erroneous_transactions/generate_data.ts index 47c48693eaa0e..7732d85efa58f 100644 --- a/x-pack/test/apm_api_integration/tests/errors/top_erroneous_transactions/generate_data.ts +++ b/x-pack/test/apm_api_integration/tests/errors/top_erroneous_transactions/generate_data.ts @@ -21,12 +21,12 @@ export const config = { }; export async function generateData({ - synthtraceEsClient, + apmSynthtraceEsClient, serviceName, start, end, }: { - synthtraceEsClient: ApmSynthtraceEsClient; + apmSynthtraceEsClient: ApmSynthtraceEsClient; serviceName: string; start: number; end: number; @@ -69,5 +69,5 @@ export async function generateData({ ]; }); - await synthtraceEsClient.index(documents); + await apmSynthtraceEsClient.index(documents); } diff --git a/x-pack/test/apm_api_integration/tests/errors/top_erroneous_transactions/top_erroneous_transactions.spec.ts b/x-pack/test/apm_api_integration/tests/errors/top_erroneous_transactions/top_erroneous_transactions.spec.ts index e22099af5cbbe..ff985e0af388f 100644 --- a/x-pack/test/apm_api_integration/tests/errors/top_erroneous_transactions/top_erroneous_transactions.spec.ts +++ b/x-pack/test/apm_api_integration/tests/errors/top_erroneous_transactions/top_erroneous_transactions.spec.ts @@ -21,7 +21,7 @@ type ErroneousTransactions = export default function ApiTest({ getService }: FtrProviderContext) { const registry = getService('registry'); const apmApiClient = getService('apmApiClient'); - const synthtraceEsClient = getService('synthtraceEsClient'); + const apmSynthtraceEsClient = getService('apmSynthtraceEsClient'); const serviceName = 'synth-go'; const start = new Date('2021-01-01T00:00:00.000Z').getTime(); @@ -73,10 +73,10 @@ export default function ApiTest({ getService }: FtrProviderContext) { describe('returns the correct data', () => { before(async () => { - await generateData({ serviceName, start, end, synthtraceEsClient }); + await generateData({ serviceName, start, end, apmSynthtraceEsClient }); }); - after(() => synthtraceEsClient.clean()); + after(() => apmSynthtraceEsClient.clean()); describe('without comparison', () => { const numberOfBuckets = 15; diff --git a/x-pack/test/apm_api_integration/tests/errors/top_errors_for_transaction/generate_data.ts b/x-pack/test/apm_api_integration/tests/errors/top_errors_for_transaction/generate_data.ts index 6026f762292c3..9f983fbb8877b 100644 --- a/x-pack/test/apm_api_integration/tests/errors/top_errors_for_transaction/generate_data.ts +++ b/x-pack/test/apm_api_integration/tests/errors/top_errors_for_transaction/generate_data.ts @@ -21,12 +21,12 @@ export const config = { }; export async function generateData({ - synthtraceEsClient, + apmSynthtraceEsClient, serviceName, start, end, }: { - synthtraceEsClient: ApmSynthtraceEsClient; + apmSynthtraceEsClient: ApmSynthtraceEsClient; serviceName: string; start: number; end: number; @@ -72,5 +72,5 @@ export async function generateData({ ]; }); - await synthtraceEsClient.index(documents); + await apmSynthtraceEsClient.index(documents); } diff --git a/x-pack/test/apm_api_integration/tests/errors/top_errors_for_transaction/top_errors_main_stats.spec.ts b/x-pack/test/apm_api_integration/tests/errors/top_errors_for_transaction/top_errors_main_stats.spec.ts index 9bb171ff64f30..8e946e081554f 100644 --- a/x-pack/test/apm_api_integration/tests/errors/top_errors_for_transaction/top_errors_main_stats.spec.ts +++ b/x-pack/test/apm_api_integration/tests/errors/top_errors_for_transaction/top_errors_main_stats.spec.ts @@ -20,7 +20,7 @@ type ErrorGroups = export default function ApiTest({ getService }: FtrProviderContext) { const registry = getService('registry'); const apmApiClient = getService('apmApiClient'); - const synthtraceEsClient = getService('synthtraceEsClient'); + const apmSynthtraceEsClient = getService('apmSynthtraceEsClient'); const serviceName = 'synth-go'; const start = new Date('2021-01-01T00:00:00.000Z').getTime(); @@ -66,10 +66,10 @@ export default function ApiTest({ getService }: FtrProviderContext) { } = config; before(async () => { - await generateData({ serviceName, start, end, synthtraceEsClient }); + await generateData({ serviceName, start, end, apmSynthtraceEsClient }); }); - after(() => synthtraceEsClient.clean()); + after(() => apmSynthtraceEsClient.clean()); describe('returns the correct data', () => { const NUMBER_OF_BUCKETS = 15; diff --git a/x-pack/test/apm_api_integration/tests/fleet/input_only_package.spec.ts b/x-pack/test/apm_api_integration/tests/fleet/input_only_package.spec.ts index 5d02209ca0aa6..b7d90ff9713ce 100644 --- a/x-pack/test/apm_api_integration/tests/fleet/input_only_package.spec.ts +++ b/x-pack/test/apm_api_integration/tests/fleet/input_only_package.spec.ts @@ -33,7 +33,7 @@ export default function ApiTest(ftrProviderContext: FtrProviderContext) { const bettertest = getBettertest(supertest); const config = getService('config'); const synthtraceKibanaClient = getService('synthtraceKibanaClient'); - const synthtraceEsClient = getService('synthtraceEsClient'); + const apmSynthtraceEsClient = getService('apmSynthtraceEsClient'); const API_KEY_NAME = 'apm_api_key_testing'; const APM_AGENT_POLICY_NAME = 'apm_agent_policy_testing'; @@ -104,7 +104,7 @@ export default function ApiTest(ftrProviderContext: FtrProviderContext) { async function cleanAll() { try { - await synthtraceEsClient.clean(); + await apmSynthtraceEsClient.clean(); await es.security.invalidateApiKey({ name: API_KEY_NAME }); await deleteAgentPolicyAndPackagePolicyByName({ bettertest, diff --git a/x-pack/test/apm_api_integration/tests/historical_data/has_data.spec.ts b/x-pack/test/apm_api_integration/tests/historical_data/has_data.spec.ts index 440fe7fd39b3b..e0b5a0e076ffd 100644 --- a/x-pack/test/apm_api_integration/tests/historical_data/has_data.spec.ts +++ b/x-pack/test/apm_api_integration/tests/historical_data/has_data.spec.ts @@ -13,7 +13,7 @@ import { FtrProviderContext } from '../../common/ftr_provider_context'; export default function ApiTest({ getService }: FtrProviderContext) { const registry = getService('registry'); const apmApiClient = getService('apmApiClient'); - const synthtraceEsClient = getService('synthtraceEsClient'); + const apmSynthtraceEsClient = getService('apmSynthtraceEsClient'); // FLAKY: https://github.com/elastic/kibana/issues/177385 registry.when('Historical data ', { config: 'basic', archives: [] }, () => { @@ -45,10 +45,10 @@ export default function ApiTest({ getService }: FtrProviderContext) { ), ]; - await synthtraceEsClient.index(documents); + await apmSynthtraceEsClient.index(documents); }); - after(() => synthtraceEsClient.clean()); + after(() => apmSynthtraceEsClient.clean()); it('returns hasData=true', async () => { const response = await apmApiClient.readUser({ endpoint: `GET /internal/apm/has_data` }); diff --git a/x-pack/test/apm_api_integration/tests/infrastructure/generate_data.ts b/x-pack/test/apm_api_integration/tests/infrastructure/generate_data.ts index eb9a34f6e1f63..437c4791e1972 100644 --- a/x-pack/test/apm_api_integration/tests/infrastructure/generate_data.ts +++ b/x-pack/test/apm_api_integration/tests/infrastructure/generate_data.ts @@ -8,11 +8,11 @@ import { apm, timerange } from '@kbn/apm-synthtrace-client'; import type { ApmSynthtraceEsClient } from '@kbn/apm-synthtrace'; export async function generateData({ - synthtraceEsClient, + apmSynthtraceEsClient, start, end, }: { - synthtraceEsClient: ApmSynthtraceEsClient; + apmSynthtraceEsClient: ApmSynthtraceEsClient; start: number; end: number; }) { @@ -24,7 +24,7 @@ export async function generateData({ .service({ name: 'synth-java', environment: 'production', agentName: 'java' }) .instance('instance-b'); - await synthtraceEsClient.index( + await apmSynthtraceEsClient.index( timerange(start, end) .interval('1m') .generator((timestamp) => { diff --git a/x-pack/test/apm_api_integration/tests/infrastructure/infrastructure_attributes.spec.ts b/x-pack/test/apm_api_integration/tests/infrastructure/infrastructure_attributes.spec.ts index e1b0d3c66cbaa..7a79e2f8be4b1 100644 --- a/x-pack/test/apm_api_integration/tests/infrastructure/infrastructure_attributes.spec.ts +++ b/x-pack/test/apm_api_integration/tests/infrastructure/infrastructure_attributes.spec.ts @@ -11,7 +11,7 @@ import { generateData } from './generate_data'; export default function ApiTest({ getService }: FtrProviderContext) { const registry = getService('registry'); const apmApiClient = getService('apmApiClient'); - const synthtraceEsClient = getService('synthtraceEsClient'); + const apmSynthtraceEsClient = getService('apmSynthtraceEsClient'); const start = new Date('2021-01-01T00:00:00.000Z').getTime(); const end = new Date('2021-01-01T00:15:00.000Z').getTime() - 1; @@ -52,10 +52,10 @@ export default function ApiTest({ getService }: FtrProviderContext) { registry.when('Infrastructure attributes', { config: 'basic', archives: [] }, () => { describe('when data is loaded', () => { beforeEach(async () => { - await generateData({ start, end, synthtraceEsClient }); + await generateData({ start, end, apmSynthtraceEsClient }); }); - afterEach(() => synthtraceEsClient.clean()); + afterEach(() => apmSynthtraceEsClient.clean()); describe('when service runs in container', () => { it('returns arrays of container ids and pod names', async () => { diff --git a/x-pack/test/apm_api_integration/tests/latency/service_apis.spec.ts b/x-pack/test/apm_api_integration/tests/latency/service_apis.spec.ts index 397c2f107ccd9..35ef23c8a4430 100644 --- a/x-pack/test/apm_api_integration/tests/latency/service_apis.spec.ts +++ b/x-pack/test/apm_api_integration/tests/latency/service_apis.spec.ts @@ -17,7 +17,7 @@ import { FtrProviderContext } from '../../common/ftr_provider_context'; export default function ApiTest({ getService }: FtrProviderContext) { const registry = getService('registry'); const apmApiClient = getService('apmApiClient'); - const synthtraceEsClient = getService('synthtraceEsClient'); + const apmSynthtraceEsClient = getService('apmSynthtraceEsClient'); const serviceName = 'synth-go'; const start = new Date('2021-01-01T00:00:00.000Z').getTime(); @@ -170,7 +170,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { .service({ name: serviceName, environment: 'development', agentName: 'go' }) .instance('instance-b'); - await synthtraceEsClient.index([ + await apmSynthtraceEsClient.index([ timerange(start, end) .interval('1m') .rate(GO_PROD_RATE) @@ -192,7 +192,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { ]); }); - after(() => synthtraceEsClient.clean()); + after(() => apmSynthtraceEsClient.clean()); describe('compare latency value between service inventory, latency chart, service inventory and transactions apis', () => { before(async () => { diff --git a/x-pack/test/apm_api_integration/tests/latency/service_maps.spec.ts b/x-pack/test/apm_api_integration/tests/latency/service_maps.spec.ts index 6796e448d216d..298fde675bc4a 100644 --- a/x-pack/test/apm_api_integration/tests/latency/service_maps.spec.ts +++ b/x-pack/test/apm_api_integration/tests/latency/service_maps.spec.ts @@ -15,7 +15,7 @@ import { FtrProviderContext } from '../../common/ftr_provider_context'; export default function ApiTest({ getService }: FtrProviderContext) { const registry = getService('registry'); const apmApiClient = getService('apmApiClient'); - const synthtraceEsClient = getService('synthtraceEsClient'); + const apmSynthtraceEsClient = getService('apmSynthtraceEsClient'); const serviceName = 'synth-go'; const start = new Date('2021-01-01T00:00:00.000Z').getTime(); @@ -87,7 +87,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { .service({ name: serviceName, environment: 'development', agentName: 'go' }) .instance('instance-b'); - await synthtraceEsClient.index([ + await apmSynthtraceEsClient.index([ timerange(start, end) .interval('1m') .rate(GO_PROD_RATE) @@ -112,7 +112,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { ]); }); - after(() => synthtraceEsClient.clean()); + after(() => apmSynthtraceEsClient.clean()); // FLAKY: https://github.com/elastic/kibana/issues/176976 describe('compare latency value between service inventory and service maps', () => { diff --git a/x-pack/test/apm_api_integration/tests/metrics/memory/generate_data.ts b/x-pack/test/apm_api_integration/tests/metrics/memory/generate_data.ts index 22abd71989206..c5bc09bc6f67b 100644 --- a/x-pack/test/apm_api_integration/tests/metrics/memory/generate_data.ts +++ b/x-pack/test/apm_api_integration/tests/metrics/memory/generate_data.ts @@ -22,11 +22,11 @@ export const expectedValues = { }; export async function generateData({ - synthtraceEsClient, + apmSynthtraceEsClient, start, end, }: { - synthtraceEsClient: ApmSynthtraceEsClient; + apmSynthtraceEsClient: ApmSynthtraceEsClient; start: number; end: number; }) { @@ -73,5 +73,5 @@ export async function generateData({ .timestamp(timestamp), ]); - await synthtraceEsClient.index(transactionsEvents); + await apmSynthtraceEsClient.index(transactionsEvents); } diff --git a/x-pack/test/apm_api_integration/tests/metrics/memory/memory_metrics.spec.ts b/x-pack/test/apm_api_integration/tests/metrics/memory/memory_metrics.spec.ts index 5af51dff5604c..e0f8fc1cf28c2 100644 --- a/x-pack/test/apm_api_integration/tests/metrics/memory/memory_metrics.spec.ts +++ b/x-pack/test/apm_api_integration/tests/metrics/memory/memory_metrics.spec.ts @@ -12,7 +12,7 @@ import { config, generateData } from './generate_data'; export default function ApiTest({ getService }: FtrProviderContext) { const registry = getService('registry'); const apmApiClient = getService('apmApiClient'); - const synthtraceEsClient = getService('synthtraceEsClient'); + const apmSynthtraceEsClient = getService('apmSynthtraceEsClient'); const start = new Date('2023-01-01T00:00:00.000Z').getTime(); const end = new Date('2023-01-01T00:15:00.000Z').getTime() - 1; @@ -36,10 +36,10 @@ export default function ApiTest({ getService }: FtrProviderContext) { // FLAKY: https://github.com/elastic/kibana/issues/176990 registry.when('Memory', { config: 'trial', archives: [] }, () => { before(async () => { - await generateData({ start, end, synthtraceEsClient }); + await generateData({ start, end, apmSynthtraceEsClient }); }); - after(() => synthtraceEsClient.clean()); + after(() => apmSynthtraceEsClient.clean()); it('returns system memory stats', async () => { const expectedFreeMemory = 1 - config.memoryFree / config.memoryTotal; diff --git a/x-pack/test/apm_api_integration/tests/metrics/serverless/generate_data.ts b/x-pack/test/apm_api_integration/tests/metrics/serverless/generate_data.ts index e6a7cc57f0698..b835201d51564 100644 --- a/x-pack/test/apm_api_integration/tests/metrics/serverless/generate_data.ts +++ b/x-pack/test/apm_api_integration/tests/metrics/serverless/generate_data.ts @@ -26,11 +26,11 @@ export const expectedValues = { }; export async function generateData({ - synthtraceEsClient, + apmSynthtraceEsClient, start, end, }: { - synthtraceEsClient: ApmSynthtraceEsClient; + apmSynthtraceEsClient: ApmSynthtraceEsClient; start: number; end: number; }) { @@ -116,5 +116,5 @@ export async function generateData({ .success(), ]); - await synthtraceEsClient.index(transactionsEvents); + await apmSynthtraceEsClient.index(transactionsEvents); } diff --git a/x-pack/test/apm_api_integration/tests/metrics/serverless/serverless_active_instances.spec.ts b/x-pack/test/apm_api_integration/tests/metrics/serverless/serverless_active_instances.spec.ts index cbb6317c3bd75..1b15e03c91987 100644 --- a/x-pack/test/apm_api_integration/tests/metrics/serverless/serverless_active_instances.spec.ts +++ b/x-pack/test/apm_api_integration/tests/metrics/serverless/serverless_active_instances.spec.ts @@ -14,7 +14,7 @@ import { config, expectedValues, generateData } from './generate_data'; export default function ApiTest({ getService }: FtrProviderContext) { const registry = getService('registry'); const apmApiClient = getService('apmApiClient'); - const synthtraceEsClient = getService('synthtraceEsClient'); + const apmSynthtraceEsClient = getService('apmSynthtraceEsClient'); const start = new Date('2021-01-01T00:00:00.000Z').getTime(); const end = new Date('2021-01-01T00:15:00.000Z').getTime() - 1; @@ -49,10 +49,10 @@ export default function ApiTest({ getService }: FtrProviderContext) { const { expectedMemoryUsed } = expectedValues; before(async () => { - await generateData({ start, end, synthtraceEsClient }); + await generateData({ start, end, apmSynthtraceEsClient }); }); - after(() => synthtraceEsClient.clean()); + after(() => apmSynthtraceEsClient.clean()); describe('Python service', () => { let activeInstances: APIReturnType<'GET /internal/apm/services/{serviceName}/metrics/serverless/active_instances'>; diff --git a/x-pack/test/apm_api_integration/tests/metrics/serverless/serverless_functions_overview.spec.ts b/x-pack/test/apm_api_integration/tests/metrics/serverless/serverless_functions_overview.spec.ts index 133953dd9772f..94792228a2859 100644 --- a/x-pack/test/apm_api_integration/tests/metrics/serverless/serverless_functions_overview.spec.ts +++ b/x-pack/test/apm_api_integration/tests/metrics/serverless/serverless_functions_overview.spec.ts @@ -13,7 +13,7 @@ import { config, expectedValues, generateData } from './generate_data'; export default function ApiTest({ getService }: FtrProviderContext) { const registry = getService('registry'); const apmApiClient = getService('apmApiClient'); - const synthtraceEsClient = getService('synthtraceEsClient'); + const apmSynthtraceEsClient = getService('apmSynthtraceEsClient'); const start = new Date('2021-01-01T00:00:00.000Z').getTime(); const end = new Date('2021-01-01T00:15:00.000Z').getTime() - 1; @@ -46,10 +46,10 @@ export default function ApiTest({ getService }: FtrProviderContext) { const { expectedMemoryUsed } = expectedValues; before(async () => { - await generateData({ start, end, synthtraceEsClient }); + await generateData({ start, end, apmSynthtraceEsClient }); }); - after(() => synthtraceEsClient.clean()); + after(() => apmSynthtraceEsClient.clean()); describe('Python service', () => { let functionsOverview: APIReturnType<'GET /internal/apm/services/{serviceName}/metrics/serverless/functions_overview'>; diff --git a/x-pack/test/apm_api_integration/tests/metrics/serverless/serverless_metrics_charts.spec.ts b/x-pack/test/apm_api_integration/tests/metrics/serverless/serverless_metrics_charts.spec.ts index b94d63e491ffd..192fb3c87c48b 100644 --- a/x-pack/test/apm_api_integration/tests/metrics/serverless/serverless_metrics_charts.spec.ts +++ b/x-pack/test/apm_api_integration/tests/metrics/serverless/serverless_metrics_charts.spec.ts @@ -21,7 +21,7 @@ function isNotNullOrZeroCoordinate(coordinate: Coordinate) { export default function ApiTest({ getService }: FtrProviderContext) { const registry = getService('registry'); const apmApiClient = getService('apmApiClient'); - const synthtraceEsClient = getService('synthtraceEsClient'); + const apmSynthtraceEsClient = getService('apmSynthtraceEsClient'); const start = new Date('2021-01-01T00:00:00.000Z').getTime(); const end = new Date('2021-01-01T00:15:00.000Z').getTime() - 1; @@ -77,10 +77,10 @@ export default function ApiTest({ getService }: FtrProviderContext) { } = config; before(async () => { - await generateData({ start, end, synthtraceEsClient }); + await generateData({ start, end, apmSynthtraceEsClient }); }); - after(() => synthtraceEsClient.clean()); + after(() => apmSynthtraceEsClient.clean()); describe('Python service', () => { let serverlessMetrics: APIReturnType<'GET /internal/apm/services/{serviceName}/metrics/serverless/charts'>; diff --git a/x-pack/test/apm_api_integration/tests/metrics/serverless/serverless_summary.spec.ts b/x-pack/test/apm_api_integration/tests/metrics/serverless/serverless_summary.spec.ts index 0f013ca69776b..727c7eee1e3cd 100644 --- a/x-pack/test/apm_api_integration/tests/metrics/serverless/serverless_summary.spec.ts +++ b/x-pack/test/apm_api_integration/tests/metrics/serverless/serverless_summary.spec.ts @@ -13,7 +13,7 @@ import { config, expectedValues, generateData } from './generate_data'; export default function ApiTest({ getService }: FtrProviderContext) { const registry = getService('registry'); const apmApiClient = getService('apmApiClient'); - const synthtraceEsClient = getService('synthtraceEsClient'); + const apmSynthtraceEsClient = getService('apmSynthtraceEsClient'); const start = new Date('2021-01-01T00:00:00.000Z').getTime(); const end = new Date('2021-01-01T00:15:00.000Z').getTime() - 1; @@ -55,10 +55,10 @@ export default function ApiTest({ getService }: FtrProviderContext) { const { expectedMemoryUsedRate } = expectedValues; before(async () => { - await generateData({ start, end, synthtraceEsClient }); + await generateData({ start, end, apmSynthtraceEsClient }); }); - after(() => synthtraceEsClient.clean()); + after(() => apmSynthtraceEsClient.clean()); describe('Python service', () => { let serverlessSummary: APIReturnType<'GET /internal/apm/services/{serviceName}/metrics/serverless/summary'>; diff --git a/x-pack/test/apm_api_integration/tests/mobile/crashes/crash_group_list.spec.ts b/x-pack/test/apm_api_integration/tests/mobile/crashes/crash_group_list.spec.ts index 05897e7c22cd3..274199437f188 100644 --- a/x-pack/test/apm_api_integration/tests/mobile/crashes/crash_group_list.spec.ts +++ b/x-pack/test/apm_api_integration/tests/mobile/crashes/crash_group_list.spec.ts @@ -19,7 +19,7 @@ type ErrorGroups = export default function ApiTest({ getService }: FtrProviderContext) { const registry = getService('registry'); const apmApiClient = getService('apmApiClient'); - const synthtraceEsClient = getService('synthtraceEsClient'); + const apmSynthtraceEsClient = getService('apmSynthtraceEsClient'); const serviceName = 'synth-swift'; const start = new Date('2021-01-01T00:00:00.000Z').getTime(); @@ -73,7 +73,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { .service({ name: serviceName, environment: 'production', agentName: 'swift' }) .instance('instance-a'); - await synthtraceEsClient.index([ + await apmSynthtraceEsClient.index([ timerange(start, end) .interval('1m') .rate(appleTransaction.successRate) @@ -131,7 +131,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { ]); }); - after(() => synthtraceEsClient.clean()); + after(() => apmSynthtraceEsClient.clean()); describe('returns the correct data', () => { let errorGroups: ErrorGroups; diff --git a/x-pack/test/apm_api_integration/tests/mobile/crashes/distribution.spec.ts b/x-pack/test/apm_api_integration/tests/mobile/crashes/distribution.spec.ts index d098d83f7a19e..aad32f3490d2a 100644 --- a/x-pack/test/apm_api_integration/tests/mobile/crashes/distribution.spec.ts +++ b/x-pack/test/apm_api_integration/tests/mobile/crashes/distribution.spec.ts @@ -21,7 +21,7 @@ type ErrorsDistribution = export default function ApiTest({ getService }: FtrProviderContext) { const registry = getService('registry'); const apmApiClient = getService('apmApiClient'); - const synthtraceEsClient = getService('synthtraceEsClient'); + const apmSynthtraceEsClient = getService('apmSynthtraceEsClient'); const serviceName = 'synth-swift'; const start = new Date('2021-01-01T00:00:00.000Z').getTime(); @@ -65,10 +65,10 @@ export default function ApiTest({ getService }: FtrProviderContext) { describe('errors distribution', () => { const { appleTransaction, bananaTransaction } = config; before(async () => { - await generateData({ serviceName, start, end, synthtraceEsClient }); + await generateData({ serviceName, start, end, apmSynthtraceEsClient }); }); - after(() => synthtraceEsClient.clean()); + after(() => apmSynthtraceEsClient.clean()); describe('without comparison', () => { let errorsDistribution: ErrorsDistribution; diff --git a/x-pack/test/apm_api_integration/tests/mobile/crashes/generate_data.ts b/x-pack/test/apm_api_integration/tests/mobile/crashes/generate_data.ts index 606d97fb9ce04..1e25cef4d3fd3 100644 --- a/x-pack/test/apm_api_integration/tests/mobile/crashes/generate_data.ts +++ b/x-pack/test/apm_api_integration/tests/mobile/crashes/generate_data.ts @@ -21,12 +21,12 @@ export const config = { }; export async function generateData({ - synthtraceEsClient, + apmSynthtraceEsClient, serviceName, start, end, }: { - synthtraceEsClient: ApmSynthtraceEsClient; + apmSynthtraceEsClient: ApmSynthtraceEsClient; serviceName: string; start: number; end: number; @@ -72,5 +72,5 @@ export async function generateData({ ]; }); - await synthtraceEsClient.index(documents); + await apmSynthtraceEsClient.index(documents); } diff --git a/x-pack/test/apm_api_integration/tests/mobile/errors/generate_data.ts b/x-pack/test/apm_api_integration/tests/mobile/errors/generate_data.ts index 663849f274adb..c1ae372335824 100644 --- a/x-pack/test/apm_api_integration/tests/mobile/errors/generate_data.ts +++ b/x-pack/test/apm_api_integration/tests/mobile/errors/generate_data.ts @@ -21,12 +21,12 @@ export const config = { }; export async function generateData({ - synthtraceEsClient, + apmSynthtraceEsClient, serviceName, start, end, }: { - synthtraceEsClient: ApmSynthtraceEsClient; + apmSynthtraceEsClient: ApmSynthtraceEsClient; serviceName: string; start: number; end: number; @@ -69,5 +69,5 @@ export async function generateData({ ]; }); - await synthtraceEsClient.index(documents); + await apmSynthtraceEsClient.index(documents); } diff --git a/x-pack/test/apm_api_integration/tests/mobile/errors/group_id_samples.spec.ts b/x-pack/test/apm_api_integration/tests/mobile/errors/group_id_samples.spec.ts index 29413e79ffd74..e3e69a540881c 100644 --- a/x-pack/test/apm_api_integration/tests/mobile/errors/group_id_samples.spec.ts +++ b/x-pack/test/apm_api_integration/tests/mobile/errors/group_id_samples.spec.ts @@ -22,7 +22,7 @@ type ErrorSampleDetails = export default function ApiTest({ getService }: FtrProviderContext) { const registry = getService('registry'); const apmApiClient = getService('apmApiClient'); - const synthtraceEsClient = getService('synthtraceEsClient'); + const apmSynthtraceEsClient = getService('apmSynthtraceEsClient'); const serviceName = 'synth-go'; const start = new Date('2021-01-01T00:00:00.000Z').getTime(); @@ -80,10 +80,10 @@ export default function ApiTest({ getService }: FtrProviderContext) { const { bananaTransaction } = config; describe('error group id', () => { before(async () => { - await generateData({ serviceName, start, end, synthtraceEsClient }); + await generateData({ serviceName, start, end, apmSynthtraceEsClient }); }); - after(() => synthtraceEsClient.clean()); + after(() => apmSynthtraceEsClient.clean()); describe('return correct data', () => { let errorsSamplesResponse: ErrorGroupSamples; @@ -108,10 +108,10 @@ export default function ApiTest({ getService }: FtrProviderContext) { registry.when('when error sample data is loaded', { config: 'basic', archives: [] }, () => { describe('error sample id', () => { before(async () => { - await generateData({ serviceName, start, end, synthtraceEsClient }); + await generateData({ serviceName, start, end, apmSynthtraceEsClient }); }); - after(() => synthtraceEsClient.clean()); + after(() => apmSynthtraceEsClient.clean()); describe('return correct data', () => { let errorSampleDetailsResponse: ErrorSampleDetails; @@ -146,7 +146,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { const errorMessage = 'Error 1'; const groupId = getErrorGroupingKey(errorMessage); - await synthtraceEsClient.index([ + await apmSynthtraceEsClient.index([ timerange(start, end) .interval('15m') .rate(1) @@ -174,7 +174,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { errorGroupSamplesResponse = (await callErrorGroupSamplesApi({ groupId })).body; }); - after(() => synthtraceEsClient.clean()); + after(() => apmSynthtraceEsClient.clean()); it('returns the errors in the correct order (sampled first, then unsampled)', () => { const idsOfErrors = errorGroupSamplesResponse.errorSampleIds.map((id) => parseInt(id, 10)); diff --git a/x-pack/test/apm_api_integration/tests/mobile/generate_mobile_data.ts b/x-pack/test/apm_api_integration/tests/mobile/generate_mobile_data.ts index 91a8aac9bc3d3..a4420b3f53c7c 100644 --- a/x-pack/test/apm_api_integration/tests/mobile/generate_mobile_data.ts +++ b/x-pack/test/apm_api_integration/tests/mobile/generate_mobile_data.ts @@ -12,11 +12,11 @@ export const SERVICE_VERSIONS = ['2.3', '1.2', '1.1']; export async function generateMobileData({ start, end, - synthtraceEsClient, + apmSynthtraceEsClient, }: { start: number; end: number; - synthtraceEsClient: ApmSynthtraceEsClient; + apmSynthtraceEsClient: ApmSynthtraceEsClient; }) { const galaxy10 = apm .mobileApp({ @@ -210,7 +210,7 @@ export async function generateMobileData({ }) .setNetworkConnection({ type: 'wifi' }); - return await synthtraceEsClient.index([ + return await apmSynthtraceEsClient.index([ timerange(start, end) .interval('5m') .rate(1) diff --git a/x-pack/test/apm_api_integration/tests/mobile/mobile_detailed_statistics_by_field.spec.ts b/x-pack/test/apm_api_integration/tests/mobile/mobile_detailed_statistics_by_field.spec.ts index 0e128ba6b102f..40bf9729bee6e 100644 --- a/x-pack/test/apm_api_integration/tests/mobile/mobile_detailed_statistics_by_field.spec.ts +++ b/x-pack/test/apm_api_integration/tests/mobile/mobile_detailed_statistics_by_field.spec.ts @@ -19,7 +19,7 @@ type MobileDetailedStatisticsResponse = export default function ApiTest({ getService }: FtrProviderContext) { const apmApiClient = getService('apmApiClient'); const registry = getService('registry'); - const synthtraceEsClient = getService('synthtraceEsClient'); + const apmSynthtraceEsClient = getService('apmSynthtraceEsClient'); const start = new Date('2023-01-01T00:00:00.000Z').getTime(); const end = new Date('2023-01-01T00:15:00.000Z').getTime() - 1; @@ -79,13 +79,13 @@ export default function ApiTest({ getService }: FtrProviderContext) { () => { before(async () => { await generateMobileData({ - synthtraceEsClient, + apmSynthtraceEsClient, start, end, }); }); - after(() => synthtraceEsClient.clean()); + after(() => apmSynthtraceEsClient.clean()); describe('when comparison is disable', () => { it('returns current period data only', async () => { diff --git a/x-pack/test/apm_api_integration/tests/mobile/mobile_filters.spec.ts b/x-pack/test/apm_api_integration/tests/mobile/mobile_filters.spec.ts index 2dbe88baf179e..4286266801609 100644 --- a/x-pack/test/apm_api_integration/tests/mobile/mobile_filters.spec.ts +++ b/x-pack/test/apm_api_integration/tests/mobile/mobile_filters.spec.ts @@ -17,11 +17,11 @@ type MobileFilters = APIReturnType<'GET /internal/apm/services/{serviceName}/mob async function generateData({ start, end, - synthtraceEsClient, + apmSynthtraceEsClient, }: { start: number; end: number; - synthtraceEsClient: ApmSynthtraceEsClient; + apmSynthtraceEsClient: ApmSynthtraceEsClient; }) { const galaxy10 = apm .mobileApp({ @@ -88,7 +88,7 @@ async function generateData({ carrierMCC: '440', }); - return await synthtraceEsClient.index([ + return await apmSynthtraceEsClient.index([ timerange(start, end) .interval('5m') .rate(1) @@ -136,7 +136,7 @@ async function generateData({ export default function ApiTest({ getService }: FtrProviderContext) { const apmApiClient = getService('apmApiClient'); const registry = getService('registry'); - const synthtraceEsClient = getService('synthtraceEsClient'); + const apmSynthtraceEsClient = getService('apmSynthtraceEsClient'); const start = new Date('2023-01-01T00:00:00.000Z').getTime(); const end = new Date('2023-01-01T00:15:00.000Z').getTime() - 1; @@ -181,13 +181,13 @@ export default function ApiTest({ getService }: FtrProviderContext) { registry.when('Mobile filters', { config: 'basic', archives: [] }, () => { before(async () => { await generateData({ - synthtraceEsClient, + apmSynthtraceEsClient, start, end, }); }); - after(() => synthtraceEsClient.clean()); + after(() => apmSynthtraceEsClient.clean()); describe('when data is loaded', () => { let response: MobileFilters; diff --git a/x-pack/test/apm_api_integration/tests/mobile/mobile_http_requests_timeseries.spec.ts b/x-pack/test/apm_api_integration/tests/mobile/mobile_http_requests_timeseries.spec.ts index b924af87d3e20..4c661c9ae14f6 100644 --- a/x-pack/test/apm_api_integration/tests/mobile/mobile_http_requests_timeseries.spec.ts +++ b/x-pack/test/apm_api_integration/tests/mobile/mobile_http_requests_timeseries.spec.ts @@ -13,7 +13,7 @@ import { generateMobileData } from './generate_mobile_data'; export default function ApiTest({ getService }: FtrProviderContext) { const apmApiClient = getService('apmApiClient'); const registry = getService('registry'); - const synthtraceEsClient = getService('synthtraceEsClient'); + const apmSynthtraceEsClient = getService('apmSynthtraceEsClient'); const start = new Date('2023-01-01T00:00:00.000Z').getTime(); const end = new Date('2023-01-01T02:00:00.000Z').getTime(); @@ -66,13 +66,13 @@ export default function ApiTest({ getService }: FtrProviderContext) { registry.when('Mobile HTTP requests with data loaded', { config: 'basic', archives: [] }, () => { before(async () => { await generateMobileData({ - synthtraceEsClient, + apmSynthtraceEsClient, start, end, }); }); - after(() => synthtraceEsClient.clean()); + after(() => apmSynthtraceEsClient.clean()); describe('when data is loaded', () => { it('returns timeseries for http requests chart', async () => { diff --git a/x-pack/test/apm_api_integration/tests/mobile/mobile_location_stats.spec.ts b/x-pack/test/apm_api_integration/tests/mobile/mobile_location_stats.spec.ts index 8e6e7d7cfd52e..0acf17308b0d8 100644 --- a/x-pack/test/apm_api_integration/tests/mobile/mobile_location_stats.spec.ts +++ b/x-pack/test/apm_api_integration/tests/mobile/mobile_location_stats.spec.ts @@ -22,11 +22,11 @@ type MobileLocationStats = async function generateData({ start, end, - synthtraceEsClient, + apmSynthtraceEsClient, }: { start: number; end: number; - synthtraceEsClient: ApmSynthtraceEsClient; + apmSynthtraceEsClient: ApmSynthtraceEsClient; }) { const galaxy10 = apm .mobileApp({ @@ -130,7 +130,7 @@ async function generateData({ carrierMCC: '440', }); - await synthtraceEsClient.index([ + await apmSynthtraceEsClient.index([ timerange(start, end) .interval('5m') .rate(1) @@ -179,7 +179,7 @@ async function generateData({ export default function ApiTest({ getService }: FtrProviderContext) { const apmApiClient = getService('apmApiClient'); const registry = getService('registry'); - const synthtraceEsClient = getService('synthtraceEsClient'); + const apmSynthtraceEsClient = getService('apmSynthtraceEsClient'); const start = new Date('2023-01-01T00:00:00.000Z').getTime(); const end = new Date('2023-01-01T00:15:00.000Z').getTime() - 1; @@ -236,13 +236,13 @@ export default function ApiTest({ getService }: FtrProviderContext) { registry.when('Location stats', { config: 'basic', archives: [] }, () => { before(async () => { await generateData({ - synthtraceEsClient, + apmSynthtraceEsClient, start, end, }); }); - after(() => synthtraceEsClient.clean()); + after(() => apmSynthtraceEsClient.clean()); describe('when data is loaded', () => { let response: MobileLocationStats; diff --git a/x-pack/test/apm_api_integration/tests/mobile/mobile_main_statistics_by_field.spec.ts b/x-pack/test/apm_api_integration/tests/mobile/mobile_main_statistics_by_field.spec.ts index 57832797b3798..a3f95eaeb495d 100644 --- a/x-pack/test/apm_api_integration/tests/mobile/mobile_main_statistics_by_field.spec.ts +++ b/x-pack/test/apm_api_integration/tests/mobile/mobile_main_statistics_by_field.spec.ts @@ -30,11 +30,11 @@ function calculateThroughput({ start, end }: { start: number; end: number }) { async function generateData({ start, end, - synthtraceEsClient, + apmSynthtraceEsClient, }: { start: number; end: number; - synthtraceEsClient: ApmSynthtraceEsClient; + apmSynthtraceEsClient: ApmSynthtraceEsClient; }) { const galaxy10 = apm .mobileApp({ @@ -101,7 +101,7 @@ async function generateData({ carrierMCC: '440', }); - return await synthtraceEsClient.index([ + return await apmSynthtraceEsClient.index([ timerange(start, end) .interval('5m') .rate(1) @@ -129,7 +129,7 @@ async function generateData({ export default function ApiTest({ getService }: FtrProviderContext) { const apmApiClient = getService('apmApiClient'); const registry = getService('registry'); - const synthtraceEsClient = getService('synthtraceEsClient'); + const apmSynthtraceEsClient = getService('apmSynthtraceEsClient'); const start = new Date('2023-01-01T00:00:00.000Z').getTime(); const end = new Date('2023-01-01T00:15:00.000Z').getTime() - 1; @@ -182,13 +182,13 @@ export default function ApiTest({ getService }: FtrProviderContext) { registry.when('Mobile main statistics', { config: 'basic', archives: [] }, () => { before(async () => { await generateData({ - synthtraceEsClient, + apmSynthtraceEsClient, start, end, }); }); - after(() => synthtraceEsClient.clean()); + after(() => apmSynthtraceEsClient.clean()); describe('when data is loaded', () => { const huaweiLatency = calculateLatency(HUAWEI_DURATION); diff --git a/x-pack/test/apm_api_integration/tests/mobile/mobile_most_used_chart.spec.ts b/x-pack/test/apm_api_integration/tests/mobile/mobile_most_used_chart.spec.ts index b4d595a728356..497e6987a3e2f 100644 --- a/x-pack/test/apm_api_integration/tests/mobile/mobile_most_used_chart.spec.ts +++ b/x-pack/test/apm_api_integration/tests/mobile/mobile_most_used_chart.spec.ts @@ -17,7 +17,7 @@ type MostUsedCharts = export default function ApiTest({ getService }: FtrProviderContext) { const apmApiClient = getService('apmApiClient'); const registry = getService('registry'); - const synthtraceEsClient = getService('synthtraceEsClient'); + const apmSynthtraceEsClient = getService('apmSynthtraceEsClient'); const start = new Date('2023-01-01T00:00:00.000Z').getTime(); const end = new Date('2023-01-01T00:15:00.000Z').getTime() - 1; @@ -68,13 +68,13 @@ export default function ApiTest({ getService }: FtrProviderContext) { registry.when('Mobile stats', { config: 'basic', archives: [] }, () => { before(async () => { await generateMobileData({ - synthtraceEsClient, + apmSynthtraceEsClient, start, end, }); }); - after(() => synthtraceEsClient.clean()); + after(() => apmSynthtraceEsClient.clean()); describe('when data is loaded', () => { let response: MostUsedCharts; diff --git a/x-pack/test/apm_api_integration/tests/mobile/mobile_sessions_timeseries.spec.ts b/x-pack/test/apm_api_integration/tests/mobile/mobile_sessions_timeseries.spec.ts index d9d70e3ede65f..99f0f245c8c4c 100644 --- a/x-pack/test/apm_api_integration/tests/mobile/mobile_sessions_timeseries.spec.ts +++ b/x-pack/test/apm_api_integration/tests/mobile/mobile_sessions_timeseries.spec.ts @@ -13,7 +13,7 @@ import { generateMobileData } from './generate_mobile_data'; export default function ApiTest({ getService }: FtrProviderContext) { const apmApiClient = getService('apmApiClient'); const registry = getService('registry'); - const synthtraceEsClient = getService('synthtraceEsClient'); + const apmSynthtraceEsClient = getService('apmSynthtraceEsClient'); const start = new Date('2023-01-01T00:00:00.000Z').getTime(); const end = new Date('2023-01-01T02:00:00.000Z').getTime(); @@ -62,13 +62,13 @@ export default function ApiTest({ getService }: FtrProviderContext) { registry.when('with data loaded', { config: 'basic', archives: [] }, () => { before(async () => { await generateMobileData({ - synthtraceEsClient, + apmSynthtraceEsClient, start, end, }); }); - after(() => synthtraceEsClient.clean()); + after(() => apmSynthtraceEsClient.clean()); describe('when data is loaded', () => { it('returns timeseries for sessions chart', async () => { diff --git a/x-pack/test/apm_api_integration/tests/mobile/mobile_stats.spec.ts b/x-pack/test/apm_api_integration/tests/mobile/mobile_stats.spec.ts index 8de8fea4a5536..22b7d0c8b8f65 100644 --- a/x-pack/test/apm_api_integration/tests/mobile/mobile_stats.spec.ts +++ b/x-pack/test/apm_api_integration/tests/mobile/mobile_stats.spec.ts @@ -22,11 +22,11 @@ type MobileStats = APIReturnType<'GET /internal/apm/mobile-services/{serviceName async function generateData({ start, end, - synthtraceEsClient, + apmSynthtraceEsClient, }: { start: number; end: number; - synthtraceEsClient: ApmSynthtraceEsClient; + apmSynthtraceEsClient: ApmSynthtraceEsClient; }) { const galaxy10 = apm .mobileApp({ @@ -93,7 +93,7 @@ async function generateData({ carrierMCC: '440', }); - return await synthtraceEsClient.index([ + return await apmSynthtraceEsClient.index([ timerange(start, end) .interval('5m') .rate(1) @@ -137,7 +137,7 @@ async function generateData({ export default function ApiTest({ getService }: FtrProviderContext) { const apmApiClient = getService('apmApiClient'); const registry = getService('registry'); - const synthtraceEsClient = getService('synthtraceEsClient'); + const apmSynthtraceEsClient = getService('apmSynthtraceEsClient'); const start = new Date('2023-01-01T00:00:00.000Z').getTime(); const end = new Date('2023-01-01T00:15:00.000Z').getTime() - 1; @@ -188,13 +188,13 @@ export default function ApiTest({ getService }: FtrProviderContext) { registry.when('Mobile stats', { config: 'basic', archives: [] }, () => { before(async () => { await generateData({ - synthtraceEsClient, + apmSynthtraceEsClient, start, end, }); }); - after(() => synthtraceEsClient.clean()); + after(() => apmSynthtraceEsClient.clean()); describe('when data is loaded', () => { let response: MobileStats; diff --git a/x-pack/test/apm_api_integration/tests/mobile/mobile_terms_by_field.spec.ts b/x-pack/test/apm_api_integration/tests/mobile/mobile_terms_by_field.spec.ts index 80f8ed366dd52..d50371423c166 100644 --- a/x-pack/test/apm_api_integration/tests/mobile/mobile_terms_by_field.spec.ts +++ b/x-pack/test/apm_api_integration/tests/mobile/mobile_terms_by_field.spec.ts @@ -17,11 +17,11 @@ import { FtrProviderContext } from '../../common/ftr_provider_context'; async function generateData({ start, end, - synthtraceEsClient, + apmSynthtraceEsClient, }: { start: number; end: number; - synthtraceEsClient: ApmSynthtraceEsClient; + apmSynthtraceEsClient: ApmSynthtraceEsClient; }) { const galaxy10 = apm .mobileApp({ @@ -88,7 +88,7 @@ async function generateData({ carrierMCC: '440', }); - return await synthtraceEsClient.index([ + return await apmSynthtraceEsClient.index([ timerange(start, end) .interval('5m') .rate(1) @@ -127,7 +127,7 @@ async function generateData({ export default function ApiTest({ getService }: FtrProviderContext) { const apmApiClient = getService('apmApiClient'); const registry = getService('registry'); - const synthtraceEsClient = getService('synthtraceEsClient'); + const apmSynthtraceEsClient = getService('apmSynthtraceEsClient'); const start = new Date('2023-01-01T00:00:00.000Z').getTime(); const end = new Date('2023-01-01T00:15:00.000Z').getTime() - 1; @@ -189,13 +189,13 @@ export default function ApiTest({ getService }: FtrProviderContext) { registry.when('Mobile terms', { config: 'basic', archives: [] }, () => { before(async () => { await generateData({ - synthtraceEsClient, + apmSynthtraceEsClient, start, end, }); }); - after(() => synthtraceEsClient.clean()); + after(() => apmSynthtraceEsClient.clean()); describe('when data is loaded', () => { it('returns mobile devices', async () => { diff --git a/x-pack/test/apm_api_integration/tests/observability_overview/observability_overview.spec.ts b/x-pack/test/apm_api_integration/tests/observability_overview/observability_overview.spec.ts index a72ca0539c7af..763d8eee929d2 100644 --- a/x-pack/test/apm_api_integration/tests/observability_overview/observability_overview.spec.ts +++ b/x-pack/test/apm_api_integration/tests/observability_overview/observability_overview.spec.ts @@ -16,7 +16,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { const registry = getService('registry'); const apmApiClient = getService('apmApiClient'); - const synthtraceEsClient = getService('synthtraceEsClient'); + const apmSynthtraceEsClient = getService('apmSynthtraceEsClient'); const start = new Date('2021-01-01T00:00:00.000Z').getTime(); const end = new Date('2021-01-01T00:15:00.000Z').getTime() - 1; @@ -106,7 +106,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { .service({ name: 'synth-java', environment: 'production', agentName: 'java' }) .instance('instance-c'); - await synthtraceEsClient.index([ + await apmSynthtraceEsClient.index([ timerange(start, end) .interval('1m') .rate(GO_PROD_RATE) @@ -137,7 +137,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { ]); }); - after(() => synthtraceEsClient.clean()); + after(() => apmSynthtraceEsClient.clean()); describe('compare throughput values', () => { let throughputValues: Awaited>; diff --git a/x-pack/test/apm_api_integration/tests/service_groups/service_group_count/generate_data.ts b/x-pack/test/apm_api_integration/tests/service_groups/service_group_count/generate_data.ts index 292307d7cc1e3..7f9b1487bb8ef 100644 --- a/x-pack/test/apm_api_integration/tests/service_groups/service_group_count/generate_data.ts +++ b/x-pack/test/apm_api_integration/tests/service_groups/service_group_count/generate_data.ts @@ -8,11 +8,11 @@ import { apm, timerange } from '@kbn/apm-synthtrace-client'; import type { ApmSynthtraceEsClient } from '@kbn/apm-synthtrace'; export async function generateData({ - synthtraceEsClient, + apmSynthtraceEsClient, start, end, }: { - synthtraceEsClient: ApmSynthtraceEsClient; + apmSynthtraceEsClient: ApmSynthtraceEsClient; start: number; end: number; }) { @@ -28,7 +28,7 @@ export async function generateData({ .instance('instance-3'), ]; - await synthtraceEsClient.index( + await apmSynthtraceEsClient.index( synthServices.map((service) => timerange(start, end) .interval('5m') diff --git a/x-pack/test/apm_api_integration/tests/service_groups/service_group_count/service_group_count.spec.ts b/x-pack/test/apm_api_integration/tests/service_groups/service_group_count/service_group_count.spec.ts index 427edcf0b1614..044006e273348 100644 --- a/x-pack/test/apm_api_integration/tests/service_groups/service_group_count/service_group_count.spec.ts +++ b/x-pack/test/apm_api_integration/tests/service_groups/service_group_count/service_group_count.spec.ts @@ -22,7 +22,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { const registry = getService('registry'); const apmApiClient = getService('apmApiClient'); const supertest = getService('supertest'); - const synthtraceEsClient = getService('synthtraceEsClient'); + const apmSynthtraceEsClient = getService('apmSynthtraceEsClient'); const es = getService('es'); const log = getService('log'); const start = Date.now() - 24 * 60 * 60 * 1000; @@ -52,7 +52,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { before(async () => { const [, { body: synthbeansServiceGroup }, { body: opbeansServiceGroup }] = await Promise.all( [ - generateData({ start, end, synthtraceEsClient }), + generateData({ start, end, apmSynthtraceEsClient }), createServiceGroupApi({ apmApiClient, groupName: 'synthbeans', @@ -71,7 +71,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { after(async () => { await deleteAllServiceGroups(apmApiClient); - await synthtraceEsClient.clean(); + await apmSynthtraceEsClient.clean(); }); it('returns the correct number of services', async () => { diff --git a/x-pack/test/apm_api_integration/tests/service_groups/service_group_with_overflow/generate_data.ts b/x-pack/test/apm_api_integration/tests/service_groups/service_group_with_overflow/generate_data.ts index e688e6ac6836a..b9fe538d580dd 100644 --- a/x-pack/test/apm_api_integration/tests/service_groups/service_group_with_overflow/generate_data.ts +++ b/x-pack/test/apm_api_integration/tests/service_groups/service_group_with_overflow/generate_data.ts @@ -8,11 +8,11 @@ import { apm, timerange } from '@kbn/apm-synthtrace-client'; import type { ApmSynthtraceEsClient } from '@kbn/apm-synthtrace'; export async function generateData({ - synthtraceEsClient, + apmSynthtraceEsClient, start, end, }: { - synthtraceEsClient: ApmSynthtraceEsClient; + apmSynthtraceEsClient: ApmSynthtraceEsClient; start: string; end: string; }) { @@ -25,7 +25,7 @@ export async function generateData({ .instance('instance-2'), ]; - await synthtraceEsClient.index( + await apmSynthtraceEsClient.index( synthServices.map((service) => timerange(start, end) .interval('5m') diff --git a/x-pack/test/apm_api_integration/tests/service_groups/service_group_with_overflow/service_group_with_overflow.spec.ts b/x-pack/test/apm_api_integration/tests/service_groups/service_group_with_overflow/service_group_with_overflow.spec.ts index 26d6b54025cca..93b873143599a 100644 --- a/x-pack/test/apm_api_integration/tests/service_groups/service_group_with_overflow/service_group_with_overflow.spec.ts +++ b/x-pack/test/apm_api_integration/tests/service_groups/service_group_with_overflow/service_group_with_overflow.spec.ts @@ -18,7 +18,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { const registry = getService('registry'); const apmApiClient = getService('apmApiClient'); const es = getService('es'); - const synthtraceEsClient = getService('synthtraceEsClient'); + const apmSynthtraceEsClient = getService('apmSynthtraceEsClient'); registry.when( 'Display overflow bucket in Service Groups', @@ -33,11 +33,11 @@ export default function ApiTest({ getService }: FtrProviderContext) { after(async () => { await deleteAllServiceGroups(apmApiClient); - synthtraceEsClient.clean(); + apmSynthtraceEsClient.clean(); }); before(async () => { - await generateData({ start, end, synthtraceEsClient }); + await generateData({ start, end, apmSynthtraceEsClient }); const docs = [ createServiceTransactionMetricsDocs({ diff --git a/x-pack/test/apm_api_integration/tests/service_maps/service_maps_kuery_filter.spec.ts b/x-pack/test/apm_api_integration/tests/service_maps/service_maps_kuery_filter.spec.ts index aacee3d7393be..4be91cbe7bab6 100644 --- a/x-pack/test/apm_api_integration/tests/service_maps/service_maps_kuery_filter.spec.ts +++ b/x-pack/test/apm_api_integration/tests/service_maps/service_maps_kuery_filter.spec.ts @@ -16,7 +16,7 @@ import { FtrProviderContext } from '../../common/ftr_provider_context'; export default function ApiTest({ getService }: FtrProviderContext) { const registry = getService('registry'); const apmApiClient = getService('apmApiClient'); - const synthtraceEsClient = getService('synthtraceEsClient'); + const apmSynthtraceEsClient = getService('apmSynthtraceEsClient'); const start = new Date('2023-01-01T00:00:00.000Z').getTime(); const end = new Date('2023-01-01T00:15:00.000Z').getTime() - 1; @@ -68,10 +68,10 @@ export default function ApiTest({ getService }: FtrProviderContext) { }, }) ); - await synthtraceEsClient.index(events); + await apmSynthtraceEsClient.index(events); }); - after(() => synthtraceEsClient.clean()); + after(() => apmSynthtraceEsClient.clean()); it('returns full service map when no kuery is defined', async () => { const { status, body } = await callApi(); diff --git a/x-pack/test/apm_api_integration/tests/service_nodes/get_service_nodes.spec.ts b/x-pack/test/apm_api_integration/tests/service_nodes/get_service_nodes.spec.ts index 4806f344219bb..6b24587b6bc13 100644 --- a/x-pack/test/apm_api_integration/tests/service_nodes/get_service_nodes.spec.ts +++ b/x-pack/test/apm_api_integration/tests/service_nodes/get_service_nodes.spec.ts @@ -12,7 +12,7 @@ import { FtrProviderContext } from '../../common/ftr_provider_context'; export default function ApiTest({ getService }: FtrProviderContext) { const apmApiClient = getService('apmApiClient'); const registry = getService('registry'); - const synthtraceEsClient = getService('synthtraceEsClient'); + const apmSynthtraceEsClient = getService('apmSynthtraceEsClient'); const start = new Date('2021-01-01T00:00:00.000Z').getTime(); const end = new Date('2021-01-01T00:15:00.000Z').getTime() - 1; @@ -54,7 +54,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { const instance = apm .service({ name: serviceName, environment: 'production', agentName: 'go' }) .instance(instanceName); - await synthtraceEsClient.index( + await apmSynthtraceEsClient.index( timerange(start, end) .interval('1m') .rate(1) @@ -70,7 +70,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { ) ); }); - after(() => synthtraceEsClient.clean()); + after(() => apmSynthtraceEsClient.clean()); it('returns service nodes', async () => { const response = await callApi(); diff --git a/x-pack/test/apm_api_integration/tests/service_overview/instance_details.spec.ts b/x-pack/test/apm_api_integration/tests/service_overview/instance_details.spec.ts index cdc613ddcbeb8..013237934904f 100644 --- a/x-pack/test/apm_api_integration/tests/service_overview/instance_details.spec.ts +++ b/x-pack/test/apm_api_integration/tests/service_overview/instance_details.spec.ts @@ -17,7 +17,7 @@ type ServiceOverviewInstanceDetails = export default function ApiTest({ getService }: FtrProviderContext) { const registry = getService('registry'); const apmApiClient = getService('apmApiClient'); - const synthtrace = getService('synthtraceEsClient'); + const synthtrace = getService('apmSynthtraceEsClient'); const start = '2023-08-22T00:00:00.000Z'; const end = '2023-08-22T01:00:00.000Z'; diff --git a/x-pack/test/apm_api_integration/tests/service_overview/instances_main_statistics.spec.ts b/x-pack/test/apm_api_integration/tests/service_overview/instances_main_statistics.spec.ts index 1f53d20a97889..b0a6bf51d1ccf 100644 --- a/x-pack/test/apm_api_integration/tests/service_overview/instances_main_statistics.spec.ts +++ b/x-pack/test/apm_api_integration/tests/service_overview/instances_main_statistics.spec.ts @@ -25,7 +25,7 @@ type ServiceOverviewInstancesMainStatistics = export default function ApiTest({ getService }: FtrProviderContext) { const registry = getService('registry'); const apmApiClient = getService('apmApiClient'); - const synthtrace = getService('synthtraceEsClient'); + const synthtrace = getService('apmSynthtraceEsClient'); const start = new Date('2021-01-01T00:00:00.000Z').getTime(); const end = new Date('2021-01-01T00:10:00.000Z').getTime(); diff --git a/x-pack/test/apm_api_integration/tests/services/error_groups/error_groups_detailed_statistics.spec.ts b/x-pack/test/apm_api_integration/tests/services/error_groups/error_groups_detailed_statistics.spec.ts index 9ec17ff8374ad..620d705f4463f 100644 --- a/x-pack/test/apm_api_integration/tests/services/error_groups/error_groups_detailed_statistics.spec.ts +++ b/x-pack/test/apm_api_integration/tests/services/error_groups/error_groups_detailed_statistics.spec.ts @@ -24,7 +24,7 @@ type ErrorGroupsDetailedStatistics = export default function ApiTest({ getService }: FtrProviderContext) { const registry = getService('registry'); const apmApiClient = getService('apmApiClient'); - const synthtraceEsClient = getService('synthtraceEsClient'); + const apmSynthtraceEsClient = getService('apmSynthtraceEsClient'); const serviceName = 'synth-go'; const start = new Date('2021-01-01T00:00:00.000Z').getTime(); @@ -69,10 +69,10 @@ export default function ApiTest({ getService }: FtrProviderContext) { describe('when data is loaded', () => { const { PROD_LIST_ERROR_RATE, PROD_ID_ERROR_RATE } = config; before(async () => { - await generateData({ serviceName, start, end, synthtraceEsClient }); + await generateData({ serviceName, start, end, apmSynthtraceEsClient }); }); - after(() => synthtraceEsClient.clean()); + after(() => apmSynthtraceEsClient.clean()); describe('without data comparison', () => { let errorGroupsDetailedStatistics: ErrorGroupsDetailedStatistics; diff --git a/x-pack/test/apm_api_integration/tests/services/error_groups/error_groups_main_statistics.spec.ts b/x-pack/test/apm_api_integration/tests/services/error_groups/error_groups_main_statistics.spec.ts index 7096b65b1dbfa..3377cdabb3847 100644 --- a/x-pack/test/apm_api_integration/tests/services/error_groups/error_groups_main_statistics.spec.ts +++ b/x-pack/test/apm_api_integration/tests/services/error_groups/error_groups_main_statistics.spec.ts @@ -20,7 +20,7 @@ type ErrorGroupsMainStatistics = export default function ApiTest({ getService }: FtrProviderContext) { const registry = getService('registry'); const apmApiClient = getService('apmApiClient'); - const synthtraceEsClient = getService('synthtraceEsClient'); + const apmSynthtraceEsClient = getService('apmSynthtraceEsClient'); const serviceName = 'synth-go'; const start = new Date('2021-01-01T00:00:00.000Z').getTime(); @@ -64,10 +64,10 @@ export default function ApiTest({ getService }: FtrProviderContext) { const { PROD_LIST_ERROR_RATE, PROD_ID_ERROR_RATE, ERROR_NAME_1, ERROR_NAME_2 } = config; before(async () => { - await generateData({ serviceName, start, end, synthtraceEsClient }); + await generateData({ serviceName, start, end, apmSynthtraceEsClient }); }); - after(() => synthtraceEsClient.clean()); + after(() => apmSynthtraceEsClient.clean()); describe('returns the correct data', () => { let errorGroupMainStatistics: ErrorGroupsMainStatistics; diff --git a/x-pack/test/apm_api_integration/tests/services/error_groups/generate_data.ts b/x-pack/test/apm_api_integration/tests/services/error_groups/generate_data.ts index 01421a73b8d27..33d1ad4fc566f 100644 --- a/x-pack/test/apm_api_integration/tests/services/error_groups/generate_data.ts +++ b/x-pack/test/apm_api_integration/tests/services/error_groups/generate_data.ts @@ -17,12 +17,12 @@ export const config = { }; export async function generateData({ - synthtraceEsClient, + apmSynthtraceEsClient, serviceName, start, end, }: { - synthtraceEsClient: ApmSynthtraceEsClient; + apmSynthtraceEsClient: ApmSynthtraceEsClient; serviceName: string; start: number; end: number; @@ -43,7 +43,7 @@ export async function generateData({ ERROR_NAME_2, } = config; - await synthtraceEsClient.index([ + await apmSynthtraceEsClient.index([ timerange(start, end) .interval('1m') .rate(PROD_LIST_RATE) diff --git a/x-pack/test/apm_api_integration/tests/services/get_service_node_metadata.spec.ts b/x-pack/test/apm_api_integration/tests/services/get_service_node_metadata.spec.ts index 5203c2c463401..6644ed8bc7d1c 100644 --- a/x-pack/test/apm_api_integration/tests/services/get_service_node_metadata.spec.ts +++ b/x-pack/test/apm_api_integration/tests/services/get_service_node_metadata.spec.ts @@ -14,7 +14,7 @@ import { FtrProviderContext } from '../../common/ftr_provider_context'; export default function ApiTest({ getService }: FtrProviderContext) { const apmApiClient = getService('apmApiClient'); const registry = getService('registry'); - const synthtraceEsClient = getService('synthtraceEsClient'); + const apmSynthtraceEsClient = getService('apmSynthtraceEsClient'); const start = new Date('2021-01-01T00:00:00.000Z').getTime(); const end = new Date('2021-01-01T00:15:00.000Z').getTime() - 1; @@ -66,7 +66,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { const instance = apm .service({ name: serviceName, environment: 'production', agentName: 'go' }) .instance(instanceName); - await synthtraceEsClient.index( + await apmSynthtraceEsClient.index( timerange(start, end) .interval('1m') .rate(1) @@ -80,7 +80,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { ) ); }); - after(() => synthtraceEsClient.clean()); + after(() => apmSynthtraceEsClient.clean()); it('returns service node metadata', async () => { const response = await callApi(); diff --git a/x-pack/test/apm_api_integration/tests/services/service_alerts.spec.ts b/x-pack/test/apm_api_integration/tests/services/service_alerts.spec.ts index 2d32e0a85ffde..958c2ed88f460 100644 --- a/x-pack/test/apm_api_integration/tests/services/service_alerts.spec.ts +++ b/x-pack/test/apm_api_integration/tests/services/service_alerts.spec.ts @@ -18,7 +18,7 @@ export default function ServiceAlerts({ getService }: FtrProviderContext) { const registry = getService('registry'); const apmApiClient = getService('apmApiClient'); const supertest = getService('supertest'); - const synthtraceEsClient = getService('synthtraceEsClient'); + const apmSynthtraceEsClient = getService('apmSynthtraceEsClient'); const es = getService('es'); const dayInMs = 24 * 60 * 60 * 1000; const start = Date.now() - dayInMs; @@ -73,7 +73,7 @@ export default function ServiceAlerts({ getService }: FtrProviderContext) { .instance('instance-1'), ]; - await synthtraceEsClient.index( + await apmSynthtraceEsClient.index( synthServices.map((service) => timerange(start, end) .interval('5m') @@ -114,7 +114,7 @@ export default function ServiceAlerts({ getService }: FtrProviderContext) { }); after(async () => { - await synthtraceEsClient.clean(); + await apmSynthtraceEsClient.clean(); }); describe('with alerts', () => { diff --git a/x-pack/test/apm_api_integration/tests/services/service_details/generate_data.ts b/x-pack/test/apm_api_integration/tests/services/service_details/generate_data.ts index 811e0c2b9ede1..653f0113ba285 100644 --- a/x-pack/test/apm_api_integration/tests/services/service_details/generate_data.ts +++ b/x-pack/test/apm_api_integration/tests/services/service_details/generate_data.ts @@ -43,11 +43,11 @@ export const dataConfig = { }; export async function generateData({ - synthtraceEsClient, + apmSynthtraceEsClient, start, end, }: { - synthtraceEsClient: ApmSynthtraceEsClient; + apmSynthtraceEsClient: ApmSynthtraceEsClient; start: number; end: number; }) { @@ -127,5 +127,5 @@ export async function generateData({ ), ]; - await synthtraceEsClient.index(traceEvents); + await apmSynthtraceEsClient.index(traceEvents); } diff --git a/x-pack/test/apm_api_integration/tests/services/service_details/service_details.spec.ts b/x-pack/test/apm_api_integration/tests/services/service_details/service_details.spec.ts index 9ba86c29943ae..4d8b250ec623c 100644 --- a/x-pack/test/apm_api_integration/tests/services/service_details/service_details.spec.ts +++ b/x-pack/test/apm_api_integration/tests/services/service_details/service_details.spec.ts @@ -16,7 +16,7 @@ type ServiceDetails = APIReturnType<'GET /internal/apm/services/{serviceName}/me export default function ApiTest({ getService }: FtrProviderContext) { const registry = getService('registry'); const apmApiClient = getService('apmApiClient'); - const synthtraceEsClient = getService('synthtraceEsClient'); + const apmSynthtraceEsClient = getService('apmSynthtraceEsClient'); const { service: { name: serviceName }, @@ -57,13 +57,13 @@ export default function ApiTest({ getService }: FtrProviderContext) { let status: number; before(async () => { - await generateData({ synthtraceEsClient, start, end }); + await generateData({ apmSynthtraceEsClient, start, end }); const response = await callApi(); body = response.body; status = response.status; }); - after(() => synthtraceEsClient.clean()); + after(() => apmSynthtraceEsClient.clean()); it('returns correct HTTP status', () => { expect(status).to.be(200); diff --git a/x-pack/test/apm_api_integration/tests/services/service_icons/generate_data.ts b/x-pack/test/apm_api_integration/tests/services/service_icons/generate_data.ts index ddfe8b5728656..bc842d2342c58 100644 --- a/x-pack/test/apm_api_integration/tests/services/service_icons/generate_data.ts +++ b/x-pack/test/apm_api_integration/tests/services/service_icons/generate_data.ts @@ -22,11 +22,11 @@ export const dataConfig = { }; export async function generateData({ - synthtraceEsClient, + apmSynthtraceEsClient, start, end, }: { - synthtraceEsClient: ApmSynthtraceEsClient; + apmSynthtraceEsClient: ApmSynthtraceEsClient; start: number; end: number; }) { @@ -53,5 +53,5 @@ export async function generateData({ .success() ); - await synthtraceEsClient.index(traceEvents); + await apmSynthtraceEsClient.index(traceEvents); } diff --git a/x-pack/test/apm_api_integration/tests/services/service_icons/service_icons.spec.ts b/x-pack/test/apm_api_integration/tests/services/service_icons/service_icons.spec.ts index ee7e31f7c81dd..3516edd1800cb 100644 --- a/x-pack/test/apm_api_integration/tests/services/service_icons/service_icons.spec.ts +++ b/x-pack/test/apm_api_integration/tests/services/service_icons/service_icons.spec.ts @@ -16,7 +16,7 @@ type ServiceIconMetadata = APIReturnType<'GET /internal/apm/services/{serviceNam export default function ApiTest({ getService }: FtrProviderContext) { const registry = getService('registry'); const apmApiClient = getService('apmApiClient'); - const synthtraceEsClient = getService('synthtraceEsClient'); + const apmSynthtraceEsClient = getService('apmSynthtraceEsClient'); const { serviceName } = dataConfig; const start = new Date('2021-01-01T00:00:00.000Z').getTime(); @@ -50,13 +50,13 @@ export default function ApiTest({ getService }: FtrProviderContext) { let status: number; before(async () => { - await generateData({ synthtraceEsClient, start, end }); + await generateData({ apmSynthtraceEsClient, start, end }); const response = await callApi(); body = response.body; status = response.status; }); - after(() => synthtraceEsClient.clean()); + after(() => apmSynthtraceEsClient.clean()); it('returns correct HTTP status', () => { expect(status).to.be(200); diff --git a/x-pack/test/apm_api_integration/tests/services/services_detailed_statistics.spec.ts b/x-pack/test/apm_api_integration/tests/services/services_detailed_statistics.spec.ts index 44ac364bdf7d4..0a33450e7f980 100644 --- a/x-pack/test/apm_api_integration/tests/services/services_detailed_statistics.spec.ts +++ b/x-pack/test/apm_api_integration/tests/services/services_detailed_statistics.spec.ts @@ -23,7 +23,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { const apmApiClient = getService('apmApiClient'); - const synthtrace = getService('synthtraceEsClient'); + const synthtrace = getService('apmSynthtraceEsClient'); const start = '2021-01-01T00:00:00.000Z'; const end = '2021-01-01T00:59:59.999Z'; diff --git a/x-pack/test/apm_api_integration/tests/services/throughput.spec.ts b/x-pack/test/apm_api_integration/tests/services/throughput.spec.ts index 624706d30115a..d8b3227890f1d 100644 --- a/x-pack/test/apm_api_integration/tests/services/throughput.spec.ts +++ b/x-pack/test/apm_api_integration/tests/services/throughput.spec.ts @@ -26,7 +26,7 @@ type ThroughputReturn = APIReturnType<'GET /internal/apm/services/{serviceName}/ export default function ApiTest({ getService }: FtrProviderContext) { const registry = getService('registry'); const apmApiClient = getService('apmApiClient'); - const synthtraceEsClient = getService('synthtraceEsClient'); + const apmSynthtraceEsClient = getService('apmSynthtraceEsClient'); const serviceName = 'synth-go'; const start = new Date('2021-01-01T00:00:00.000Z').getTime(); @@ -97,7 +97,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { .service({ name: 'synth-java', environment: 'development', agentName: 'java' }) .instance('instance-c'); - await synthtraceEsClient.index([ + await apmSynthtraceEsClient.index([ timerange(start, end) .interval('1m') .rate(GO_PROD_RATE) @@ -128,7 +128,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { ]); }); - after(() => synthtraceEsClient.clean()); + after(() => apmSynthtraceEsClient.clean()); describe('compare transactions and metrics based throughput', () => { let throughputMetrics: ThroughputReturn; diff --git a/x-pack/test/apm_api_integration/tests/services/top_services.spec.ts b/x-pack/test/apm_api_integration/tests/services/top_services.spec.ts index d35e28d30aec7..48b394c092638 100644 --- a/x-pack/test/apm_api_integration/tests/services/top_services.spec.ts +++ b/x-pack/test/apm_api_integration/tests/services/top_services.spec.ts @@ -20,7 +20,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { const registry = getService('registry'); const apmApiClient = getService('apmApiClient'); - const synthtrace = getService('synthtraceEsClient'); + const synthtrace = getService('apmSynthtraceEsClient'); const archiveName = 'apm_8.0.0'; diff --git a/x-pack/test/apm_api_integration/tests/services/transaction_types.spec.ts b/x-pack/test/apm_api_integration/tests/services/transaction_types.spec.ts index b8e5586d2efad..57dbbb1c6ee49 100644 --- a/x-pack/test/apm_api_integration/tests/services/transaction_types.spec.ts +++ b/x-pack/test/apm_api_integration/tests/services/transaction_types.spec.ts @@ -14,7 +14,7 @@ import { FtrProviderContext } from '../../common/ftr_provider_context'; export default function ApiTest({ getService }: FtrProviderContext) { const registry = getService('registry'); const apmApiClient = getService('apmApiClient'); - const synthtrace = getService('synthtraceEsClient'); + const synthtrace = getService('apmSynthtraceEsClient'); const start = '2023-10-28T00:00:00.000Z'; const end = '2023-10-28T00:14:59.999Z'; diff --git a/x-pack/test/apm_api_integration/tests/settings/agent_configuration/add_agent_config_metrics.ts b/x-pack/test/apm_api_integration/tests/settings/agent_configuration/add_agent_config_metrics.ts index b2fe4fd609996..dc915f3accb79 100644 --- a/x-pack/test/apm_api_integration/tests/settings/agent_configuration/add_agent_config_metrics.ts +++ b/x-pack/test/apm_api_integration/tests/settings/agent_configuration/add_agent_config_metrics.ts @@ -9,14 +9,14 @@ import type { ApmSynthtraceEsClient } from '@kbn/apm-synthtrace'; import { Readable } from 'stream'; export function addAgentConfigEtagMetric({ - synthtraceEsClient, + apmSynthtraceEsClient, timestamp, etag, }: { - synthtraceEsClient: ApmSynthtraceEsClient; + apmSynthtraceEsClient: ApmSynthtraceEsClient; timestamp: number; etag: string; }) { const agentConfigMetric = observer().agentConfig().etag(etag).timestamp(timestamp); - return synthtraceEsClient.index(Readable.from([agentConfigMetric])); + return apmSynthtraceEsClient.index(Readable.from([agentConfigMetric])); } diff --git a/x-pack/test/apm_api_integration/tests/settings/agent_configuration/agent_configuration.spec.ts b/x-pack/test/apm_api_integration/tests/settings/agent_configuration/agent_configuration.spec.ts index 431eca227d605..98a971610a149 100644 --- a/x-pack/test/apm_api_integration/tests/settings/agent_configuration/agent_configuration.spec.ts +++ b/x-pack/test/apm_api_integration/tests/settings/agent_configuration/agent_configuration.spec.ts @@ -20,7 +20,7 @@ export default function agentConfigurationTests({ getService }: FtrProviderConte const apmApiClient = getService('apmApiClient'); const log = getService('log'); - const synthtraceEsClient = getService('synthtraceEsClient'); + const apmSynthtraceEsClient = getService('apmSynthtraceEsClient'); const archiveName = 'apm_8.0.0'; @@ -416,13 +416,13 @@ export default function agentConfigurationTests({ getService }: FtrProviderConte describe('when there are agent config metrics for this etag', () => { before(async () => { await addAgentConfigEtagMetric({ - synthtraceEsClient, + apmSynthtraceEsClient, timestamp: Date.now(), etag: agentConfiguration.etag, }); }); - after(() => synthtraceEsClient.clean()); + after(() => apmSynthtraceEsClient.clean()); it(`should have 'applied_by_agent=true' when getting a config from all configurations`, async () => { const { diff --git a/x-pack/test/apm_api_integration/tests/span_links/span_links.spec.ts b/x-pack/test/apm_api_integration/tests/span_links/span_links.spec.ts index d9488107d9d5f..871f44da4cdc1 100644 --- a/x-pack/test/apm_api_integration/tests/span_links/span_links.spec.ts +++ b/x-pack/test/apm_api_integration/tests/span_links/span_links.spec.ts @@ -13,7 +13,7 @@ import { generateSpanLinksData } from './data_generator'; export default function ApiTest({ getService }: FtrProviderContext) { const registry = getService('registry'); const apmApiClient = getService('apmApiClient'); - const synthtraceEsClient = getService('synthtraceEsClient'); + const apmSynthtraceEsClient = getService('apmSynthtraceEsClient'); const start = new Date('2022-01-01T00:00:00.000Z').getTime(); const end = new Date('2022-01-01T00:15:00.000Z').getTime() - 1; @@ -27,7 +27,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { ids = spanLinksData.ids; - await synthtraceEsClient.index([ + await apmSynthtraceEsClient.index([ Readable.from(spanLinksData.events.producerInternalOnly), Readable.from(spanLinksData.events.producerExternalOnly), Readable.from(spanLinksData.events.producerConsumer), @@ -35,7 +35,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { ]); }); - after(() => synthtraceEsClient.clean()); + after(() => apmSynthtraceEsClient.clean()); describe('Span links count on traces', () => { async function fetchTraces({ diff --git a/x-pack/test/apm_api_integration/tests/storage_explorer/get_services.spec.ts b/x-pack/test/apm_api_integration/tests/storage_explorer/get_services.spec.ts index 70f9ab369dcf5..01d258a18717a 100644 --- a/x-pack/test/apm_api_integration/tests/storage_explorer/get_services.spec.ts +++ b/x-pack/test/apm_api_integration/tests/storage_explorer/get_services.spec.ts @@ -11,7 +11,7 @@ import { FtrProviderContext } from '../../common/ftr_provider_context'; export default function ApiTest({ getService }: FtrProviderContext) { const registry = getService('registry'); - const synthtraceEsClient = getService('synthtraceEsClient'); + const apmSynthtraceEsClient = getService('apmSynthtraceEsClient'); const apmApiClient = getService('apmApiClient'); const start = '2021-01-01T12:00:00.000Z'; @@ -84,10 +84,10 @@ export default function ApiTest({ getService }: FtrProviderContext) { serviceC.transaction({ transactionName: 'GET /api' }).duration(1000).timestamp(timestamp) ); - await synthtraceEsClient.index([eventsWithinTimerange, eventsOutsideOfTimerange]); + await apmSynthtraceEsClient.index([eventsWithinTimerange, eventsOutsideOfTimerange]); }); - after(() => synthtraceEsClient.clean()); + after(() => apmSynthtraceEsClient.clean()); it('with no kuery, environment or index lifecycle phase set it returns services based on the terms enum API', async () => { const items = await getServices(); diff --git a/x-pack/test/apm_api_integration/tests/storage_explorer/storage_details.spec.ts b/x-pack/test/apm_api_integration/tests/storage_explorer/storage_details.spec.ts index 8c9dc354356a9..84f9ca4e35e97 100644 --- a/x-pack/test/apm_api_integration/tests/storage_explorer/storage_details.spec.ts +++ b/x-pack/test/apm_api_integration/tests/storage_explorer/storage_details.spec.ts @@ -21,7 +21,7 @@ type StorageDetails = APIReturnType<'GET /internal/apm/services/{serviceName}/st export default function ApiTest({ getService }: FtrProviderContext) { const registry = getService('registry'); const apmApiClient = getService('apmApiClient'); - const synthtraceEsClient = getService('synthtraceEsClient'); + const apmSynthtraceEsClient = getService('apmSynthtraceEsClient'); const start = new Date('2021-01-01T00:00:00.000Z').getTime(); const end = new Date('2021-01-01T00:15:00.000Z').getTime() - 1; @@ -78,7 +78,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { .service({ name: serviceName, environment: 'production', agentName: 'go' }) .instance('instance'); - await synthtraceEsClient.index([ + await apmSynthtraceEsClient.index([ timerange(start, end) .interval('5m') .rate(1) @@ -110,7 +110,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { ]); }); - after(() => synthtraceEsClient.clean()); + after(() => apmSynthtraceEsClient.clean()); it.skip('returns correct stats for processor events', async () => { const { status, body } = await callApi(); diff --git a/x-pack/test/apm_api_integration/tests/storage_explorer/storage_explorer.spec.ts b/x-pack/test/apm_api_integration/tests/storage_explorer/storage_explorer.spec.ts index f6ade43b4e29f..6f90d35c6ebff 100644 --- a/x-pack/test/apm_api_integration/tests/storage_explorer/storage_explorer.spec.ts +++ b/x-pack/test/apm_api_integration/tests/storage_explorer/storage_explorer.spec.ts @@ -15,7 +15,7 @@ import { FtrProviderContext } from '../../common/ftr_provider_context'; export default function ApiTest({ getService }: FtrProviderContext) { const registry = getService('registry'); const apmApiClient = getService('apmApiClient'); - const synthtraceEsClient = getService('synthtraceEsClient'); + const apmSynthtraceEsClient = getService('apmSynthtraceEsClient'); const start = new Date('2021-01-01T00:00:00.000Z').getTime(); const end = new Date('2021-01-01T00:15:00.000Z').getTime() - 1; @@ -72,7 +72,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { .service({ name: nodeServiceName, environment: 'dev', agentName: 'node' }) .instance('instance-node-dev'); - await synthtraceEsClient.index([ + await apmSynthtraceEsClient.index([ timerange(start, end) .interval('5m') .rate(1) @@ -103,7 +103,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { ]); }); - after(() => synthtraceEsClient.clean()); + after(() => apmSynthtraceEsClient.clean()); it('returns correct stats', async () => { const { status, body } = await callApi(); diff --git a/x-pack/test/apm_api_integration/tests/storage_explorer/storage_explorer_summary_stats.spec.ts b/x-pack/test/apm_api_integration/tests/storage_explorer/storage_explorer_summary_stats.spec.ts index cab335bded51f..97375f0b685e2 100644 --- a/x-pack/test/apm_api_integration/tests/storage_explorer/storage_explorer_summary_stats.spec.ts +++ b/x-pack/test/apm_api_integration/tests/storage_explorer/storage_explorer_summary_stats.spec.ts @@ -15,7 +15,7 @@ import { roundNumber } from '../../utils'; export default function ApiTest({ getService }: FtrProviderContext) { const registry = getService('registry'); const apmApiClient = getService('apmApiClient'); - const synthtraceEsClient = getService('synthtraceEsClient'); + const apmSynthtraceEsClient = getService('apmSynthtraceEsClient'); const start = new Date('2021-01-01T00:00:00.000Z').getTime(); const end = new Date('2021-01-01T00:15:00.000Z').getTime() - 1; @@ -73,7 +73,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { .service({ name: nodeServiceName, environment: 'dev', agentName: 'node' }) .instance('instance-node'); - await synthtraceEsClient.index([ + await apmSynthtraceEsClient.index([ timerange(start, end) .interval('1m') .rate(1) @@ -95,7 +95,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { ]); }); - after(() => synthtraceEsClient.clean()); + after(() => apmSynthtraceEsClient.clean()); it('returns correct summary stats', async () => { const { status, body } = await callApi(); diff --git a/x-pack/test/apm_api_integration/tests/storage_explorer/storage_explorer_timeseries_chart.spec.ts b/x-pack/test/apm_api_integration/tests/storage_explorer/storage_explorer_timeseries_chart.spec.ts index 757d9be55ee71..64f94bf3900df 100644 --- a/x-pack/test/apm_api_integration/tests/storage_explorer/storage_explorer_timeseries_chart.spec.ts +++ b/x-pack/test/apm_api_integration/tests/storage_explorer/storage_explorer_timeseries_chart.spec.ts @@ -16,7 +16,7 @@ type StorageTimeSeries = APIReturnType<'GET /internal/apm/storage_chart'>; export default function ApiTest({ getService }: FtrProviderContext) { const registry = getService('registry'); const apmApiClient = getService('apmApiClient'); - const synthtraceEsClient = getService('synthtraceEsClient'); + const apmSynthtraceEsClient = getService('apmSynthtraceEsClient'); const start = new Date('2021-01-01T00:00:00.000Z').getTime(); const end = new Date('2021-01-01T00:15:00.000Z').getTime() - 1; @@ -64,7 +64,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { .service({ name: 'synth-go-2', environment: 'production', agentName: 'go' }) .instance('instance'); - await synthtraceEsClient.index([ + await apmSynthtraceEsClient.index([ timerange(start, end) .interval('5m') .rate(1) @@ -90,7 +90,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { status = response.status; }); - after(() => synthtraceEsClient.clean()); + after(() => apmSynthtraceEsClient.clean()); it('returns correct HTTP status', async () => { expect(status).to.be(200); diff --git a/x-pack/test/apm_api_integration/tests/suggestions/generate_data.ts b/x-pack/test/apm_api_integration/tests/suggestions/generate_data.ts index 283c907782cdf..0311861436ec1 100644 --- a/x-pack/test/apm_api_integration/tests/suggestions/generate_data.ts +++ b/x-pack/test/apm_api_integration/tests/suggestions/generate_data.ts @@ -9,11 +9,11 @@ import type { ApmSynthtraceEsClient } from '@kbn/apm-synthtrace'; import { times } from 'lodash'; export async function generateData({ - synthtraceEsClient, + apmSynthtraceEsClient, start, end, }: { - synthtraceEsClient: ApmSynthtraceEsClient; + apmSynthtraceEsClient: ApmSynthtraceEsClient; start: number; end: number; }) { @@ -73,5 +73,5 @@ export async function generateData({ return [...autoGeneratedDocs, customDoc]; }); - return await synthtraceEsClient.index(docs); + return await apmSynthtraceEsClient.index(docs); } diff --git a/x-pack/test/apm_api_integration/tests/suggestions/suggestions.spec.ts b/x-pack/test/apm_api_integration/tests/suggestions/suggestions.spec.ts index 932f6f5636016..d4d1c3b141700 100644 --- a/x-pack/test/apm_api_integration/tests/suggestions/suggestions.spec.ts +++ b/x-pack/test/apm_api_integration/tests/suggestions/suggestions.spec.ts @@ -23,19 +23,19 @@ const end = new Date(endNumber).toISOString(); export default function suggestionsTests({ getService }: FtrProviderContext) { const registry = getService('registry'); const apmApiClient = getService('apmApiClient'); - const synthtraceEsClient = getService('synthtraceEsClient'); + const apmSynthtraceEsClient = getService('apmSynthtraceEsClient'); // FLAKY: https://github.com/elastic/kibana/issues/177538 registry.when('suggestions when data is loaded', { config: 'basic', archives: [] }, async () => { before(async () => { await generateData({ - synthtraceEsClient, + apmSynthtraceEsClient, start: startNumber, end: endNumber, }); }); - after(() => synthtraceEsClient.clean()); + after(() => apmSynthtraceEsClient.clean()); describe(`field: ${SERVICE_ENVIRONMENT}`, () => { describe('when fieldValue is empty', () => { diff --git a/x-pack/test/apm_api_integration/tests/throughput/dependencies_apis.spec.ts b/x-pack/test/apm_api_integration/tests/throughput/dependencies_apis.spec.ts index 3edf6946df9a6..fe591631fafe7 100644 --- a/x-pack/test/apm_api_integration/tests/throughput/dependencies_apis.spec.ts +++ b/x-pack/test/apm_api_integration/tests/throughput/dependencies_apis.spec.ts @@ -14,7 +14,7 @@ import { roundNumber } from '../../utils'; export default function ApiTest({ getService }: FtrProviderContext) { const registry = getService('registry'); const apmApiClient = getService('apmApiClient'); - const synthtraceEsClient = getService('synthtraceEsClient'); + const apmSynthtraceEsClient = getService('apmSynthtraceEsClient'); const start = new Date('2021-01-01T00:00:00.000Z').getTime(); const end = new Date('2021-01-01T00:15:00.000Z').getTime() - 1; @@ -106,7 +106,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { .service({ name: 'synth-java', environment: 'development', agentName: 'java' }) .instance('instance-c'); - await synthtraceEsClient.index([ + await apmSynthtraceEsClient.index([ timerange(start, end) .interval('1m') .rate(GO_PROD_RATE) @@ -174,7 +174,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { ]); }); - after(() => synthtraceEsClient.clean()); + after(() => apmSynthtraceEsClient.clean()); describe('verify top dependencies', () => { before(async () => { diff --git a/x-pack/test/apm_api_integration/tests/throughput/service_apis.spec.ts b/x-pack/test/apm_api_integration/tests/throughput/service_apis.spec.ts index eb8019d3b358f..9d69ce74bf0ea 100644 --- a/x-pack/test/apm_api_integration/tests/throughput/service_apis.spec.ts +++ b/x-pack/test/apm_api_integration/tests/throughput/service_apis.spec.ts @@ -17,7 +17,7 @@ import { roundNumber } from '../../utils'; export default function ApiTest({ getService }: FtrProviderContext) { const registry = getService('registry'); const apmApiClient = getService('apmApiClient'); - const synthtraceEsClient = getService('synthtraceEsClient'); + const apmSynthtraceEsClient = getService('apmSynthtraceEsClient'); const serviceName = 'synth-go'; const start = new Date('2021-01-01T00:00:00.000Z').getTime(); @@ -154,7 +154,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { .service({ name: serviceName, environment: 'development', agentName: 'go' }) .instance('instance-b'); - await synthtraceEsClient.index([ + await apmSynthtraceEsClient.index([ timerange(start, end) .interval('1m') .rate(GO_PROD_RATE) @@ -176,7 +176,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { ]); }); - after(() => synthtraceEsClient.clean()); + after(() => apmSynthtraceEsClient.clean()); describe('compare throughput value between service inventory, throughput chart, service inventory and transactions apis', () => { before(async () => { diff --git a/x-pack/test/apm_api_integration/tests/throughput/service_maps.spec.ts b/x-pack/test/apm_api_integration/tests/throughput/service_maps.spec.ts index e502e4ea66066..5ee475344e286 100644 --- a/x-pack/test/apm_api_integration/tests/throughput/service_maps.spec.ts +++ b/x-pack/test/apm_api_integration/tests/throughput/service_maps.spec.ts @@ -15,7 +15,7 @@ import { roundNumber } from '../../utils'; export default function ApiTest({ getService }: FtrProviderContext) { const registry = getService('registry'); const apmApiClient = getService('apmApiClient'); - const synthtraceEsClient = getService('synthtraceEsClient'); + const apmSynthtraceEsClient = getService('apmSynthtraceEsClient'); const serviceName = 'synth-go'; const start = new Date('2021-01-01T00:00:00.000Z').getTime(); @@ -95,7 +95,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { .service({ name: serviceName, environment: 'development', agentName: 'go' }) .instance('instance-b'); - await synthtraceEsClient.index([ + await apmSynthtraceEsClient.index([ timerange(start, end) .interval('1m') .rate(GO_PROD_RATE) @@ -117,7 +117,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { ]); }); - after(() => synthtraceEsClient.clean()); + after(() => apmSynthtraceEsClient.clean()); // FLAKY: https://github.com/elastic/kibana/issues/176984 describe('compare throughput value between service inventory and service maps', () => { diff --git a/x-pack/test/apm_api_integration/tests/time_range_metadata/many_apm_server_versions.spec.ts b/x-pack/test/apm_api_integration/tests/time_range_metadata/many_apm_server_versions.spec.ts index 8c3ffbd652815..01b4b35530836 100644 --- a/x-pack/test/apm_api_integration/tests/time_range_metadata/many_apm_server_versions.spec.ts +++ b/x-pack/test/apm_api_integration/tests/time_range_metadata/many_apm_server_versions.spec.ts @@ -26,7 +26,7 @@ import { ApmApiClient } from '../../common/config'; export default function ApiTest({ getService }: FtrProviderContext) { const registry = getService('registry'); const apmApiClient = getService('apmApiClient'); - const synthtrace = getService('synthtraceEsClient'); + const synthtrace = getService('apmSynthtraceEsClient'); const es = getService('es'); const baseTime = new Date('2023-10-01T00:00:00.000Z').getTime(); diff --git a/x-pack/test/apm_api_integration/tests/time_range_metadata/time_range_metadata.spec.ts b/x-pack/test/apm_api_integration/tests/time_range_metadata/time_range_metadata.spec.ts index b46b6c98fb1dc..43aee07583c18 100644 --- a/x-pack/test/apm_api_integration/tests/time_range_metadata/time_range_metadata.spec.ts +++ b/x-pack/test/apm_api_integration/tests/time_range_metadata/time_range_metadata.spec.ts @@ -23,7 +23,7 @@ import { FtrProviderContext } from '../../common/ftr_provider_context'; export default function ApiTest({ getService }: FtrProviderContext) { const registry = getService('registry'); const apmApiClient = getService('apmApiClient'); - const synthtraceEsClient = getService('synthtraceEsClient'); + const apmSynthtraceEsClient = getService('apmSynthtraceEsClient'); const es = getService('es'); const log = getService('log'); @@ -95,7 +95,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { start: withoutSummaryFieldStart, end: withoutSummaryFieldEnd, isLegacy: true, - synthtrace: synthtraceEsClient, + synthtrace: apmSynthtraceEsClient, logger: log, }); @@ -103,13 +103,13 @@ export default function ApiTest({ getService }: FtrProviderContext) { start: withSummaryFieldStart, end: withSummaryFieldEnd, isLegacy: false, - synthtrace: synthtraceEsClient, + synthtrace: apmSynthtraceEsClient, logger: log, }); }); after(() => { - return synthtraceEsClient.clean(); + return apmSynthtraceEsClient.clean(); }); describe('Values for hasDurationSummaryField for transaction metrics', () => { @@ -155,7 +155,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { before(() => { const instance = apm.service('my-service', 'production', 'java').instance('instance'); - return synthtraceEsClient.index( + return apmSynthtraceEsClient.index( timerange(moment(start).subtract(1, 'day'), end) .interval('1m') .rate(1) @@ -166,7 +166,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { }); after(() => { - return synthtraceEsClient.clean(); + return apmSynthtraceEsClient.clean(); }); describe('with default settings', () => { @@ -508,7 +508,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { }); after(() => { - return synthtraceEsClient.clean(); + return apmSynthtraceEsClient.clean(); }); } ); diff --git a/x-pack/test/apm_api_integration/tests/traces/critical_path.spec.ts b/x-pack/test/apm_api_integration/tests/traces/critical_path.spec.ts index baa194a7ab56a..6d55c55ba6dbf 100644 --- a/x-pack/test/apm_api_integration/tests/traces/critical_path.spec.ts +++ b/x-pack/test/apm_api_integration/tests/traces/critical_path.spec.ts @@ -16,7 +16,7 @@ import { FtrProviderContext } from '../../common/ftr_provider_context'; export default function ApiTest({ getService }: FtrProviderContext) { const registry = getService('registry'); const apmApiClient = getService('apmApiClient'); - const synthtraceEsClient = getService('synthtraceEsClient'); + const apmSynthtraceEsClient = getService('apmSynthtraceEsClient'); const start = new Date('2022-01-01T00:00:00.000Z').getTime(); const end = new Date('2022-01-01T00:15:00.000Z').getTime() - 1; @@ -63,7 +63,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { const traceIds = compact(uniq(serialized.map((event) => event['trace.id']))); - await synthtraceEsClient.index(Readable.from(unserialized)); + await apmSynthtraceEsClient.index(Readable.from(unserialized)); return apmApiClient .readUser({ @@ -271,7 +271,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { fn: () => generateTrace(), }); - await synthtraceEsClient.clean(); + await apmSynthtraceEsClient.clean(); const { rootNodes: filteredRootNodes } = await fetchAndBuildCriticalPathTree({ fn: () => generateTrace(), @@ -411,7 +411,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { }, ]); - await synthtraceEsClient.clean(); + await apmSynthtraceEsClient.clean(); const { rootNodes: filteredRootNodes } = await fetchAndBuildCriticalPathTree({ fn: () => generateTrace(), @@ -428,6 +428,6 @@ export default function ApiTest({ getService }: FtrProviderContext) { ]); }); - after(() => synthtraceEsClient.clean()); + after(() => apmSynthtraceEsClient.clean()); }); } diff --git a/x-pack/test/apm_api_integration/tests/traces/find_traces.spec.ts b/x-pack/test/apm_api_integration/tests/traces/find_traces.spec.ts index 653672879c281..369490ae06d44 100644 --- a/x-pack/test/apm_api_integration/tests/traces/find_traces.spec.ts +++ b/x-pack/test/apm_api_integration/tests/traces/find_traces.spec.ts @@ -17,7 +17,7 @@ import { generateTrace } from './generate_trace'; export default function ApiTest({ getService }: FtrProviderContext) { const registry = getService('registry'); const apmApiClient = getService('apmApiClient'); - const synthtraceEsClient = getService('synthtraceEsClient'); + const apmSynthtraceEsClient = getService('apmSynthtraceEsClient'); const start = new Date('2022-01-01T00:00:00.000Z').getTime(); const end = new Date('2022-01-01T00:15:00.000Z').getTime() - 1; @@ -103,7 +103,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { .service({ name: 'python', environment: 'production', agentName: 'python' }) .instance('python'); - return synthtraceEsClient.index( + return apmSynthtraceEsClient.index( timerange(start, end) .interval('15m') .rate(1) @@ -220,6 +220,6 @@ export default function ApiTest({ getService }: FtrProviderContext) { }); }); - after(() => synthtraceEsClient.clean()); + after(() => apmSynthtraceEsClient.clean()); }); } diff --git a/x-pack/test/apm_api_integration/tests/traces/large_trace/generate_large_trace.ts b/x-pack/test/apm_api_integration/tests/traces/large_trace/generate_large_trace.ts index 3cd580a6e7a96..a6d55c7d02bce 100644 --- a/x-pack/test/apm_api_integration/tests/traces/large_trace/generate_large_trace.ts +++ b/x-pack/test/apm_api_integration/tests/traces/large_trace/generate_large_trace.ts @@ -16,14 +16,14 @@ export function generateLargeTrace({ start, end, rootTransactionName, - synthtraceEsClient, + apmSynthtraceEsClient, repeaterFactor, environment, }: { start: number; end: number; rootTransactionName: string; - synthtraceEsClient: ApmSynthtraceEsClient; + apmSynthtraceEsClient: ApmSynthtraceEsClient; repeaterFactor: number; environment: string; }) { @@ -137,5 +137,5 @@ export function generateLargeTrace({ }).getTransaction(); }); - return synthtraceEsClient.index(traces); + return apmSynthtraceEsClient.index(traces); } diff --git a/x-pack/test/apm_api_integration/tests/traces/large_trace/large_trace.spec.ts b/x-pack/test/apm_api_integration/tests/traces/large_trace/large_trace.spec.ts index d16a9efd082ed..023db5c0d2ba0 100644 --- a/x-pack/test/apm_api_integration/tests/traces/large_trace/large_trace.spec.ts +++ b/x-pack/test/apm_api_integration/tests/traces/large_trace/large_trace.spec.ts @@ -26,7 +26,7 @@ const environment = 'long_trace_scenario'; export default function ApiTest({ getService }: FtrProviderContext) { const registry = getService('registry'); const apmApiClient = getService('apmApiClient'); - const synthtraceEsClient = getService('synthtraceEsClient'); + const apmSynthtraceEsClient = getService('apmSynthtraceEsClient'); const es = getService('es'); // FLAKY: https://github.com/elastic/kibana/issues/177660 @@ -37,14 +37,14 @@ export default function ApiTest({ getService }: FtrProviderContext) { start, end, rootTransactionName, - synthtraceEsClient, + apmSynthtraceEsClient, repeaterFactor: 10, environment, }); }); after(async () => { - await synthtraceEsClient.clean(); + await apmSynthtraceEsClient.clean(); }); describe('when maxTraceItems is 5000 (default)', () => { diff --git a/x-pack/test/apm_api_integration/tests/traces/span_details.spec.ts b/x-pack/test/apm_api_integration/tests/traces/span_details.spec.ts index 2598a6cdf97ab..a428ea9cb2e50 100644 --- a/x-pack/test/apm_api_integration/tests/traces/span_details.spec.ts +++ b/x-pack/test/apm_api_integration/tests/traces/span_details.spec.ts @@ -12,7 +12,7 @@ import { FtrProviderContext } from '../../common/ftr_provider_context'; export default function ApiTest({ getService }: FtrProviderContext) { const registry = getService('registry'); const apmApiClient = getService('apmApiClient'); - const synthtraceEsClient = getService('synthtraceEsClient'); + const apmSynthtraceEsClient = getService('apmSynthtraceEsClient'); const start = new Date('2022-01-01T00:00:00.000Z').getTime(); const end = new Date('2022-01-01T00:15:00.000Z').getTime() - 1; @@ -100,10 +100,10 @@ export default function ApiTest({ getService }: FtrProviderContext) { parentTransactionId = span?.['parent.id']!; traceId = span?.['trace.id']!; - await synthtraceEsClient.index(Readable.from(unserialized)); + await apmSynthtraceEsClient.index(Readable.from(unserialized)); }); - after(() => synthtraceEsClient.clean()); + after(() => apmSynthtraceEsClient.clean()); describe('span details', () => { let spanDetails: Awaited>['body']; diff --git a/x-pack/test/apm_api_integration/tests/traces/trace_by_id.spec.ts b/x-pack/test/apm_api_integration/tests/traces/trace_by_id.spec.ts index 8bcf83a503022..de07f3664104c 100644 --- a/x-pack/test/apm_api_integration/tests/traces/trace_by_id.spec.ts +++ b/x-pack/test/apm_api_integration/tests/traces/trace_by_id.spec.ts @@ -13,7 +13,7 @@ import { FtrProviderContext } from '../../common/ftr_provider_context'; export default function ApiTest({ getService }: FtrProviderContext) { const registry = getService('registry'); const apmApiClient = getService('apmApiClient'); - const synthtraceEsClient = getService('synthtraceEsClient'); + const apmSynthtraceEsClient = getService('apmSynthtraceEsClient'); const start = new Date('2022-01-01T00:00:00.000Z').getTime(); const end = new Date('2022-01-01T00:15:00.000Z').getTime() - 1; @@ -90,10 +90,10 @@ export default function ApiTest({ getService }: FtrProviderContext) { entryTransactionId = serialized[0]['transaction.id']!; serviceATraceId = serialized[0]['trace.id']!; - await synthtraceEsClient.index(Readable.from(unserialized)); + await apmSynthtraceEsClient.index(Readable.from(unserialized)); }); - after(() => synthtraceEsClient.clean()); + after(() => apmSynthtraceEsClient.clean()); describe('return trace', () => { let traces: APIReturnType<'GET /internal/apm/traces/{traceId}'>; diff --git a/x-pack/test/apm_api_integration/tests/traces/transaction_details.spec.ts b/x-pack/test/apm_api_integration/tests/traces/transaction_details.spec.ts index 674f56c79a607..3665bfd8e8ea6 100644 --- a/x-pack/test/apm_api_integration/tests/traces/transaction_details.spec.ts +++ b/x-pack/test/apm_api_integration/tests/traces/transaction_details.spec.ts @@ -12,7 +12,7 @@ import { FtrProviderContext } from '../../common/ftr_provider_context'; export default function ApiTest({ getService }: FtrProviderContext) { const registry = getService('registry'); const apmApiClient = getService('apmApiClient'); - const synthtraceEsClient = getService('synthtraceEsClient'); + const apmSynthtraceEsClient = getService('apmSynthtraceEsClient'); const start = new Date('2022-01-01T00:00:00.000Z').getTime(); const end = new Date('2022-01-01T00:15:00.000Z').getTime() - 1; @@ -96,10 +96,10 @@ export default function ApiTest({ getService }: FtrProviderContext) { transactionId = transaction?.['transaction.id']!; traceId = transaction?.['trace.id']!; - await synthtraceEsClient.index(Readable.from(unserialized)); + await apmSynthtraceEsClient.index(Readable.from(unserialized)); }); - after(() => synthtraceEsClient.clean()); + after(() => apmSynthtraceEsClient.clean()); describe('transaction details', () => { let transactionDetails: Awaited>['body']; diff --git a/x-pack/test/apm_api_integration/tests/transactions/error_rate.spec.ts b/x-pack/test/apm_api_integration/tests/transactions/error_rate.spec.ts index 123bb0d6d594d..724390fdfa61f 100644 --- a/x-pack/test/apm_api_integration/tests/transactions/error_rate.spec.ts +++ b/x-pack/test/apm_api_integration/tests/transactions/error_rate.spec.ts @@ -24,7 +24,7 @@ type ErrorRate = export default function ApiTest({ getService }: FtrProviderContext) { const registry = getService('registry'); const apmApiClient = getService('apmApiClient'); - const synthtraceEsClient = getService('synthtraceEsClient'); + const apmSynthtraceEsClient = getService('apmSynthtraceEsClient'); // url parameters const start = new Date('2021-01-01T00:00:00.000Z').getTime(); @@ -142,10 +142,10 @@ export default function ApiTest({ getService }: FtrProviderContext) { .failure() ), ]; - await synthtraceEsClient.index(documents); + await apmSynthtraceEsClient.index(documents); }); - after(() => synthtraceEsClient.clean()); + after(() => apmSynthtraceEsClient.clean()); describe('returns the transaction error rate', () => { let errorRateResponse: ErrorRate; diff --git a/x-pack/test/apm_api_integration/tests/transactions/latency.spec.ts b/x-pack/test/apm_api_integration/tests/transactions/latency.spec.ts index eb876e6e312b7..eefe5cfb0d0fe 100644 --- a/x-pack/test/apm_api_integration/tests/transactions/latency.spec.ts +++ b/x-pack/test/apm_api_integration/tests/transactions/latency.spec.ts @@ -25,7 +25,7 @@ type LatencyChartReturnType = export default function ApiTest({ getService }: FtrProviderContext) { const registry = getService('registry'); const apmApiClient = getService('apmApiClient'); - const synthtraceEsClient = getService('synthtraceEsClient'); + const apmSynthtraceEsClient = getService('apmSynthtraceEsClient'); const serviceName = 'synth-go'; const start = new Date('2021-01-01T00:00:00.000Z').getTime(); @@ -90,7 +90,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { .service({ name: serviceName, environment: 'development', agentName: 'go' }) .instance('instance-b'); - await synthtraceEsClient.index([ + await apmSynthtraceEsClient.index([ timerange(start, end) .ratePerMinute(GO_PROD_RATE) .generator((timestamp) => @@ -110,7 +110,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { ]); }); - after(() => synthtraceEsClient.clean()); + after(() => apmSynthtraceEsClient.clean()); const expectedLatencyAvgValueMs = ((GO_PROD_RATE * GO_PROD_DURATION + GO_DEV_RATE * GO_DEV_DURATION) / diff --git a/x-pack/test/apm_api_integration/tests/transactions/transactions_groups_alerts.spec.ts b/x-pack/test/apm_api_integration/tests/transactions/transactions_groups_alerts.spec.ts index d8868f59aa7eb..7468437d8bc72 100644 --- a/x-pack/test/apm_api_integration/tests/transactions/transactions_groups_alerts.spec.ts +++ b/x-pack/test/apm_api_integration/tests/transactions/transactions_groups_alerts.spec.ts @@ -25,7 +25,7 @@ type TransactionsGroupsMainStatistics = export default function ApiTest({ getService }: FtrProviderContext) { const registry = getService('registry'); const apmApiClient = getService('apmApiClient'); - const synthtraceEsClient = getService('synthtraceEsClient'); + const apmSynthtraceEsClient = getService('apmSynthtraceEsClient'); const supertest = getService('supertest'); const es = getService('es'); const serviceName = 'synth-go'; @@ -107,7 +107,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { .service({ name: serviceName, environment: 'production', agentName: 'go' }) .instance('instance-a'); - await synthtraceEsClient.index([ + await apmSynthtraceEsClient.index([ timerange(start, end) .interval('1m') .rate(1) @@ -135,7 +135,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { ]); }); - after(() => synthtraceEsClient.clean()); + after(() => apmSynthtraceEsClient.clean()); describe('Transaction groups with avg transaction duration alerts', () => { let ruleId: string; diff --git a/x-pack/test/apm_api_integration/tests/transactions/transactions_groups_detailed_statistics.spec.ts b/x-pack/test/apm_api_integration/tests/transactions/transactions_groups_detailed_statistics.spec.ts index e195e035d50a2..77a4b67b4bc4e 100644 --- a/x-pack/test/apm_api_integration/tests/transactions/transactions_groups_detailed_statistics.spec.ts +++ b/x-pack/test/apm_api_integration/tests/transactions/transactions_groups_detailed_statistics.spec.ts @@ -21,7 +21,7 @@ type TransactionsGroupsDetailedStatistics = export default function ApiTest({ getService }: FtrProviderContext) { const registry = getService('registry'); const apmApiClient = getService('apmApiClient'); - const synthtraceEsClient = getService('synthtraceEsClient'); + const apmSynthtraceEsClient = getService('apmSynthtraceEsClient'); const serviceName = 'synth-go'; const start = new Date('2021-01-01T00:00:00.000Z').getTime(); @@ -94,7 +94,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { const transactionName = 'GET /api/product/list'; - await synthtraceEsClient.index([ + await apmSynthtraceEsClient.index([ timerange(start, end) .interval('1m') .rate(GO_PROD_RATE) @@ -118,7 +118,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { ]); }); - after(() => synthtraceEsClient.clean()); + after(() => apmSynthtraceEsClient.clean()); describe('without comparisons', () => { let transactionsStatistics: TransactionsGroupsDetailedStatistics; diff --git a/x-pack/test/apm_api_integration/tests/transactions/transactions_groups_main_statistics.spec.ts b/x-pack/test/apm_api_integration/tests/transactions/transactions_groups_main_statistics.spec.ts index 646e1b790add0..d7c5e78fdcd12 100644 --- a/x-pack/test/apm_api_integration/tests/transactions/transactions_groups_main_statistics.spec.ts +++ b/x-pack/test/apm_api_integration/tests/transactions/transactions_groups_main_statistics.spec.ts @@ -16,7 +16,7 @@ import { FtrProviderContext } from '../../common/ftr_provider_context'; export default function ApiTest({ getService }: FtrProviderContext) { const registry = getService('registry'); const apmApiClient = getService('apmApiClient'); - const synthtraceEsClient = getService('synthtraceEsClient'); + const apmSynthtraceEsClient = getService('apmSynthtraceEsClient'); const serviceName = 'synth-go'; const start = new Date('2021-01-01T00:00:00.000Z').getTime(); @@ -97,7 +97,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { .service({ name: serviceName, environment: 'production', agentName: 'go' }) .instance('instance-a'); - await synthtraceEsClient.index([ + await apmSynthtraceEsClient.index([ timerange(start, end) .interval('1m') .rate(GO_PROD_RATE) @@ -124,7 +124,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { }), ]); }); - after(() => synthtraceEsClient.clean()); + after(() => apmSynthtraceEsClient.clean()); it('returns the correct data', async () => { const transactionsGroupsPrimaryStatistics = await callApi(); diff --git a/x-pack/test/observability_api_integration/common/bootstrap_synthtrace.ts b/x-pack/test/observability_api_integration/common/bootstrap_synthtrace.ts new file mode 100644 index 0000000000000..fd3997e7630cf --- /dev/null +++ b/x-pack/test/observability_api_integration/common/bootstrap_synthtrace.ts @@ -0,0 +1,50 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ +import { + ApmSynthtraceEsClient, + ApmSynthtraceKibanaClient, + createLogger, + LogLevel, +} from '@kbn/apm-synthtrace'; +import url from 'url'; +import { kbnTestConfig } from '@kbn/test'; +import { FtrProviderContext } from './ftr_provider_context'; + +export async function bootstrapApmSynthtraceEsClient( + context: FtrProviderContext, + kibanaClient: ApmSynthtraceKibanaClient +) { + const es = context.getService('es'); + + const kibanaVersion = await kibanaClient.fetchLatestApmPackageVersion(); + await kibanaClient.installApmPackage(kibanaVersion); + + const esClient = new ApmSynthtraceEsClient({ + client: es, + logger: createLogger(LogLevel.info), + version: kibanaVersion, + refreshAfterIndex: true, + }); + + return esClient; +} + +export function getSynthtraceKibanaClient(kibanaServerUrl: string) { + const kibanaServerUrlWithAuth = url + .format({ + ...url.parse(kibanaServerUrl), + auth: `elastic:${kbnTestConfig.getUrlParts().password}`, + }) + .slice(0, -1); + + const kibanaClient = new ApmSynthtraceKibanaClient({ + target: kibanaServerUrlWithAuth, + logger: createLogger(LogLevel.debug), + }); + + return kibanaClient; +} diff --git a/x-pack/test/observability_api_integration/common/config.ts b/x-pack/test/observability_api_integration/common/config.ts index 83249182084f3..8baf4f5d116f0 100644 --- a/x-pack/test/observability_api_integration/common/config.ts +++ b/x-pack/test/observability_api_integration/common/config.ts @@ -5,7 +5,13 @@ * 2.0. */ -import { FtrConfigProviderContext } from '@kbn/test'; +import { Config, FtrConfigProviderContext, kbnTestConfig } from '@kbn/test'; +import { format, UrlObject } from 'url'; +import { LogsSynthtraceEsClient, createLogger, LogLevel } from '@kbn/apm-synthtrace'; +import supertest from 'supertest'; +import { bootstrapApmSynthtraceEsClient, getSynthtraceKibanaClient } from './bootstrap_synthtrace'; +import { FtrProviderContext } from './ftr_provider_context'; +import { createObsApiClient } from './obs_api_supertest'; interface Settings { license: 'basic' | 'trial'; @@ -13,6 +19,41 @@ interface Settings { name: string; } +export type CustomApiTestServices = ReturnType; +function getCustomApiTestServices(xPackAPITestsConfig: Config) { + const servers = xPackAPITestsConfig.get('servers'); + const kibanaServer = servers.kibana as UrlObject; + const kibanaServerUrl = format(kibanaServer); + const synthtraceKibanaClient = getSynthtraceKibanaClient(kibanaServerUrl); + + return { + apmSynthtraceEsClient: (context: FtrProviderContext) => { + return bootstrapApmSynthtraceEsClient(context, synthtraceKibanaClient); + }, + logSynthtraceEsClient: (context: FtrProviderContext) => + new LogsSynthtraceEsClient({ + client: context.getService('es'), + logger: createLogger(LogLevel.info), + refreshAfterIndex: true, + }), + synthtraceKibanaClient: () => synthtraceKibanaClient, + obsApiClient: async (context: FtrProviderContext) => { + const getApiClientForUsername = (username: string) => { + const url = format({ + ...kibanaServer, + auth: `${username}:${kbnTestConfig.getUrlParts().password}`, + }); + + return createObsApiClient(supertest(url)); + }; + + return { + adminUser: getApiClientForUsername('elastic'), + }; + }, + }; +} + export function createTestConfig(settings: Settings) { const { testFiles, license, name } = settings; @@ -21,10 +62,15 @@ export function createTestConfig(settings: Settings) { require.resolve('../../api_integration/config.ts') ); + const customTestServices = getCustomApiTestServices(xPackAPITestsConfig); + return { testFiles, servers: xPackAPITestsConfig.get('servers'), - services: xPackAPITestsConfig.get('services'), + services: { + ...xPackAPITestsConfig.get('services'), + ...customTestServices, + }, junit: { reportName: name, }, diff --git a/x-pack/test/observability_api_integration/common/ftr_provider_context.ts b/x-pack/test/observability_api_integration/common/ftr_provider_context.ts index 2ea45b854eb28..b1d69d89e287a 100644 --- a/x-pack/test/observability_api_integration/common/ftr_provider_context.ts +++ b/x-pack/test/observability_api_integration/common/ftr_provider_context.ts @@ -5,4 +5,12 @@ * 2.0. */ +import { GenericFtrProviderContext } from '@kbn/test'; +import { services } from '../../api_integration/services'; +import { CustomApiTestServices } from './config'; + export type { FtrProviderContext } from '../../api_integration/ftr_provider_context'; +export type ObsFtrProviderContext = GenericFtrProviderContext< + typeof services & CustomApiTestServices, + {} +>; diff --git a/x-pack/test/observability_api_integration/common/obs_api_supertest.ts b/x-pack/test/observability_api_integration/common/obs_api_supertest.ts new file mode 100644 index 0000000000000..e0788dcd6785d --- /dev/null +++ b/x-pack/test/observability_api_integration/common/obs_api_supertest.ts @@ -0,0 +1,111 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import { format } from 'url'; +import supertest from 'supertest'; +import request from 'superagent'; +import { formatRequest, ClientRequestParamsOf, ReturnOf } from '@kbn/server-route-repository'; +import type { + ObservabilityServerRouteRepository, + APIEndpoint, +} from '@kbn/observability-plugin/server'; + +export type APIReturnType = ReturnOf< + ObservabilityServerRouteRepository, + TEndpoint +>; + +export type APIClientRequestParamsOf = ClientRequestParamsOf< + ObservabilityServerRouteRepository, + TEndpoint +>; + +export function createObsApiClient(st: supertest.SuperTest) { + return async ( + options: { + type?: 'form-data'; + endpoint: TEndpoint; + spaceId?: string; + } & APIClientRequestParamsOf & { params?: { query?: { _inspect?: boolean } } } + ): Promise> => { + const { endpoint, type } = options; + + const params = 'params' in options ? (options.params as Record) : {}; + + const { method, pathname, version } = formatRequest(endpoint, params.path); + const pathnameWithSpaceId = options.spaceId ? `/s/${options.spaceId}${pathname}` : pathname; + const url = format({ pathname: pathnameWithSpaceId, query: params?.query }); + + // eslint-disable-next-line no-console + console.debug(`Calling Observability API: ${method.toUpperCase()} ${url}`); + + const headers: Record = { + 'kbn-xsrf': 'foo', + 'x-elastic-internal-origin': 'foo', + }; + + if (version) { + headers['Elastic-Api-Version'] = version; + } + + let res: request.Response; + if (type === 'form-data') { + const fields: Array<[string, any]> = Object.entries(params.body); + const formDataRequest = st[method](url) + .set(headers) + .set('Content-type', 'multipart/form-data'); + + for (const field of fields) { + formDataRequest.field(field[0], field[1]); + } + + res = await formDataRequest; + } else if (params.body) { + res = await st[method](url).send(params.body).set(headers); + } else { + res = await st[method](url).set(headers); + } + + // supertest doesn't throw on http errors + if (res?.status !== 200) { + throw new ObservabilityApiError(res, endpoint); + } + + return res; + }; +} + +type ApiErrorResponse = Omit & { + body: { + statusCode: number; + error: string; + message: string; + attributes: object; + }; +}; + +export type ObservabilityApiSupertest = ReturnType; + +export class ObservabilityApiError extends Error { + res: ApiErrorResponse; + + constructor(res: request.Response, endpoint: string) { + super( + `Unhandled ObservabilityApiError. +Status: "${res.status}" +Endpoint: "${endpoint}" +Body: ${JSON.stringify(res.body)}` + ); + + this.res = res; + } +} + +export interface SupertestReturnType { + status: number; + body: APIReturnType; +} diff --git a/x-pack/test/observability_api_integration/trial/tests/index.ts b/x-pack/test/observability_api_integration/trial/tests/index.ts index e426efd90188c..3d7f31517121d 100644 --- a/x-pack/test/observability_api_integration/trial/tests/index.ts +++ b/x-pack/test/observability_api_integration/trial/tests/index.ts @@ -11,5 +11,6 @@ import { FtrProviderContext } from '../../common/ftr_provider_context'; export default function apmApiIntegrationTests({ loadTestFile }: FtrProviderContext) { describe('Observability specs (trial)', function () { loadTestFile(require.resolve('./annotations')); + loadTestFile(require.resolve('./obs_alert_details_context')); }); } diff --git a/x-pack/test/observability_api_integration/trial/tests/obs_alert_details_context.ts b/x-pack/test/observability_api_integration/trial/tests/obs_alert_details_context.ts new file mode 100644 index 0000000000000..bf75c8c5585d4 --- /dev/null +++ b/x-pack/test/observability_api_integration/trial/tests/obs_alert_details_context.ts @@ -0,0 +1,515 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import moment from 'moment'; +import { log, apm, generateShortId, timerange } from '@kbn/apm-synthtrace-client'; +import expect from '@kbn/expect'; +import { LogCategory } from '@kbn/apm-plugin/server/routes/assistant_functions/get_log_categories'; +import { SupertestReturnType } from '../../common/obs_api_supertest'; +import { ObsFtrProviderContext } from '../../common/ftr_provider_context'; + +// eslint-disable-next-line import/no-default-export +export default function ApiTest({ getService }: ObsFtrProviderContext) { + const obsApiClient = getService('obsApiClient'); + const apmSynthtraceClient = getService('apmSynthtraceEsClient'); + const logSynthtraceClient = getService('logSynthtraceEsClient'); + + describe('fetching observability alerts details context for AI assistant contextual insights', () => { + const start = moment().subtract(10, 'minutes').valueOf(); + const end = moment().valueOf(); + const range = timerange(start, end); + + describe('when no traces or logs are available', async () => { + let response: SupertestReturnType<'GET /internal/observability/assistant/alert_details_contextual_insights'>; + before(async () => { + response = await obsApiClient.adminUser({ + endpoint: 'GET /internal/observability/assistant/alert_details_contextual_insights', + params: { + query: { + alert_started_at: new Date(end).toISOString(), + }, + }, + }); + }); + + it('returns nothing', () => { + expect(response.body.alertContext).to.eql([]); + }); + }); + + describe('when traces and logs are ingested and logs are not annotated with service.name', async () => { + before(async () => { + await Promise.all([ + ingestTraces({ 'service.name': 'Backend', 'container.id': 'my-container-a' }), + ingestLogs({ + 'container.id': 'my-container-a', + 'kubernetes.pod.name': 'pod-a', + }), + ]); + }); + + after(async () => { + await cleanup(); + }); + + describe('when no params are specified', async () => { + let response: SupertestReturnType<'GET /internal/observability/assistant/alert_details_contextual_insights'>; + before(async () => { + response = await obsApiClient.adminUser({ + endpoint: 'GET /internal/observability/assistant/alert_details_contextual_insights', + params: { + query: { + alert_started_at: new Date(end).toISOString(), + }, + }, + }); + }); + + it('returns only 1 log category', async () => { + expect(response.body.alertContext).to.have.length(1); + + const logCategories = response.body.alertContext.find( + ({ key }) => key === 'logCategories' + )?.data as LogCategory[]; + + expect( + logCategories.map(({ errorCategory }: { errorCategory: string }) => errorCategory) + ).to.eql(['Error message from container my-container-a']); + }); + }); + + describe('when service name is specified', async () => { + let response: SupertestReturnType<'GET /internal/observability/assistant/alert_details_contextual_insights'>; + before(async () => { + response = await obsApiClient.adminUser({ + endpoint: 'GET /internal/observability/assistant/alert_details_contextual_insights', + params: { + query: { + alert_started_at: new Date(end).toISOString(), + 'service.name': 'Backend', + }, + }, + }); + }); + + it('returns service summary', () => { + const serviceSummary = response.body.alertContext.find( + ({ key }) => key === 'serviceSummary' + ); + expect(serviceSummary?.data).to.eql({ + 'service.name': 'Backend', + 'service.environment': ['production'], + 'agent.name': 'java', + 'service.version': ['1.0.0'], + 'language.name': 'java', + instances: 1, + anomalies: [], + alerts: [], + deployments: [], + }); + }); + + it('returns downstream dependencies', async () => { + const downstreamDependencies = response.body.alertContext.find( + ({ key }) => key === 'downstreamDependencies' + ); + expect(downstreamDependencies?.data).to.eql([ + { + 'span.destination.service.resource': 'elasticsearch', + 'span.type': 'db', + 'span.subtype': 'elasticsearch', + }, + ]); + }); + + it('returns log categories', () => { + const logCategories = response.body.alertContext.find( + ({ key }) => key === 'logCategories' + )?.data as LogCategory[]; + + expect(logCategories).to.have.length(1); + + const logCategory = logCategories[0]; + expect(logCategory?.sampleMessage).to.match( + /Error message #\d{16} from container my-container-a/ + ); + expect(logCategory?.docCount).to.be.greaterThan(0); + expect(logCategory?.errorCategory).to.be('Error message from container my-container-a'); + }); + }); + + describe('when container id is specified', async () => { + let response: SupertestReturnType<'GET /internal/observability/assistant/alert_details_contextual_insights'>; + before(async () => { + response = await obsApiClient.adminUser({ + endpoint: 'GET /internal/observability/assistant/alert_details_contextual_insights', + params: { + query: { + alert_started_at: new Date(end).toISOString(), + 'container.id': 'my-container-a', + }, + }, + }); + }); + + it('returns service summary', () => { + const serviceSummary = response.body.alertContext.find( + ({ key }) => key === 'serviceSummary' + ); + expect(serviceSummary?.data).to.eql({ + 'service.name': 'Backend', + 'service.environment': ['production'], + 'agent.name': 'java', + 'service.version': ['1.0.0'], + 'language.name': 'java', + instances: 1, + anomalies: [], + alerts: [], + deployments: [], + }); + }); + + it('returns downstream dependencies', async () => { + const downstreamDependencies = response.body.alertContext.find( + ({ key }) => key === 'downstreamDependencies' + ); + expect(downstreamDependencies?.data).to.eql([ + { + 'span.destination.service.resource': 'elasticsearch', + 'span.type': 'db', + 'span.subtype': 'elasticsearch', + }, + ]); + }); + + it('returns log categories', () => { + const logCategories = response.body.alertContext.find( + ({ key }) => key === 'logCategories' + )?.data as LogCategory[]; + expect(logCategories).to.have.length(1); + + const logCategory = logCategories[0]; + expect(logCategory?.sampleMessage).to.match( + /Error message #\d{16} from container my-container-a/ + ); + expect(logCategory?.docCount).to.be.greaterThan(0); + expect(logCategory?.errorCategory).to.be('Error message from container my-container-a'); + }); + }); + + describe('when non-existing container id is specified', async () => { + let response: SupertestReturnType<'GET /internal/observability/assistant/alert_details_contextual_insights'>; + before(async () => { + response = await obsApiClient.adminUser({ + endpoint: 'GET /internal/observability/assistant/alert_details_contextual_insights', + params: { + query: { + alert_started_at: new Date(end).toISOString(), + 'container.id': 'non-existing-container', + }, + }, + }); + }); + + it('returns nothing', () => { + expect(response.body.alertContext).to.eql([]); + }); + }); + + describe('when non-existing service.name is specified', async () => { + let response: SupertestReturnType<'GET /internal/observability/assistant/alert_details_contextual_insights'>; + before(async () => { + response = await obsApiClient.adminUser({ + endpoint: 'GET /internal/observability/assistant/alert_details_contextual_insights', + params: { + query: { + alert_started_at: new Date(end).toISOString(), + 'service.name': 'non-existing-service', + }, + }, + }); + }); + + it('returns empty service summary', () => { + const serviceSummary = response.body.alertContext.find( + ({ key }) => key === 'serviceSummary' + ); + expect(serviceSummary?.data).to.eql({ + 'service.name': 'non-existing-service', + 'service.environment': [], + instances: 1, + anomalies: [], + alerts: [], + deployments: [], + }); + }); + + it('returns no downstream dependencies', async () => { + const downstreamDependencies = response.body.alertContext.find( + ({ key }) => key === 'downstreamDependencies' + ); + expect(downstreamDependencies).to.eql(undefined); + }); + + it('returns log categories', () => { + const logCategories = response.body.alertContext.find( + ({ key }) => key === 'logCategories' + )?.data as LogCategory[]; + expect(logCategories).to.have.length(1); + }); + }); + }); + + describe('when traces and logs are ingested and logs are annotated with service.name', async () => { + before(async () => { + await ingestTraces({ 'service.name': 'Backend', 'container.id': 'my-container-a' }); + await ingestLogs({ + 'service.name': 'Backend', + 'container.id': 'my-container-a', + 'kubernetes.pod.name': 'pod-a', + }); + + // also ingest unrelated Frontend traces and logs that should not show up in the response when fetching "Backend"-related things + await ingestTraces({ 'service.name': 'Frontend', 'container.id': 'my-container-b' }); + await ingestLogs({ + 'service.name': 'Frontend', + 'container.id': 'my-container-b', + 'kubernetes.pod.name': 'pod-b', + }); + + // also ingest logs that are not annotated with service.name + await ingestLogs({ + 'container.id': 'my-container-c', + 'kubernetes.pod.name': 'pod-c', + }); + }); + + after(async () => { + await cleanup(); + }); + + describe('when no params are specified', async () => { + let response: SupertestReturnType<'GET /internal/observability/assistant/alert_details_contextual_insights'>; + before(async () => { + response = await obsApiClient.adminUser({ + endpoint: 'GET /internal/observability/assistant/alert_details_contextual_insights', + params: { + query: { + alert_started_at: new Date(end).toISOString(), + }, + }, + }); + }); + + it('returns no service summary', async () => { + const serviceSummary = response.body.alertContext.find( + ({ key }) => key === 'serviceSummary' + ); + expect(serviceSummary).to.be(undefined); + }); + + it('returns 1 log category', async () => { + const logCategories = response.body.alertContext.find( + ({ key }) => key === 'logCategories' + )?.data as LogCategory[]; + expect( + logCategories.map(({ errorCategory }: { errorCategory: string }) => errorCategory) + ).to.eql(['Error message from service', 'Error message from container my-container-c']); + }); + }); + + describe('when service name is specified', async () => { + let response: SupertestReturnType<'GET /internal/observability/assistant/alert_details_contextual_insights'>; + before(async () => { + response = await obsApiClient.adminUser({ + endpoint: 'GET /internal/observability/assistant/alert_details_contextual_insights', + params: { + query: { + alert_started_at: new Date(end).toISOString(), + 'service.name': 'Backend', + }, + }, + }); + }); + + it('returns log categories', () => { + const logCategories = response.body.alertContext.find( + ({ key }) => key === 'logCategories' + )?.data as LogCategory[]; + expect(logCategories).to.have.length(1); + + const logCategory = logCategories[0]; + expect(logCategory?.sampleMessage).to.match(/Error message #\d{16} from service Backend/); + expect(logCategory?.docCount).to.be.greaterThan(0); + expect(logCategory?.errorCategory).to.be('Error message from service Backend'); + }); + }); + + describe('when container id is specified', async () => { + let response: SupertestReturnType<'GET /internal/observability/assistant/alert_details_contextual_insights'>; + before(async () => { + response = await obsApiClient.adminUser({ + endpoint: 'GET /internal/observability/assistant/alert_details_contextual_insights', + params: { + query: { + alert_started_at: new Date(end).toISOString(), + 'container.id': 'my-container-a', + }, + }, + }); + }); + + it('returns log categories', () => { + const logCategories = response.body.alertContext.find( + ({ key }) => key === 'logCategories' + )?.data as LogCategory[]; + expect(logCategories).to.have.length(1); + + const logCategory = logCategories[0]; + expect(logCategory?.sampleMessage).to.match(/Error message #\d{16} from service Backend/); + expect(logCategory?.docCount).to.be.greaterThan(0); + expect(logCategory?.errorCategory).to.be('Error message from service Backend'); + }); + }); + + describe('when non-existing service.name is specified', async () => { + let response: SupertestReturnType<'GET /internal/observability/assistant/alert_details_contextual_insights'>; + before(async () => { + response = await obsApiClient.adminUser({ + endpoint: 'GET /internal/observability/assistant/alert_details_contextual_insights', + params: { + query: { + alert_started_at: new Date(end).toISOString(), + 'service.name': 'non-existing-service', + }, + }, + }); + }); + + it('returns empty service summary', () => { + const serviceSummary = response.body.alertContext.find( + ({ key }) => key === 'serviceSummary' + ); + expect(serviceSummary?.data).to.eql({ + 'service.name': 'non-existing-service', + 'service.environment': [], + instances: 1, + anomalies: [], + alerts: [], + deployments: [], + }); + }); + + it('does not return log categories', () => { + const logCategories = response.body.alertContext.find( + ({ key }) => key === 'logCategories' + )?.data as LogCategory[]; + expect(logCategories).to.have.length(1); + + expect( + logCategories.map(({ errorCategory }: { errorCategory: string }) => errorCategory) + ).to.eql(['Error message from container my-container-c']); + }); + }); + }); + + function ingestTraces(eventMetadata: { + 'service.name': string; + 'container.id'?: string; + 'host.name'?: string; + 'kubernetes.pod.name'?: string; + }) { + const serviceInstance = apm + .service({ + name: eventMetadata['service.name'], + environment: 'production', + agentName: 'java', + }) + .instance('my-instance'); + + const events = range + .interval('1m') + .rate(1) + .generator((timestamp) => { + return serviceInstance + .transaction({ transactionName: 'tx' }) + .timestamp(timestamp) + .duration(10000) + .defaults({ 'service.version': '1.0.0', ...eventMetadata }) + .outcome('success') + .children( + serviceInstance + .span({ + spanName: 'GET apm-*/_search', + spanType: 'db', + spanSubtype: 'elasticsearch', + }) + .duration(1000) + .success() + .destination('elasticsearch') + .timestamp(timestamp) + ); + }); + + return apmSynthtraceClient.index(events); + } + + function ingestLogs(eventMetadata: { + 'service.name'?: string; + 'container.id'?: string; + 'kubernetes.pod.name'?: string; + 'host.name'?: string; + }) { + const getMessage = () => { + const msgPrefix = `Error message #${generateShortId()}`; + + if (eventMetadata['service.name']) { + return `${msgPrefix} from service ${eventMetadata['service.name']}`; + } + + if (eventMetadata['container.id']) { + return `${msgPrefix} from container ${eventMetadata['container.id']}`; + } + + if (eventMetadata['kubernetes.pod.name']) { + return `${msgPrefix} from pod ${eventMetadata['kubernetes.pod.name']}`; + } + + if (eventMetadata['host.name']) { + return `${msgPrefix} from host ${eventMetadata['host.name']}`; + } + + return msgPrefix; + }; + + const events = range + .interval('1m') + .rate(1) + .generator((timestamp) => { + return [ + log + .create() + .message(getMessage()) + .logLevel('error') + .defaults({ + 'trace.id': generateShortId(), + 'agent.name': 'synth-agent', + ...eventMetadata, + }) + .timestamp(timestamp), + ]; + }); + + return logSynthtraceClient.index(events); + } + + async function cleanup() { + await apmSynthtraceClient.clean(); + await logSynthtraceClient.clean(); + } + }); +}