Commit d98d8a40 by Mitsuhiro Tanda

fix dimension convertion

parent c140d7aa
...@@ -335,14 +335,14 @@ func (e *CloudWatchExecutor) handleGetDimensionValues(ctx context.Context, param ...@@ -335,14 +335,14 @@ func (e *CloudWatchExecutor) handleGetDimensionValues(ctx context.Context, param
namespace := parameters.Get("namespace").MustString() namespace := parameters.Get("namespace").MustString()
metricName := parameters.Get("metricName").MustString() metricName := parameters.Get("metricName").MustString()
dimensionKey := parameters.Get("dimensionKey").MustString() dimensionKey := parameters.Get("dimensionKey").MustString()
dimensionsJson := parameters.Get("dimensionKey").MustMap() dimensionsJson := parameters.Get("dimensions").MustMap()
var dimensions []*cloudwatch.DimensionFilter var dimensions []*cloudwatch.DimensionFilter
for _, d := range dimensionsJson { for k, v := range dimensionsJson {
if dd, ok := d.(map[string]string); ok { if vv, ok := v.(string); ok {
dimensions = append(dimensions, &cloudwatch.DimensionFilter{ dimensions = append(dimensions, &cloudwatch.DimensionFilter{
Name: aws.String(dd["Name"]), Name: aws.String(k),
Value: aws.String(dd["Value"]), Value: aws.String(vv),
}) })
} }
} }
......
...@@ -40,11 +40,7 @@ function (angular, _, moment, dateMath, kbn, templatingVariable) { ...@@ -40,11 +40,7 @@ function (angular, _, moment, dateMath, kbn, templatingVariable) {
item.region = templateSrv.replace(item.region, options.scopedVars); item.region = templateSrv.replace(item.region, options.scopedVars);
item.namespace = templateSrv.replace(item.namespace, options.scopedVars); item.namespace = templateSrv.replace(item.namespace, options.scopedVars);
item.metricName = templateSrv.replace(item.metricName, options.scopedVars); item.metricName = templateSrv.replace(item.metricName, options.scopedVars);
var dimensions = {}; item.dimensions = self.convertDimensionFormat(item.dimensions, options.scopeVars);
_.each(item.dimensions, function (value, key) {
dimensions[templateSrv.replace(key, options.scopedVars)] = templateSrv.replace(value, options.scopedVars);
});
item.dimensions = dimensions;
item.period = self.getPeriod(item, options); item.period = self.getPeriod(item, options);
return _.extend({ return _.extend({
...@@ -266,16 +262,12 @@ function (angular, _, moment, dateMath, kbn, templatingVariable) { ...@@ -266,16 +262,12 @@ function (angular, _, moment, dateMath, kbn, templatingVariable) {
var defaultPeriod = annotation.prefixMatching ? '' : '300'; var defaultPeriod = annotation.prefixMatching ? '' : '300';
var period = annotation.period || defaultPeriod; var period = annotation.period || defaultPeriod;
period = parseInt(period, 10); period = parseInt(period, 10);
var dimensions = {};
_.each(annotation.dimensions, function (value, key) {
dimensions[templateSrv.replace(key, options.scopedVars)] = templateSrv.replace(value, options.scopedVars);
});
var parameters = { var parameters = {
prefixMatching: annotation.prefixMatching, prefixMatching: annotation.prefixMatching,
region: templateSrv.replace(annotation.region), region: templateSrv.replace(annotation.region),
namespace: templateSrv.replace(annotation.namespace), namespace: templateSrv.replace(annotation.namespace),
metricName: templateSrv.replace(annotation.metricName), metricName: templateSrv.replace(annotation.metricName),
dimensions: dimensions, dimensions: this.convertDimensionFormat(annotation.dimensions, {}),
statistics: _.map(annotation.statistics, function (s) { return templateSrv.replace(s); }), statistics: _.map(annotation.statistics, function (s) { return templateSrv.replace(s); }),
period: period, period: period,
actionPrefix: annotation.actionPrefix || '', actionPrefix: annotation.actionPrefix || '',
...@@ -385,12 +377,11 @@ function (angular, _, moment, dateMath, kbn, templatingVariable) { ...@@ -385,12 +377,11 @@ function (angular, _, moment, dateMath, kbn, templatingVariable) {
}; };
this.convertDimensionFormat = function(dimensions, scopedVars) { this.convertDimensionFormat = function(dimensions, scopedVars) {
return _.map(dimensions, function(value, key) { var convertedDimensions = {};
return { _.each(dimensions, function (value, key) {
Name: templateSrv.replace(key, scopedVars), convertedDimensions[templateSrv.replace(key, scopedVars)] = templateSrv.replace(value, scopedVars);
Value: templateSrv.replace(value, scopedVars)
};
}); });
return convertedDimensions;
}; };
} }
......
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