From 0a7fb56b164ff29c9c97da68f1bf12425b9fa529 Mon Sep 17 00:00:00 2001 From: Derek Marcotte Date: Wed, 1 Mar 2017 17:37:50 -0500 Subject: [PATCH] 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. --- web/ui/static/js/prom_console.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/web/ui/static/js/prom_console.js b/web/ui/static/js/prom_console.js index 2192c8b7e..c0f0b8464 100644 --- a/web/ui/static/js/prom_console.js +++ b/web/ui/static/js/prom_console.js @@ -523,6 +523,14 @@ PromConsole.Graph.prototype._clearGraph = function() { 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() { for (var j = 0; j < this._xhrs.length; j++) { this._xhrs[j].abort(); @@ -532,9 +540,7 @@ PromConsole.Graph.prototype.dispatch = function() { var pending_requests = this.params.expr.length; for (var i = 0; i < this.params.expr.length; ++i) { var endTime = this.params.endTime; - var url = PATH_PREFIX + "/api/v1/query_range?query=" + encodeURIComponent(this.params.expr[i]) + - "&step=" + this.params.duration / this.graphTd.offsetWidth + - "&start=" + (endTime - this.params.duration) + "&end=" + endTime; + var url = this.buildQueryUrl(this.params.expr[i]); var xhr = new XMLHttpRequest(); xhr.open('get', url, true); xhr.responseType = 'json';