diff --git a/src/core_plugins/metrics/server/lib/vis_data/get_annotations.js b/src/core_plugins/metrics/server/lib/vis_data/get_annotations.js index cdf84b26c0c55..9b90ac3cd2ee9 100644 --- a/src/core_plugins/metrics/server/lib/vis_data/get_annotations.js +++ b/src/core_plugins/metrics/server/lib/vis_data/get_annotations.js @@ -9,7 +9,7 @@ function validAnnotation(annotation) { annotation.template; } -export default (req, panel) => { +export default async (req, panel) => { const { callWithRequest } = req.server.plugins.elasticsearch.getCluster('data'); const bodies = panel.annotations .filter(validAnnotation) @@ -31,22 +31,22 @@ export default (req, panel) => { }); if (!bodies.length) return { responses: [] }; - return callWithRequest(req, 'msearch', { - body: bodies.reduce((acc, item) => acc.concat(item), []) - }) - .then(resp => { - const results = {}; - panel.annotations - .filter(validAnnotation) - .forEach((annotation, index) => { - const data = resp.responses[index]; - results[annotation.id] = handleAnnotationResponse(data, annotation); - }); - return results; - }) - .catch(error => { - if (error.message === 'missing-indices') return {}; - throw error; + try { + const resp = await callWithRequest(req, 'msearch', { + body: bodies.reduce((acc, item) => acc.concat(item), []) }); + const results = {}; + panel.annotations + .filter(validAnnotation) + .forEach((annotation, index) => { + const data = resp.responses[index]; + results[annotation.id] = handleAnnotationResponse(data, annotation); + }); + return results; + } catch (error) { + if (error.message === 'missing-indices') return { responses: [] }; + throw error; + } + }; diff --git a/src/core_plugins/metrics/server/lib/vis_data/get_panel_data.js b/src/core_plugins/metrics/server/lib/vis_data/get_panel_data.js index dd00dc4dda6f3..d0528ea24df1a 100644 --- a/src/core_plugins/metrics/server/lib/vis_data/get_panel_data.js +++ b/src/core_plugins/metrics/server/lib/vis_data/get_panel_data.js @@ -21,7 +21,7 @@ export default function getPanelData(req) { }; }) .then(resp => { - if (!panel.annotations) return resp; + if (!panel.annotations || panel.annotations.length === 0) return resp; return getAnnotations(req, panel).then(annotations => { resp[panel.id].annotations = annotations; return resp;