-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Investigation app] add entities route and investigation Contextual I…
…nsight (#194432) ## Summary Adds a route that can be used to fetch entities related to an investigation. The route fetches associated entities by service name, host name, or container id. It then identifies the associated indices and datastreams. The discovered entities are passed to the contextual insight to inform the LLM. ![image](https://github.com/user-attachments/assets/855a8d68-b039-4557-ba23-5661cd961021) This PR represents the first step in developing an AI-informed hypothesis at the beginning of the investigation. Over time, further insights will be provided to the LLM to deepen it's investigative analysis and propose a more helpful root cause hypothesis. ### Testing 1. Create some APM data. I'm using the otel demo and triggering a failure via the flagd service. Since this is in flux, you can reach out to me about this workflow. However, you can also create APM data via `synth-trace`. 2. Create an custom threshold rule that you expect to trigger an alert. I created mine to using `http.response.status_code: 500 / http.response.status_code : *` and set a low threshold base on the amount of failures in my current test data. Be sure to also group the alert by `service.name` 3. Wait for the alert to fire, then visit the alert details page and start an investigation 4. notice the contextual insight. Expand it to see more information --------- Co-authored-by: kibanamachine <[email protected]>
- Loading branch information
1 parent
19e37bf
commit e4bb435
Showing
25 changed files
with
1,485 additions
and
53 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
packages/kbn-investigation-shared/src/rest_specs/entity.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* 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", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
* Public License v 1"; you may not use this file except in compliance with, at | ||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
|
||
import { z } from '@kbn/zod'; | ||
|
||
const metricsSchema = z.object({ | ||
failedTransactionRate: z.number().optional(), | ||
latency: z.number().optional(), | ||
throughput: z.number().optional(), | ||
logErrorRate: z.number().optional(), | ||
logRate: z.number().optional(), | ||
}); | ||
|
||
const entitySchema = z.object({ | ||
id: z.string(), | ||
definitionId: z.string(), | ||
definitionVersion: z.string(), | ||
displayName: z.string(), | ||
firstSeenTimestamp: z.string(), | ||
lastSeenTimestamp: z.string(), | ||
identityFields: z.array(z.string()), | ||
schemaVersion: z.string(), | ||
type: z.string(), | ||
metrics: metricsSchema, | ||
}); | ||
|
||
const entitySourceSchema = z.object({ | ||
dataStream: z.string().optional(), | ||
}); | ||
|
||
const entityWithSourceSchema = z.intersection( | ||
entitySchema, | ||
z.object({ | ||
sources: z.array(entitySourceSchema), | ||
}) | ||
); | ||
|
||
type EntityWithSource = z.output<typeof entityWithSourceSchema>; | ||
type EntitySource = z.output<typeof entitySourceSchema>; | ||
|
||
export { entitySchema, entityWithSourceSchema }; | ||
export type { EntityWithSource, EntitySource }; |
34 changes: 34 additions & 0 deletions
34
packages/kbn-investigation-shared/src/rest_specs/get_entities.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* 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", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
* Public License v 1"; you may not use this file except in compliance with, at | ||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
|
||
import { z } from '@kbn/zod'; | ||
import { entityWithSourceSchema } from './entity'; | ||
|
||
const getEntitiesParamsSchema = z | ||
.object({ | ||
query: z | ||
.object({ | ||
'service.name': z.string(), | ||
'service.environment': z.string(), | ||
'host.name': z.string(), | ||
'container.id': z.string(), | ||
}) | ||
.partial(), | ||
}) | ||
.partial(); | ||
|
||
const getEntitiesResponseSchema = z.object({ | ||
entities: z.array(entityWithSourceSchema), | ||
}); | ||
|
||
type GetEntitiesParams = z.infer<typeof getEntitiesParamsSchema.shape.query>; | ||
type GetEntitiesResponse = z.output<typeof getEntitiesResponseSchema>; | ||
|
||
export { getEntitiesParamsSchema, getEntitiesResponseSchema }; | ||
export type { GetEntitiesParams, GetEntitiesResponse }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
x-pack/plugins/observability_solution/investigate_app/public/hooks/use_fetch_entities.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* 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 { useQuery } from '@tanstack/react-query'; | ||
import { GetEntitiesResponse } from '@kbn/investigation-shared'; | ||
import { useKibana } from './use_kibana'; | ||
import { investigationKeys } from './query_key_factory'; | ||
|
||
export interface EntityParams { | ||
investigationId: string; | ||
serviceName?: string; | ||
serviceEnvironment?: string; | ||
hostName?: string; | ||
containerId?: string; | ||
} | ||
|
||
export function useFetchEntities({ | ||
investigationId, | ||
serviceName, | ||
serviceEnvironment, | ||
hostName, | ||
containerId, | ||
}: EntityParams) { | ||
const { | ||
core: { http }, | ||
} = useKibana(); | ||
|
||
const { isInitialLoading, isLoading, isError, isSuccess, isRefetching, data } = useQuery({ | ||
queryKey: investigationKeys.entities({ | ||
investigationId, | ||
serviceName, | ||
serviceEnvironment, | ||
hostName, | ||
containerId, | ||
}), | ||
queryFn: async ({ signal }) => { | ||
return await http.get<GetEntitiesResponse>('/api/observability/investigation/entities', { | ||
query: { | ||
'service.name': serviceName, | ||
'service.environment': serviceEnvironment, | ||
'host.name': hostName, | ||
'container.id': containerId, | ||
}, | ||
version: '2023-10-31', | ||
signal, | ||
}); | ||
}, | ||
refetchOnWindowFocus: false, | ||
onError: (error: Error) => { | ||
// ignore error | ||
}, | ||
enabled: Boolean(investigationId && (serviceName || hostName || containerId)), | ||
}); | ||
|
||
return { | ||
data, | ||
isInitialLoading, | ||
isLoading, | ||
isRefetching, | ||
isSuccess, | ||
isError, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.