Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #13246 - Add checks for empty annotations #13422

Merged
merged 3 commits into from
Aug 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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