Cloudwatch: Backend cleanup (#59663)
* cleanup cloudwatch.go * streamline interface naming * use utility func * rename test utils file * move util function to where they are used * move dtos to models * split integration tests from the rest * Update pkg/tsdb/cloudwatch/cloudwatch.go Co-authored-by: Isabella Siu <Isabella.siu@grafana.com> * refactor error codes aggregation * move error messages to models Co-authored-by: Isabella Siu <Isabella.siu@grafana.com>
This commit is contained in:
co-authored by
Isabella Siu
parent
ada0c771ef
commit
fde9a5d112
@@ -0,0 +1,46 @@
|
||||
package models
|
||||
|
||||
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(errors map[string]bool) QueryRowResponse {
|
||||
return QueryRowResponse{
|
||||
partialDataSet: make(map[string]*cloudwatch.MetricDataResult),
|
||||
ErrorCodes: errors,
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user