From 97464236c76301dab933ab8407f7ebe0ee1ec292 Mon Sep 17 00:00:00 2001 From: Callum Styan Date: Mon, 8 Jan 2018 15:59:18 -0800 Subject: [PATCH] comments with TargetProvider should read Discoverer instead (#3667) --- discovery/azure/azure.go | 4 ++-- discovery/consul/consul.go | 2 +- discovery/dns/dns.go | 4 ++-- discovery/ec2/ec2.go | 4 ++-- discovery/file/file.go | 2 +- discovery/gce/gce.go | 4 ++-- discovery/kubernetes/endpoints.go | 2 +- discovery/kubernetes/ingress.go | 2 +- discovery/kubernetes/kubernetes.go | 4 ++-- discovery/kubernetes/node.go | 2 +- discovery/kubernetes/node_test.go | 4 ++-- discovery/kubernetes/pod.go | 2 +- discovery/kubernetes/service.go | 2 +- discovery/marathon/marathon.go | 2 +- discovery/openstack/hypervisor.go | 2 +- discovery/openstack/instance.go | 2 +- discovery/openstack/openstack.go | 2 +- discovery/triton/triton.go | 4 ++-- discovery/zookeeper/zookeeper.go | 4 ++-- retrieval/helpers_test.go | 24 ------------------------ 20 files changed, 27 insertions(+), 51 deletions(-) diff --git a/discovery/azure/azure.go b/discovery/azure/azure.go index 782b224eac..eaf5501e20 100644 --- a/discovery/azure/azure.go +++ b/discovery/azure/azure.go @@ -95,7 +95,7 @@ func init() { } // Discovery periodically performs Azure-SD requests. It implements -// the TargetProvider interface. +// the Discoverer interface. type Discovery struct { cfg *SDConfig interval time.Duration @@ -116,7 +116,7 @@ func NewDiscovery(cfg *SDConfig, logger log.Logger) *Discovery { } } -// Run implements the TargetProvider interface. +// Run implements the Discoverer interface. func (d *Discovery) Run(ctx context.Context, ch chan<- []*targetgroup.Group) { ticker := time.NewTicker(d.interval) defer ticker.Stop() diff --git a/discovery/consul/consul.go b/discovery/consul/consul.go index 66600dfb5e..02045faee8 100644 --- a/discovery/consul/consul.go +++ b/discovery/consul/consul.go @@ -202,7 +202,7 @@ func (d *Discovery) shouldWatch(name string) bool { return false } -// Run implements the TargetProvider interface. +// Run implements the Discoverer interface. func (d *Discovery) Run(ctx context.Context, ch chan<- []*targetgroup.Group) { // Watched services and their cancelation functions. services := map[string]func(){} diff --git a/discovery/dns/dns.go b/discovery/dns/dns.go index f4b8676bbd..709d44cba0 100644 --- a/discovery/dns/dns.go +++ b/discovery/dns/dns.go @@ -102,7 +102,7 @@ func init() { } // Discovery periodically performs DNS-SD requests. It implements -// the TargetProvider interface. +// the Discoverer interface. type Discovery struct { names []string @@ -136,7 +136,7 @@ func NewDiscovery(conf SDConfig, logger log.Logger) *Discovery { } } -// Run implements the TargetProvider interface. +// Run implements the Discoverer interface. func (d *Discovery) Run(ctx context.Context, ch chan<- []*targetgroup.Group) { ticker := time.NewTicker(d.interval) defer ticker.Stop() diff --git a/discovery/ec2/ec2.go b/discovery/ec2/ec2.go index 81875ba59b..6ac985ef40 100644 --- a/discovery/ec2/ec2.go +++ b/discovery/ec2/ec2.go @@ -117,7 +117,7 @@ func init() { } // Discovery periodically performs EC2-SD requests. It implements -// the TargetProvider interface. +// the Discoverer interface. type Discovery struct { aws *aws.Config interval time.Duration @@ -149,7 +149,7 @@ func NewDiscovery(conf *SDConfig, logger log.Logger) *Discovery { } } -// Run implements the TargetProvider interface. +// Run implements the Discoverer interface. func (d *Discovery) Run(ctx context.Context, ch chan<- []*targetgroup.Group) { ticker := time.NewTicker(d.interval) defer ticker.Stop() diff --git a/discovery/file/file.go b/discovery/file/file.go index f17d551917..5de5814afe 100644 --- a/discovery/file/file.go +++ b/discovery/file/file.go @@ -221,7 +221,7 @@ func (d *Discovery) watchFiles() { } } -// Run implements the TargetProvider interface. +// Run implements the Discoverer interface. func (d *Discovery) Run(ctx context.Context, ch chan<- []*targetgroup.Group) { watcher, err := fsnotify.NewWatcher() if err != nil { diff --git a/discovery/gce/gce.go b/discovery/gce/gce.go index 52b5563568..fb37276bc9 100644 --- a/discovery/gce/gce.go +++ b/discovery/gce/gce.go @@ -114,7 +114,7 @@ func init() { } // Discovery periodically performs GCE-SD requests. It implements -// the TargetProvider interface. +// the Discoverer interface. type Discovery struct { project string zone string @@ -155,7 +155,7 @@ func NewDiscovery(conf SDConfig, logger log.Logger) (*Discovery, error) { return gd, nil } -// Run implements the TargetProvider interface. +// 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() diff --git a/discovery/kubernetes/endpoints.go b/discovery/kubernetes/endpoints.go index 62ccc9f5b7..97729b1170 100644 --- a/discovery/kubernetes/endpoints.go +++ b/discovery/kubernetes/endpoints.go @@ -58,7 +58,7 @@ func NewEndpoints(l log.Logger, svc, eps, pod cache.SharedInformer) *Endpoints { return ep } -// Run implements the retrieval.TargetProvider interface. +// Run implements the Discoverer interface. func (e *Endpoints) Run(ctx context.Context, ch chan<- []*targetgroup.Group) { // Send full initial set of endpoint targets. var initial []*targetgroup.Group diff --git a/discovery/kubernetes/ingress.go b/discovery/kubernetes/ingress.go index 58998ccdcf..07b5eb143a 100644 --- a/discovery/kubernetes/ingress.go +++ b/discovery/kubernetes/ingress.go @@ -38,7 +38,7 @@ func NewIngress(l log.Logger, inf cache.SharedInformer) *Ingress { return &Ingress{logger: l, informer: inf, store: inf.GetStore()} } -// Run implements the TargetProvider interface. +// Run implements the Discoverer interface. func (s *Ingress) Run(ctx context.Context, ch chan<- []*targetgroup.Group) { // Send full initial set of pod targets. var initial []*targetgroup.Group diff --git a/discovery/kubernetes/kubernetes.go b/discovery/kubernetes/kubernetes.go index 1e92e64445..699ab17c97 100644 --- a/discovery/kubernetes/kubernetes.go +++ b/discovery/kubernetes/kubernetes.go @@ -152,7 +152,7 @@ func init() { } } -// Discovery implements the TargetProvider interface for discovering +// Discovery implements the Discoverer interface for discovering // targets from Kubernetes. type Discovery struct { client kubernetes.Interface @@ -244,7 +244,7 @@ func New(l log.Logger, conf *SDConfig) (*Discovery, error) { const resyncPeriod = 10 * time.Minute -// Run implements the TargetProvider interface. +// Run implements the Discoverer interface. func (d *Discovery) Run(ctx context.Context, ch chan<- []*targetgroup.Group) { rclient := d.client.Core().RESTClient() reclient := d.client.Extensions().RESTClient() diff --git a/discovery/kubernetes/node.go b/discovery/kubernetes/node.go index 337a2f234d..253146e6cb 100644 --- a/discovery/kubernetes/node.go +++ b/discovery/kubernetes/node.go @@ -44,7 +44,7 @@ func NewNode(l log.Logger, inf cache.SharedInformer) *Node { return &Node{logger: l, informer: inf, store: inf.GetStore()} } -// Run implements the TargetProvider interface. +// Run implements the Discoverer interface. func (n *Node) Run(ctx context.Context, ch chan<- []*targetgroup.Group) { // Send full initial set of pod targets. var initial []*targetgroup.Group diff --git a/discovery/kubernetes/node_test.go b/discovery/kubernetes/node_test.go index 489d05b6a8..551ee60a0d 100644 --- a/discovery/kubernetes/node_test.go +++ b/discovery/kubernetes/node_test.go @@ -103,12 +103,12 @@ func (i *fakeInformer) Update(obj interface{}) { } } -type targetProvider interface { +type discoverer interface { Run(ctx context.Context, up chan<- []*targetgroup.Group) } type k8sDiscoveryTest struct { - discovery targetProvider + discovery discoverer afterStart func() expectedInitial []*targetgroup.Group expectedRes []*targetgroup.Group diff --git a/discovery/kubernetes/pod.go b/discovery/kubernetes/pod.go index f2d2706f32..95e9f25b92 100644 --- a/discovery/kubernetes/pod.go +++ b/discovery/kubernetes/pod.go @@ -50,7 +50,7 @@ func NewPod(l log.Logger, pods cache.SharedInformer) *Pod { } } -// Run implements the TargetProvider interface. +// Run implements the Discoverer interface. func (p *Pod) Run(ctx context.Context, ch chan<- []*targetgroup.Group) { // Send full initial set of pod targets. var initial []*targetgroup.Group diff --git a/discovery/kubernetes/service.go b/discovery/kubernetes/service.go index 1c6c97465b..09856ed06b 100644 --- a/discovery/kubernetes/service.go +++ b/discovery/kubernetes/service.go @@ -44,7 +44,7 @@ func NewService(l log.Logger, inf cache.SharedInformer) *Service { return &Service{logger: l, informer: inf, store: inf.GetStore()} } -// Run implements the TargetProvider interface. +// Run implements the Discoverer interface. func (s *Service) Run(ctx context.Context, ch chan<- []*targetgroup.Group) { // Send full initial set of pod targets. var initial []*targetgroup.Group diff --git a/discovery/marathon/marathon.go b/discovery/marathon/marathon.go index 5dff4f98c5..8239212dac 100644 --- a/discovery/marathon/marathon.go +++ b/discovery/marathon/marathon.go @@ -175,7 +175,7 @@ func NewDiscovery(conf SDConfig, logger log.Logger) (*Discovery, error) { }, nil } -// Run implements the TargetProvider interface. +// Run implements the Discoverer interface. func (d *Discovery) Run(ctx context.Context, ch chan<- []*targetgroup.Group) { for { select { diff --git a/discovery/openstack/hypervisor.go b/discovery/openstack/hypervisor.go index c18e2d2132..360eedb0ae 100644 --- a/discovery/openstack/hypervisor.go +++ b/discovery/openstack/hypervisor.go @@ -53,7 +53,7 @@ func NewHypervisorDiscovery(opts *gophercloud.AuthOptions, region: region, interval: interval, port: port, logger: l} } -// Run implements the TargetProvider interface. +// Run implements the Discoverer interface. func (h *HypervisorDiscovery) Run(ctx context.Context, ch chan<- []*targetgroup.Group) { // Get an initial set right away. tg, err := h.refresh() diff --git a/discovery/openstack/instance.go b/discovery/openstack/instance.go index bed9344580..f588f65737 100644 --- a/discovery/openstack/instance.go +++ b/discovery/openstack/instance.go @@ -62,7 +62,7 @@ func NewInstanceDiscovery(opts *gophercloud.AuthOptions, region: region, interval: interval, port: port, logger: l} } -// Run implements the TargetProvider interface. +// Run implements the Discoverer interface. func (i *InstanceDiscovery) Run(ctx context.Context, ch chan<- []*targetgroup.Group) { // Get an initial set right away. tg, err := i.refresh() diff --git a/discovery/openstack/openstack.go b/discovery/openstack/openstack.go index b1bafd85d8..127154dab0 100644 --- a/discovery/openstack/openstack.go +++ b/discovery/openstack/openstack.go @@ -112,7 +112,7 @@ func init() { } // Discovery periodically performs OpenStack-SD requests. It implements -// the TargetProvider interface. +// the Discoverer interface. type Discovery interface { Run(ctx context.Context, ch chan<- []*targetgroup.Group) refresh() (tg *targetgroup.Group, err error) diff --git a/discovery/triton/triton.go b/discovery/triton/triton.go index b6fde88ba0..90622afcee 100644 --- a/discovery/triton/triton.go +++ b/discovery/triton/triton.go @@ -115,7 +115,7 @@ type DiscoveryResponse struct { } // Discovery periodically performs Triton-SD requests. It implements -// the TargetProvider interface. +// the Discoverer interface. type Discovery struct { client *http.Client interval time.Duration @@ -151,7 +151,7 @@ func New(logger log.Logger, conf *SDConfig) (*Discovery, error) { }, nil } -// Run implements the TargetProvider interface. +// Run implements the Discoverer interface. func (d *Discovery) Run(ctx context.Context, ch chan<- []*targetgroup.Group) { defer close(ch) diff --git a/discovery/zookeeper/zookeeper.go b/discovery/zookeeper/zookeeper.go index b76d07b55b..05b2b7486a 100644 --- a/discovery/zookeeper/zookeeper.go +++ b/discovery/zookeeper/zookeeper.go @@ -113,7 +113,7 @@ func (c *NerveSDConfig) UnmarshalYAML(unmarshal func(interface{}) error) error { return nil } -// Discovery implements the TargetProvider interface for discovering +// Discovery implements the Discoverer interface for discovering // targets from Zookeeper. type Discovery struct { conn *zk.Conn @@ -169,7 +169,7 @@ func NewDiscovery( return sd } -// Run implements the TargetProvider interface. +// Run implements the Discoverer interface. func (d *Discovery) Run(ctx context.Context, ch chan<- []*targetgroup.Group) { defer func() { for _, tc := range d.treeCaches { diff --git a/retrieval/helpers_test.go b/retrieval/helpers_test.go index 6d3d92ed6e..018bf9c197 100644 --- a/retrieval/helpers_test.go +++ b/retrieval/helpers_test.go @@ -14,7 +14,6 @@ package retrieval import ( - "github.com/prometheus/prometheus/discovery/targetgroup" "github.com/prometheus/prometheus/pkg/labels" "github.com/prometheus/prometheus/storage" ) @@ -69,26 +68,3 @@ func (a *collectResultAppender) Add(m labels.Labels, t int64, v float64) (uint64 func (a *collectResultAppender) Commit() error { return nil } func (a *collectResultAppender) Rollback() error { return nil } - -// fakeTargetProvider implements a TargetProvider and allows manual injection -// of TargetGroups through the update channel. -type fakeTargetProvider struct { - sources []string - update chan *targetgroup.Group -} - -func (tp *fakeTargetProvider) Run(ch chan<- targetgroup.Group, done <-chan struct{}) { - defer close(ch) - for { - select { - case tg := <-tp.update: - ch <- *tg - case <-done: - return - } - } -} - -func (tp *fakeTargetProvider) Sources() []string { - return tp.sources -}