Browse Source

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

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

8
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

Loading…
Cancel
Save