Adding Consul Enterprise Admin Partitions (#11482)

* Adding Consul Enterprise Admin Partitions

Signed-off-by: dcanadillas <dcanadillas@hashicorp.com>
This commit is contained in:
David Cañadillas 2022-10-21 14:13:01 +02:00 committed by GitHub
parent 5ac12ac351
commit 51a44e6657
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 0 deletions

View file

@ -60,6 +60,8 @@ const (
datacenterLabel = model.MetaLabelPrefix + "consul_dc" datacenterLabel = model.MetaLabelPrefix + "consul_dc"
// namespaceLabel is the name of the label containing the namespace (Consul Enterprise only). // namespaceLabel is the name of the label containing the namespace (Consul Enterprise only).
namespaceLabel = model.MetaLabelPrefix + "consul_namespace" namespaceLabel = model.MetaLabelPrefix + "consul_namespace"
// partitionLabel is the name of the label containing the Admin Partition (Consul Enterprise only).
partitionLabel = model.MetaLabelPrefix + "consul_partition"
// 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.
@ -112,6 +114,7 @@ type SDConfig struct {
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"` Namespace string `yaml:"namespace,omitempty"`
Partition string `yaml:"partition,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"`
@ -183,6 +186,7 @@ type Discovery struct {
client *consul.Client client *consul.Client
clientDatacenter string clientDatacenter string
clientNamespace string clientNamespace string
clientPartition 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.
@ -210,6 +214,7 @@ func NewDiscovery(conf *SDConfig, logger log.Logger) (*Discovery, error) {
Scheme: conf.Scheme, Scheme: conf.Scheme,
Datacenter: conf.Datacenter, Datacenter: conf.Datacenter,
Namespace: conf.Namespace, Namespace: conf.Namespace,
Partition: conf.Partition,
Token: string(conf.Token), Token: string(conf.Token),
HttpClient: wrapper, HttpClient: wrapper,
} }
@ -227,6 +232,7 @@ func NewDiscovery(conf *SDConfig, logger log.Logger) (*Discovery, error) {
refreshInterval: time.Duration(conf.RefreshInterval), refreshInterval: time.Duration(conf.RefreshInterval),
clientDatacenter: conf.Datacenter, clientDatacenter: conf.Datacenter,
clientNamespace: conf.Namespace, clientNamespace: conf.Namespace,
clientPartition: conf.Partition,
finalizer: wrapper.CloseIdleConnections, finalizer: wrapper.CloseIdleConnections,
logger: logger, logger: logger,
} }
@ -547,6 +553,7 @@ func (srv *consulService) watch(ctx context.Context, ch chan<- []*targetgroup.Gr
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), namespaceLabel: model.LabelValue(serviceNode.Service.Namespace),
partitionLabel: model.LabelValue(serviceNode.Service.Partition),
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)),

View file

@ -518,6 +518,7 @@ The following meta labels are available on targets during [relabeling](#relabel_
* `__meta_consul_address`: the address of the target * `__meta_consul_address`: the address of the target
* `__meta_consul_dc`: the datacenter name for the target * `__meta_consul_dc`: the datacenter name for the target
* `__meta_consul_health`: the health status of the service * `__meta_consul_health`: the health status of the service
* `__meta_consul_partition`: the admin partition name where the service is registered
* `__meta_consul_metadata_<key>`: each node metadata key value of the target * `__meta_consul_metadata_<key>`: each node metadata key value of the target
* `__meta_consul_node`: the node name defined for the target * `__meta_consul_node`: the node name defined for the target
* `__meta_consul_service_address`: the service address of the target * `__meta_consul_service_address`: the service address of the target
@ -536,6 +537,8 @@ The following meta labels are available on targets during [relabeling](#relabel_
[ datacenter: <string> ] [ datacenter: <string> ]
# Namespaces are only supported in Consul Enterprise. # Namespaces are only supported in Consul Enterprise.
[ namespace: <string> ] [ namespace: <string> ]
# Admin Partitions are only supported in Consul Enterprise.
[ partition: <string> ]
[ scheme: <string> | default = "http" ] [ scheme: <string> | default = "http" ]
# The username and password fields are deprecated in favor of the basic_auth configuration. # The username and password fields are deprecated in favor of the basic_auth configuration.
[ username: <string> ] [ username: <string> ]