mirror of
https://github.com/grafana/grafana.git
synced 2024-11-30 20:54:22 -06:00
ef9e08ffcf
* 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>
51 lines
1.6 KiB
Go
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
|
|
}
|