CloudWatch: Remove HighResolution toggle since it's not being used (#20440)
* Remove highres flag since it's not being used * Remove not used code. Init id field correctly * Fix broken tests * Remove GMS related calculations * Rename period field * Add breaking changes to changelog. Also update upgrading docs * Update snapshot * Update docs after feedback * Changes after feedback
This commit is contained in:
@@ -16,8 +16,6 @@ type cloudWatchQuery struct {
|
||||
Dimensions map[string][]string
|
||||
Period int
|
||||
Alias string
|
||||
Identifier string
|
||||
HighResolution bool
|
||||
MatchExact bool
|
||||
UsedExpression string
|
||||
RequestExceededMaxLimit bool
|
||||
|
||||
@@ -16,7 +16,6 @@ func TestCloudWatchQuery(t *testing.T) {
|
||||
Stats: "Average",
|
||||
Period: 300,
|
||||
Id: "id1",
|
||||
Identifier: "id1",
|
||||
}
|
||||
|
||||
Convey("it is a search expression", func() {
|
||||
@@ -36,7 +35,6 @@ func TestCloudWatchQuery(t *testing.T) {
|
||||
Stats: "Average",
|
||||
Period: 300,
|
||||
Id: "id1",
|
||||
Identifier: "id1",
|
||||
MatchExact: true,
|
||||
Dimensions: map[string][]string{
|
||||
"InstanceId": {"i-12345678"},
|
||||
@@ -60,7 +58,6 @@ func TestCloudWatchQuery(t *testing.T) {
|
||||
Stats: "Average",
|
||||
Period: 300,
|
||||
Id: "id1",
|
||||
Identifier: "id1",
|
||||
Dimensions: map[string][]string{
|
||||
"InstanceId": {"i-12345678", "i-34562312"},
|
||||
},
|
||||
@@ -83,7 +80,6 @@ func TestCloudWatchQuery(t *testing.T) {
|
||||
Stats: "Average",
|
||||
Period: 300,
|
||||
Id: "id1",
|
||||
Identifier: "id1",
|
||||
Dimensions: map[string][]string{
|
||||
"InstanceId": {"i-12345678", "*"},
|
||||
"InstanceType": {"abc", "def"},
|
||||
@@ -108,7 +104,6 @@ func TestCloudWatchQuery(t *testing.T) {
|
||||
Period: 300,
|
||||
Id: "id1",
|
||||
MatchExact: false,
|
||||
Identifier: "id1",
|
||||
Dimensions: make(map[string][]string),
|
||||
}
|
||||
Convey("and match exact is false", func() {
|
||||
@@ -152,7 +147,6 @@ func TestCloudWatchQuery(t *testing.T) {
|
||||
Stats: "Average",
|
||||
Period: 300,
|
||||
Id: "id1",
|
||||
Identifier: "id1",
|
||||
MatchExact: false,
|
||||
Dimensions: map[string][]string{
|
||||
"InstanceId": {"i-12345678"},
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package cloudwatch
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/aws/aws-sdk-go/aws"
|
||||
@@ -30,11 +29,6 @@ func (e *CloudWatchExecutor) buildMetricDataInput(queryContext *tsdb.TsdbQuery,
|
||||
ScanBy: aws.String("TimestampAscending"),
|
||||
}
|
||||
for _, query := range queries {
|
||||
// 1 minutes resolution metrics is stored for 15 days, 15 * 24 * 60 = 21600
|
||||
if query.HighResolution && (((endTime.Unix() - startTime.Unix()) / int64(query.Period)) > 21600) {
|
||||
return nil, &queryError{errors.New("too long query period"), query.RefId}
|
||||
}
|
||||
|
||||
metricDataQuery, err := e.buildMetricDataQuery(query)
|
||||
if err != nil {
|
||||
return nil, &queryError{err, query.RefId}
|
||||
|
||||
@@ -19,7 +19,6 @@ func TestMetricDataQueryBuilder(t *testing.T) {
|
||||
"LoadBalancer": {"lb1", "lb2", "lb3"},
|
||||
},
|
||||
Period: 300,
|
||||
Identifier: "id1",
|
||||
Expression: "",
|
||||
MatchExact: matchExact,
|
||||
}
|
||||
@@ -38,7 +37,6 @@ func TestMetricDataQueryBuilder(t *testing.T) {
|
||||
"InstanceId": {"i-123", "i-456", "i-789"},
|
||||
},
|
||||
Period: 300,
|
||||
Identifier: "id1",
|
||||
Expression: "",
|
||||
MatchExact: matchExact,
|
||||
}
|
||||
@@ -55,7 +53,6 @@ func TestMetricDataQueryBuilder(t *testing.T) {
|
||||
"LoadBalancer": {"*"},
|
||||
},
|
||||
Period: 300,
|
||||
Identifier: "id1",
|
||||
Expression: "",
|
||||
MatchExact: matchExact,
|
||||
}
|
||||
@@ -72,7 +69,6 @@ func TestMetricDataQueryBuilder(t *testing.T) {
|
||||
"LoadBalancer": {"*"},
|
||||
},
|
||||
Period: 300,
|
||||
Identifier: "id1",
|
||||
Expression: "",
|
||||
MatchExact: matchExact,
|
||||
}
|
||||
@@ -90,7 +86,6 @@ func TestMetricDataQueryBuilder(t *testing.T) {
|
||||
"InstanceId": {"i-123", "*", "i-789"},
|
||||
},
|
||||
Period: 300,
|
||||
Identifier: "id1",
|
||||
Expression: "",
|
||||
MatchExact: matchExact,
|
||||
}
|
||||
@@ -110,7 +105,6 @@ func TestMetricDataQueryBuilder(t *testing.T) {
|
||||
"LoadBalancer": {"lb1", "lb2", "lb3"},
|
||||
},
|
||||
Period: 300,
|
||||
Identifier: "id1",
|
||||
Expression: "",
|
||||
MatchExact: matchExact,
|
||||
}
|
||||
@@ -128,7 +122,6 @@ func TestMetricDataQueryBuilder(t *testing.T) {
|
||||
"InstanceId": {"i-123", "i-456", "i-789"},
|
||||
},
|
||||
Period: 300,
|
||||
Identifier: "id1",
|
||||
Expression: "",
|
||||
MatchExact: matchExact,
|
||||
}
|
||||
@@ -145,7 +138,6 @@ func TestMetricDataQueryBuilder(t *testing.T) {
|
||||
"LoadBalancer": {"*"},
|
||||
},
|
||||
Period: 300,
|
||||
Identifier: "id1",
|
||||
Expression: "",
|
||||
MatchExact: matchExact,
|
||||
}
|
||||
@@ -163,7 +155,6 @@ func TestMetricDataQueryBuilder(t *testing.T) {
|
||||
"InstanceId": {"i-123", "*", "i-789"},
|
||||
},
|
||||
Period: 300,
|
||||
Identifier: "id1",
|
||||
Expression: "",
|
||||
MatchExact: matchExact,
|
||||
}
|
||||
@@ -188,7 +179,6 @@ func TestMetricDataQueryBuilder(t *testing.T) {
|
||||
"lb6": {`l\\(b5"`},
|
||||
},
|
||||
Period: 300,
|
||||
Identifier: "id1",
|
||||
Expression: "",
|
||||
MatchExact: true,
|
||||
}
|
||||
|
||||
@@ -26,19 +26,18 @@ func (e *CloudWatchExecutor) transformRequestQueriesToCloudWatchQueries(requestQ
|
||||
}
|
||||
|
||||
query := &cloudWatchQuery{
|
||||
Id: id,
|
||||
RefId: requestQuery.RefId,
|
||||
Region: requestQuery.Region,
|
||||
Namespace: requestQuery.Namespace,
|
||||
MetricName: requestQuery.MetricName,
|
||||
Dimensions: requestQuery.Dimensions,
|
||||
Stats: *stat,
|
||||
Period: requestQuery.Period,
|
||||
Alias: requestQuery.Alias,
|
||||
Expression: requestQuery.Expression,
|
||||
ReturnData: requestQuery.ReturnData,
|
||||
HighResolution: requestQuery.HighResolution,
|
||||
MatchExact: requestQuery.MatchExact,
|
||||
Id: id,
|
||||
RefId: requestQuery.RefId,
|
||||
Region: requestQuery.Region,
|
||||
Namespace: requestQuery.Namespace,
|
||||
MetricName: requestQuery.MetricName,
|
||||
Dimensions: requestQuery.Dimensions,
|
||||
Stats: *stat,
|
||||
Period: requestQuery.Period,
|
||||
Alias: requestQuery.Alias,
|
||||
Expression: requestQuery.Expression,
|
||||
ReturnData: requestQuery.ReturnData,
|
||||
MatchExact: requestQuery.MatchExact,
|
||||
}
|
||||
|
||||
if _, ok := cloudwatchQueries[id]; ok {
|
||||
|
||||
@@ -15,14 +15,13 @@ func TestQueryTransformer(t *testing.T) {
|
||||
Convey("one cloudwatchQuery is generated when its request query has one stat", func() {
|
||||
requestQueries := []*requestQuery{
|
||||
{
|
||||
RefId: "D",
|
||||
Region: "us-east-1",
|
||||
Namespace: "ec2",
|
||||
MetricName: "CPUUtilization",
|
||||
Statistics: aws.StringSlice([]string{"Average"}),
|
||||
Period: 600,
|
||||
Id: "",
|
||||
HighResolution: false,
|
||||
RefId: "D",
|
||||
Region: "us-east-1",
|
||||
Namespace: "ec2",
|
||||
MetricName: "CPUUtilization",
|
||||
Statistics: aws.StringSlice([]string{"Average"}),
|
||||
Period: 600,
|
||||
Id: "",
|
||||
},
|
||||
}
|
||||
|
||||
@@ -34,14 +33,13 @@ func TestQueryTransformer(t *testing.T) {
|
||||
Convey("two cloudwatchQuery is generated when there's two stats", func() {
|
||||
requestQueries := []*requestQuery{
|
||||
{
|
||||
RefId: "D",
|
||||
Region: "us-east-1",
|
||||
Namespace: "ec2",
|
||||
MetricName: "CPUUtilization",
|
||||
Statistics: aws.StringSlice([]string{"Average", "Sum"}),
|
||||
Period: 600,
|
||||
Id: "",
|
||||
HighResolution: false,
|
||||
RefId: "D",
|
||||
Region: "us-east-1",
|
||||
Namespace: "ec2",
|
||||
MetricName: "CPUUtilization",
|
||||
Statistics: aws.StringSlice([]string{"Average", "Sum"}),
|
||||
Period: 600,
|
||||
Id: "",
|
||||
},
|
||||
}
|
||||
|
||||
@@ -53,14 +51,13 @@ func TestQueryTransformer(t *testing.T) {
|
||||
Convey("that id will be used in the cloudwatch query", func() {
|
||||
requestQueries := []*requestQuery{
|
||||
{
|
||||
RefId: "D",
|
||||
Region: "us-east-1",
|
||||
Namespace: "ec2",
|
||||
MetricName: "CPUUtilization",
|
||||
Statistics: aws.StringSlice([]string{"Average"}),
|
||||
Period: 600,
|
||||
Id: "myid",
|
||||
HighResolution: false,
|
||||
RefId: "D",
|
||||
Region: "us-east-1",
|
||||
Namespace: "ec2",
|
||||
MetricName: "CPUUtilization",
|
||||
Statistics: aws.StringSlice([]string{"Average"}),
|
||||
Period: 600,
|
||||
Id: "myid",
|
||||
},
|
||||
}
|
||||
|
||||
@@ -75,14 +72,13 @@ func TestQueryTransformer(t *testing.T) {
|
||||
Convey("id will be generated based on ref id if query only has one stat", func() {
|
||||
requestQueries := []*requestQuery{
|
||||
{
|
||||
RefId: "D",
|
||||
Region: "us-east-1",
|
||||
Namespace: "ec2",
|
||||
MetricName: "CPUUtilization",
|
||||
Statistics: aws.StringSlice([]string{"Average"}),
|
||||
Period: 600,
|
||||
Id: "",
|
||||
HighResolution: false,
|
||||
RefId: "D",
|
||||
Region: "us-east-1",
|
||||
Namespace: "ec2",
|
||||
MetricName: "CPUUtilization",
|
||||
Statistics: aws.StringSlice([]string{"Average"}),
|
||||
Period: 600,
|
||||
Id: "",
|
||||
},
|
||||
}
|
||||
|
||||
@@ -95,14 +91,13 @@ func TestQueryTransformer(t *testing.T) {
|
||||
Convey("id will be generated based on ref and stat name if query has two stats", func() {
|
||||
requestQueries := []*requestQuery{
|
||||
{
|
||||
RefId: "D",
|
||||
Region: "us-east-1",
|
||||
Namespace: "ec2",
|
||||
MetricName: "CPUUtilization",
|
||||
Statistics: aws.StringSlice([]string{"Average", "Sum"}),
|
||||
Period: 600,
|
||||
Id: "",
|
||||
HighResolution: false,
|
||||
RefId: "D",
|
||||
Region: "us-east-1",
|
||||
Namespace: "ec2",
|
||||
MetricName: "CPUUtilization",
|
||||
Statistics: aws.StringSlice([]string{"Average", "Sum"}),
|
||||
Period: 600,
|
||||
Id: "",
|
||||
},
|
||||
}
|
||||
|
||||
@@ -117,14 +112,13 @@ func TestQueryTransformer(t *testing.T) {
|
||||
Convey("dot should be removed when query has more than one stat and one of them is a percentile", func() {
|
||||
requestQueries := []*requestQuery{
|
||||
{
|
||||
RefId: "D",
|
||||
Region: "us-east-1",
|
||||
Namespace: "ec2",
|
||||
MetricName: "CPUUtilization",
|
||||
Statistics: aws.StringSlice([]string{"Average", "p46.32"}),
|
||||
Period: 600,
|
||||
Id: "",
|
||||
HighResolution: false,
|
||||
RefId: "D",
|
||||
Region: "us-east-1",
|
||||
Namespace: "ec2",
|
||||
MetricName: "CPUUtilization",
|
||||
Statistics: aws.StringSlice([]string{"Average", "p46.32"}),
|
||||
Period: 600,
|
||||
Id: "",
|
||||
},
|
||||
}
|
||||
|
||||
@@ -137,24 +131,22 @@ func TestQueryTransformer(t *testing.T) {
|
||||
Convey("should return an error if two queries have the same id", func() {
|
||||
requestQueries := []*requestQuery{
|
||||
{
|
||||
RefId: "D",
|
||||
Region: "us-east-1",
|
||||
Namespace: "ec2",
|
||||
MetricName: "CPUUtilization",
|
||||
Statistics: aws.StringSlice([]string{"Average", "p46.32"}),
|
||||
Period: 600,
|
||||
Id: "myId",
|
||||
HighResolution: false,
|
||||
RefId: "D",
|
||||
Region: "us-east-1",
|
||||
Namespace: "ec2",
|
||||
MetricName: "CPUUtilization",
|
||||
Statistics: aws.StringSlice([]string{"Average", "p46.32"}),
|
||||
Period: 600,
|
||||
Id: "myId",
|
||||
},
|
||||
{
|
||||
RefId: "E",
|
||||
Region: "us-east-1",
|
||||
Namespace: "ec2",
|
||||
MetricName: "CPUUtilization",
|
||||
Statistics: aws.StringSlice([]string{"Average", "p46.32"}),
|
||||
Period: 600,
|
||||
Id: "myId",
|
||||
HighResolution: false,
|
||||
RefId: "E",
|
||||
Region: "us-east-1",
|
||||
Namespace: "ec2",
|
||||
MetricName: "CPUUtilization",
|
||||
Statistics: aws.StringSlice([]string{"Average", "p46.32"}),
|
||||
Period: 600,
|
||||
Id: "myId",
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -97,23 +97,21 @@ func parseRequestQuery(model *simplejson.Json, refId string) (*requestQuery, err
|
||||
returnData = true
|
||||
}
|
||||
|
||||
highResolution := model.Get("highResolution").MustBool(false)
|
||||
matchExact := model.Get("matchExact").MustBool(true)
|
||||
|
||||
return &requestQuery{
|
||||
RefId: refId,
|
||||
Region: region,
|
||||
Namespace: namespace,
|
||||
MetricName: metricName,
|
||||
Dimensions: dimensions,
|
||||
Statistics: aws.StringSlice(statistics),
|
||||
Period: period,
|
||||
Alias: alias,
|
||||
Id: id,
|
||||
Expression: expression,
|
||||
ReturnData: returnData,
|
||||
HighResolution: highResolution,
|
||||
MatchExact: matchExact,
|
||||
RefId: refId,
|
||||
Region: region,
|
||||
Namespace: namespace,
|
||||
MetricName: metricName,
|
||||
Dimensions: dimensions,
|
||||
Statistics: aws.StringSlice(statistics),
|
||||
Period: period,
|
||||
Alias: alias,
|
||||
Id: id,
|
||||
Expression: expression,
|
||||
ReturnData: returnData,
|
||||
MatchExact: matchExact,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -22,10 +22,9 @@ func TestRequestParser(t *testing.T) {
|
||||
"InstanceId": []interface{}{"test"},
|
||||
"InstanceType": []interface{}{"test2", "test3"},
|
||||
},
|
||||
"statistics": []interface{}{"Average"},
|
||||
"period": "600",
|
||||
"hide": false,
|
||||
"highResolution": false,
|
||||
"statistics": []interface{}{"Average"},
|
||||
"period": "600",
|
||||
"hide": false,
|
||||
})
|
||||
|
||||
res, err := parseRequestQuery(query, "ref1")
|
||||
@@ -38,7 +37,6 @@ func TestRequestParser(t *testing.T) {
|
||||
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)
|
||||
@@ -59,10 +57,9 @@ func TestRequestParser(t *testing.T) {
|
||||
"InstanceId": "test",
|
||||
"InstanceType": "test2",
|
||||
},
|
||||
"statistics": []interface{}{"Average"},
|
||||
"period": "600",
|
||||
"hide": false,
|
||||
"highResolution": false,
|
||||
"statistics": []interface{}{"Average"},
|
||||
"period": "600",
|
||||
"hide": false,
|
||||
})
|
||||
|
||||
res, err := parseRequestQuery(query, "ref1")
|
||||
@@ -75,7 +72,6 @@ func TestRequestParser(t *testing.T) {
|
||||
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)
|
||||
|
||||
@@ -63,7 +63,7 @@ func parseGetMetricDataTimeSeries(metricDataResults map[string]*cloudwatch.Metri
|
||||
result := tsdb.TimeSeriesSlice{}
|
||||
for label, metricDataResult := range metricDataResults {
|
||||
if *metricDataResult.StatusCode != "Complete" {
|
||||
return nil, fmt.Errorf("too many datapoint requested in query %s. Please try to reduce the time range", query.RefId)
|
||||
return nil, fmt.Errorf("too many datapoints requested in query %s. Please try to reduce the time range", query.RefId)
|
||||
}
|
||||
|
||||
for _, message := range metricDataResult.Messages {
|
||||
|
||||
@@ -27,7 +27,6 @@ type requestQuery struct {
|
||||
ExtendedStatistics []*string
|
||||
Period int
|
||||
Alias string
|
||||
HighResolution bool
|
||||
MatchExact bool
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user