[APM] Add telemetry for top traces (#166263)

Closes https://github.com/elastic/kibana/issues/161985
This commit is contained in:
Miriam 2023-09-14 08:29:54 +01:00 committed by GitHub
parent de8e1ccee2
commit dcce011f91
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 190 additions and 1 deletions

View file

@ -1957,6 +1957,22 @@ exports[`APM telemetry helpers getApmTelemetry generates a JSON object with the
}
}
},
"top_traces": {
"properties": {
"max": {
"type": "long",
"_meta": {
"description": "Max number of documents in top 100 traces withing the last day"
}
},
"median": {
"type": "long",
"_meta": {
"description": "Median number of documents in top 100 traces within the last day"
}
}
}
},
"tasks": {
"properties": {
"aggregated_transactions": {
@ -2168,6 +2184,20 @@ exports[`APM telemetry helpers getApmTelemetry generates a JSON object with the
}
}
}
},
"top_traces": {
"properties": {
"took": {
"properties": {
"ms": {
"type": "long",
"_meta": {
"description": "Execution time in milliseconds for the \\"top_traces\\" task"
}
}
}
}
}
}
}
}

View file

@ -590,4 +590,56 @@ describe('data telemetry collection tasks', () => {
});
});
});
describe('top_traces', () => {
const task = tasks.find((t) => t.name === 'top_traces');
it('returns max and median number of documents in top traces', async () => {
const search = jest.fn().mockResolvedValueOnce({
aggregations: {
top_traces: {
buckets: [
{
key: '521485',
doc_count: 1026,
},
{
key: '594439',
doc_count: 1025,
},
{
key: '070251',
doc_count: 1023,
},
{
key: '108079',
doc_count: 1023,
},
{
key: '118887',
doc_count: 1023,
},
],
},
max: {
value: 1026,
},
median: {
values: {
'50.0': 1023,
},
},
},
});
expect(
await task?.executor({ indices, telemetryClient: { search } } as any)
).toEqual({
top_traces: {
max: 1026,
median: 1023,
},
});
});
});
});

View file

@ -39,6 +39,7 @@ import {
SERVICE_RUNTIME_NAME,
SERVICE_RUNTIME_VERSION,
SERVICE_VERSION,
TRACE_ID,
TRANSACTION_NAME,
TRANSACTION_RESULT,
TRANSACTION_TYPE,
@ -1484,4 +1485,48 @@ export const tasks: TelemetryTask[] = [
};
},
},
{
name: 'top_traces',
executor: async ({ indices, telemetryClient }) => {
const response = await telemetryClient.search({
index: [indices.transaction, indices.span, indices.error],
body: {
size: 0,
track_total_hits: false,
timeout,
query: {
bool: {
filter: [range1d],
},
},
aggs: {
top_traces: {
terms: {
field: TRACE_ID,
size: 100,
},
},
max: {
max_bucket: {
buckets_path: 'top_traces>_count',
},
},
median: {
percentiles_bucket: {
buckets_path: 'top_traces>_count',
percents: [50],
},
},
},
},
});
return {
top_traces: {
max: response.aggregations?.max.value ?? 0,
median: response.aggregations?.median.values['50.0'] ?? 0,
},
};
},
},
];

View file

@ -1006,6 +1006,22 @@ export const apmSchema: MakeSchemaFrom<APMUsage, true> = {
},
},
per_service: { type: 'array', items: { ...apmPerServiceSchema } },
top_traces: {
max: {
type: 'long',
_meta: {
description:
'Max number of documents in top 100 traces withing the last day',
},
},
median: {
type: 'long',
_meta: {
description:
'Median number of documents in top 100 traces within the last day',
},
},
},
tasks: {
aggregated_transactions: {
took: {
@ -1169,5 +1185,16 @@ export const apmSchema: MakeSchemaFrom<APMUsage, true> = {
},
},
},
top_traces: {
took: {
ms: {
type: 'long',
_meta: {
description:
'Execution time in milliseconds for the "top_traces" task',
},
},
},
},
},
};

View file

@ -211,6 +211,10 @@ export interface APMUsage {
total: number;
};
per_service: APMPerService[];
top_traces: {
max: number;
median: number;
};
tasks: Record<
| 'aggregated_transactions'
| 'cloud'
@ -226,7 +230,8 @@ export interface APMUsage {
| 'cardinality'
| 'environments'
| 'service_groups'
| 'per_service',
| 'per_service'
| 'top_traces',
{ took: { ms: number } }
>;
}

View file

@ -5067,6 +5067,22 @@
}
}
},
"top_traces": {
"properties": {
"max": {
"type": "long",
"_meta": {
"description": "Max number of documents in top 100 traces withing the last day"
}
},
"median": {
"type": "long",
"_meta": {
"description": "Median number of documents in top 100 traces within the last day"
}
}
}
},
"tasks": {
"properties": {
"aggregated_transactions": {
@ -5278,6 +5294,20 @@
}
}
}
},
"top_traces": {
"properties": {
"took": {
"properties": {
"ms": {
"type": "long",
"_meta": {
"description": "Execution time in milliseconds for the \"top_traces\" task"
}
}
}
}
}
}
}
}