Skip to content

Commit

Permalink
[Observability Inspector] Make id unique to capture multiple invocati…
Browse files Browse the repository at this point in the history
…ons of the same query (elastic#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`. 

<img width="866" alt="image"
src="https://github.com/elastic/kibana/assets/209966/013f0da7-eb0e-4ee4-9d93-1ff26dc9c27a">
  • Loading branch information
sorenlouv authored Dec 18, 2023
1 parent 74b1e12 commit 387cb38
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export function InspectorContextProvider({ children }: { children: ReactNode })
const requestParams = { id, name };

const requestResponder = inspectorAdapters.requests.start(
id,
name,
requestParams,
operation.startTime
);
Expand Down

0 comments on commit 387cb38

Please sign in to comment.