grafana/pkg/tsdb/cloudwatch/query_row_response.go
Shirley ef9e08ffcf
CloudWatch: Change aggregateResponse to return slice instead of map (#48805)
* Rename tests

* Change test names

* Change metrics from map to slice

* Add test for one output, multiple MetricDataResults

* Rename test input file

* Use map instead of iterating over the response metrics

* Rename variable

* move partial data set to query row response

* remove not used label field

* remove incorrect placeholder

Co-authored-by: Erik Sundell <erik.sundell87@gmail.com>
2022-05-18 09:16:38 +02:00

51 lines
1.6 KiB
Go

package cloudwatch
import "github.com/aws/aws-sdk-go/service/cloudwatch"
// queryRowResponse represents the GetMetricData response for a query row in the query editor.
type queryRowResponse struct {
partialDataSet map[string]*cloudwatch.MetricDataResult
ErrorCodes map[string]bool
HasArithmeticError bool
ArithmeticErrorMessage string
Metrics []*cloudwatch.MetricDataResult
StatusCode string
}
func newQueryRowResponse() queryRowResponse {
return queryRowResponse{
partialDataSet: make(map[string]*cloudwatch.MetricDataResult),
ErrorCodes: map[string]bool{
maxMetricsExceeded: false,
maxQueryTimeRangeExceeded: false,
maxQueryResultsExceeded: false,
maxMatchingResultsExceeded: false},
HasArithmeticError: false,
ArithmeticErrorMessage: "",
Metrics: []*cloudwatch.MetricDataResult{},
}
}
func (q *queryRowResponse) addMetricDataResult(mdr *cloudwatch.MetricDataResult) {
if partialData, ok := q.partialDataSet[*mdr.Label]; ok {
partialData.Timestamps = append(partialData.Timestamps, mdr.Timestamps...)
partialData.Values = append(partialData.Values, mdr.Values...)
q.StatusCode = *mdr.StatusCode
if *mdr.StatusCode != "PartialData" {
delete(q.partialDataSet, *mdr.Label)
}
return
}
q.Metrics = append(q.Metrics, mdr)
q.StatusCode = *mdr.StatusCode
if *mdr.StatusCode == "PartialData" {
q.partialDataSet[*mdr.Label] = mdr
}
}
func (q *queryRowResponse) addArithmeticError(message *string) {
q.HasArithmeticError = true
q.ArithmeticErrorMessage = *message
}