mirror of https://github.com/grafana/grafana.git
CloudWatch: Use context in aws DescribeInstancesPages (#76855)
This commit is contained in:
parent
ecbc52f515
commit
015062cf65
|
|
@ -251,7 +251,7 @@ func (e *cloudWatchExecutor) ec2DescribeInstances(ctx context.Context, pluginCtx
|
|||
}
|
||||
|
||||
var resp ec2.DescribeInstancesOutput
|
||||
if err := client.DescribeInstancesPages(params, func(page *ec2.DescribeInstancesOutput, lastPage bool) bool {
|
||||
if err := client.DescribeInstancesPagesWithContext(ctx, params, func(page *ec2.DescribeInstancesOutput, lastPage bool) bool {
|
||||
resp.Reservations = append(resp.Reservations, page.Reservations...)
|
||||
return !lastPage
|
||||
}); err != nil {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
package mocks
|
||||
|
||||
import (
|
||||
"github.com/aws/aws-sdk-go/aws"
|
||||
"github.com/aws/aws-sdk-go/aws/request"
|
||||
"github.com/aws/aws-sdk-go/service/ec2"
|
||||
"github.com/grafana/grafana/pkg/tsdb/cloudwatch/models/resources"
|
||||
"github.com/stretchr/testify/mock"
|
||||
|
|
@ -24,7 +26,7 @@ func (e *EC2Mock) DescribeRegions(in *ec2.DescribeRegionsInput) (*ec2.DescribeRe
|
|||
return args.Get(0).(*ec2.DescribeRegionsOutput), args.Error(1)
|
||||
}
|
||||
|
||||
func (e *EC2Mock) DescribeInstancesPages(in *ec2.DescribeInstancesInput, fn func(*ec2.DescribeInstancesOutput, bool) bool) error {
|
||||
func (e *EC2Mock) DescribeInstancesPagesWithContext(ctx aws.Context, in *ec2.DescribeInstancesInput, fn func(*ec2.DescribeInstancesOutput, bool) bool, opts ...request.Option) error {
|
||||
args := e.Called(in, fn)
|
||||
return args.Error(0)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import (
|
|||
"context"
|
||||
"net/url"
|
||||
|
||||
"github.com/aws/aws-sdk-go/aws/request"
|
||||
"github.com/aws/aws-sdk-go/service/cloudwatch"
|
||||
"github.com/aws/aws-sdk-go/service/cloudwatchlogs"
|
||||
"github.com/aws/aws-sdk-go/service/ec2"
|
||||
|
|
@ -70,5 +71,5 @@ type OAMAPIProvider interface {
|
|||
|
||||
type EC2APIProvider interface {
|
||||
DescribeRegions(in *ec2.DescribeRegionsInput) (*ec2.DescribeRegionsOutput, error)
|
||||
DescribeInstancesPages(in *ec2.DescribeInstancesInput, fn func(*ec2.DescribeInstancesOutput, bool) bool) error
|
||||
DescribeInstancesPagesWithContext(ctx context.Context, in *ec2.DescribeInstancesInput, fn func(*ec2.DescribeInstancesOutput, bool) bool, opts ...request.Option) error
|
||||
}
|
||||
|
|
|
|||
|
|
@ -130,7 +130,7 @@ func (c *mockEC2Client) DescribeRegions(in *ec2.DescribeRegionsInput) (*ec2.Desc
|
|||
return args.Get(0).(*ec2.DescribeRegionsOutput), args.Error(1)
|
||||
}
|
||||
|
||||
func (c *mockEC2Client) DescribeInstancesPages(in *ec2.DescribeInstancesInput, fn func(*ec2.DescribeInstancesOutput, bool) bool) error {
|
||||
func (c *mockEC2Client) DescribeInstancesPagesWithContext(ctx aws.Context, in *ec2.DescribeInstancesInput, fn func(*ec2.DescribeInstancesOutput, bool) bool, opts ...request.Option) error {
|
||||
args := c.Called(in, fn)
|
||||
return args.Error(0)
|
||||
}
|
||||
|
|
@ -155,8 +155,8 @@ func (c oldEC2Client) DescribeRegions(*ec2.DescribeRegionsInput) (*ec2.DescribeR
|
|||
}, nil
|
||||
}
|
||||
|
||||
func (c oldEC2Client) DescribeInstancesPages(in *ec2.DescribeInstancesInput,
|
||||
fn func(*ec2.DescribeInstancesOutput, bool) bool) error {
|
||||
func (c oldEC2Client) DescribeInstancesPagesWithContext(ctx aws.Context, in *ec2.DescribeInstancesInput,
|
||||
fn func(*ec2.DescribeInstancesOutput, bool) bool, opts ...request.Option) error {
|
||||
reservations := []*ec2.Reservation{}
|
||||
for _, r := range c.reservations {
|
||||
instances := []*ec2.Instance{}
|
||||
|
|
|
|||
Loading…
Reference in New Issue