Skip to content

Commit f4c759e

Browse files
[7.x] [APM] Separate count/retainment telemetry requests (#632… (#63337)
Separate count/retainment telemetry requests to make them less prone to timing out. Co-authored-by: Elastic Machine <[email protected]> Co-authored-by: Elastic Machine <[email protected]>
1 parent 1819923 commit f4c759e

File tree

1 file changed

+29
-11
lines changed
  • x-pack/plugins/apm/server/lib/apm_telemetry/collect_data_telemetry

1 file changed

+29
-11
lines changed

x-pack/plugins/apm/server/lib/apm_telemetry/collect_data_telemetry/tasks.ts

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@ export const tasks: TelemetryTask[] = [
6161
return prevJob.then(async data => {
6262
const { processorEvent, timeRange } = current;
6363

64-
const response = await search({
64+
const totalHitsResponse = await search({
6565
index: indicesByProcessorEvent[processorEvent],
6666
body: {
67-
size: 1,
67+
size: 0,
6868
query: {
6969
bool: {
7070
filter: [
@@ -83,25 +83,43 @@ export const tasks: TelemetryTask[] = [
8383
]
8484
}
8585
},
86-
sort: {
87-
'@timestamp': 'asc'
88-
},
89-
_source: ['@timestamp'],
9086
track_total_hits: true
9187
}
9288
});
9389

94-
const event = response.hits.hits[0]?._source as {
95-
'@timestamp': number;
96-
};
90+
const retainmentResponse =
91+
timeRange === 'all'
92+
? await search({
93+
index: indicesByProcessorEvent[processorEvent],
94+
body: {
95+
query: {
96+
bool: {
97+
filter: [
98+
{ term: { [PROCESSOR_EVENT]: processorEvent } }
99+
]
100+
}
101+
},
102+
sort: {
103+
'@timestamp': 'asc'
104+
},
105+
_source: ['@timestamp']
106+
}
107+
})
108+
: null;
109+
110+
const event = retainmentResponse?.hits.hits[0]?._source as
111+
| {
112+
'@timestamp': number;
113+
}
114+
| undefined;
97115

98116
return merge({}, data, {
99117
counts: {
100118
[processorEvent]: {
101-
[timeRange]: response.hits.total.value
119+
[timeRange]: totalHitsResponse.hits.total.value
102120
}
103121
},
104-
...(timeRange === 'all' && event
122+
...(event
105123
? {
106124
retainment: {
107125
[processorEvent]: {

0 commit comments

Comments
 (0)