Show gaps in graphs. (#2766)

Fixes #345
This commit is contained in:
Brian Brazil 2017-05-26 16:17:48 +01:00 committed by GitHub
parent 2a426bfead
commit d66799d7f3
3 changed files with 78 additions and 66 deletions

File diff suppressed because one or more lines are too long

View file

@ -386,6 +386,7 @@ Prometheus.Graph.prototype.submitQuery = function() {
url = PATH_PREFIX + "/api/v1/query";
success = function(json, textStatus) { self.handleConsoleResponse(json, textStatus); };
}
self.params = params;
self.queryXhr = $.ajax({
method: self.queryForm.attr("method"),
@ -518,7 +519,21 @@ Prometheus.Graph.prototype.transformData = function(json) {
color: palette.color()
};
});
Rickshaw.Series.zeroFill(data);
data.forEach(function(s) {
// Insert nulls for all missing steps.
var newSeries = [];
var pos = 0;
for (var t = self.params.start; t <= self.params.end; t += self.params.step) {
// Allow for floating point inaccuracy.
if (s.data.length > pos && s.data[pos].x < t + self.params.step / 100) {
newSeries.push(s.data[pos]);
pos++;
} else {
newSeries.push({x: t, y: null});
}
}
s.data = newSeries;
});
return data;
};

View file

@ -447,13 +447,30 @@ PromConsole.Graph.prototype._render = function(data) {
// Get the data into the right format.
var seriesLen = 0;
for (var e = 0; e < data.length; e++) {
for (var i = 0; i < data[e].data.result.length; i++) {
series[seriesLen++] = {
series[seriesLen] = {
data: data[e].data.result[i].values.map(function(s) { return {x: s[0], y: self._parseValue(s[1])}; }),
color: palette.color(),
name: self._escapeHTML(nameFuncs[e](data[e].data.result[i].metric)),
};
// Insert nulls for all missing steps.
var newSeries = [];
var pos = 0;
var start = self.params.endTime - self.params.duration;
var step = self.params.duration / this.graphTd.offsetWidth;
for (var t = start; t <= self.params.endTime; t += step) {
// Allow for floating point inaccuracy.
if (series[seriesLen].data.length > pos && series[seriesLen].data[pos].x < t + step / 100) {
newSeries.push(series[seriesLen].data[pos]);
pos++;
} else {
newSeries.push({x: t, y: null});
}
}
series[seriesLen].data = newSeries;
seriesLen++;
}
}
this._clearGraph();
@ -490,6 +507,9 @@ PromConsole.Graph.prototype._render = function(data) {
}
},
yFormatter: function(y) {
if (y === null) {
return "";
}
return this.params.yHoverFormatter(y) + this.params.yUnits;
}.bind(this)
});