From 300e2985c18498e35b2b82cd88c86459471beed3 Mon Sep 17 00:00:00 2001 From: Coen Warmer Date: Mon, 4 Sep 2023 20:18:58 +0200 Subject: [PATCH] [Observability AI Assistant] Use POST for get_apm_services_list (#165621) Co-authored-by: Dario Gieselaar --- .../get_apm_services_list.ts | 4 ++-- .../routes/assistant_functions/route.ts | 23 +++++++++---------- .../public/functions/index.ts | 2 +- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/x-pack/plugins/apm/public/assistant_functions/get_apm_services_list.ts b/x-pack/plugins/apm/public/assistant_functions/get_apm_services_list.ts index 83f1c53d5ca7..9047f768449e 100644 --- a/x-pack/plugins/apm/public/assistant_functions/get_apm_services_list.ts +++ b/x-pack/plugins/apm/public/assistant_functions/get_apm_services_list.ts @@ -66,10 +66,10 @@ export function registerGetApmServicesListFunction({ } as const, }, async ({ arguments: args }, signal) => { - return callApmApi('GET /internal/apm/assistant/get_services_list', { + return callApmApi('POST /internal/apm/assistant/get_services_list', { signal, params: { - query: args, + body: args, }, }); } diff --git a/x-pack/plugins/apm/server/routes/assistant_functions/route.ts b/x-pack/plugins/apm/server/routes/assistant_functions/route.ts index 486fdb57fca8..436f514e423f 100644 --- a/x-pack/plugins/apm/server/routes/assistant_functions/route.ts +++ b/x-pack/plugins/apm/server/routes/assistant_functions/route.ts @@ -18,7 +18,6 @@ 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 { environmentRt } from '../default_api_types'; import { getServicesItems } from '../services/get_services/get_services_items'; import { CorrelationValue, @@ -26,20 +25,20 @@ import { getApmCorrelationValues, } from './get_apm_correlation_values'; import { - type APMDownstreamDependency, downstreamDependenciesRouteRt, getAssistantDownstreamDependencies, + type APMDownstreamDependency, } from './get_apm_downstream_dependencies'; import { errorRouteRt, getApmErrorDocument } from './get_apm_error_document'; import { getApmServiceSummary, - type ServiceSummary, serviceSummaryRouteRt, + type ServiceSummary, } from './get_apm_service_summary'; import { - type ApmTimeseries, getApmTimeseries, getApmTimeseriesRt, + type ApmTimeseries, } from './get_apm_timeseries'; const getApmTimeSeriesRoute = createApmServerRoute({ @@ -204,15 +203,15 @@ interface ApmServicesListItem { type ApmServicesListContent = ApmServicesListItem[]; const getApmServicesListRoute = createApmServerRoute({ - endpoint: 'GET /internal/apm/assistant/get_services_list', + endpoint: 'POST /internal/apm/assistant/get_services_list', params: t.type({ - query: t.intersection([ + body: t.intersection([ t.type({ start: t.string, end: t.string, }), t.partial({ - 'service.environment': environmentRt.props.environment, + 'service.environment': t.string, healthStatus: t.array( t.union([ t.literal(ServiceHealthStatus.unknown), @@ -229,9 +228,9 @@ const getApmServicesListRoute = createApmServerRoute({ }, handler: async (resources): Promise<{ content: ApmServicesListContent }> => { const { params } = resources; - const { query } = params; + const { body } = params; - const { healthStatus } = query; + const { healthStatus } = body; const [apmEventClient, apmAlertsClient, mlClient, randomSampler] = await Promise.all([ @@ -245,8 +244,8 @@ const getApmServicesListRoute = createApmServerRoute({ }), ]); - const start = datemath.parse(query.start)?.valueOf()!; - const end = datemath.parse(query.end)?.valueOf()!; + const start = datemath.parse(body.start)?.valueOf()!; + const end = datemath.parse(body.end)?.valueOf()!; const serviceItems = await getServicesItems({ apmAlertsClient, @@ -254,7 +253,7 @@ const getApmServicesListRoute = createApmServerRoute({ documentType: ApmDocumentType.TransactionMetric, start, end, - environment: query['service.environment'] ?? ENVIRONMENT_ALL.value, + environment: body['service.environment'] || ENVIRONMENT_ALL.value, kuery: '', logger: resources.logger, randomSampler, diff --git a/x-pack/plugins/observability_ai_assistant/public/functions/index.ts b/x-pack/plugins/observability_ai_assistant/public/functions/index.ts index fd2e3b9c6bca..a0c1a264bfb5 100644 --- a/x-pack/plugins/observability_ai_assistant/public/functions/index.ts +++ b/x-pack/plugins/observability_ai_assistant/public/functions/index.ts @@ -56,7 +56,7 @@ export async function registerFunctions({ ); if (isReady) { - description += `You can use the "summarize" functions to store new information you have learned in a knowledge database. Once you have established that you did not know the answer to a question, and the user gave you this information, it's important that you create a summarisation of what you have learned and store it in the knowledge database. + description += `You can use the "summarize" functions to store new information you have learned in a knowledge database. Once you have established that you did not know the answer to a question, and the user gave you this information, it's important that you create a summarisation of what you have learned and store it in the knowledge database. Don't create a new summarization if you see a similar summarization in the conversation, instead, update the existing one by re-using its ID. Additionally, you can use the "recall" function to retrieve relevant information from the knowledge database. `;