Expose PromConsole.Graph.buildQueryUrl, refactor dispatch to use (#2461)

Expose buildQueryUrl, refactor dispatch to use

buildQueryUrl will allow users to execute queries over the range of an
existing graph.  This will be helpful to select data series they wish to
annotate the graph with, for example.
This commit is contained in:
Derek Marcotte 2017-03-01 17:37:50 -05:00 committed by Brian Brazil
parent 7e14533b32
commit 0a7fb56b16

View file

@ -523,6 +523,14 @@ PromConsole.Graph.prototype._clearGraph = function() {
PromConsole.Graph.prototype._xhrs = []; PromConsole.Graph.prototype._xhrs = [];
PromConsole.Graph.prototype.buildQueryUrl = function(expr) {
var p = this.params;
return PATH_PREFIX + "/api/v1/query_range?query=" +
encodeURIComponent(expr) +
"&step=" + p.duration / this.graphTd.offsetWidth +
"&start=" + (p.endTime - p.duration) + "&end=" + p.endTime;
};
PromConsole.Graph.prototype.dispatch = function() { PromConsole.Graph.prototype.dispatch = function() {
for (var j = 0; j < this._xhrs.length; j++) { for (var j = 0; j < this._xhrs.length; j++) {
this._xhrs[j].abort(); this._xhrs[j].abort();
@ -532,9 +540,7 @@ PromConsole.Graph.prototype.dispatch = function() {
var pending_requests = this.params.expr.length; var pending_requests = this.params.expr.length;
for (var i = 0; i < this.params.expr.length; ++i) { for (var i = 0; i < this.params.expr.length; ++i) {
var endTime = this.params.endTime; var endTime = this.params.endTime;
var url = PATH_PREFIX + "/api/v1/query_range?query=" + encodeURIComponent(this.params.expr[i]) + var url = this.buildQueryUrl(this.params.expr[i]);
"&step=" + this.params.duration / this.graphTd.offsetWidth +
"&start=" + (endTime - this.params.duration) + "&end=" + endTime;
var xhr = new XMLHttpRequest(); var xhr = new XMLHttpRequest();
xhr.open('get', url, true); xhr.open('get', url, true);
xhr.responseType = 'json'; xhr.responseType = 'json';