Commit feed90c0 by Mitsuhiro Tanda

re-implement get regions

parent 0c951484
......@@ -80,10 +80,6 @@ func init() {
"DescribeAlarmsForMetric": handleDescribeAlarmsForMetric,
"DescribeAlarmHistory": handleDescribeAlarmHistory,
"DescribeInstances": handleDescribeInstances,
"__GetRegions": handleGetRegions,
"__GetNamespaces": handleGetNamespaces,
"__GetMetrics": handleGetMetrics,
"__GetDimensions": handleGetDimensions,
}
}
......
......@@ -53,6 +53,20 @@ func init() {
}
func (e *CloudWatchExecutor) Execute(ctx context.Context, queries tsdb.QuerySlice, queryContext *tsdb.QueryContext) *tsdb.BatchResult {
var result *tsdb.BatchResult
queryType := queries[0].Model.Get("type").MustString()
switch queryType {
case "timeSeriesQuery":
result = e.executeTimeSeriesQuery(ctx, queries, queryContext)
break
case "metricFindQuery":
result = e.executeMetricFindQuery(ctx, queries, queryContext)
break
}
return result
}
func (e *CloudWatchExecutor) executeTimeSeriesQuery(ctx context.Context, queries tsdb.QuerySlice, queryContext *tsdb.QueryContext) *tsdb.BatchResult {
result := &tsdb.BatchResult{
QueryResults: make(map[string]*tsdb.QueryResult),
}
......
......@@ -11,7 +11,7 @@ function (angular, _, moment, dateMath, kbn, templatingVariable, CloudWatchAnnot
'use strict';
/** @ngInject */
function CloudWatchDatasource(instanceSettings, $q, backendSrv, templateSrv) {
function CloudWatchDatasource(instanceSettings, $q, backendSrv, templateSrv, timeSrv) {
this.type = 'cloudwatch';
this.name = instanceSettings.name;
this.supportMetrics = true;
......@@ -133,7 +133,21 @@ function (angular, _, moment, dateMath, kbn, templatingVariable, CloudWatchAnnot
};
this.getRegions = function() {
return this.awsRequest({action: '__GetRegions'});
var range = timeSrv.timeRange();
return backendSrv.post('/api/tsdb/query', {
from: range.from,
to: range.to,
queries: [
{
refId: 'metricFindQuery',
intervalMs: 1, // dummy
maxDataPoints: 1, // dummy
datasourceId: this.instanceSettings.id,
type: 'metricFindQuery',
subtype: 'regions'
}
]
});
};
this.getNamespaces = function() {
......@@ -200,6 +214,14 @@ function (angular, _, moment, dateMath, kbn, templatingVariable, CloudWatchAnnot
var namespace;
var metricName;
var transformSuggestDataFromTable = function(suggestData) {
return _.map(suggestData.results['metricFindQuery'].tables[0].rows, function (v) {
return {
text: v[0],
value: v[1]
};
});
};
var transformSuggestData = function(suggestData) {
return _.map(suggestData, function(v) {
return { text: v };
......@@ -208,7 +230,7 @@ function (angular, _, moment, dateMath, kbn, templatingVariable, CloudWatchAnnot
var regionQuery = query.match(/^regions\(\)/);
if (regionQuery) {
return this.getRegions();
return this.getRegions().then(function (r) { return transformSuggestDataFromTable(r); });
}
var namespaceQuery = query.match(/^namespaces\(\)/);
......
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