Skip to content

Commit

Permalink
Other APM functions (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
dgieselaar committed Aug 10, 2023
1 parent d9a8802 commit b5365e2
Show file tree
Hide file tree
Showing 21 changed files with 1,092 additions and 38 deletions.
12 changes: 12 additions & 0 deletions x-pack/plugins/apm/common/assistant/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* 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.
*/

export enum CorrelationsEventType {
Transaction = 'transaction',
ExitSpan = 'exit_span',
Error = 'error',
}
1 change: 1 addition & 0 deletions x-pack/plugins/apm/common/connections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export interface ServiceNode extends NodeBase {
serviceName: string;
agentName: AgentName;
environment: string;
dependencyName?: string;
}

export interface DependencyNode extends NodeBase {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,113 @@
*/

import type { RegisterFunctionDefinition } from '@kbn/observability-ai-assistant-plugin/common/types';
import { CorrelationsEventType } from '../../../common/assistant/constants';
import { callApmApi } from '../../services/rest/create_call_apm_api';

export function registerGetApmCorrelationsFunction({
registerFunction,
}: {
registerFunction: RegisterFunctionDefinition;
}) {}
}) {
registerFunction(
{
name: 'get_apm_correlations',
contexts: ['apm'],
description: `Get field values that are more prominent in the foreground set than the
background set. This can be useful in determining what attributes (like
error.message, service.node.name or transaction.name) are contributing to for
instance a higher latency. Another option is a time-based comparison, where you
compare before and after a change point. In KQL, escaping happens with double
quotes, not single quotes. Some characters that need escaping are: ':()\\\/\".
IF you need to filter, make sure the fields are available on the event, and
ALWAYS put a field value in double quotes. Best: event.outcome:\"failure\".
Wrong: event.outcome:'failure'. This is very important! ONLY use this function
if you have something to compare it to.`,
descriptionForUser: `Get field values that are more prominent in the foreground set than the
background set. This can be useful in determining what attributes (like
error.message, service.node.name or transaction.name) are contributing to for
instance a higher latency. Another option is a time-based comparison, where you
compare before and after a change point.`,
parameters: {
type: 'object',
properties: {
sets: {
type: 'array',
items: {
type: 'object',
properties: {
label: {
type: 'string',
description:
'A unique, human readable label for the comparison set.',
},
background: {
description: 'The background data set',
$ref: '#/$defs/set',
},
foreground: {
description:
'The foreground data set. Needs to be a subset of the background set',
$ref: '#/$defs/set',
},
event: {
type: 'string',
enum: [
CorrelationsEventType.Error,
CorrelationsEventType.Transaction,
CorrelationsEventType.ExitSpan,
],
},
},
required: ['background', 'foreground', 'event'],
},
},
},
required: ['sets'],
$defs: {
set: {
type: 'object',
properties: {
'service.name': {
type: 'string',
description: 'The name of the service',
},
'service.environment': {
type: 'string',
description: 'The environment that the service is running in.',
},
start: {
type: 'string',
description:
'The start of the time range, in Elasticsearch date math, like `now`.',
},
end: {
type: 'string',
description:
'The end of the time range, in Elasticsearch date math, like `now-24h`.',
},
filter: {
type: 'string',
description:
'a KQL query to filter the data by. Always escape, with double quotes. If no filter should be applied, leave it empty.',
},
label: {
type: 'string',
description: 'A unique, human readable label.',
},
},
required: ['service.name', 'start', 'end', 'label'],
},
},
} as const,
},
async ({ arguments: args }, signal) => {
return callApmApi('POST /internal/apm/assistant/get_correlation_values', {
signal,
params: {
body: args,
},
});
}
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,60 @@
*/

import type { RegisterFunctionDefinition } from '@kbn/observability-ai-assistant-plugin/common/types';
import { callApmApi } from '../../services/rest/create_call_apm_api';

export function registerGetApmDownstreamDependenciesFunction({
registerFunction,
}: {
registerFunction: RegisterFunctionDefinition;
}) {}
}) {
registerFunction(
{
name: 'get_apm_downstream_dependencies',
contexts: ['apm'],
description: `Get the downstream dependencies (services or uninstrumented backends) for a
service. This allows you to map the dowstream dependency name to a service, by
returning both span.destination.service.resource and service.name. Use this to
drilldown further if needed.`,
descriptionForUser: `Get the downstream dependencies (services or uninstrumented backends) for a
service. This allows you to map the dowstream dependency name to a service, by
returning both span.destination.service.resource and service.name. Use this to
drilldown further if needed.`,
parameters: {
type: 'object',
properties: {
'service.name': {
type: 'string',
description: 'The name of the service',
},
'service.environment': {
type: 'string',
description: 'The environment that the service is running in',
},
start: {
type: 'string',
description:
'The start of the time range, in Elasticsearch date math, like `now`.',
},
end: {
type: 'string',
description:
'The end of the time range, in Elasticsearch date math, like `now-24h`.',
},
},
required: ['service.name', 'start', 'end'],
} as const,
},
async ({ arguments: args }, signal) => {
return callApmApi(
'GET /internal/apm/assistant/get_downstream_dependencies',
{
signal,
params: {
query: args,
},
}
);
}
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,51 @@
*/

import type { RegisterFunctionDefinition } from '@kbn/observability-ai-assistant-plugin/common/types';
import { callApmApi } from '../../services/rest/create_call_apm_api';

export function registerGetApmErrorDocumentFunction({
registerFunction,
}: {
registerFunction: RegisterFunctionDefinition;
}) {}
}) {
registerFunction(
{
name: 'get_apm_error_document',
contexts: ['apm'],
description: `Get a sample error document based on its grouping name. This also includes the
stacktrace of the error, which might give you a hint as to what the cause is.
ONLY use this for error events.`,
descriptionForUser: `Get a sample error document based on its grouping name. This also includes the
stacktrace of the error, which might give you a hint as to what the cause is.`,
parameters: {
type: 'object',
properties: {
'error.grouping_name': {
type: 'string',
description:
'The grouping name of the error. Use the field value returned by get_apm_chart or get_correlation_values.',
},
start: {
type: 'string',
description:
'The start of the time range, in Elasticsearch date math, lik e `now`.',
},
end: {
type: 'string',
description:
'The end of the time range, in Elasticsearch date math, like `now-24h`.',
},
},
required: ['start', 'end', 'error.grouping_name'],
} as const,
},
async ({ arguments: args }, signal) => {
return callApmApi('GET /internal/apm/assistant/get_error_document', {
signal,
params: {
query: args,
},
});
}
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,57 @@
*/

import type { RegisterFunctionDefinition } from '@kbn/observability-ai-assistant-plugin/common/types';
import { callApmApi } from '../../services/rest/create_call_apm_api';

export function registerGetApmServiceSummaryFunction({
registerFunction,
}: {
registerFunction: RegisterFunctionDefinition;
}) {}
}) {
registerFunction(
{
name: 'get_apm_service_summary',
contexts: ['apm'],
description: `Gets a summary of a single service, including: the language, service version,
deployments, and the infrastructure that it is running in, for instance on how
many pods, and a list of its downstream dependencies. It also returns active
alerts and anomalies.`,
descriptionForUser: `Gets a summary of a single service, including: the language, service version,
deployments, and the infrastructure that it is running in, for instance on how
many pods, and a list of its downstream dependencies. It also returns active
alerts and anomalies.`,
parameters: {
type: 'object',
properties: {
'service.name': {
type: 'string',
description: 'The name of the service that should be summarized.',
},
'service.environment': {
type: 'string',
description: 'The environment that the service is running in',
},
start: {
type: 'string',
description:
'The start of the time range, in Elasticsearch date math, like `now`.',
},
end: {
type: 'string',
description:
'The end of the time range, in Elasticsearch date math, like `now-24h`.',
},
},
required: ['service.name', 'start', 'end'],
} as const,
},
async ({ arguments: args }, signal) => {
return callApmApi('GET /internal/apm/assistant/get_service_summary', {
signal,
params: {
query: args,
},
});
}
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ export const getDestinationMap = ({
environment: mergedDestination.environment,
id: objectHash({ serviceName: mergedDestination.serviceName }),
type: NodeType.service,
dependencyName: mergedDestination.dependencyName,
};
} else {
node = {
Expand Down
Loading

0 comments on commit b5365e2

Please sign in to comment.