Skip to content

Commit a447638

Browse files
committed
[Obs AI Assistant] Move alert context from apm to obs api (#182243)
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 (cherry picked from commit 0c9a323)
1 parent de8bd2b commit a447638

142 files changed

Lines changed: 1447 additions & 1324 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

x-pack/plugins/observability_solution/apm/server/plugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import { createApmSourceMapIndexTemplate } from './routes/source_maps/create_apm
4040
import { addApiKeysToEveryPackagePolicyIfMissing } from './routes/fleet/api_keys/add_api_keys_to_policies_if_missing';
4141
import { apmTutorialCustomIntegration } from '../common/tutorial/tutorials';
4242
import { registerAssistantFunctions } from './assistant_functions';
43-
import { getAlertDetailsContextHandler } from './routes/assistant_functions/get_observability_alert_details_context/get_alert_details_context_handler';
43+
import { getAlertDetailsContextHandler } from './routes/assistant_functions/get_observability_alert_details_context';
4444

4545
export class APMPlugin
4646
implements Plugin<APMPluginSetup, void, APMPluginSetupDependencies, APMPluginStartDependencies>

x-pack/plugins/observability_solution/apm/server/routes/assistant_functions/get_changepoints/index.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
* 2.0.
66
*/
77

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

1918
export async function getServiceChangePoints({
2019
apmEventClient,
21-
alertStartedAt,
20+
start,
21+
end,
2222
serviceName,
2323
serviceEnvironment,
2424
transactionType,
2525
transactionName,
2626
}: {
2727
apmEventClient: APMEventClient;
28-
alertStartedAt: string;
28+
start: string;
29+
end: string;
2930
serviceName: string | undefined;
3031
serviceEnvironment: string | undefined;
3132
transactionType: string | undefined;
@@ -38,8 +39,8 @@ export async function getServiceChangePoints({
3839
const res = await getApmTimeseries({
3940
apmEventClient,
4041
arguments: {
41-
start: moment(alertStartedAt).subtract(12, 'hours').toISOString(),
42-
end: alertStartedAt,
42+
start,
43+
end,
4344
stats: [
4445
{
4546
title: 'Latency',
@@ -95,12 +96,14 @@ export async function getServiceChangePoints({
9596

9697
export async function getExitSpanChangePoints({
9798
apmEventClient,
98-
alertStartedAt,
99+
start,
100+
end,
99101
serviceName,
100102
serviceEnvironment,
101103
}: {
102104
apmEventClient: APMEventClient;
103-
alertStartedAt: string;
105+
start: string;
106+
end: string;
104107
serviceName: string | undefined;
105108
serviceEnvironment: string | undefined;
106109
}): Promise<ChangePointGrouping[]> {
@@ -111,8 +114,8 @@ export async function getExitSpanChangePoints({
111114
const res = await getApmTimeseries({
112115
apmEventClient,
113116
arguments: {
114-
start: moment(alertStartedAt).subtract(30, 'minute').toISOString(),
115-
end: alertStartedAt,
117+
start,
118+
end,
116119
stats: [
117120
{
118121
title: 'Exit span latency',

x-pack/plugins/observability_solution/apm/server/routes/assistant_functions/get_log_categories/index.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,11 @@ import {
1717
} from '../../../../common/es_fields/apm';
1818
import { getTypedSearch } from '../../../utils/create_typed_es_client';
1919

20-
export type LogCategories =
21-
| Array<{
22-
errorCategory: string;
23-
docCount: number;
24-
sampleMessage: string;
25-
}>
26-
| undefined;
20+
export interface LogCategory {
21+
errorCategory: string;
22+
docCount: number;
23+
sampleMessage: string;
24+
}
2725

2826
export async function getLogCategories({
2927
esClient,
@@ -40,7 +38,7 @@ export async function getLogCategories({
4038
'container.id'?: string;
4139
'kubernetes.pod.name'?: string;
4240
};
43-
}): Promise<LogCategories> {
41+
}): Promise<LogCategory[] | undefined> {
4442
const start = datemath.parse(args.start)?.valueOf()!;
4543
const end = datemath.parse(args.end)?.valueOf()!;
4644

x-pack/plugins/observability_solution/apm/server/routes/assistant_functions/get_observability_alert_details_context/get_alert_details_context_handler.ts

Lines changed: 0 additions & 85 deletions
This file was deleted.

x-pack/plugins/observability_solution/apm/server/routes/assistant_functions/get_observability_alert_details_context/get_apm_alert_details_context_prompt.ts

Lines changed: 0 additions & 85 deletions
This file was deleted.

x-pack/plugins/observability_solution/apm/server/routes/assistant_functions/get_observability_alert_details_context/get_container_id_from_signals.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { rangeQuery, typedSearch } from '@kbn/observability-plugin/server/utils/
1212
import * as t from 'io-ts';
1313
import moment from 'moment';
1414
import { ESSearchRequest } from '@kbn/es-types';
15-
import { observabilityAlertDetailsContextRt } from '@kbn/observability-plugin/server/services';
15+
import { alertDetailsContextRt } from '@kbn/observability-plugin/server/services';
1616
import { ApmDocumentType } from '../../../../common/document_type';
1717
import {
1818
APMEventClient,
@@ -26,7 +26,7 @@ export async function getContainerIdFromSignals({
2626
coreContext,
2727
apmEventClient,
2828
}: {
29-
query: t.TypeOf<typeof observabilityAlertDetailsContextRt>;
29+
query: t.TypeOf<typeof alertDetailsContextRt>;
3030
esClient: ElasticsearchClient;
3131
coreContext: Pick<CoreRequestHandlerContext, 'uiSettings'>;
3232
apmEventClient: APMEventClient;

x-pack/plugins/observability_solution/apm/server/routes/assistant_functions/get_observability_alert_details_context/get_service_name_from_signals.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { rangeQuery, termQuery, typedSearch } from '@kbn/observability-plugin/se
1212
import * as t from 'io-ts';
1313
import moment from 'moment';
1414
import { ESSearchRequest } from '@kbn/es-types';
15-
import { observabilityAlertDetailsContextRt } from '@kbn/observability-plugin/server/services';
15+
import { alertDetailsContextRt } from '@kbn/observability-plugin/server/services';
1616
import { ApmDocumentType } from '../../../../common/document_type';
1717
import {
1818
APMEventClient,
@@ -26,7 +26,7 @@ export async function getServiceNameFromSignals({
2626
coreContext,
2727
apmEventClient,
2828
}: {
29-
query: t.TypeOf<typeof observabilityAlertDetailsContextRt>;
29+
query: t.TypeOf<typeof alertDetailsContextRt>;
3030
esClient: ElasticsearchClient;
3131
coreContext: Pick<CoreRequestHandlerContext, 'uiSettings'>;
3232
apmEventClient: APMEventClient;

0 commit comments

Comments
 (0)