Merge pull request #990 from prometheus/fabxc/allconsul

Scrape all services on empty services list.
This commit is contained in:
Fabian Reinartz 2015-08-14 17:46:45 +02:00
commit d8f5da9152
2 changed files with 3 additions and 5 deletions

View file

@ -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")
}

View file

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