560be84dc8
* CloudWatch: Backport aws-sdk-go-v2 update from external plugin (#107136) (cherry picked froma18ea34688) * Datasources: Update grafana-aws-sdk for new sigv4 middleware and aws-sdk-go v1 removal (#107522) (cherry picked from commit66d9a33cc9) * CloudWatch: Fix proxy transport issue (#107807) (cherry picked fromc3eeb1fcd9) * CloudWatch: Fix http client handling + assume role bug (#107893) (cherry picked from commitf34a9fc0c2) * CloudWatch: Use default region when query region is unset (#109089) (cherry picked from commit5f4097a159) * CloudWatch: Fix handling region for legacy alerts (#109217) (cherry picked from commit2bf9aea8ef) * Update go.mod owners --------- Co-authored-by: Isabella Siu <Isabella.siu@grafana.com>
40 lines
1.2 KiB
Go
40 lines
1.2 KiB
Go
package cloudwatch
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/aws/aws-sdk-go-v2/aws"
|
|
"github.com/aws/aws-sdk-go-v2/service/cloudwatch"
|
|
cloudwatchtypes "github.com/aws/aws-sdk-go-v2/service/cloudwatch/types"
|
|
|
|
"github.com/grafana/grafana/pkg/tsdb/cloudwatch/models"
|
|
)
|
|
|
|
func (ds *DataSource) buildMetricDataInput(ctx context.Context, startTime time.Time, endTime time.Time,
|
|
queries []*models.CloudWatchQuery) (*cloudwatch.GetMetricDataInput, error) {
|
|
metricDataInput := &cloudwatch.GetMetricDataInput{
|
|
StartTime: aws.Time(startTime),
|
|
EndTime: aws.Time(endTime),
|
|
ScanBy: cloudwatchtypes.ScanByTimestampAscending,
|
|
}
|
|
|
|
shouldSetLabelOptions := len(queries) > 0 && len(queries[0].TimezoneUTCOffset) > 0
|
|
|
|
if shouldSetLabelOptions {
|
|
metricDataInput.LabelOptions = &cloudwatchtypes.LabelOptions{
|
|
Timezone: aws.String(queries[0].TimezoneUTCOffset),
|
|
}
|
|
}
|
|
|
|
for _, query := range queries {
|
|
metricDataQuery, err := ds.buildMetricDataQuery(ctx, query)
|
|
if err != nil {
|
|
return nil, &models.QueryError{Err: err, RefID: query.RefId}
|
|
}
|
|
metricDataInput.MetricDataQueries = append(metricDataInput.MetricDataQueries, metricDataQuery)
|
|
}
|
|
|
|
return metricDataInput, nil
|
|
}
|