Commit b5112aee by Torkel Ödegaard

Data source proxy, and session timeout fix for influxdb, #1667

parent 22adf0d0
......@@ -10,7 +10,7 @@ function (angular, _, config, kbn, moment) {
var module = angular.module('grafana.services');
module.factory('ElasticDatasource', function($q, $http, templateSrv) {
module.factory('ElasticDatasource', function($q, backendSrv, templateSrv) {
function ElasticDatasource(datasource) {
this.type = 'elasticsearch';
......@@ -38,7 +38,7 @@ function (angular, _, config, kbn, moment) {
};
}
return $http(options);
return backendSrv.datasourceRequest(options);
};
ElasticDatasource.prototype._get = function(url) {
......
......@@ -12,7 +12,7 @@ function (angular, _, kbn, InfluxSeries, InfluxQueryBuilder) {
var module = angular.module('grafana.services');
module.factory('InfluxDatasource_08', function($q, $http, templateSrv) {
module.factory('InfluxDatasource_08', function($q, backendSrv, templateSrv) {
function InfluxDatasource(datasource) {
this.urls = _.map(datasource.url.split(','), function(url) {
......@@ -172,86 +172,14 @@ function (angular, _, kbn, InfluxSeries, InfluxQueryBuilder) {
options.headers.Authorization = 'Basic ' + _this.basicAuth;
}
return $http(options).success(function (data) {
deferred.resolve(data);
return backendSrv.datasourceRequest(options).then(function(response) {
deferred.resolve(response.data);
});
}, 10);
return deferred.promise;
};
InfluxDatasource.prototype.saveDashboard = function(dashboard) {
var tags = dashboard.tags.join(',');
var title = dashboard.title;
var temp = dashboard.temp;
var id = kbn.slugifyForUrl(title);
if (temp) { delete dashboard.temp; }
var data = [{
name: 'grafana.dashboard_' + btoa(id),
columns: ['time', 'sequence_number', 'title', 'tags', 'dashboard', 'id'],
points: [[1000000000000, 1, title, tags, angular.toJson(dashboard), id]]
}];
if (temp) {
return this._saveDashboardTemp(data, title, id);
}
else {
var self = this;
return this._influxRequest('POST', '/series', data).then(function() {
self._removeUnslugifiedDashboard(id, title, false);
return { title: title, url: '/dashboard/db/' + id };
}, function(err) {
throw 'Failed to save dashboard to InfluxDB: ' + err.data;
});
}
};
InfluxDatasource.prototype._removeUnslugifiedDashboard = function(id, title, isTemp) {
if (id === title) { return; }
var self = this;
self._getDashboardInternal(title, isTemp).then(function(dashboard) {
if (dashboard !== null) {
self.deleteDashboard(title);
}
});
};
InfluxDatasource.prototype._saveDashboardTemp = function(data, title, id) {
data[0].name = 'grafana.temp_dashboard_' + btoa(id);
data[0].columns.push('expires');
data[0].points[0].push(this._getTempDashboardExpiresDate());
return this._influxRequest('POST', '/series', data).then(function() {
var baseUrl = window.location.href.replace(window.location.hash,'');
var url = baseUrl + "#dashboard/temp/" + id;
return { title: title, url: url };
}, function(err) {
throw 'Failed to save shared dashboard to InfluxDB: ' + err.data;
});
};
InfluxDatasource.prototype._getTempDashboardExpiresDate = function() {
var ttlLength = this.saveTempTTL.substring(0, this.saveTempTTL.length - 1);
var ttlTerm = this.saveTempTTL.substring(this.saveTempTTL.length - 1, this.saveTempTTL.length).toLowerCase();
var expires = Date.now();
switch(ttlTerm) {
case "m":
expires += ttlLength * 60000;
break;
case "d":
expires += ttlLength * 86400000;
break;
case "w":
expires += ttlLength * 604800000;
break;
default:
throw "Unknown ttl duration format";
}
return expires;
};
InfluxDatasource.prototype._getDashboardInternal = function(id, isTemp) {
var queryString = 'select dashboard from "grafana.dashboard_' + btoa(id) + '"';
......
define([
'helpers',
'plugins/datasource/influxdb_08/datasource'
'plugins/datasource/influxdb_08/datasource',
'services/backendSrv',
'services/alertSrv'
], function(helpers) {
'use strict';
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment