From dd2f8152043b757ac39b11a5c14244ec2c93f8b7 Mon Sep 17 00:00:00 2001 From: Nikolay Date: Thu, 24 Dec 2020 12:26:14 +0300 Subject: [PATCH] fixes kubernetes_sd (#983) * fixes kubernetes_sd, adds missing service metadata for pod ports without endpoint https://github.com/VictoriaMetrics/VictoriaMetrics/issues/982 * fix test --- lib/promscrape/discovery/kubernetes/endpoints.go | 3 +++ lib/promscrape/discovery/kubernetes/endpointslices.go | 3 +++ lib/promscrape/discovery/kubernetes/endpointslices_test.go | 7 +++++++ 3 files changed, 13 insertions(+) diff --git a/lib/promscrape/discovery/kubernetes/endpoints.go b/lib/promscrape/discovery/kubernetes/endpoints.go index 1bb3aaeb8..edd538746 100644 --- a/lib/promscrape/discovery/kubernetes/endpoints.go +++ b/lib/promscrape/discovery/kubernetes/endpoints.go @@ -158,6 +158,9 @@ func (eps *Endpoints) appendTargetLabels(ms []map[string]string, pods []Pod, svc } p.appendCommonLabels(m) p.appendContainerLabels(m, c, &cp) + if svc != nil { + svc.appendCommonLabels(m) + } ms = append(ms, m) } } diff --git a/lib/promscrape/discovery/kubernetes/endpointslices.go b/lib/promscrape/discovery/kubernetes/endpointslices.go index 48a06a25c..f1f9da645 100644 --- a/lib/promscrape/discovery/kubernetes/endpointslices.go +++ b/lib/promscrape/discovery/kubernetes/endpointslices.go @@ -113,6 +113,9 @@ func (eps *EndpointSlice) appendTargetLabels(ms []map[string]string, pods []Pod, } p.appendCommonLabels(m) p.appendContainerLabels(m, c, &cp) + if svc != nil { + svc.appendCommonLabels(m) + } ms = append(ms, m) } } diff --git a/lib/promscrape/discovery/kubernetes/endpointslices_test.go b/lib/promscrape/discovery/kubernetes/endpointslices_test.go index 44acef3d7..900751b74 100644 --- a/lib/promscrape/discovery/kubernetes/endpointslices_test.go +++ b/lib/promscrape/discovery/kubernetes/endpointslices_test.go @@ -420,6 +420,13 @@ func TestEndpointSlice_appendTargetLabels(t *testing.T) { "__meta_kubernetes_pod_phase": "", "__meta_kubernetes_pod_ready": "unknown", "__meta_kubernetes_pod_uid": "some-pod-uuid", + "__meta_kubernetes_service_cluster_ip": "", + "__meta_kubernetes_service_label_service_label_1": "value-1", + "__meta_kubernetes_service_label_service_label_2": "value-2", + "__meta_kubernetes_service_labelpresent_service_label_1": "true", + "__meta_kubernetes_service_labelpresent_service_label_2": "true", + "__meta_kubernetes_service_name": "custom-esl", + "__meta_kubernetes_service_type": "ClusterIP", }), }, },