Skip to content

Commit

Permalink
[AI Assistant] Move alert details context from APM api to Obs api
Browse files Browse the repository at this point in the history
  • Loading branch information
sorenlouv committed May 1, 2024
1 parent d883196 commit b4ab511
Show file tree
Hide file tree
Showing 33 changed files with 1,044 additions and 862 deletions.
3 changes: 2 additions & 1 deletion packages/kbn-apm-synthtrace/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
export { createLogger, LogLevel } from './src/lib/utils/create_logger';

export { ApmSynthtraceEsClient } from './src/lib/apm/client/apm_synthtrace_es_client';
export { ApmSynthtraceKibanaClient } from './src/lib/apm/client/apm_synthtrace_kibana_client';
export { SynthtraceKibanaClient } from './src/lib/apm/client/apm_synthtrace_kibana_client';

export { InfraSynthtraceEsClient } from './src/lib/infra/infra_synthtrace_es_client';
export { InfraSynthtraceKibanaClient } from './src/lib/infra/infra_synthtrace_kibana_client';
export { MonitoringSynthtraceEsClient } from './src/lib/monitoring/monitoring_synthtrace_es_client';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
* Side Public License, v 1.
*/

import { ApmSynthtraceKibanaClient } from '../../lib/apm/client/apm_synthtrace_kibana_client';
import { SynthtraceKibanaClient } from '../../lib/apm/client/apm_synthtrace_kibana_client';
import { Logger } from '../../lib/utils/create_logger';

export function getKibanaClient({ target, logger }: { target: string; logger: Logger }) {
const kibanaClient = new ApmSynthtraceKibanaClient({
const kibanaClient = new SynthtraceKibanaClient({
logger,
target,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import pRetry from 'p-retry';
import { Logger } from '../../utils/create_logger';
import { kibanaHeaders } from '../../shared/client_headers';

export class ApmSynthtraceKibanaClient {
export class SynthtraceKibanaClient {
private readonly logger: Logger;
private target: string;

Expand Down
4 changes: 2 additions & 2 deletions packages/kbn-journeys/services/synthtrace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import {
ApmSynthtraceEsClient,
ApmSynthtraceKibanaClient,
SynthtraceKibanaClient,
InfraSynthtraceEsClient,
InfraSynthtraceKibanaClient,
} from '@kbn/apm-synthtrace';
Expand Down Expand Up @@ -103,7 +103,7 @@ async function initApmSynthtraceClient(options: SynthtraceClientOptions) {
auth: `${auth.getUsername()}:${auth.getPassword()}`,
});

const synthKbnClient = new ApmSynthtraceKibanaClient({
const synthKbnClient = new SynthtraceKibanaClient({
logger,
target: kibanaUrlWithAuth,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import { ApmSynthtraceKibanaClient, createLogger, LogLevel } from '@kbn/apm-synthtrace';
import { SynthtraceKibanaClient, createLogger, LogLevel } from '@kbn/apm-synthtrace';
import cypress from 'cypress';
import path from 'path';
import Url from 'url';
Expand Down Expand Up @@ -39,7 +39,7 @@ export async function cypressTestRunner({ getService }: FtrProviderContext) {
});

const esRequestTimeout = config.get('timeouts.esRequestTimeout');
const kibanaClient = new ApmSynthtraceKibanaClient({
const kibanaClient = new SynthtraceKibanaClient({
logger: createLogger(LogLevel.info),
target: kibanaUrl,
});
Expand Down
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.

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { isEmpty } from 'lodash';
import { AlertDetailsContextualInsight } from '@kbn/observability-plugin/server/services';
import { APMDownstreamDependency } from '../get_apm_downstream_dependencies';
import { ServiceSummary } from '../get_apm_service_summary';
import { LogCategories } from '../get_log_categories';
import { LogCategory } from '../get_log_categories';
import { ApmAnomalies } from '../get_apm_service_summary/get_anomalies';
import { ChangePointGrouping } from '../get_changepoints';

Expand All @@ -27,7 +27,7 @@ export function getApmAlertDetailsContextPrompt({
serviceEnvironment?: string;
serviceSummary?: ServiceSummary;
downstreamDependencies?: APMDownstreamDependency[];
logCategories: LogCategories;
logCategories?: LogCategory[];
serviceChangePoints?: ChangePointGrouping[];
exitSpanChangePoints?: ChangePointGrouping[];
anomalies?: ApmAnomalies;
Expand Down
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 b4ab511

Please sign in to comment.