mirror of
https://github.com/prometheus/prometheus.git
synced 2025-01-13 06:47:28 -08:00
Merge pull request #8900 from fhemberger/feat/consul_sd_namespace
consul_sd: Add namespace support for Consul Enterprise
This commit is contained in:
commit
2b55017379
|
@ -60,6 +60,8 @@ const (
|
||||||
servicePortLabel = model.MetaLabelPrefix + "consul_service_port"
|
servicePortLabel = model.MetaLabelPrefix + "consul_service_port"
|
||||||
// datacenterLabel is the name of the label containing the datacenter ID.
|
// datacenterLabel is the name of the label containing the datacenter ID.
|
||||||
datacenterLabel = model.MetaLabelPrefix + "consul_dc"
|
datacenterLabel = model.MetaLabelPrefix + "consul_dc"
|
||||||
|
// namespaceLabel is the name of the label containing the namespace (Consul Enterprise only).
|
||||||
|
namespaceLabel = model.MetaLabelPrefix + "consul_namespace"
|
||||||
// taggedAddressesLabel is the prefix for the labels mapping to a target's tagged addresses.
|
// taggedAddressesLabel is the prefix for the labels mapping to a target's tagged addresses.
|
||||||
taggedAddressesLabel = model.MetaLabelPrefix + "consul_tagged_address_"
|
taggedAddressesLabel = model.MetaLabelPrefix + "consul_tagged_address_"
|
||||||
// serviceIDLabel is the name of the label containing the service ID.
|
// serviceIDLabel is the name of the label containing the service ID.
|
||||||
|
@ -110,6 +112,7 @@ type SDConfig struct {
|
||||||
Server string `yaml:"server,omitempty"`
|
Server string `yaml:"server,omitempty"`
|
||||||
Token config.Secret `yaml:"token,omitempty"`
|
Token config.Secret `yaml:"token,omitempty"`
|
||||||
Datacenter string `yaml:"datacenter,omitempty"`
|
Datacenter string `yaml:"datacenter,omitempty"`
|
||||||
|
Namespace string `yaml:"namespace,omitempty"`
|
||||||
TagSeparator string `yaml:"tag_separator,omitempty"`
|
TagSeparator string `yaml:"tag_separator,omitempty"`
|
||||||
Scheme string `yaml:"scheme,omitempty"`
|
Scheme string `yaml:"scheme,omitempty"`
|
||||||
Username string `yaml:"username,omitempty"`
|
Username string `yaml:"username,omitempty"`
|
||||||
|
@ -168,6 +171,7 @@ func (c *SDConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
||||||
type Discovery struct {
|
type Discovery struct {
|
||||||
client *consul.Client
|
client *consul.Client
|
||||||
clientDatacenter string
|
clientDatacenter string
|
||||||
|
clientNamespace string
|
||||||
tagSeparator string
|
tagSeparator string
|
||||||
watchedServices []string // Set of services which will be discovered.
|
watchedServices []string // Set of services which will be discovered.
|
||||||
watchedTags []string // Tags used to filter instances of a service.
|
watchedTags []string // Tags used to filter instances of a service.
|
||||||
|
@ -205,6 +209,7 @@ func NewDiscovery(conf *SDConfig, logger log.Logger) (*Discovery, error) {
|
||||||
Address: conf.Server,
|
Address: conf.Server,
|
||||||
Scheme: conf.Scheme,
|
Scheme: conf.Scheme,
|
||||||
Datacenter: conf.Datacenter,
|
Datacenter: conf.Datacenter,
|
||||||
|
Namespace: conf.Namespace,
|
||||||
Token: string(conf.Token),
|
Token: string(conf.Token),
|
||||||
HttpAuth: &consul.HttpBasicAuth{
|
HttpAuth: &consul.HttpBasicAuth{
|
||||||
Username: conf.Username,
|
Username: conf.Username,
|
||||||
|
@ -225,6 +230,7 @@ func NewDiscovery(conf *SDConfig, logger log.Logger) (*Discovery, error) {
|
||||||
allowStale: conf.AllowStale,
|
allowStale: conf.AllowStale,
|
||||||
refreshInterval: time.Duration(conf.RefreshInterval),
|
refreshInterval: time.Duration(conf.RefreshInterval),
|
||||||
clientDatacenter: conf.Datacenter,
|
clientDatacenter: conf.Datacenter,
|
||||||
|
clientNamespace: conf.Namespace,
|
||||||
finalizer: transport.CloseIdleConnections,
|
finalizer: transport.CloseIdleConnections,
|
||||||
logger: logger,
|
logger: logger,
|
||||||
}
|
}
|
||||||
|
@ -543,6 +549,7 @@ func (srv *consulService) watch(ctx context.Context, ch chan<- []*targetgroup.Gr
|
||||||
model.AddressLabel: model.LabelValue(addr),
|
model.AddressLabel: model.LabelValue(addr),
|
||||||
addressLabel: model.LabelValue(serviceNode.Node.Address),
|
addressLabel: model.LabelValue(serviceNode.Node.Address),
|
||||||
nodeLabel: model.LabelValue(serviceNode.Node.Node),
|
nodeLabel: model.LabelValue(serviceNode.Node.Node),
|
||||||
|
namespaceLabel: model.LabelValue(serviceNode.Service.Namespace),
|
||||||
tagsLabel: model.LabelValue(tags),
|
tagsLabel: model.LabelValue(tags),
|
||||||
serviceAddressLabel: model.LabelValue(serviceNode.Service.Address),
|
serviceAddressLabel: model.LabelValue(serviceNode.Service.Address),
|
||||||
servicePortLabel: model.LabelValue(strconv.Itoa(serviceNode.Service.Port)),
|
servicePortLabel: model.LabelValue(strconv.Itoa(serviceNode.Service.Port)),
|
||||||
|
|
|
@ -440,6 +440,8 @@ The following meta labels are available on targets during [relabeling](#relabel_
|
||||||
[ server: <host> | default = "localhost:8500" ]
|
[ server: <host> | default = "localhost:8500" ]
|
||||||
[ token: <secret> ]
|
[ token: <secret> ]
|
||||||
[ datacenter: <string> ]
|
[ datacenter: <string> ]
|
||||||
|
# Namespaces are only supported in Consul Enterprise.
|
||||||
|
[ namespace: <string> ]
|
||||||
[ scheme: <string> | default = "http" ]
|
[ scheme: <string> | default = "http" ]
|
||||||
[ username: <string> ]
|
[ username: <string> ]
|
||||||
[ password: <secret> ]
|
[ password: <secret> ]
|
||||||
|
|
Loading…
Reference in a new issue