diff --git a/discovery/kubernetes/endpoints.go b/discovery/kubernetes/endpoints.go index b700399ff..69ea4ce59 100644 --- a/discovery/kubernetes/endpoints.go +++ b/discovery/kubernetes/endpoints.go @@ -178,10 +178,12 @@ func endpointsSource(ep *apiv1.Endpoints) string { } const ( - endpointsNameLabel = metaLabelPrefix + "endpoints_name" - endpointReadyLabel = metaLabelPrefix + "endpoint_ready" - endpointPortNameLabel = metaLabelPrefix + "endpoint_port_name" - endpointPortProtocolLabel = metaLabelPrefix + "endpoint_port_protocol" + endpointsNameLabel = metaLabelPrefix + "endpoints_name" + endpointReadyLabel = metaLabelPrefix + "endpoint_ready" + endpointPortNameLabel = metaLabelPrefix + "endpoint_port_name" + endpointPortProtocolLabel = metaLabelPrefix + "endpoint_port_protocol" + endpointAddressTargetKindLabel = metaLabelPrefix + "endpoint_address_target_kind" + endpointAddressTargetNameLabel = metaLabelPrefix + "endpoint_address_target_name" ) func (e *Endpoints) buildEndpoints(eps *apiv1.Endpoints) *targetgroup.Group { @@ -210,6 +212,11 @@ func (e *Endpoints) buildEndpoints(eps *apiv1.Endpoints) *targetgroup.Group { endpointReadyLabel: lv(ready), } + if addr.TargetRef != nil { + target[model.LabelName(endpointAddressTargetKindLabel)] = lv(addr.TargetRef.Kind) + target[model.LabelName(endpointAddressTargetNameLabel)] = lv(addr.TargetRef.Name) + } + pod := e.resolvePodRef(addr.TargetRef) if pod == nil { // This target is not a Pod, so don't continue with Pod specific logic. diff --git a/discovery/kubernetes/endpoints_test.go b/discovery/kubernetes/endpoints_test.go index f7fe99f9d..8b042ac26 100644 --- a/discovery/kubernetes/endpoints_test.go +++ b/discovery/kubernetes/endpoints_test.go @@ -199,20 +199,22 @@ func TestEndpointsDiscoveryAdd(t *testing.T) { { Targets: []model.LabelSet{ { - "__address__": "4.3.2.1:9000", - "__meta_kubernetes_endpoint_port_name": "testport", - "__meta_kubernetes_endpoint_port_protocol": "TCP", - "__meta_kubernetes_endpoint_ready": "true", - "__meta_kubernetes_pod_name": "testpod", - "__meta_kubernetes_pod_ip": "1.2.3.4", - "__meta_kubernetes_pod_ready": "unknown", - "__meta_kubernetes_pod_node_name": "testnode", - "__meta_kubernetes_pod_host_ip": "2.3.4.5", - "__meta_kubernetes_pod_container_name": "c1", - "__meta_kubernetes_pod_container_port_name": "mainport", - "__meta_kubernetes_pod_container_port_number": "9000", - "__meta_kubernetes_pod_container_port_protocol": "TCP", - "__meta_kubernetes_pod_uid": "deadbeef", + "__address__": "4.3.2.1:9000", + "__meta_kubernetes_endpoint_port_name": "testport", + "__meta_kubernetes_endpoint_port_protocol": "TCP", + "__meta_kubernetes_endpoint_ready": "true", + "__meta_kubernetes_endpoint_address_target_kind": "Pod", + "__meta_kubernetes_endpoint_address_target_name": "testpod", + "__meta_kubernetes_pod_name": "testpod", + "__meta_kubernetes_pod_ip": "1.2.3.4", + "__meta_kubernetes_pod_ready": "unknown", + "__meta_kubernetes_pod_node_name": "testnode", + "__meta_kubernetes_pod_host_ip": "2.3.4.5", + "__meta_kubernetes_pod_container_name": "c1", + "__meta_kubernetes_pod_container_port_name": "mainport", + "__meta_kubernetes_pod_container_port_number": "9000", + "__meta_kubernetes_pod_container_port_protocol": "TCP", + "__meta_kubernetes_pod_uid": "deadbeef", }, { "__address__": "1.2.3.4:9001", diff --git a/docs/configuration/configuration.md b/docs/configuration/configuration.md index 809287f4a..605455254 100644 --- a/docs/configuration/configuration.md +++ b/docs/configuration/configuration.md @@ -670,6 +670,8 @@ Available meta labels: * `__meta_kubernetes_endpoint_ready`: Set to `true` or `false` for the endpoint's ready state. * `__meta_kubernetes_endpoint_port_name`: Name of the endpoint port. * `__meta_kubernetes_endpoint_port_protocol`: Protocol of the endpoint port. + * `__meta_kubernetes_endpoint_address_target_kind`: Kind of the endpoint address target. + * `__meta_kubernetes_endpoint_address_target_name`: Name of the endpoint address target. * If the endpoints belong to a service, all labels of the `role: service` discovery are attached. * For all targets backed by a pod, all labels of the `role: pod` discovery are attached.