Skip to content

Commit

Permalink
[Obs AI Assistant] Move alert context from apm to obs api (#182243)
Browse files Browse the repository at this point in the history
Follow-up to #181501

This moves the alert details context used by the AI Assistant from the
apm api `GET /internal/apm/assistant/get_obs_alert_details_context` to
the Obs api
`/internal/observability/assistant/alert_details_contextual_insights`.

This also involves adding a type safe API client to the observability
API tests

### Other changes:

- Rename `synthtraceEsClient` to `apmSynthtraceEsClient` to indicate it
is specific to APM
  • Loading branch information
sorenlouv authored May 2, 2024
1 parent d4d34da commit 0c9a323
Show file tree
Hide file tree
Showing 142 changed files with 1,447 additions and 1,324 deletions.
2 changes: 1 addition & 1 deletion x-pack/plugins/observability_solution/apm/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import { createApmSourceMapIndexTemplate } from './routes/source_maps/create_apm
import { addApiKeysToEveryPackagePolicyIfMissing } from './routes/fleet/api_keys/add_api_keys_to_policies_if_missing';
import { apmTutorialCustomIntegration } from '../common/tutorial/tutorials';
import { registerAssistantFunctions } from './assistant_functions';
import { getAlertDetailsContextHandler } from './routes/assistant_functions/get_observability_alert_details_context/get_alert_details_context_handler';
import { getAlertDetailsContextHandler } from './routes/assistant_functions/get_observability_alert_details_context';

export class APMPlugin
implements Plugin<APMPluginSetup, void, APMPluginSetupDependencies, APMPluginStartDependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* 2.0.
*/

import moment from 'moment';
import { LatencyAggregationType } from '../../../../common/latency_aggregation_types';
import { APMEventClient } from '../../../lib/helpers/create_es_client/create_apm_event_client';
import { ApmTimeseriesType, getApmTimeseries, TimeseriesChangePoint } from '../get_apm_timeseries';
Expand All @@ -18,14 +17,16 @@ export interface ChangePointGrouping {

export async function getServiceChangePoints({
apmEventClient,
alertStartedAt,
start,
end,
serviceName,
serviceEnvironment,
transactionType,
transactionName,
}: {
apmEventClient: APMEventClient;
alertStartedAt: string;
start: string;
end: string;
serviceName: string | undefined;
serviceEnvironment: string | undefined;
transactionType: string | undefined;
Expand All @@ -38,8 +39,8 @@ export async function getServiceChangePoints({
const res = await getApmTimeseries({
apmEventClient,
arguments: {
start: moment(alertStartedAt).subtract(12, 'hours').toISOString(),
end: alertStartedAt,
start,
end,
stats: [
{
title: 'Latency',
Expand Down Expand Up @@ -95,12 +96,14 @@ export async function getServiceChangePoints({

export async function getExitSpanChangePoints({
apmEventClient,
alertStartedAt,
start,
end,
serviceName,
serviceEnvironment,
}: {
apmEventClient: APMEventClient;
alertStartedAt: string;
start: string;
end: string;
serviceName: string | undefined;
serviceEnvironment: string | undefined;
}): Promise<ChangePointGrouping[]> {
Expand All @@ -111,8 +114,8 @@ export async function getExitSpanChangePoints({
const res = await getApmTimeseries({
apmEventClient,
arguments: {
start: moment(alertStartedAt).subtract(30, 'minute').toISOString(),
end: alertStartedAt,
start,
end,
stats: [
{
title: 'Exit span latency',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,11 @@ import {
} from '../../../../common/es_fields/apm';
import { getTypedSearch } from '../../../utils/create_typed_es_client';

export type LogCategories =
| Array<{
errorCategory: string;
docCount: number;
sampleMessage: string;
}>
| undefined;
export interface LogCategory {
errorCategory: string;
docCount: number;
sampleMessage: string;
}

export async function getLogCategories({
esClient,
Expand All @@ -40,7 +38,7 @@ export async function getLogCategories({
'container.id'?: string;
'kubernetes.pod.name'?: string;
};
}): Promise<LogCategories> {
}): Promise<LogCategory[] | undefined> {
const start = datemath.parse(args.start)?.valueOf()!;
const end = datemath.parse(args.end)?.valueOf()!;

Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { rangeQuery, typedSearch } from '@kbn/observability-plugin/server/utils/
import * as t from 'io-ts';
import moment from 'moment';
import { ESSearchRequest } from '@kbn/es-types';
import { observabilityAlertDetailsContextRt } from '@kbn/observability-plugin/server/services';
import { alertDetailsContextRt } from '@kbn/observability-plugin/server/services';
import { ApmDocumentType } from '../../../../common/document_type';
import {
APMEventClient,
Expand All @@ -26,7 +26,7 @@ export async function getContainerIdFromSignals({
coreContext,
apmEventClient,
}: {
query: t.TypeOf<typeof observabilityAlertDetailsContextRt>;
query: t.TypeOf<typeof alertDetailsContextRt>;
esClient: ElasticsearchClient;
coreContext: Pick<CoreRequestHandlerContext, 'uiSettings'>;
apmEventClient: APMEventClient;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { rangeQuery, termQuery, typedSearch } from '@kbn/observability-plugin/se
import * as t from 'io-ts';
import moment from 'moment';
import { ESSearchRequest } from '@kbn/es-types';
import { observabilityAlertDetailsContextRt } from '@kbn/observability-plugin/server/services';
import { alertDetailsContextRt } from '@kbn/observability-plugin/server/services';
import { ApmDocumentType } from '../../../../common/document_type';
import {
APMEventClient,
Expand All @@ -26,7 +26,7 @@ export async function getServiceNameFromSignals({
coreContext,
apmEventClient,
}: {
query: t.TypeOf<typeof observabilityAlertDetailsContextRt>;
query: t.TypeOf<typeof alertDetailsContextRt>;
esClient: ElasticsearchClient;
coreContext: Pick<CoreRequestHandlerContext, 'uiSettings'>;
apmEventClient: APMEventClient;
Expand Down
Loading

0 comments on commit 0c9a323

Please sign in to comment.