From 91fb3f2224cd9e228ad516ec4b232bd89cfa1839 Mon Sep 17 00:00:00 2001 From: Jesse White Date: Fri, 1 Sep 2017 01:19:51 -0400 Subject: [PATCH 001/146] fix: cancel the initial timer when changing the auto-refresh interval, fixes #9139 (#9140) --- public/app/features/dashboard/time_srv.ts | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/public/app/features/dashboard/time_srv.ts b/public/app/features/dashboard/time_srv.ts index abde4152b63..2c16915b5aa 100644 --- a/public/app/features/dashboard/time_srv.ts +++ b/public/app/features/dashboard/time_srv.ts @@ -116,16 +116,14 @@ class TimeSrv { setAutoRefresh(interval) { this.dashboard.refresh = interval; + this.cancelNextRefresh(); if (interval) { var intervalMs = kbn.interval_to_ms(interval); - this.$timeout(() => { + this.refreshTimer = this.timer.register(this.$timeout(() => { this.startNextRefreshTimer(intervalMs); this.refreshDashboard(); - }, intervalMs); - - } else { - this.cancelNextRefresh(); + }, intervalMs)); } // update url From 56cb16ff5bd6273128593657b10d3a9b9ed6abe6 Mon Sep 17 00:00:00 2001 From: Mitsuhiro Tanda Date: Thu, 7 Sep 2017 01:03:02 +0900 Subject: [PATCH 002/146] (prometheus) instant query support --- .../datasource/prometheus/datasource.ts | 25 +++++++++++- .../datasource/prometheus/query_ctrl.ts | 1 + .../prometheus/specs/datasource_specs.ts | 39 +++++++++++++++++-- 3 files changed, 60 insertions(+), 5 deletions(-) diff --git a/public/app/plugins/datasource/prometheus/datasource.ts b/public/app/plugins/datasource/prometheus/datasource.ts index 4b4bfb4cdde..3544a702f29 100644 --- a/public/app/plugins/datasource/prometheus/datasource.ts +++ b/public/app/plugins/datasource/prometheus/datasource.ts @@ -100,6 +100,7 @@ export class PrometheusDatasource { var query: any = {}; query.expr = this.templateSrv.replace(target.expr, options.scopedVars, self.interpolateQueryExpr); query.requestId = options.panelId + target.refId; + query.format = target.format; var interval = this.templateSrv.replace(target.interval, options.scopedVars) || options.interval; var intervalFactor = target.intervalFactor || 1; @@ -115,7 +116,11 @@ export class PrometheusDatasource { } var allQueryPromise = _.map(queries, query => { - return this.performTimeSeriesQuery(query, start, end); + if (query.format === 'time_series') { + return this.performTimeSeriesQuery(query, start, end); + } else { + return this.performInstantQuery(query, end); + } }); return this.$q.all(allQueryPromise).then(responseList => { @@ -131,7 +136,11 @@ export class PrometheusDatasource { result.push(self.transformMetricDataToTable(response.data.data.result)); } else { for (let metricData of response.data.data.result) { - result.push(self.transformMetricData(metricData, activeTargets[index], start, end)); + if (response.data.data.resultType === 'matrix') { + result.push(self.transformMetricData(metricData, activeTargets[index], start, end)); + } else if (response.data.data.resultType === 'vector') { + result.push(self.transformInstantMetricData(metricData, activeTargets[index])); + } } } }); @@ -158,6 +167,11 @@ export class PrometheusDatasource { return this._request('GET', url, query.requestId); } + performInstantQuery(query, time) { + var url = '/api/v1/query?query=' + encodeURIComponent(query.expr) + '&time=' + time; + return this._request('GET', url, query.requestId); + } + performSuggestQuery(query, cache = false) { var url = '/api/v1/label/__name__/values'; @@ -342,6 +356,13 @@ export class PrometheusDatasource { return table; } + transformInstantMetricData(md, options) { + var dps = [], metricLabel = null; + metricLabel = this.createMetricLabel(md.metric, options); + dps.push([parseFloat(md.value[1]), md.value[0] * 1000]); + return { target: metricLabel, datapoints: dps }; + } + createMetricLabel(labelData, options) { if (_.isUndefined(options) || _.isEmpty(options.legendFormat)) { return this.getOriginalMetricName(labelData); diff --git a/public/app/plugins/datasource/prometheus/query_ctrl.ts b/public/app/plugins/datasource/prometheus/query_ctrl.ts index 17a564d0b46..9a3a9603f61 100644 --- a/public/app/plugins/datasource/prometheus/query_ctrl.ts +++ b/public/app/plugins/datasource/prometheus/query_ctrl.ts @@ -36,6 +36,7 @@ class PrometheusQueryCtrl extends QueryCtrl { this.formats = [ {text: 'Time series', value: 'time_series'}, {text: 'Table', value: 'table'}, + {text: 'Instant', value: 'instant'}, ]; this.updateLink(); diff --git a/public/app/plugins/datasource/prometheus/specs/datasource_specs.ts b/public/app/plugins/datasource/prometheus/specs/datasource_specs.ts index 9588090c7bb..95ccbbb6325 100644 --- a/public/app/plugins/datasource/prometheus/specs/datasource_specs.ts +++ b/public/app/plugins/datasource/prometheus/specs/datasource_specs.ts @@ -26,7 +26,7 @@ describe('PrometheusDatasource', function() { '&start=1443438675&end=1443460275&step=60'; var query = { range: { from: moment(1443438674760), to: moment(1443460274760) }, - targets: [{ expr: 'test{job="testjob"}' }], + targets: [{ expr: 'test{job="testjob"}', format: 'time_series' }], interval: '60s' }; var response = { @@ -62,7 +62,7 @@ describe('PrometheusDatasource', function() { '&start=' + start + '&end=' + end + '&step=' + step; var query = { range: { from: moment(1443438674760), to: moment(1443460274760) }, - targets: [{ expr: 'test{job="testjob"}' }], + targets: [{ expr: 'test{job="testjob"}', format: 'time_series' }], interval: '60s' }; var response = { @@ -119,7 +119,40 @@ describe('PrometheusDatasource', function() { expect(results.data[1].datapoints[3][0]).to.be(null); }); }); - describe('When performing annotationQuery', function() { + describe('When querying prometheus with one target and format = instant', function () { + var results; + var urlExpected = 'proxied/api/v1/query?query=' + + encodeURIComponent('test{job="testjob"}') + + '&time=1443460275'; + var query = { + range: { from: moment(1443438674760), to: moment(1443460274760) }, + targets: [{ expr: 'test{job="testjob"}', format: 'instant' }], + interval: '60s' + }; + var response = { + status: "success", + data: { + resultType: "vector", + result: [{ + metric: { "__name__": "test", job: "testjob" }, + value: [1443454528, "3846"] + }] + } + }; + beforeEach(function () { + ctx.$httpBackend.expect('GET', urlExpected).respond(response); + ctx.ds.query(query).then(function (data) { results = data; }); + ctx.$httpBackend.flush(); + }); + it('should generate the correct query', function () { + ctx.$httpBackend.verifyNoOutstandingExpectation(); + }); + it('should return series list', function () { + expect(results.data.length).to.be(1); + expect(results.data[0].target).to.be('test{job="testjob"}'); + }); + }); + describe('When performing annotationQuery', function () { var results; var urlExpected = 'proxied/api/v1/query_range?query=' + encodeURIComponent('ALERTS{alertstate="firing"}') + From 6f8110956df68c31f7ffaf8bbdbaa87d7a6c78f1 Mon Sep 17 00:00:00 2001 From: Mitsuhiro Tanda Date: Thu, 7 Sep 2017 18:34:46 +0900 Subject: [PATCH 003/146] (prometheus) support instant query for table format, use checkbox to switch query type --- .../datasource/prometheus/datasource.ts | 7 ++- .../prometheus/partials/query.editor.html | 2 + .../datasource/prometheus/query_ctrl.ts | 4 +- .../prometheus/specs/datasource_specs.ts | 45 ++++++++++++++++++- 4 files changed, 53 insertions(+), 5 deletions(-) diff --git a/public/app/plugins/datasource/prometheus/datasource.ts b/public/app/plugins/datasource/prometheus/datasource.ts index 3544a702f29..0975870f842 100644 --- a/public/app/plugins/datasource/prometheus/datasource.ts +++ b/public/app/plugins/datasource/prometheus/datasource.ts @@ -100,7 +100,7 @@ export class PrometheusDatasource { var query: any = {}; query.expr = this.templateSrv.replace(target.expr, options.scopedVars, self.interpolateQueryExpr); query.requestId = options.panelId + target.refId; - query.format = target.format; + query.instant = target.instant; var interval = this.templateSrv.replace(target.interval, options.scopedVars) || options.interval; var intervalFactor = target.intervalFactor || 1; @@ -116,7 +116,7 @@ export class PrometheusDatasource { } var allQueryPromise = _.map(queries, query => { - if (query.format === 'time_series') { + if (!query.instant) { return this.performTimeSeriesQuery(query, start, end); } else { return this.performInstantQuery(query, end); @@ -333,6 +333,9 @@ export class PrometheusDatasource { // Populate rows, set value to empty string when label not present. _.each(md, function(series) { + if (series.value) { + series.values = [series.value]; + } if (series.values) { for (i = 0; i < series.values.length; i++) { var values = series.values[i]; diff --git a/public/app/plugins/datasource/prometheus/partials/query.editor.html b/public/app/plugins/datasource/prometheus/partials/query.editor.html index 5140c9e7bbd..2099c4348c2 100644 --- a/public/app/plugins/datasource/prometheus/partials/query.editor.html +++ b/public/app/plugins/datasource/prometheus/partials/query.editor.html @@ -45,6 +45,8 @@
+ +