From 4997dcb4a173fa341bb2b7e65704ee59dc78253e Mon Sep 17 00:00:00 2001 From: Simon Pasquier Date: Tue, 26 Feb 2019 14:47:43 +0100 Subject: [PATCH] discovery/gce: pass context to the client (#5233) Signed-off-by: Simon Pasquier --- discovery/gce/gce.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/discovery/gce/gce.go b/discovery/gce/gce.go index 5a468b9d0..da9e2f4c9 100644 --- a/discovery/gce/gce.go +++ b/discovery/gce/gce.go @@ -154,7 +154,7 @@ func NewDiscovery(conf SDConfig, logger log.Logger) (*Discovery, error) { // Run implements the Discoverer interface. func (d *Discovery) Run(ctx context.Context, ch chan<- []*targetgroup.Group) { // 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 { @@ -170,7 +170,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 @@ -185,7 +185,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() { gceSDRefreshDuration.Observe(time.Since(t0).Seconds()) @@ -202,7 +202,7 @@ func (d *Discovery) refresh() (tg *targetgroup.Group, err error) { if len(d.filter) > 0 { ilc = ilc.Filter(d.filter) } - err = ilc.Pages(context.TODO(), func(l *compute.InstanceList) error { + err = ilc.Pages(ctx, func(l *compute.InstanceList) error { for _, inst := range l.Items { if len(inst.NetworkInterfaces) == 0 { continue