diff --git a/discovery/kubernetes/service.go b/discovery/kubernetes/service.go index 017f4ba652..1b19c07b60 100644 --- a/discovery/kubernetes/service.go +++ b/discovery/kubernetes/service.go @@ -152,6 +152,7 @@ const ( servicePortProtocolLabel = metaLabelPrefix + "service_port_protocol" serviceClusterIPLabel = metaLabelPrefix + "service_cluster_ip" serviceExternalNameLabel = metaLabelPrefix + "service_external_name" + serviceType = metaLabelPrefix + "service_type" ) func serviceLabels(svc *apiv1.Service) model.LabelSet { @@ -188,6 +189,7 @@ func (s *Service) buildService(svc *apiv1.Service) *targetgroup.Group { model.AddressLabel: lv(addr), servicePortNameLabel: lv(port.Name), servicePortProtocolLabel: lv(string(port.Protocol)), + serviceType: lv(string(svc.Spec.Type)), } if svc.Spec.Type == apiv1.ServiceTypeExternalName { diff --git a/discovery/kubernetes/service_test.go b/discovery/kubernetes/service_test.go index 783b5d06bf..c43a188d0e 100644 --- a/discovery/kubernetes/service_test.go +++ b/discovery/kubernetes/service_test.go @@ -112,6 +112,7 @@ func TestServiceDiscoveryAdd(t *testing.T) { { "__meta_kubernetes_service_port_protocol": "TCP", "__address__": "testservice.default.svc:30900", + "__meta_kubernetes_service_type": "ClusterIP", "__meta_kubernetes_service_cluster_ip": "10.0.0.1", "__meta_kubernetes_service_port_name": "testport", }, @@ -127,6 +128,7 @@ func TestServiceDiscoveryAdd(t *testing.T) { { "__meta_kubernetes_service_port_protocol": "TCP", "__address__": "testservice-external.default.svc:31900", + "__meta_kubernetes_service_type": "ExternalName", "__meta_kubernetes_service_port_name": "testport", "__meta_kubernetes_service_external_name": "FooExternalName", }, @@ -175,12 +177,14 @@ func TestServiceDiscoveryUpdate(t *testing.T) { { "__meta_kubernetes_service_port_protocol": "TCP", "__address__": "testservice.default.svc:30900", + "__meta_kubernetes_service_type": "ClusterIP", "__meta_kubernetes_service_cluster_ip": "10.0.0.1", "__meta_kubernetes_service_port_name": "testport0", }, { "__meta_kubernetes_service_port_protocol": "UDP", "__address__": "testservice.default.svc:30901", + "__meta_kubernetes_service_type": "ClusterIP", "__meta_kubernetes_service_cluster_ip": "10.0.0.1", "__meta_kubernetes_service_port_name": "testport1", }, @@ -218,6 +222,7 @@ func TestServiceDiscoveryNamespaces(t *testing.T) { { "__meta_kubernetes_service_port_protocol": "TCP", "__address__": "testservice.ns1.svc:30900", + "__meta_kubernetes_service_type": "ClusterIP", "__meta_kubernetes_service_cluster_ip": "10.0.0.1", "__meta_kubernetes_service_port_name": "testport", }, @@ -233,6 +238,7 @@ func TestServiceDiscoveryNamespaces(t *testing.T) { { "__meta_kubernetes_service_port_protocol": "TCP", "__address__": "testservice.ns2.svc:30900", + "__meta_kubernetes_service_type": "ClusterIP", "__meta_kubernetes_service_cluster_ip": "10.0.0.1", "__meta_kubernetes_service_port_name": "testport", }, diff --git a/docs/configuration/configuration.md b/docs/configuration/configuration.md index 9cc7a159a9..811ed65632 100644 --- a/docs/configuration/configuration.md +++ b/docs/configuration/configuration.md @@ -743,6 +743,7 @@ Available meta labels: * `__meta_kubernetes_service_name`: The name of the service object. * `__meta_kubernetes_service_port_name`: Name of the service port for the target. * `__meta_kubernetes_service_port_protocol`: Protocol of the service port for the target. +* `__meta_kubernetes_service_type`: The type of the service. #### `pod`