Skip to content

Commit

Permalink
[8.10] [Observability AI Assistant] Use POST for get_apm_services_list (
Browse files Browse the repository at this point in the history
#165621) (#165628)

# Backport

This will backport the following commits from `main` to `8.10`:
- [[Observability AI Assistant] Use POST for get_apm_services_list
(#165621)](#165621)

<!--- Backport version: 8.9.7 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Coen
Warmer","email":"coen.warmer@gmail.com"},"sourceCommit":{"committedDate":"2023-09-04T18:18:58Z","message":"[Observability
AI Assistant] Use POST for get_apm_services_list
(#165621)\n\nCo-authored-by: Dario Gieselaar
<dario.gieselaar@elastic.co>","sha":"300e2985c18498e35b2b82cd88c86459471beed3","branchLabelMapping":{"^v8.11.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Team:APM","release_note:skip","backport:prev-minor","v8.10.0","v8.11.0"],"number":165621,"url":"#165621
AI Assistant] Use POST for get_apm_services_list
(#165621)\n\nCo-authored-by: Dario Gieselaar
<dario.gieselaar@elastic.co>","sha":"300e2985c18498e35b2b82cd88c86459471beed3"}},"sourceBranch":"main","suggestedTargetBranches":["8.10"],"targetPullRequestStates":[{"branch":"8.10","label":"v8.10.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.11.0","labelRegex":"^v8.11.0$","isSourceBranch":true,"state":"MERGED","url":"#165621
AI Assistant] Use POST for get_apm_services_list
(#165621)\n\nCo-authored-by: Dario Gieselaar
<dario.gieselaar@elastic.co>","sha":"300e2985c18498e35b2b82cd88c86459471beed3"}}]}]
BACKPORT-->

Co-authored-by: Coen Warmer <coen.warmer@gmail.com>
  • Loading branch information
kibanamachine and CoenWarmer committed Sep 4, 2023
1 parent 310c5f1 commit 913dd8b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ export function registerGetApmServicesListFunction({
} as const,
},
async ({ arguments: args }, signal) => {
return callApmApi('GET /internal/apm/assistant/get_services_list', {
return callApmApi('POST /internal/apm/assistant/get_services_list', {
signal,
params: {
query: args,
body: args,
},
});
}
Expand Down
23 changes: 11 additions & 12 deletions x-pack/plugins/apm/server/routes/assistant_functions/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,27 @@ import { getApmEventClient } from '../../lib/helpers/get_apm_event_client';
import { getMlClient } from '../../lib/helpers/get_ml_client';
import { getRandomSampler } from '../../lib/helpers/get_random_sampler';
import { createApmServerRoute } from '../apm_routes/create_apm_server_route';
import { environmentRt } from '../default_api_types';
import { getServicesItems } from '../services/get_services/get_services_items';
import {
CorrelationValue,
correlationValuesRouteRt,
getApmCorrelationValues,
} from './get_apm_correlation_values';
import {
type APMDownstreamDependency,
downstreamDependenciesRouteRt,
getAssistantDownstreamDependencies,
type APMDownstreamDependency,
} from './get_apm_downstream_dependencies';
import { errorRouteRt, getApmErrorDocument } from './get_apm_error_document';
import {
getApmServiceSummary,
type ServiceSummary,
serviceSummaryRouteRt,
type ServiceSummary,
} from './get_apm_service_summary';
import {
type ApmTimeseries,
getApmTimeseries,
getApmTimeseriesRt,
type ApmTimeseries,
} from './get_apm_timeseries';

const getApmTimeSeriesRoute = createApmServerRoute({
Expand Down Expand Up @@ -204,15 +203,15 @@ interface ApmServicesListItem {
type ApmServicesListContent = ApmServicesListItem[];

const getApmServicesListRoute = createApmServerRoute({
endpoint: 'GET /internal/apm/assistant/get_services_list',
endpoint: 'POST /internal/apm/assistant/get_services_list',
params: t.type({
query: t.intersection([
body: t.intersection([
t.type({
start: t.string,
end: t.string,
}),
t.partial({
'service.environment': environmentRt.props.environment,
'service.environment': t.string,
healthStatus: t.array(
t.union([
t.literal(ServiceHealthStatus.unknown),
Expand All @@ -229,9 +228,9 @@ const getApmServicesListRoute = createApmServerRoute({
},
handler: async (resources): Promise<{ content: ApmServicesListContent }> => {
const { params } = resources;
const { query } = params;
const { body } = params;

const { healthStatus } = query;
const { healthStatus } = body;

const [apmEventClient, apmAlertsClient, mlClient, randomSampler] =
await Promise.all([
Expand All @@ -245,16 +244,16 @@ const getApmServicesListRoute = createApmServerRoute({
}),
]);

const start = datemath.parse(query.start)?.valueOf()!;
const end = datemath.parse(query.end)?.valueOf()!;
const start = datemath.parse(body.start)?.valueOf()!;
const end = datemath.parse(body.end)?.valueOf()!;

const serviceItems = await getServicesItems({
apmAlertsClient,
apmEventClient,
documentType: ApmDocumentType.TransactionMetric,
start,
end,
environment: query['service.environment'] ?? ENVIRONMENT_ALL.value,
environment: body['service.environment'] || ENVIRONMENT_ALL.value,
kuery: '',
logger: resources.logger,
randomSampler,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export async function registerFunctions({
);

if (isReady) {
description += `You can use the "summarize" functions to store new information you have learned in a knowledge database. Once you have established that you did not know the answer to a question, and the user gave you this information, it's important that you create a summarisation of what you have learned and store it in the knowledge database.
description += `You can use the "summarize" functions to store new information you have learned in a knowledge database. Once you have established that you did not know the answer to a question, and the user gave you this information, it's important that you create a summarisation of what you have learned and store it in the knowledge database. Don't create a new summarization if you see a similar summarization in the conversation, instead, update the existing one by re-using its ID.
Additionally, you can use the "recall" function to retrieve relevant information from the knowledge database.
`;
Expand Down

0 comments on commit 913dd8b

Please sign in to comment.