|
|
@@ -4,6 +4,7 @@ import (
|
|
|
"encoding/json"
|
|
|
"fmt"
|
|
|
"io/ioutil"
|
|
|
+ "net/url"
|
|
|
"testing"
|
|
|
"time"
|
|
|
|
|
|
@@ -61,8 +62,8 @@ func TestAzureMonitor(t *testing.T) {
|
|
|
})
|
|
|
|
|
|
Convey("Parse AzureMonitor API response in the time series format", func() {
|
|
|
- Convey("when data from query aggregated to one time series", func() {
|
|
|
- data, err := loadTestFile("./test-data/1-azure-monitor-response.json")
|
|
|
+ Convey("when data from query aggregated as average to one time series", func() {
|
|
|
+ data, err := loadTestFile("./test-data/1-azure-monitor-response-avg.json")
|
|
|
So(err, ShouldBeNil)
|
|
|
So(data.Interval, ShouldEqual, "PT1M")
|
|
|
|
|
|
@@ -71,6 +72,9 @@ func TestAzureMonitor(t *testing.T) {
|
|
|
UrlComponents: map[string]string{
|
|
|
"resourceName": "grafana",
|
|
|
},
|
|
|
+ Params: url.Values{
|
|
|
+ "aggregation": {"Average"},
|
|
|
+ },
|
|
|
}
|
|
|
err = executor.parseResponse(res, data, query)
|
|
|
So(err, ShouldBeNil)
|
|
|
@@ -78,6 +82,101 @@ func TestAzureMonitor(t *testing.T) {
|
|
|
So(len(res.Series), ShouldEqual, 1)
|
|
|
So(res.Series[0].Name, ShouldEqual, "grafana.Percentage CPU")
|
|
|
So(len(res.Series[0].Points), ShouldEqual, 5)
|
|
|
+
|
|
|
+ So(res.Series[0].Points[0][0].Float64, ShouldEqual, 2.0875)
|
|
|
+ So(res.Series[0].Points[0][1].Float64, ShouldEqual, 1549620780000)
|
|
|
+
|
|
|
+ So(res.Series[0].Points[1][0].Float64, ShouldEqual, 2.1525)
|
|
|
+ So(res.Series[0].Points[1][1].Float64, ShouldEqual, 1549620840000)
|
|
|
+
|
|
|
+ So(res.Series[0].Points[2][0].Float64, ShouldEqual, 2.155)
|
|
|
+ So(res.Series[0].Points[2][1].Float64, ShouldEqual, 1549620900000)
|
|
|
+
|
|
|
+ So(res.Series[0].Points[3][0].Float64, ShouldEqual, 3.6925)
|
|
|
+ So(res.Series[0].Points[3][1].Float64, ShouldEqual, 1549620960000)
|
|
|
+
|
|
|
+ So(res.Series[0].Points[4][0].Float64, ShouldEqual, 2.44)
|
|
|
+ So(res.Series[0].Points[4][1].Float64, ShouldEqual, 1549621020000)
|
|
|
+ })
|
|
|
+
|
|
|
+ Convey("when data from query aggregated as total to one time series", func() {
|
|
|
+ data, err := loadTestFile("./test-data/2-azure-monitor-response-total.json")
|
|
|
+ So(err, ShouldBeNil)
|
|
|
+
|
|
|
+ res := &tsdb.QueryResult{Meta: simplejson.New(), RefId: "A"}
|
|
|
+ query := &AzureMonitorQuery{
|
|
|
+ UrlComponents: map[string]string{
|
|
|
+ "resourceName": "grafana",
|
|
|
+ },
|
|
|
+ Params: url.Values{
|
|
|
+ "aggregation": {"Total"},
|
|
|
+ },
|
|
|
+ }
|
|
|
+ err = executor.parseResponse(res, data, query)
|
|
|
+ So(err, ShouldBeNil)
|
|
|
+
|
|
|
+ So(res.Series[0].Points[0][0].Float64, ShouldEqual, 8.26)
|
|
|
+ So(res.Series[0].Points[0][1].Float64, ShouldEqual, 1549718940000)
|
|
|
+ })
|
|
|
+
|
|
|
+ Convey("when data from query aggregated as maximum to one time series", func() {
|
|
|
+ data, err := loadTestFile("./test-data/3-azure-monitor-response-maximum.json")
|
|
|
+ So(err, ShouldBeNil)
|
|
|
+
|
|
|
+ res := &tsdb.QueryResult{Meta: simplejson.New(), RefId: "A"}
|
|
|
+ query := &AzureMonitorQuery{
|
|
|
+ UrlComponents: map[string]string{
|
|
|
+ "resourceName": "grafana",
|
|
|
+ },
|
|
|
+ Params: url.Values{
|
|
|
+ "aggregation": {"Maximum"},
|
|
|
+ },
|
|
|
+ }
|
|
|
+ err = executor.parseResponse(res, data, query)
|
|
|
+ So(err, ShouldBeNil)
|
|
|
+
|
|
|
+ So(res.Series[0].Points[0][0].Float64, ShouldEqual, 3.07)
|
|
|
+ So(res.Series[0].Points[0][1].Float64, ShouldEqual, 1549722360000)
|
|
|
+ })
|
|
|
+
|
|
|
+ Convey("when data from query aggregated as minimum to one time series", func() {
|
|
|
+ data, err := loadTestFile("./test-data/4-azure-monitor-response-minimum.json")
|
|
|
+ So(err, ShouldBeNil)
|
|
|
+
|
|
|
+ res := &tsdb.QueryResult{Meta: simplejson.New(), RefId: "A"}
|
|
|
+ query := &AzureMonitorQuery{
|
|
|
+ UrlComponents: map[string]string{
|
|
|
+ "resourceName": "grafana",
|
|
|
+ },
|
|
|
+ Params: url.Values{
|
|
|
+ "aggregation": {"Minimum"},
|
|
|
+ },
|
|
|
+ }
|
|
|
+ err = executor.parseResponse(res, data, query)
|
|
|
+ So(err, ShouldBeNil)
|
|
|
+
|
|
|
+ So(res.Series[0].Points[0][0].Float64, ShouldEqual, 1.51)
|
|
|
+ So(res.Series[0].Points[0][1].Float64, ShouldEqual, 1549723380000)
|
|
|
+ })
|
|
|
+
|
|
|
+ Convey("when data from query aggregated as Count to one time series", func() {
|
|
|
+ data, err := loadTestFile("./test-data/5-azure-monitor-response-count.json")
|
|
|
+ So(err, ShouldBeNil)
|
|
|
+
|
|
|
+ res := &tsdb.QueryResult{Meta: simplejson.New(), RefId: "A"}
|
|
|
+ query := &AzureMonitorQuery{
|
|
|
+ UrlComponents: map[string]string{
|
|
|
+ "resourceName": "grafana",
|
|
|
+ },
|
|
|
+ Params: url.Values{
|
|
|
+ "aggregation": {"Count"},
|
|
|
+ },
|
|
|
+ }
|
|
|
+ err = executor.parseResponse(res, data, query)
|
|
|
+ So(err, ShouldBeNil)
|
|
|
+
|
|
|
+ So(res.Series[0].Points[0][0].Float64, ShouldEqual, 4)
|
|
|
+ So(res.Series[0].Points[0][1].Float64, ShouldEqual, 1549723440000)
|
|
|
})
|
|
|
})
|
|
|
})
|