Skip to content

Commit b949fe1

Browse files
author
Olivier Biesmans
committed
Fix downsampling option in querier URL
Signed-off-by: Olivier Biesmans <olivier.biesmans@blablacar.com>
1 parent 749b378 commit b949fe1

File tree

4 files changed

+91
-79
lines changed

4 files changed

+91
-79
lines changed

pkg/query/api/v1.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -207,11 +207,10 @@ func (api *API) parseDownsamplingParamMillis(r *http.Request, defaultVal time.Du
207207
const maxSourceResolutionParam = "max_source_resolution"
208208
maxSourceResolution := 0 * time.Second
209209

210-
if api.enableAutodownsampling {
210+
val := r.FormValue(maxSourceResolutionParam)
211+
if api.enableAutodownsampling || (val == "auto") {
211212
maxSourceResolution = defaultVal
212-
}
213-
214-
if val := r.FormValue(maxSourceResolutionParam); val != "" {
213+
} else if val != "" {
215214
var err error
216215
maxSourceResolution, err = parseDuration(val)
217216
if err != nil {

pkg/ui/bindata.go

Lines changed: 71 additions & 71 deletions
Large diffs are not rendered by default.

pkg/ui/static/js/graph.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ Prometheus.Graph.prototype.initialize = function() {
4444
if (self.options.tab === undefined) {
4545
self.options.tab = 1;
4646
}
47+
if (self.options.max_source_resolution === undefined) {
48+
self.options.max_source_resolution = "0s";
49+
}
4750

4851
// Draw graph controls and container from Handlebars template.
4952

@@ -93,6 +96,8 @@ Prometheus.Graph.prototype.initialize = function() {
9396
self.stacked = self.queryForm.find("input[name=stacked]");
9497
self.insertMetric = self.queryForm.find("select[name=insert_metric]");
9598
self.refreshInterval = self.queryForm.find("select[name=refresh]");
99+
self.maxSourceResolutionInput = self.queryForm.find("select[name=max_source_resolution_input]");
100+
96101

97102
self.consoleTab = graphWrapper.find(".console");
98103
self.graphTab = graphWrapper.find(".graph_container");
@@ -231,6 +236,8 @@ Prometheus.Graph.prototype.initialize = function() {
231236
stylePartialResponseBtn();
232237
});
233238

239+
self.maxSourceResolutionInput.val(self.options.max_source_resolution);
240+
234241
self.queryForm.submit(function() {
235242
self.consoleTab.addClass("reload");
236243
self.graphTab.addClass("reload");
@@ -377,7 +384,6 @@ Prometheus.Graph.prototype.getOptions = function() {
377384
"range_input",
378385
"end_input",
379386
"step_input",
380-
"downsample_input",
381387
"stacked",
382388
"moment_input"
383389
];
@@ -390,6 +396,9 @@ Prometheus.Graph.prototype.getOptions = function() {
390396
}
391397
}
392398
});
399+
400+
options.max_source_resolution = self.maxSourceResolutionInput.val();
401+
393402
options.expr = self.expr.val();
394403
options.tab = self.options.tab;
395404
return options;
@@ -521,7 +530,11 @@ Prometheus.Graph.prototype.submitQuery = function() {
521530
var startTime = new Date().getTime();
522531
var rangeSeconds = self.parseDuration(self.rangeInput.val());
523532
var resolution = parseInt(self.queryForm.find("input[name=step_input]").val()) || Math.max(Math.floor(rangeSeconds / 250), 1);
524-
var maxSourceResolution = self.queryForm.find("select[name=max_source_resolution_input]").val();
533+
var maxSourceResolution = self.maxSourceResolutionInput.val()
534+
// normalize max_source_resolution parameter
535+
if ( maxSourceResolution == "auto") {
536+
maxSourceResolution = ""
537+
}
525538
var endDate = self.getEndDate() / 1000;
526539
var moment = self.getMoment() / 1000;
527540

pkg/ui/static/js/graph_template.handlebar

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@
114114

115115
<div class="prometheus_input_group pull-left">
116116
<select name="max_source_resolution_input" title="Downsampling option" id="max_source_resolution_input{{id}}">
117-
<option value="">Auto downsampling</option>
118-
<option selected="selected" value="0s">Only raw data</option>
117+
<option value="auto">Auto downsampling</option>
118+
<option value="0s">Only raw data</option>
119119
<option value="5m">Max 5m downsampling</option>
120120
<option value="1h">Max 1h downsampling</option>
121121
</select>

0 commit comments

Comments
 (0)