|
|
|
@ -7,36 +7,11 @@ define([ |
|
|
|
|
function (angular, _, coreModule, config) { |
|
|
|
|
'use strict'; |
|
|
|
|
|
|
|
|
|
coreModule.default.service('datasourceSrv', function($q, $injector, $rootScope) { |
|
|
|
|
coreModule.default.service('datasourceSrv', function($q, $injector, $rootScope, templateSrv) { |
|
|
|
|
var self = this; |
|
|
|
|
|
|
|
|
|
this.init = function() { |
|
|
|
|
this.datasources = {}; |
|
|
|
|
this.metricSources = []; |
|
|
|
|
this.annotationSources = []; |
|
|
|
|
|
|
|
|
|
_.each(config.datasources, function(value, key) { |
|
|
|
|
if (value.meta && value.meta.metrics) { |
|
|
|
|
self.metricSources.push({ |
|
|
|
|
value: key === config.defaultDatasource ? null : key, |
|
|
|
|
name: key, |
|
|
|
|
meta: value.meta, |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
if (value.meta && value.meta.annotations) { |
|
|
|
|
self.annotationSources.push(value); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
this.metricSources.sort(function(a, b) { |
|
|
|
|
if (a.meta.builtIn || a.name > b.name) { |
|
|
|
|
return 1; |
|
|
|
|
} |
|
|
|
|
if (a.name < b.name) { |
|
|
|
|
return -1; |
|
|
|
|
} |
|
|
|
|
return 0; |
|
|
|
|
}); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
this.get = function(name) { |
|
|
|
@ -44,6 +19,8 @@ function (angular, _, coreModule, config) { |
|
|
|
|
return this.get(config.defaultDatasource); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
name = templateSrv.replace(name); |
|
|
|
|
|
|
|
|
|
if (this.datasources[name]) { |
|
|
|
|
return $q.when(this.datasources[name]); |
|
|
|
|
} |
|
|
|
@ -89,11 +66,61 @@ function (angular, _, coreModule, config) { |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
this.getAnnotationSources = function() { |
|
|
|
|
return this.annotationSources; |
|
|
|
|
return _.reduce(config.datasources, function(memo, key, value) { |
|
|
|
|
|
|
|
|
|
if (value.meta && value.meta.annotations) { |
|
|
|
|
memo.push(value); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return memo; |
|
|
|
|
}, []); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
this.getMetricSources = function() { |
|
|
|
|
return this.metricSources; |
|
|
|
|
this.getMetricSources = function(options) { |
|
|
|
|
var metricSources = []; |
|
|
|
|
|
|
|
|
|
_.each(config.datasources, function(value, key) { |
|
|
|
|
if (value.meta && value.meta.metrics) { |
|
|
|
|
metricSources.push({ |
|
|
|
|
value: key === config.defaultDatasource ? null : key, |
|
|
|
|
name: key, |
|
|
|
|
meta: value.meta, |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
if (!options || !options.skipVariables) { |
|
|
|
|
// look for data source variables
|
|
|
|
|
for (var i = 0; i < templateSrv.variables.length; i++) { |
|
|
|
|
var variable = templateSrv.variables[i]; |
|
|
|
|
if (variable.type !== 'datasource') { |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var first = variable.current.value; |
|
|
|
|
var ds = config.datasources[first]; |
|
|
|
|
|
|
|
|
|
if (ds) { |
|
|
|
|
metricSources.push({ |
|
|
|
|
name: '[[' + variable.name + ']]', |
|
|
|
|
value: '[[' + variable.name + ']]', |
|
|
|
|
meta: ds.meta, |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
metricSources.sort(function(a, b) { |
|
|
|
|
if (a.meta.builtIn || a.name > b.name) { |
|
|
|
|
return 1; |
|
|
|
|
} |
|
|
|
|
if (a.name < b.name) { |
|
|
|
|
return -1; |
|
|
|
|
} |
|
|
|
|
return 0; |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
return metricSources; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
this.init(); |
|
|
|
|