discovery/gce/gce.go
func NewDiscovery(conf SDConfig, logger log.Logger) (*Discovery, error) {
	d := &Discovery{
		project:      conf.Project,
		zone:         conf.Zone,
		filter:       conf.Filter,
		port:         conf.Port,
		tagSeparator: conf.TagSeparator,
	}
	var err error
	d.client, err = google.DefaultClient(context.Background(), compute.ComputeReadonlyScope)
	if err != nil {
		return nil, errors.Wrap(err, "error setting up communication with GCE service")
	}
	d.svc, err = compute.NewService(context.Background(), option.WithHTTPClient(d.client))
	if err != nil {
		return nil, errors.Wrap(err, "error setting up communication with GCE service")
	}
	d.isvc = compute.NewInstancesService(d.svc)

	d.Discovery = refresh.NewDiscovery(
		logger,
		"gce",
		time.Duration(conf.RefreshInterval),
		d.refresh,
	)
	return d, nil
}
func NewDiscovery(conf SDConfig, logger log.Logger) (*Discovery, error) {
	d := &Discovery{
		project:      conf.Project,
		zone:         conf.Zone,
		filter:       conf.Filter,
		port:         conf.Port,
		tagSeparator: conf.TagSeparator,
	}
	var err error
	d.client, err = google.DefaultClient(context.Background(), compute.ComputeReadonlyScope)
	if err != nil {
		return nil, errors.Wrap(err, "error setting up communication with GCE service")
	}
	d.svc, err = compute.NewService(context.Background(), option.WithHTTPClient(d.client))
	if err != nil {
		return nil, errors.Wrap(err, "error setting up communication with GCE service")
	}
	d.isvc = compute.NewInstancesService(d.svc)

	d.Discovery = refresh.NewDiscovery(
		logger,
		"gce",
		time.Duration(conf.RefreshInterval),
		d.refresh,
	)
	return d, nil
}
// NewDiscovery returns a new Discovery which periodically refreshes its targets.