From e9410a50ba30235360a11a5022cb023ef78df4de Mon Sep 17 00:00:00 2001 From: Bharat Kunwar Date: Thu, 25 Jul 2019 12:31:21 +0100 Subject: [PATCH] Support time range to query dimension names/values At present, dimensions are not scoped by time window, which makes dimension related queries to large databases timeout because it searches all of time instead of a time window specified on the grafana app. This commit implements the client side changes to address issue by scoping the search to time range specified on the app. It also bumps up the plugin version to 1.3.0 since it is a minor backward compatible API change. Depends-On: https://review.opendev.org/#/c/670318 Change-Id: I13614595707697552119926273f06967b8d49b1d Story: 2006204 Task: 35789 --- datasource.js | 10 ++++++++++ package.json | 2 +- plugin.json | 2 +- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/datasource.js b/datasource.js index 62bd62e..831c010 100644 --- a/datasource.js +++ b/datasource.js @@ -51,6 +51,14 @@ function (angular, _, moment, sdk, dateMath, kbn) { self = this; } + MonascaDatasource.prototype.timeRange = function() { + var timeRange = angular.element('grafana-app').injector().get('timeSrv').timeRange(); + return { + start_time: this.translateTime(timeRange.from), + end_time: this.translateTime(timeRange.to), + }; + }; + MonascaDatasource.prototype.query = function(options) { var datasource = this; var from = this.translateTime(options.range.from); @@ -110,6 +118,7 @@ function (angular, _, moment, sdk, dateMath, kbn) { MonascaDatasource.prototype.dimensionNamesQuery = function(params) { var datasource = this; var url = this.url_version + '/metrics/dimensions/names'; + params = Object.assign(params, this.timeRange()) return this._limitedMonascaRequest(url, params, false).then(function(data) { return datasource.convertDataList(data, 'dimension_name'); }).catch(function(err) {throw err;}); @@ -118,6 +127,7 @@ function (angular, _, moment, sdk, dateMath, kbn) { MonascaDatasource.prototype.dimensionValuesQuery = function(params) { var datasource = this; var url = this.url_version + '/metrics/dimensions/names/values'; + params = Object.assign(params, this.timeRange()) return this._limitedMonascaRequest(url, params, false).then(function(data) { return datasource.convertDataList(data, 'dimension_value'); }).catch(function(err) {throw err;}); diff --git a/package.json b/package.json index 89450e1..af1a0eb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "monasca-grafana-datasource", - "version": "1.2.1", + "version": "1.3.0", "description": "Grafana datasource for use with OpenStack Monasca API", "main": "datasource.js", "directories": { diff --git a/plugin.json b/plugin.json index 7477e46..f504a6d 100644 --- a/plugin.json +++ b/plugin.json @@ -26,7 +26,7 @@ {"name": "GitHub", "url": "https://github.com/openstack/monasca-grafana-datasource"}, {"name": "License", "url": "https://github.com/openstack/monasca-grafana-datasource/LICENSE"} ], - "version": "1.2.1", + "version": "1.3.0", "updated": "2017-10-23" },