[APM] Use top_hits instead of top_metrics (#94694)

* [APM] Use top_hits instead of top_metrics for high cardinality fields

Closes #94676.

* Update snapshots
This commit is contained in:
Dario Gieselaar 2021-03-16 17:19:42 +01:00 committed by GitHub
parent bae6021d7f
commit c921ed956c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 22 deletions

View file

@ -71,12 +71,9 @@ export const getDestinationMap = ({
},
aggs: {
sample: {
top_metrics: {
metrics: [
{ field: SPAN_TYPE },
{ field: SPAN_SUBTYPE },
{ field: SPAN_ID },
] as const,
top_hits: {
size: 1,
_source: [SPAN_TYPE, SPAN_SUBTYPE, SPAN_ID],
sort: {
'@timestamp': 'desc',
},
@ -91,15 +88,15 @@ export const getDestinationMap = ({
const outgoingConnections =
response.aggregations?.connections.buckets.map((bucket) => {
const fieldValues = bucket.sample.top[0].metrics;
const sample = bucket.sample.hits.hits[0]._source;
return {
[SPAN_DESTINATION_SERVICE_RESOURCE]: String(
bucket.key[SPAN_DESTINATION_SERVICE_RESOURCE]
),
[SPAN_ID]: (fieldValues[SPAN_ID] ?? '') as string,
[SPAN_TYPE]: (fieldValues[SPAN_TYPE] ?? '') as string,
[SPAN_SUBTYPE]: (fieldValues[SPAN_SUBTYPE] ?? '') as string,
[SPAN_ID]: sample.span.id,
[SPAN_TYPE]: sample.span.type,
[SPAN_SUBTYPE]: sample.span.subtype,
};
}) ?? [];

View file

@ -118,11 +118,8 @@ export async function getBuckets({
}),
aggs: {
samples: {
top_metrics: {
metrics: [
{ field: TRANSACTION_ID },
{ field: TRACE_ID },
] as const,
top_hits: {
_source: [TRANSACTION_ID, TRACE_ID],
size: 10,
sort: {
_score: 'desc',
@ -138,11 +135,12 @@ export async function getBuckets({
return (
response.aggregations?.distribution.buckets.map((bucket) => {
const samples = bucket.samples.hits.hits;
return {
key: bucket.key,
samples: bucket.samples.top.map((sample) => ({
traceId: sample.metrics[TRACE_ID] as string,
transactionId: sample.metrics[TRANSACTION_ID] as string,
samples: samples.map(({ _source: sample }) => ({
traceId: sample.trace.id,
transactionId: sample.transaction.id,
})),
};
}) ?? []

View file

@ -82,16 +82,16 @@ export default function ApiTest({ getService }: FtrProviderContext) {
.toMatchInline(`
Array [
Object {
"traceId": "a4eb3781a21dc11d289293076fd1a1b3",
"transactionId": "21892bde4ff1364d",
"traceId": "af0f18dc0841cfc1f567e7e1d55cfda7",
"transactionId": "925f02e5ac122897",
},
Object {
"traceId": "ccd327537120e857bdfa407434dfb9a4",
"transactionId": "c5f923159cc1b8a6",
},
Object {
"traceId": "af0f18dc0841cfc1f567e7e1d55cfda7",
"transactionId": "925f02e5ac122897",
"traceId": "a4eb3781a21dc11d289293076fd1a1b3",
"transactionId": "21892bde4ff1364d",
},
]
`);