Skip to content

Commit

Permalink
Fixes #13246 - Add checks for empty annotations (#13422)
Browse files Browse the repository at this point in the history
* Fixes #13246 - Add checkes for empty annotations

* Refactoring get_annotations to use async/await
  • Loading branch information
simianhacker committed Aug 10, 2017
1 parent 3e20172 commit b80e970
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
34 changes: 17 additions & 17 deletions src/core_plugins/metrics/server/lib/vis_data/get_annotations.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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;
}

};

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit b80e970

Please sign in to comment.