discovery/gce: pass context to the client (#5233)

Signed-off-by: Simon Pasquier <spasquie@redhat.com>
This commit is contained in:
Simon Pasquier 2019-02-26 14:47:43 +01:00 committed by GitHub
parent 9040dddd0c
commit 4997dcb4a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 4 deletions

View File

@ -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