grafana/pkg/tsdb/cloudwatch/metric_data_input_builder.go
Nathan Vērzemnieks b5f26560c2
Cloudwatch: Remove core imports from infra/log (#81543)
* Cloudwatch: use logging from plugin-sdk-go instead of infra/log
* Add a link to the TODO issue for moving `instrumentContext`
2024-02-07 13:53:05 +01:00

38 lines
1.0 KiB
Go

package cloudwatch
import (
"time"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/cloudwatch"
"github.com/grafana/grafana/pkg/tsdb/cloudwatch/models"
)
func (e *cloudWatchExecutor) buildMetricDataInput(startTime time.Time, endTime time.Time,
queries []*models.CloudWatchQuery) (*cloudwatch.GetMetricDataInput, error) {
metricDataInput := &cloudwatch.GetMetricDataInput{
StartTime: aws.Time(startTime),
EndTime: aws.Time(endTime),
ScanBy: aws.String("TimestampAscending"),
}
shouldSetLabelOptions := len(queries) > 0 && len(queries[0].TimezoneUTCOffset) > 0
if shouldSetLabelOptions {
metricDataInput.LabelOptions = &cloudwatch.LabelOptions{
Timezone: aws.String(queries[0].TimezoneUTCOffset),
}
}
for _, query := range queries {
metricDataQuery, err := e.buildMetricDataQuery(query)
if err != nil {
return nil, &models.QueryError{Err: err, RefID: query.RefId}
}
metricDataInput.MetricDataQueries = append(metricDataInput.MetricDataQueries, metricDataQuery)
}
return metricDataInput, nil
}