Skip to content

Commit 3e07797

Browse files
[APM] Immediately return terms for unbound queries (#74543)
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
1 parent 25c1762 commit 3e07797

4 files changed

Lines changed: 10 additions & 1 deletion

File tree

x-pack/plugins/apm/server/lib/environments/get_all_environments.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ export async function getAllEnvironments({
3737
],
3838
},
3939
body: {
40+
// use timeout + min_doc_count to return as early as possible
41+
// if filter is not defined to prevent timeouts
42+
...(!serviceName ? { timeout: '1ms' } : {}),
4043
size: 0,
4144
query: {
4245
bool: {
@@ -48,6 +51,7 @@ export async function getAllEnvironments({
4851
terms: {
4952
field: SERVICE_ENVIRONMENT,
5053
size: 100,
54+
...(!serviceName ? { min_doc_count: 0 } : {}),
5155
missing: includeMissing ? ENVIRONMENT_NOT_DEFINED.value : undefined,
5256
},
5357
},
@@ -56,6 +60,7 @@ export async function getAllEnvironments({
5660
};
5761

5862
const resp = await apmEventClient.search(params);
63+
5964
const environments =
6065
resp.aggregations?.environments.buckets.map(
6166
(bucket) => bucket.key as string

x-pack/plugins/apm/server/lib/helpers/create_es_client/call_client_with_debug.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export async function callClientWithDebug({
3434
let res: any;
3535
let esError = null;
3636
try {
37-
res = apiCaller(operationName, params);
37+
res = await apiCaller(operationName, params);
3838
} catch (e) {
3939
// catch error and throw after outputting debug info
4040
esError = e;

x-pack/plugins/apm/server/lib/settings/agent_configuration/__snapshots__/queries.test.ts.snap

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

x-pack/plugins/apm/server/lib/settings/agent_configuration/get_service_names.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,14 @@ export async function getServiceNames({ setup }: { setup: Setup }) {
2525
],
2626
},
2727
body: {
28+
timeout: '1ms',
2829
size: 0,
2930
aggs: {
3031
services: {
3132
terms: {
3233
field: SERVICE_NAME,
3334
size: 50,
35+
min_doc_count: 0,
3436
},
3537
},
3638
},

0 commit comments

Comments
 (0)