From c37675d756690665eb01c9a21eb1718e8f4a6ebd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B8ren=20Louv-Jansen?= Date: Thu, 2 May 2024 00:33:17 +0200 Subject: [PATCH] Simplify return --- .../get_apm_alert_details_context_prompt.ts | 85 ------------------- .../index.ts | 44 +++++++--- 2 files changed, 33 insertions(+), 96 deletions(-) delete mode 100644 x-pack/plugins/observability_solution/apm/server/routes/assistant_functions/get_observability_alert_details_context/get_apm_alert_details_context_prompt.ts 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 4ce7c2c6c0bd8..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 { LogCategory } 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?: LogCategory[]; - 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/index.ts b/x-pack/plugins/observability_solution/apm/server/routes/assistant_functions/get_observability_alert_details_context/index.ts index 0a21c60625c03..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 @@ -11,6 +11,7 @@ import { AlertDetailsContextualInsightsRequestContext, } from '@kbn/observability-plugin/server/services'; import moment from 'moment'; +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'; @@ -21,7 +22,6 @@ 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'; @@ -204,15 +204,37 @@ export const getAlertDetailsContextHandler = ( 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)); }; };