From 3c6dd161d738bc75a4e32b44282fe576a5085e9c Mon Sep 17 00:00:00 2001 From: Fabian Reinartz Date: Fri, 14 Aug 2015 17:39:41 +0200 Subject: [PATCH] Scrape all services on empty services list. --- config/config.go | 4 +--- retrieval/discovery/consul.go | 4 ++-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/config/config.go b/config/config.go index e7ea0f6b45..0b9d4721bf 100644 --- a/config/config.go +++ b/config/config.go @@ -529,6 +529,7 @@ type ConsulSDConfig struct { Username string `yaml:"username,omitempty"` Password string `yaml:"password,omitempty"` // The list of services for which targets are discovered. + // Defaults to all services if empty. Services []string `yaml:"services"` // Catches all undefined fields and must be empty after parsing. @@ -546,9 +547,6 @@ func (c *ConsulSDConfig) UnmarshalYAML(unmarshal func(interface{}) error) error if strings.TrimSpace(c.Server) == "" { return fmt.Errorf("Consul SD configuration requires a server address") } - if len(c.Services) == 0 { - return fmt.Errorf("Consul SD configuration requires at least one service name") - } return checkOverflow(c.XXX, "consul_sd_config") } diff --git a/retrieval/discovery/consul.go b/retrieval/discovery/consul.go index 83310cd644..587af210cc 100644 --- a/retrieval/discovery/consul.go +++ b/retrieval/discovery/consul.go @@ -122,7 +122,7 @@ func (cd *ConsulDiscovery) Sources() []string { srcs := make([]string, 0, len(srvs)) for name := range srvs { - if _, ok := cd.scrapedServices[name]; ok { + if _, ok := cd.scrapedServices[name]; len(cd.scrapedServices) == 0 || ok { srcs = append(srcs, name) } } @@ -199,7 +199,7 @@ func (cd *ConsulDiscovery) watchServices(update chan<- *consulService, done <-ch } // Check for new services. for name := range srvs { - if _, ok := cd.scrapedServices[name]; !ok { + if _, ok := cd.scrapedServices[name]; len(cd.scrapedServices) > 0 && !ok { continue } srv, ok := cd.services[name]