[APM] Immediately return terms for unbound queries (#74543)

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
This commit is contained in:
Dario Gieselaar 2020-09-02 16:11:12 +02:00 committed by GitHub
parent 25c176255a
commit 3e077973e8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 1 deletions

View file

@ -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: {
@ -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,
},
},
@ -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

View file

@ -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;

View file

@ -127,11 +127,13 @@ Object {
"services": Object {
"terms": Object {
"field": "service.name",
"min_doc_count": 0,
"size": 50,
},
},
},
"size": 0,
"timeout": "1ms",
},
}
`;

View file

@ -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,
},
},
},