[APM] Avoid accessing a non-existing index when bucket is empty (#58481)

* [APM] Avoid accessing a non-existing index when bucket is empty

* Avoid invalid index access in get_service_node_metadata
This commit is contained in:
Søren Louv-Jansen 2020-02-25 17:20:37 +01:00 committed by GitHub
parent 2294748149
commit b36a553b1c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 3 deletions

View file

@ -58,8 +58,8 @@ export async function getServiceNodeMetadata({
const response = await client.search(query);
return {
host: response.aggregations?.host.buckets[0].key || NOT_AVAILABLE_LABEL,
host: response.aggregations?.host.buckets[0]?.key || NOT_AVAILABLE_LABEL,
containerId:
response.aggregations?.containerId.buckets[0].key || NOT_AVAILABLE_LABEL
response.aggregations?.containerId.buckets[0]?.key || NOT_AVAILABLE_LABEL
};
}

View file

@ -48,7 +48,7 @@ export async function getAgentNameByService({
};
const { aggregations } = await client.search(params);
const agentName = aggregations?.agent_names.buckets[0].key as
const agentName = aggregations?.agent_names.buckets[0]?.key as
| string
| undefined;
return { agentName };