Skip to content

Commit

Permalink
[APM] Immediately return terms for unbound queries (#74543)
Browse files Browse the repository at this point in the history
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
  • Loading branch information
dgieselaar and elasticmachine committed Sep 2, 2020
1 parent 25c1762 commit 3e07797
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ export async function getAllEnvironments({
],
},
body: {
// use timeout + min_doc_count to return as early as possible
// if filter is not defined to prevent timeouts
...(!serviceName ? { timeout: '1ms' } : {}),
size: 0,
query: {
bool: {
Expand All @@ -48,6 +51,7 @@ export async function getAllEnvironments({
terms: {
field: SERVICE_ENVIRONMENT,
size: 100,
...(!serviceName ? { min_doc_count: 0 } : {}),
missing: includeMissing ? ENVIRONMENT_NOT_DEFINED.value : undefined,
},
},
Expand All @@ -56,6 +60,7 @@ export async function getAllEnvironments({
};

const resp = await apmEventClient.search(params);

const environments =
resp.aggregations?.environments.buckets.map(
(bucket) => bucket.key as string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export async function callClientWithDebug({
let res: any;
let esError = null;
try {
res = apiCaller(operationName, params);
res = await apiCaller(operationName, params);
} catch (e) {
// catch error and throw after outputting debug info
esError = e;
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ export async function getServiceNames({ setup }: { setup: Setup }) {
],
},
body: {
timeout: '1ms',
size: 0,
aggs: {
services: {
terms: {
field: SERVICE_NAME,
size: 50,
min_doc_count: 0,
},
},
},
Expand Down

0 comments on commit 3e07797

Please sign in to comment.