From 52c012189002fb7f4953b032686daee39e7a3a84 Mon Sep 17 00:00:00 2001 From: Julien Pivotto Date: Thu, 30 Nov 2017 11:04:02 +0100 Subject: [PATCH] Correctly handle empty data set in the console view (#3521) When there is an empty result set, the Prometheus server replies with {"status":"success","data":{"resultType":"vector","result":null}} That "null" reply was not handled correctly by the graphing library. This commit handles that case and shows "no data" in the UI console view instead of throwing an error in the browser javascript console. Fixes #3515 Signed-off-by: Julien Pivotto --- web/ui/bindata.go | 2 +- web/ui/static/js/graph.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/web/ui/bindata.go b/web/ui/bindata.go index e6b910201..4c98e888a 100644 --- a/web/ui/bindata.go +++ b/web/ui/bindata.go @@ -465,7 +465,7 @@ func webUiStaticJsGraphJs() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "web/ui/static/js/graph.js", size: 29862, mode: os.FileMode(420), modTime: time.Unix(1511639377, 0)} + info := bindataFileInfo{name: "web/ui/static/js/graph.js", size: 29928, mode: os.FileMode(420), modTime: time.Unix(1512035831, 0)} a := &asset{bytes: bytes, info: info} return a, nil } diff --git a/web/ui/static/js/graph.js b/web/ui/static/js/graph.js index 0ae135660..8bf3f2c18 100644 --- a/web/ui/static/js/graph.js +++ b/web/ui/static/js/graph.js @@ -451,7 +451,7 @@ Prometheus.Graph.prototype.submitQuery = function() { if (xhr.responseJSON.data !== undefined) { if (xhr.responseJSON.data.resultType === "scalar") { totalTimeSeries = 1; - } else { + } else if(xhr.responseJSON.data.result !== null) { totalTimeSeries = xhr.responseJSON.data.result.length; } } @@ -720,7 +720,7 @@ Prometheus.Graph.prototype.handleConsoleResponse = function(data, textStatus) { switch(data.resultType) { case "vector": - if (data.result.length === 0) { + if (data.result === null || data.result.length === 0) { tBody.append("no data"); return; }