Cloudwatch: Fix Unexpected error (#74420)
Fix unexpected error when creating a new cloudwatch datasource. Involves a fair amount of refactoring, so if this causes unexpected issues related to region fetching we can turn this off with the cloudwatchNewRegionsHandler feature toggle, although we do not predict it will so we are enabling it to default to true and hope to remove it shortly.
This commit is contained in:
@@ -128,14 +128,21 @@ func (e *cloudWatchExecutor) getRequestContext(ctx context.Context, pluginCtx ba
|
||||
r = instance.Settings.Region
|
||||
}
|
||||
|
||||
ec2Client, err := e.getEC2Client(ctx, pluginCtx, defaultRegion)
|
||||
if err != nil {
|
||||
return models.RequestContext{}, err
|
||||
}
|
||||
|
||||
sess, err := e.newSession(ctx, pluginCtx, r)
|
||||
if err != nil {
|
||||
return models.RequestContext{}, err
|
||||
}
|
||||
|
||||
return models.RequestContext{
|
||||
OAMAPIProvider: NewOAMAPI(sess),
|
||||
MetricsClientProvider: clients.NewMetricsClient(NewMetricsAPI(sess), e.cfg),
|
||||
LogsAPIProvider: NewLogsAPI(sess),
|
||||
EC2APIProvider: ec2Client,
|
||||
Settings: instance.Settings,
|
||||
Features: e.features,
|
||||
}, nil
|
||||
@@ -233,6 +240,9 @@ func (e *cloudWatchExecutor) newSession(ctx context.Context, pluginCtx backend.P
|
||||
}
|
||||
|
||||
if region == defaultRegion {
|
||||
if len(instance.Settings.Region) == 0 {
|
||||
return nil, models.ErrMissingRegion
|
||||
}
|
||||
region = instance.Settings.Region
|
||||
}
|
||||
|
||||
@@ -300,7 +310,7 @@ func (e *cloudWatchExecutor) getEC2Client(ctx context.Context, pluginCtx backend
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return newEC2Client(sess), nil
|
||||
return NewEC2Client(sess), nil
|
||||
}
|
||||
|
||||
func (e *cloudWatchExecutor) getRGTAClient(ctx context.Context, pluginCtx backend.PluginContext, region string) (resourcegroupstaggingapiiface.ResourceGroupsTaggingAPIAPI,
|
||||
|
||||
Reference in New Issue
Block a user