Commit d82af23f by hannes Committed by Torkel Ödegaard

cloudwatch: fix ebs_volume_ids by create a client-session before call…

cloudwatch: fix ebs_volume_ids by create a client-session before call ec2:DescribeInstances. (#10566)
parent 1ce6a420
...@@ -188,18 +188,6 @@ func (e *CloudWatchExecutor) executeMetricFindQuery(ctx context.Context, queryCo ...@@ -188,18 +188,6 @@ func (e *CloudWatchExecutor) executeMetricFindQuery(ctx context.Context, queryCo
data, err = e.handleGetEbsVolumeIds(ctx, parameters, queryContext) data, err = e.handleGetEbsVolumeIds(ctx, parameters, queryContext)
break break
case "ec2_instance_attribute": case "ec2_instance_attribute":
region := parameters.Get("region").MustString()
dsInfo := e.getDsInfo(region)
cfg, err := e.getAwsConfig(dsInfo)
if err != nil {
return nil, fmt.Errorf("Failed to call ec2:DescribeInstances, %v", err)
}
sess, err := session.NewSession(cfg)
if err != nil {
return nil, fmt.Errorf("Failed to call ec2:DescribeInstances, %v", err)
}
e.ec2Svc = ec2.New(sess, cfg)
data, err = e.handleGetEc2InstanceAttribute(ctx, parameters, queryContext) data, err = e.handleGetEc2InstanceAttribute(ctx, parameters, queryContext)
break break
} }
...@@ -365,10 +353,31 @@ func (e *CloudWatchExecutor) handleGetDimensionValues(ctx context.Context, param ...@@ -365,10 +353,31 @@ func (e *CloudWatchExecutor) handleGetDimensionValues(ctx context.Context, param
return result, nil return result, nil
} }
func (e *CloudWatchExecutor) ensureClientSession(region string) error {
if e.ec2Svc == nil {
dsInfo := e.getDsInfo(region)
cfg, err := e.getAwsConfig(dsInfo)
if err != nil {
return fmt.Errorf("Failed to call ec2:getAwsConfig, %v", err)
}
sess, err := session.NewSession(cfg)
if err != nil {
return fmt.Errorf("Failed to call ec2:NewSession, %v", err)
}
e.ec2Svc = ec2.New(sess, cfg)
}
return nil
}
func (e *CloudWatchExecutor) handleGetEbsVolumeIds(ctx context.Context, parameters *simplejson.Json, queryContext *tsdb.TsdbQuery) ([]suggestData, error) { func (e *CloudWatchExecutor) handleGetEbsVolumeIds(ctx context.Context, parameters *simplejson.Json, queryContext *tsdb.TsdbQuery) ([]suggestData, error) {
region := parameters.Get("region").MustString() region := parameters.Get("region").MustString()
instanceId := parameters.Get("instanceId").MustString() instanceId := parameters.Get("instanceId").MustString()
err := e.ensureClientSession(region)
if err != nil {
return nil, err
}
instanceIds := []*string{aws.String(instanceId)} instanceIds := []*string{aws.String(instanceId)}
instances, err := e.ec2DescribeInstances(region, nil, instanceIds) instances, err := e.ec2DescribeInstances(region, nil, instanceIds)
if err != nil { if err != nil {
...@@ -404,6 +413,11 @@ func (e *CloudWatchExecutor) handleGetEc2InstanceAttribute(ctx context.Context, ...@@ -404,6 +413,11 @@ func (e *CloudWatchExecutor) handleGetEc2InstanceAttribute(ctx context.Context,
} }
} }
err := e.ensureClientSession(region)
if err != nil {
return nil, err
}
instances, err := e.ec2DescribeInstances(region, filters, nil) instances, err := e.ec2DescribeInstances(region, filters, nil)
if err != nil { if err != nil {
return nil, err return nil, err
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment