mirror of
https://github.com/prometheus/prometheus.git
synced 2024-12-28 06:59:40 -08:00
Pass through current agent Consul datacenter name
Instead of only filling __meta_consul_dc when datacenter is set in consul_sd_config this change fills the label based on what the agent reports it's current data center is, if datacenter isn't manually set, otherwise it uses whatever datacenter was set to.
This commit is contained in:
parent
60967736fa
commit
48e461f7db
|
@ -54,6 +54,7 @@ const (
|
|||
type ConsulDiscovery struct {
|
||||
client *consul.Client
|
||||
clientConf *consul.Config
|
||||
clientDatacenter string
|
||||
tagSeparator string
|
||||
scrapedServices map[string]struct{}
|
||||
|
||||
|
@ -95,6 +96,17 @@ func NewConsulDiscovery(conf *config.ConsulSDConfig) *ConsulDiscovery {
|
|||
scrapedServices: map[string]struct{}{},
|
||||
services: map[string]*consulService{},
|
||||
}
|
||||
// If the datacenter isn't set in the clientConf, let's get it from the local Consul agent
|
||||
// (Consul default is to use local node's datacenter if one isn't given for a query).
|
||||
if clientConf.Datacenter == "" {
|
||||
info, err := client.Agent().Self()
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("discovery.NewConsulDiscovery: %s", err))
|
||||
}
|
||||
cd.clientDatacenter = info["Config"]["Datacenter"].(string)
|
||||
} else {
|
||||
cd.clientDatacenter = clientConf.Datacenter
|
||||
}
|
||||
for _, name := range conf.Services {
|
||||
cd.scrapedServices[name] = struct{}{}
|
||||
}
|
||||
|
@ -214,7 +226,7 @@ func (cd *ConsulDiscovery) watchServices(update chan<- *consulService, done <-ch
|
|||
}
|
||||
srv.tgroup.Labels = clientmodel.LabelSet{
|
||||
ConsulServiceLabel: clientmodel.LabelValue(name),
|
||||
ConsulDCLabel: clientmodel.LabelValue(cd.clientConf.Datacenter),
|
||||
ConsulDCLabel: clientmodel.LabelValue(cd.clientDatacenter),
|
||||
}
|
||||
update <- srv
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue