discovery/ec2: pass context to the client (#5234)

Signed-off-by: Simon Pasquier <spasquie@redhat.com>
pull/5275/head
Simon Pasquier 6 years ago committed by GitHub
parent 4997dcb4a1
commit 8f578d9c6b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -167,7 +167,7 @@ func (d *Discovery) Run(ctx context.Context, ch chan<- []*targetgroup.Group) {
defer ticker.Stop()
// Get an initial set right away.
tg, err := d.refresh()
tg, err := d.refresh(ctx)
if err != nil {
level.Error(d.logger).Log("msg", "Refresh failed", "err", err)
} else {
@ -181,7 +181,7 @@ func (d *Discovery) Run(ctx context.Context, ch chan<- []*targetgroup.Group) {
for {
select {
case <-ticker.C:
tg, err := d.refresh()
tg, err := d.refresh(ctx)
if err != nil {
level.Error(d.logger).Log("msg", "Refresh failed", "err", err)
continue
@ -198,7 +198,7 @@ func (d *Discovery) Run(ctx context.Context, ch chan<- []*targetgroup.Group) {
}
}
func (d *Discovery) refresh() (tg *targetgroup.Group, err error) {
func (d *Discovery) refresh(ctx context.Context) (tg *targetgroup.Group, err error) {
t0 := time.Now()
defer func() {
ec2SDRefreshDuration.Observe(time.Since(t0).Seconds())
@ -236,7 +236,7 @@ func (d *Discovery) refresh() (tg *targetgroup.Group, err error) {
input := &ec2.DescribeInstancesInput{Filters: filters}
if err = ec2s.DescribeInstancesPages(input, func(p *ec2.DescribeInstancesOutput, lastPage bool) bool {
if err = ec2s.DescribeInstancesPagesWithContext(ctx, input, func(p *ec2.DescribeInstancesOutput, lastPage bool) bool {
for _, r := range p.Reservations {
for _, inst := range r.Instances {
if inst.PrivateIpAddress == nil {

Loading…
Cancel
Save