CloudWatch: Use default region when query region is unset (#109089)
CloudWatch: use default region when region is unset
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/grafana/grafana-aws-sdk/pkg/awsauth"
|
||||
"github.com/grafana/grafana-aws-sdk/pkg/awsds"
|
||||
"github.com/grafana/grafana-plugin-sdk-go/backend/log"
|
||||
"github.com/grafana/grafana-plugin-sdk-go/backend/resource/httpadapter"
|
||||
"github.com/grafana/grafana/pkg/tsdb/cloudwatch/mocks"
|
||||
@@ -23,6 +24,9 @@ func newTestDatasource(opts ...func(*DataSource)) *DataSource {
|
||||
AWSConfigProvider: awsauth.NewFakeConfigProvider(false),
|
||||
logger: log.NewNullLogger(),
|
||||
tagValueCache: cache.New(0, 0),
|
||||
Settings: models.CloudWatchSettings{
|
||||
AWSDatasourceSettings: awsds.AWSDatasourceSettings{Region: "us-east-1"},
|
||||
},
|
||||
}
|
||||
ds.resourceHandler = httpadapter.New(ds.newResourceMux())
|
||||
for _, opt := range opts {
|
||||
|
||||
@@ -59,7 +59,7 @@ type DataSource struct {
|
||||
}
|
||||
|
||||
func (ds *DataSource) newAWSConfig(ctx context.Context, region string) (aws.Config, error) {
|
||||
if region == defaultRegion {
|
||||
if region == defaultRegion || region == "" {
|
||||
if len(ds.Settings.Region) == 0 {
|
||||
return aws.Config{}, models.ErrMissingRegion
|
||||
}
|
||||
|
||||
@@ -269,6 +269,7 @@ func Test_CloudWatch_CallResource_Integration_Test(t *testing.T) {
|
||||
t.Run("Should error for any request when a default region is not selected", func(t *testing.T) {
|
||||
ds := newTestDatasource(func(ds *DataSource) {
|
||||
ds.Settings.GrafanaSettings.ListMetricsPageLimit = 1000
|
||||
ds.Settings.Region = ""
|
||||
})
|
||||
|
||||
req := &backend.CallResourceRequest{
|
||||
|
||||
Reference in New Issue
Block a user