mirror of
https://github.com/grafana/grafana.git
synced 2024-11-23 09:26:43 -06:00
39 lines
1.1 KiB
Go
39 lines
1.1 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/infra/log"
|
|
"github.com/grafana/grafana/pkg/tsdb/cloudwatch/models"
|
|
)
|
|
|
|
func (e *cloudWatchExecutor) buildMetricDataInput(logger log.Logger, 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(logger, query)
|
|
if err != nil {
|
|
return nil, &models.QueryError{Err: err, RefID: query.RefId}
|
|
}
|
|
metricDataInput.MetricDataQueries = append(metricDataInput.MetricDataQueries, metricDataQuery)
|
|
}
|
|
|
|
return metricDataInput, nil
|
|
}
|