2019-11-14 03:59:41 -06:00
|
|
|
package cloudwatch
|
|
|
|
|
|
|
|
import (
|
2020-01-17 06:22:43 -06:00
|
|
|
"time"
|
2019-11-14 03:59:41 -06:00
|
|
|
|
|
|
|
"github.com/aws/aws-sdk-go/aws"
|
|
|
|
"github.com/aws/aws-sdk-go/service/cloudwatch"
|
2022-10-20 04:21:13 -05:00
|
|
|
|
2022-11-02 09:14:02 -05:00
|
|
|
"github.com/grafana/grafana/pkg/infra/log"
|
2022-10-20 04:21:13 -05:00
|
|
|
"github.com/grafana/grafana/pkg/tsdb/cloudwatch/models"
|
2019-11-14 03:59:41 -06:00
|
|
|
)
|
|
|
|
|
2022-11-02 09:14:02 -05:00
|
|
|
func (e *cloudWatchExecutor) buildMetricDataInput(logger log.Logger, startTime time.Time, endTime time.Time,
|
2022-10-20 04:21:13 -05:00
|
|
|
queries []*models.CloudWatchQuery) (*cloudwatch.GetMetricDataInput, error) {
|
2019-11-14 03:59:41 -06:00
|
|
|
metricDataInput := &cloudwatch.GetMetricDataInput{
|
|
|
|
StartTime: aws.Time(startTime),
|
|
|
|
EndTime: aws.Time(endTime),
|
|
|
|
ScanBy: aws.String("TimestampAscending"),
|
|
|
|
}
|
2022-05-16 05:15:54 -05:00
|
|
|
|
2023-04-27 04:19:45 -05:00
|
|
|
shouldSetLabelOptions := len(queries) > 0 && len(queries[0].TimezoneUTCOffset) > 0
|
2022-05-16 05:15:54 -05:00
|
|
|
|
|
|
|
if shouldSetLabelOptions {
|
|
|
|
metricDataInput.LabelOptions = &cloudwatch.LabelOptions{
|
|
|
|
Timezone: aws.String(queries[0].TimezoneUTCOffset),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-14 03:59:41 -06:00
|
|
|
for _, query := range queries {
|
2022-11-02 09:14:02 -05:00
|
|
|
metricDataQuery, err := e.buildMetricDataQuery(logger, query)
|
2019-11-14 03:59:41 -06:00
|
|
|
if err != nil {
|
2022-10-20 04:21:13 -05:00
|
|
|
return nil, &models.QueryError{Err: err, RefID: query.RefId}
|
2019-11-14 03:59:41 -06:00
|
|
|
}
|
|
|
|
metricDataInput.MetricDataQueries = append(metricDataInput.MetricDataQueries, metricDataQuery)
|
|
|
|
}
|
|
|
|
|
|
|
|
return metricDataInput, nil
|
|
|
|
}
|