mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
* CloudWatch: Datasource improvements * Add statistic as template variale * Add wildcard to list of values * Template variable intercept dimension key * Return row specific errors when transformation error occured * Add meta feedback * Make it possible to retrieve values without known metrics * Add curated dashboard for EC2 * Fix broken tests * Use correct dashboard name * Display alert in case multi template var is being used for some certain props in the cloudwatch query * Minor fixes after feedback * Update dashboard json * Update snapshot test * Make sure region default is intercepted in cloudwatch link * Update dashboards * Include ec2 dashboard in ds * Do not include ec2 dashboard in beta1 * Display actual region
88 lines
2.9 KiB
Go
88 lines
2.9 KiB
Go
package cloudwatch
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/grafana/grafana/pkg/components/simplejson"
|
|
. "github.com/smartystreets/goconvey/convey"
|
|
)
|
|
|
|
func TestRequestParser(t *testing.T) {
|
|
Convey("TestRequestParser", t, func() {
|
|
Convey("when parsing query editor row json", func() {
|
|
Convey("using new dimensions structure", func() {
|
|
query := simplejson.NewFromAny(map[string]interface{}{
|
|
"refId": "ref1",
|
|
"region": "us-east-1",
|
|
"namespace": "ec2",
|
|
"metricName": "CPUUtilization",
|
|
"id": "",
|
|
"expression": "",
|
|
"dimensions": map[string]interface{}{
|
|
"InstanceId": []interface{}{"test"},
|
|
"InstanceType": []interface{}{"test2", "test3"},
|
|
},
|
|
"statistics": []interface{}{"Average"},
|
|
"period": "600",
|
|
"hide": false,
|
|
"highResolution": false,
|
|
})
|
|
|
|
res, err := parseRequestQuery(query, "ref1")
|
|
So(err, ShouldBeNil)
|
|
So(res.Region, ShouldEqual, "us-east-1")
|
|
So(res.RefId, ShouldEqual, "ref1")
|
|
So(res.Namespace, ShouldEqual, "ec2")
|
|
So(res.MetricName, ShouldEqual, "CPUUtilization")
|
|
So(res.Id, ShouldEqual, "")
|
|
So(res.Expression, ShouldEqual, "")
|
|
So(res.Period, ShouldEqual, 600)
|
|
So(res.ReturnData, ShouldEqual, true)
|
|
So(res.HighResolution, ShouldEqual, false)
|
|
So(len(res.Dimensions), ShouldEqual, 2)
|
|
So(len(res.Dimensions["InstanceId"]), ShouldEqual, 1)
|
|
So(len(res.Dimensions["InstanceType"]), ShouldEqual, 2)
|
|
So(res.Dimensions["InstanceType"][1], ShouldEqual, "test3")
|
|
So(len(res.Statistics), ShouldEqual, 1)
|
|
So(*res.Statistics[0], ShouldEqual, "Average")
|
|
})
|
|
|
|
Convey("using old dimensions structure (backwards compatibility)", func() {
|
|
query := simplejson.NewFromAny(map[string]interface{}{
|
|
"refId": "ref1",
|
|
"region": "us-east-1",
|
|
"namespace": "ec2",
|
|
"metricName": "CPUUtilization",
|
|
"id": "",
|
|
"expression": "",
|
|
"dimensions": map[string]interface{}{
|
|
"InstanceId": "test",
|
|
"InstanceType": "test2",
|
|
},
|
|
"statistics": []interface{}{"Average"},
|
|
"period": "600",
|
|
"hide": false,
|
|
"highResolution": false,
|
|
})
|
|
|
|
res, err := parseRequestQuery(query, "ref1")
|
|
So(err, ShouldBeNil)
|
|
So(res.Region, ShouldEqual, "us-east-1")
|
|
So(res.RefId, ShouldEqual, "ref1")
|
|
So(res.Namespace, ShouldEqual, "ec2")
|
|
So(res.MetricName, ShouldEqual, "CPUUtilization")
|
|
So(res.Id, ShouldEqual, "")
|
|
So(res.Expression, ShouldEqual, "")
|
|
So(res.Period, ShouldEqual, 600)
|
|
So(res.ReturnData, ShouldEqual, true)
|
|
So(res.HighResolution, ShouldEqual, false)
|
|
So(len(res.Dimensions), ShouldEqual, 2)
|
|
So(len(res.Dimensions["InstanceId"]), ShouldEqual, 1)
|
|
So(len(res.Dimensions["InstanceType"]), ShouldEqual, 1)
|
|
So(res.Dimensions["InstanceType"][0], ShouldEqual, "test2")
|
|
So(*res.Statistics[0], ShouldEqual, "Average")
|
|
})
|
|
})
|
|
})
|
|
}
|