2022-12-02 03:21:46 -06:00
|
|
|
package models
|
2021-09-08 09:06:43 -05:00
|
|
|
|
|
|
|
import "github.com/aws/aws-sdk-go/service/cloudwatch"
|
|
|
|
|
|
|
|
// queryRowResponse represents the GetMetricData response for a query row in the query editor.
|
2022-12-02 03:21:46 -06:00
|
|
|
type QueryRowResponse struct {
|
2022-05-18 02:16:38 -05:00
|
|
|
partialDataSet map[string]*cloudwatch.MetricDataResult
|
2022-04-04 08:44:19 -05:00
|
|
|
ErrorCodes map[string]bool
|
|
|
|
HasArithmeticError bool
|
|
|
|
ArithmeticErrorMessage string
|
2022-05-18 02:16:38 -05:00
|
|
|
Metrics []*cloudwatch.MetricDataResult
|
2022-04-04 08:44:19 -05:00
|
|
|
StatusCode string
|
2021-09-08 09:06:43 -05:00
|
|
|
}
|
|
|
|
|
2022-12-02 03:21:46 -06:00
|
|
|
func NewQueryRowResponse(errors map[string]bool) QueryRowResponse {
|
|
|
|
return QueryRowResponse{
|
|
|
|
partialDataSet: make(map[string]*cloudwatch.MetricDataResult),
|
|
|
|
ErrorCodes: errors,
|
2022-04-04 08:44:19 -05:00
|
|
|
HasArithmeticError: false,
|
|
|
|
ArithmeticErrorMessage: "",
|
2022-05-18 02:16:38 -05:00
|
|
|
Metrics: []*cloudwatch.MetricDataResult{},
|
2021-09-08 09:06:43 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-02 03:21:46 -06:00
|
|
|
func (q *QueryRowResponse) AddMetricDataResult(mdr *cloudwatch.MetricDataResult) {
|
2022-05-18 02:16:38 -05:00
|
|
|
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
|
2021-09-08 09:06:43 -05:00
|
|
|
}
|
2022-05-18 02:16:38 -05:00
|
|
|
|
|
|
|
q.Metrics = append(q.Metrics, mdr)
|
2021-09-08 09:06:43 -05:00
|
|
|
q.StatusCode = *mdr.StatusCode
|
2022-05-18 02:16:38 -05:00
|
|
|
if *mdr.StatusCode == "PartialData" {
|
|
|
|
q.partialDataSet[*mdr.Label] = mdr
|
|
|
|
}
|
2021-09-08 09:06:43 -05:00
|
|
|
}
|
|
|
|
|
2022-12-02 03:21:46 -06:00
|
|
|
func (q *QueryRowResponse) AddArithmeticError(message *string) {
|
2021-09-08 09:06:43 -05:00
|
|
|
q.HasArithmeticError = true
|
|
|
|
q.ArithmeticErrorMessage = *message
|
|
|
|
}
|