Commit 9ae6ac25 by Mitsuhiro Tanda

refactor dataproxy_cloudwatch

parent 01ec8d0b
...@@ -33,8 +33,8 @@ func ProxyCloudWatchDataSourceRequest(c *middleware.Context) { ...@@ -33,8 +33,8 @@ func ProxyCloudWatchDataSourceRequest(c *middleware.Context) {
Parameters struct { Parameters struct {
Namespace string `json:"Namespace"` Namespace string `json:"Namespace"`
MetricName string `json:"MetricName"` MetricName string `json:"MetricName"`
Dimensions []map[string]string `json:"Dimensions"` Dimensions []*cloudwatch.Dimension `json:"Dimensions"`
Statistics []string `json:"Statistics"` Statistics []*string `json:"Statistics"`
StartTime int64 `json:"StartTime"` StartTime int64 `json:"StartTime"`
EndTime int64 `json:"EndTime"` EndTime int64 `json:"EndTime"`
Period int64 `json:"Period"` Period int64 `json:"Period"`
...@@ -42,23 +42,11 @@ func ProxyCloudWatchDataSourceRequest(c *middleware.Context) { ...@@ -42,23 +42,11 @@ func ProxyCloudWatchDataSourceRequest(c *middleware.Context) {
}{} }{}
json.Unmarshal([]byte(body), reqParam) json.Unmarshal([]byte(body), reqParam)
statistics := make([]*string, 0)
for k := range reqParam.Parameters.Statistics {
statistics = append(statistics, &reqParam.Parameters.Statistics[k])
}
dimensions := make([]*cloudwatch.Dimension, 0)
for _, d := range reqParam.Parameters.Dimensions {
dimensions = append(dimensions, &cloudwatch.Dimension{
Name: aws.String(d["Name"]),
Value: aws.String(d["Value"]),
})
}
params := &cloudwatch.GetMetricStatisticsInput{ params := &cloudwatch.GetMetricStatisticsInput{
Namespace: aws.String(reqParam.Parameters.Namespace), Namespace: aws.String(reqParam.Parameters.Namespace),
MetricName: aws.String(reqParam.Parameters.MetricName), MetricName: aws.String(reqParam.Parameters.MetricName),
Dimensions: dimensions, Dimensions: reqParam.Parameters.Dimensions,
Statistics: statistics, Statistics: reqParam.Parameters.Statistics,
StartTime: aws.Time(time.Unix(reqParam.Parameters.StartTime, 0)), StartTime: aws.Time(time.Unix(reqParam.Parameters.StartTime, 0)),
EndTime: aws.Time(time.Unix(reqParam.Parameters.EndTime, 0)), EndTime: aws.Time(time.Unix(reqParam.Parameters.EndTime, 0)),
Period: aws.Int64(reqParam.Parameters.Period), Period: aws.Int64(reqParam.Parameters.Period),
...@@ -77,23 +65,15 @@ func ProxyCloudWatchDataSourceRequest(c *middleware.Context) { ...@@ -77,23 +65,15 @@ func ProxyCloudWatchDataSourceRequest(c *middleware.Context) {
Parameters struct { Parameters struct {
Namespace string `json:"Namespace"` Namespace string `json:"Namespace"`
MetricName string `json:"MetricName"` MetricName string `json:"MetricName"`
Dimensions []map[string]string `json:"Dimensions"` Dimensions []*cloudwatch.DimensionFilter `json:"Dimensions"`
} `json:"parameters"` } `json:"parameters"`
}{} }{}
json.Unmarshal([]byte(body), reqParam) json.Unmarshal([]byte(body), reqParam)
dimensions := make([]*cloudwatch.DimensionFilter, 0)
for _, d := range reqParam.Parameters.Dimensions {
dimensions = append(dimensions, &cloudwatch.DimensionFilter{
Name: aws.String(d["Name"]),
Value: aws.String(d["Value"]),
})
}
params := &cloudwatch.ListMetricsInput{ params := &cloudwatch.ListMetricsInput{
Namespace: aws.String(reqParam.Parameters.Namespace), Namespace: aws.String(reqParam.Parameters.Namespace),
MetricName: aws.String(reqParam.Parameters.MetricName), MetricName: aws.String(reqParam.Parameters.MetricName),
Dimensions: dimensions, Dimensions: reqParam.Parameters.Dimensions,
} }
resp, err := svc.ListMetrics(params) resp, err := svc.ListMetrics(params)
......
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