diff --git a/discovery/kubernetes/endpoints.go b/discovery/kubernetes/endpoints.go index ca7f31323..83e39d973 100644 --- a/discovery/kubernetes/endpoints.go +++ b/discovery/kubernetes/endpoints.go @@ -192,6 +192,8 @@ func endpointsSourceFromNamespaceAndName(namespace, name string) string { const ( endpointsNameLabel = metaLabelPrefix + "endpoints_name" + endpointNodeName = metaLabelPrefix + "endpoint_node_name" + endpointHostname = metaLabelPrefix + "endpoint_hostname" endpointReadyLabel = metaLabelPrefix + "endpoint_ready" endpointPortNameLabel = metaLabelPrefix + "endpoint_port_name" endpointPortProtocolLabel = metaLabelPrefix + "endpoint_port_protocol" @@ -230,6 +232,13 @@ func (e *Endpoints) buildEndpoints(eps *apiv1.Endpoints) *targetgroup.Group { target[model.LabelName(endpointAddressTargetNameLabel)] = lv(addr.TargetRef.Name) } + if addr.NodeName != nil { + target[model.LabelName(endpointNodeName)] = lv(*addr.NodeName) + } + if addr.Hostname != "" { + target[model.LabelName(endpointHostname)] = lv(addr.Hostname) + } + 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 bd7f072fd..7dced34a5 100644 --- a/discovery/kubernetes/endpoints_test.go +++ b/discovery/kubernetes/endpoints_test.go @@ -25,6 +25,7 @@ import ( ) func makeEndpoints() *v1.Endpoints { + var nodeName = "foobar" return &v1.Endpoints{ ObjectMeta: metav1.ObjectMeta{ Name: "testendpoints", @@ -34,7 +35,9 @@ func makeEndpoints() *v1.Endpoints { { Addresses: []v1.EndpointAddress{ { - IP: "1.2.3.4", + IP: "1.2.3.4", + Hostname: "testendpoint1", + NodeName: &nodeName, }, }, Ports: []v1.EndpointPort{ @@ -83,6 +86,8 @@ func TestEndpointsDiscoveryBeforeRun(t *testing.T) { Targets: []model.LabelSet{ { "__address__": "1.2.3.4:9000", + "__meta_kubernetes_endpoint_hostname": "testendpoint1", + "__meta_kubernetes_endpoint_node_name": "foobar", "__meta_kubernetes_endpoint_port_name": "testport", "__meta_kubernetes_endpoint_port_protocol": "TCP", "__meta_kubernetes_endpoint_ready": "true", @@ -369,6 +374,8 @@ func TestEndpointsDiscoveryWithService(t *testing.T) { Targets: []model.LabelSet{ { "__address__": "1.2.3.4:9000", + "__meta_kubernetes_endpoint_hostname": "testendpoint1", + "__meta_kubernetes_endpoint_node_name": "foobar", "__meta_kubernetes_endpoint_port_name": "testport", "__meta_kubernetes_endpoint_port_protocol": "TCP", "__meta_kubernetes_endpoint_ready": "true", @@ -435,6 +442,8 @@ func TestEndpointsDiscoveryWithServiceUpdate(t *testing.T) { Targets: []model.LabelSet{ { "__address__": "1.2.3.4:9000", + "__meta_kubernetes_endpoint_hostname": "testendpoint1", + "__meta_kubernetes_endpoint_node_name": "foobar", "__meta_kubernetes_endpoint_port_name": "testport", "__meta_kubernetes_endpoint_port_protocol": "TCP", "__meta_kubernetes_endpoint_ready": "true", @@ -545,6 +554,8 @@ func TestEndpointsDiscoveryNamespaces(t *testing.T) { Targets: []model.LabelSet{ { "__address__": "1.2.3.4:9000", + "__meta_kubernetes_endpoint_hostname": "testendpoint1", + "__meta_kubernetes_endpoint_node_name": "foobar", "__meta_kubernetes_endpoint_port_name": "testport", "__meta_kubernetes_endpoint_port_protocol": "TCP", "__meta_kubernetes_endpoint_ready": "true", diff --git a/docs/configuration/configuration.md b/docs/configuration/configuration.md index fa85131c0..9095d130d 100644 --- a/docs/configuration/configuration.md +++ b/docs/configuration/configuration.md @@ -778,6 +778,8 @@ Available meta labels: * `__meta_kubernetes_endpoints_name`: The names of the endpoints object. * For all targets discovered directly from the endpoints list (those not additionally inferred from underlying pods), the following labels are attached: + * `__meta_kubernetes_endpoint_hostname`: Hostname of the endpoint. + * `__meta_kubernetes_endpoint_node_name`: Name of the node hosting the endpoint. * `__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.