From 387cb38bd98b78a188f99f2b167d91dd2090f165 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B8ren=20Louv-Jansen?= Date: Mon, 18 Dec 2023 16:17:53 +0100 Subject: [PATCH] [Observability Inspector] Make id unique to capture multiple invocations of the same query (#173433) Observability apps that use the inspector functionality can capture Elasticsearch queries and have them show up in the Inspector UI for debugging purposes. There is one problem: the same id is generated if a query is called multiple times, meaning we can only see one instance of a specific query that might have been called several times. This change makes the id unique. This also fixes a bug where we `id` is passed instead of `name`. image --- .../common/utils/get_inspect_response.ts | 6 ++++-- .../public/contexts/inspector/inspector_context.tsx | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/x-pack/plugins/observability_shared/common/utils/get_inspect_response.ts b/x-pack/plugins/observability_shared/common/utils/get_inspect_response.ts index 85f6624225e5a..fbcb053acdc52 100644 --- a/x-pack/plugins/observability_shared/common/utils/get_inspect_response.ts +++ b/x-pack/plugins/observability_shared/common/utils/get_inspect_response.ts @@ -6,6 +6,7 @@ */ import { i18n } from '@kbn/i18n'; +import { v4 as uuidv4 } from 'uuid'; import type { KibanaRequest } from '@kbn/core/server'; import type { RequestStatistics, RequestStatus } from '@kbn/inspector-plugin/common'; import { Request } from '@kbn/inspector-plugin/common'; @@ -157,12 +158,13 @@ export function getInspectResponse({ operationName: string; startTime: number; }): InspectResponse[0] { - const id = `${operationName} (${kibanaRequest.route.path})`; + const name = `${operationName} (${kibanaRequest.route.path})`; + const id = `${name} ${uuidv4()}`; return { id, json: esRequestParams.body ?? esRequestParams, - name: id, + name, response: { json: esError ? esError.originalError : esResponse, }, diff --git a/x-pack/plugins/observability_shared/public/contexts/inspector/inspector_context.tsx b/x-pack/plugins/observability_shared/public/contexts/inspector/inspector_context.tsx index a595c6bd67a8e..0b87f0e4a5476 100644 --- a/x-pack/plugins/observability_shared/public/contexts/inspector/inspector_context.tsx +++ b/x-pack/plugins/observability_shared/public/contexts/inspector/inspector_context.tsx @@ -49,7 +49,7 @@ export function InspectorContextProvider({ children }: { children: ReactNode }) const requestParams = { id, name }; const requestResponder = inspectorAdapters.requests.start( - id, + name, requestParams, operation.startTime );