Use containers labels instead of task labels from Docker Swarm SD (#9187) (#10311)

* Remove task labels from Docker Swarm SD (#9187)

Signed-off-by: Ujjwal Goyal <importujjwal@gmail.com>

Add container labels to Docker Swarm SD (#9187)

Signed-off-by: Ujjwal Goyal <importujjwal@gmail.com>

* Reorder labels in configuration doc

Signed-off-by: Ujjwal Goyal <importujjwal@gmail.com>
pull/10413/head
Ujjwal Goyal 3 years ago committed by GitHub
parent 097b359b41
commit 9e7ae4d963
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -30,12 +30,12 @@ import (
const (
swarmLabelTaskPrefix = swarmLabel + "task_"
swarmLabelTaskID = swarmLabelTaskPrefix + "id"
swarmLabelTaskLabelPrefix = swarmLabelTaskPrefix + "label_"
swarmLabelTaskDesiredState = swarmLabelTaskPrefix + "desired_state"
swarmLabelTaskStatus = swarmLabelTaskPrefix + "state"
swarmLabelTaskContainerID = swarmLabelTaskPrefix + "container_id"
swarmLabelTaskSlot = swarmLabelTaskPrefix + "slot"
swarmLabelTaskPortMode = swarmLabelTaskPrefix + "port_publish_mode"
swarmLabelContainerLabelPrefix = swarmLabel + "container_label_"
)
func (d *Discovery) refreshTasks(ctx context.Context) ([]*targetgroup.Group, error) {
@ -75,9 +75,11 @@ func (d *Discovery) refreshTasks(ctx context.Context) ([]*targetgroup.Group, err
commonLabels[swarmLabelTaskContainerID] = s.Status.ContainerStatus.ContainerID
}
for k, v := range s.Labels {
if s.Spec.ContainerSpec != nil {
for k, v := range s.Spec.ContainerSpec.Labels {
ln := strutil.SanitizeLabelName(k)
commonLabels[swarmLabelTaskLabelPrefix+ln] = v
commonLabels[swarmLabelContainerLabelPrefix+ln] = v
}
}
for k, v := range serviceLabels[s.ServiceID] {

@ -55,6 +55,7 @@ host: %s
for i, lbls := range []model.LabelSet{
{
"__address__": model.LabelValue("10.0.0.8:9100"),
"__meta_dockerswarm_container_label_com_docker_stack_namespace": model.LabelValue("mon"),
"__meta_dockerswarm_network_id": model.LabelValue("qvwhwd6p61k4o0ulsknqb066z"),
"__meta_dockerswarm_network_ingress": model.LabelValue("true"),
"__meta_dockerswarm_network_internal": model.LabelValue("false"),
@ -82,6 +83,7 @@ host: %s
},
{
"__address__": model.LabelValue("10.0.1.3:9100"),
"__meta_dockerswarm_container_label_com_docker_stack_namespace": model.LabelValue("mon"),
"__meta_dockerswarm_network_id": model.LabelValue("npq2closzy836m07eaq1425k3"),
"__meta_dockerswarm_network_ingress": model.LabelValue("false"),
"__meta_dockerswarm_network_internal": model.LabelValue("false"),
@ -110,6 +112,7 @@ host: %s
},
{
"__address__": model.LabelValue("10.0.1.88:80"),
"__meta_dockerswarm_container_label_com_docker_stack_namespace": model.LabelValue("mon"),
"__meta_dockerswarm_network_id": model.LabelValue("npq2closzy836m07eaq1425k3"),
"__meta_dockerswarm_network_ingress": model.LabelValue("false"),
"__meta_dockerswarm_network_internal": model.LabelValue("false"),
@ -137,6 +140,7 @@ host: %s
},
{
"__address__": model.LabelValue("10.0.0.12:9100"),
"__meta_dockerswarm_container_label_com_docker_stack_namespace": model.LabelValue("mon"),
"__meta_dockerswarm_network_id": model.LabelValue("qvwhwd6p61k4o0ulsknqb066z"),
"__meta_dockerswarm_network_ingress": model.LabelValue("true"),
"__meta_dockerswarm_network_internal": model.LabelValue("false"),
@ -164,6 +168,7 @@ host: %s
},
{
"__address__": model.LabelValue("10.0.1.7:9100"),
"__meta_dockerswarm_container_label_com_docker_stack_namespace": model.LabelValue("mon"),
"__meta_dockerswarm_network_id": model.LabelValue("npq2closzy836m07eaq1425k3"),
"__meta_dockerswarm_network_ingress": model.LabelValue("false"),
"__meta_dockerswarm_network_internal": model.LabelValue("false"),
@ -192,6 +197,7 @@ host: %s
},
{
"__address__": model.LabelValue("10.0.0.11:9100"),
"__meta_dockerswarm_container_label_com_docker_stack_namespace": model.LabelValue("mon"),
"__meta_dockerswarm_network_id": model.LabelValue("qvwhwd6p61k4o0ulsknqb066z"),
"__meta_dockerswarm_network_ingress": model.LabelValue("true"),
"__meta_dockerswarm_network_internal": model.LabelValue("false"),
@ -219,6 +225,7 @@ host: %s
},
{
"__address__": model.LabelValue("10.0.1.6:9100"),
"__meta_dockerswarm_container_label_com_docker_stack_namespace": model.LabelValue("mon"),
"__meta_dockerswarm_network_id": model.LabelValue("npq2closzy836m07eaq1425k3"),
"__meta_dockerswarm_network_ingress": model.LabelValue("false"),
"__meta_dockerswarm_network_internal": model.LabelValue("false"),
@ -247,6 +254,7 @@ host: %s
},
{
"__address__": model.LabelValue("10.0.0.10:9100"),
"__meta_dockerswarm_container_label_com_docker_stack_namespace": model.LabelValue("mon"),
"__meta_dockerswarm_network_id": model.LabelValue("qvwhwd6p61k4o0ulsknqb066z"),
"__meta_dockerswarm_network_ingress": model.LabelValue("true"),
"__meta_dockerswarm_network_internal": model.LabelValue("false"),
@ -274,6 +282,7 @@ host: %s
},
{
"__address__": model.LabelValue("10.0.1.5:9100"),
"__meta_dockerswarm_container_label_com_docker_stack_namespace": model.LabelValue("mon"),
"__meta_dockerswarm_network_id": model.LabelValue("npq2closzy836m07eaq1425k3"),
"__meta_dockerswarm_network_ingress": model.LabelValue("false"),
"__meta_dockerswarm_network_internal": model.LabelValue("false"),
@ -302,6 +311,7 @@ host: %s
},
{
"__address__": model.LabelValue("10.0.1.35:80"),
"__meta_dockerswarm_container_label_com_docker_stack_namespace": model.LabelValue("mon"),
"__meta_dockerswarm_network_id": model.LabelValue("npq2closzy836m07eaq1425k3"),
"__meta_dockerswarm_network_ingress": model.LabelValue("false"),
"__meta_dockerswarm_network_internal": model.LabelValue("false"),
@ -329,6 +339,7 @@ host: %s
},
{
"__address__": model.LabelValue("10.0.1.14:80"),
"__meta_dockerswarm_container_label_com_docker_stack_namespace": model.LabelValue("mon"),
"__meta_dockerswarm_network_id": model.LabelValue("npq2closzy836m07eaq1425k3"),
"__meta_dockerswarm_network_ingress": model.LabelValue("false"),
"__meta_dockerswarm_network_internal": model.LabelValue("false"),
@ -356,6 +367,7 @@ host: %s
},
{
"__address__": model.LabelValue("10.0.1.20:80"),
"__meta_dockerswarm_container_label_com_docker_stack_namespace": model.LabelValue("mon"),
"__meta_dockerswarm_network_id": model.LabelValue("npq2closzy836m07eaq1425k3"),
"__meta_dockerswarm_network_ingress": model.LabelValue("false"),
"__meta_dockerswarm_network_internal": model.LabelValue("false"),
@ -383,6 +395,7 @@ host: %s
},
{
"__address__": model.LabelValue("10.0.1.19:80"),
"__meta_dockerswarm_container_label_com_docker_stack_namespace": model.LabelValue("mon"),
"__meta_dockerswarm_network_id": model.LabelValue("npq2closzy836m07eaq1425k3"),
"__meta_dockerswarm_network_ingress": model.LabelValue("false"),
"__meta_dockerswarm_network_internal": model.LabelValue("false"),
@ -410,6 +423,7 @@ host: %s
},
{
"__address__": model.LabelValue("10.0.1.18:80"),
"__meta_dockerswarm_container_label_com_docker_stack_namespace": model.LabelValue("mon"),
"__meta_dockerswarm_network_id": model.LabelValue("npq2closzy836m07eaq1425k3"),
"__meta_dockerswarm_network_ingress": model.LabelValue("false"),
"__meta_dockerswarm_network_internal": model.LabelValue("false"),
@ -437,6 +451,7 @@ host: %s
},
{
"__address__": model.LabelValue("10.0.1.75:80"),
"__meta_dockerswarm_container_label_com_docker_stack_namespace": model.LabelValue("mon"),
"__meta_dockerswarm_network_id": model.LabelValue("npq2closzy836m07eaq1425k3"),
"__meta_dockerswarm_network_ingress": model.LabelValue("false"),
"__meta_dockerswarm_network_internal": model.LabelValue("false"),
@ -464,6 +479,7 @@ host: %s
},
{
"__address__": model.LabelValue("10.0.0.19:9090"),
"__meta_dockerswarm_container_label_com_docker_stack_namespace": model.LabelValue("mon"),
"__meta_dockerswarm_network_id": model.LabelValue("qvwhwd6p61k4o0ulsknqb066z"),
"__meta_dockerswarm_network_ingress": model.LabelValue("true"),
"__meta_dockerswarm_network_internal": model.LabelValue("false"),
@ -491,6 +507,7 @@ host: %s
},
{
"__address__": model.LabelValue("10.0.0.19:9093"),
"__meta_dockerswarm_container_label_com_docker_stack_namespace": model.LabelValue("mon"),
"__meta_dockerswarm_network_id": model.LabelValue("qvwhwd6p61k4o0ulsknqb066z"),
"__meta_dockerswarm_network_ingress": model.LabelValue("true"),
"__meta_dockerswarm_network_internal": model.LabelValue("false"),
@ -518,6 +535,7 @@ host: %s
},
{
"__address__": model.LabelValue("10.0.0.19:9094"),
"__meta_dockerswarm_container_label_com_docker_stack_namespace": model.LabelValue("mon"),
"__meta_dockerswarm_network_id": model.LabelValue("qvwhwd6p61k4o0ulsknqb066z"),
"__meta_dockerswarm_network_ingress": model.LabelValue("true"),
"__meta_dockerswarm_network_internal": model.LabelValue("false"),
@ -545,6 +563,7 @@ host: %s
},
{
"__address__": model.LabelValue("10.0.1.81:9090"),
"__meta_dockerswarm_container_label_com_docker_stack_namespace": model.LabelValue("mon"),
"__meta_dockerswarm_network_id": model.LabelValue("npq2closzy836m07eaq1425k3"),
"__meta_dockerswarm_network_ingress": model.LabelValue("false"),
"__meta_dockerswarm_network_internal": model.LabelValue("false"),
@ -573,6 +592,7 @@ host: %s
},
{
"__address__": model.LabelValue("10.0.1.81:9093"),
"__meta_dockerswarm_container_label_com_docker_stack_namespace": model.LabelValue("mon"),
"__meta_dockerswarm_network_id": model.LabelValue("npq2closzy836m07eaq1425k3"),
"__meta_dockerswarm_network_ingress": model.LabelValue("false"),
"__meta_dockerswarm_network_internal": model.LabelValue("false"),
@ -601,6 +621,7 @@ host: %s
},
{
"__address__": model.LabelValue("10.0.1.81:9094"),
"__meta_dockerswarm_container_label_com_docker_stack_namespace": model.LabelValue("mon"),
"__meta_dockerswarm_network_id": model.LabelValue("npq2closzy836m07eaq1425k3"),
"__meta_dockerswarm_network_ingress": model.LabelValue("false"),
"__meta_dockerswarm_network_internal": model.LabelValue("false"),
@ -629,6 +650,7 @@ host: %s
},
{
"__address__": model.LabelValue("10.0.1.24:80"),
"__meta_dockerswarm_container_label_com_docker_stack_namespace": model.LabelValue("mon"),
"__meta_dockerswarm_network_id": model.LabelValue("npq2closzy836m07eaq1425k3"),
"__meta_dockerswarm_network_ingress": model.LabelValue("false"),
"__meta_dockerswarm_network_internal": model.LabelValue("false"),
@ -656,6 +678,7 @@ host: %s
},
{
"__address__": model.LabelValue("10.0.1.32:80"),
"__meta_dockerswarm_container_label_com_docker_stack_namespace": model.LabelValue("mon"),
"__meta_dockerswarm_network_id": model.LabelValue("npq2closzy836m07eaq1425k3"),
"__meta_dockerswarm_network_ingress": model.LabelValue("false"),
"__meta_dockerswarm_network_internal": model.LabelValue("false"),
@ -683,6 +706,7 @@ host: %s
},
{
"__address__": model.LabelValue("10.0.0.16:3000"),
"__meta_dockerswarm_container_label_com_docker_stack_namespace": model.LabelValue("mon"),
"__meta_dockerswarm_network_id": model.LabelValue("qvwhwd6p61k4o0ulsknqb066z"),
"__meta_dockerswarm_network_ingress": model.LabelValue("true"),
"__meta_dockerswarm_network_internal": model.LabelValue("false"),
@ -710,6 +734,7 @@ host: %s
},
{
"__address__": model.LabelValue("10.0.1.30:3000"),
"__meta_dockerswarm_container_label_com_docker_stack_namespace": model.LabelValue("mon"),
"__meta_dockerswarm_network_id": model.LabelValue("npq2closzy836m07eaq1425k3"),
"__meta_dockerswarm_network_ingress": model.LabelValue("false"),
"__meta_dockerswarm_network_internal": model.LabelValue("false"),
@ -738,6 +763,7 @@ host: %s
},
{
"__address__": model.LabelValue("10.0.232.3:82"),
"__meta_dockerswarm_container_label_com_docker_stack_namespace": model.LabelValue("mon"),
"__meta_dockerswarm_node_address": model.LabelValue("10.0.232.3"),
"__meta_dockerswarm_node_availability": model.LabelValue("active"),
"__meta_dockerswarm_node_hostname": model.LabelValue("master-3"),
@ -760,6 +786,7 @@ host: %s
},
{
"__address__": model.LabelValue("10.0.1.22:80"),
"__meta_dockerswarm_container_label_com_docker_stack_namespace": model.LabelValue("mon"),
"__meta_dockerswarm_network_id": model.LabelValue("npq2closzy836m07eaq1425k3"),
"__meta_dockerswarm_network_ingress": model.LabelValue("false"),
"__meta_dockerswarm_network_internal": model.LabelValue("false"),

@ -792,10 +792,10 @@ created using the `port` parameter defined in the SD configuration.
Available meta labels:
* `__meta_dockerswarm_container_label_<labelname>`: each label of the container
* `__meta_dockerswarm_task_id`: the id of the task
* `__meta_dockerswarm_task_container_id`: the container id of the task
* `__meta_dockerswarm_task_desired_state`: the desired state of the task
* `__meta_dockerswarm_task_label_<labelname>`: each label of the task
* `__meta_dockerswarm_task_slot`: the slot of the task
* `__meta_dockerswarm_task_state`: the state of the task
* `__meta_dockerswarm_task_port_publish_mode`: the publish mode of the task port

Loading…
Cancel
Save