diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index baf134e925..27ffd57201 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -30,6 +30,7 @@ The following tip changes can be tested by building VictoriaMetrics components f * FEATURE: [vmagent](https://docs.victoriametrics.com/vmagent.html): provide the ability to fetch target responses on behalf of `vmagent` by clicking the `response` link for the needed target at `/targets` page. This feature may be useful for debugging responses from targets located in isolated environments. * FEATURE: [vmagent](https://docs.victoriametrics.com/vmagent.html): show the total number of scrapes and the total number of scrape errors per target at `/targets` page. This information may be useful when debugging unreliable scrape targets. * FEATURE: vmagent and single-node VictoriaMetrics: disallow unknown fields at `-promscrape.config` file. Previously unknown fields were allowed. This could lead to long-living silent config errors. The previous behaviour can be returned by passing `-promscrape.config.strictParse=false` command-line flag. +* FEATURE: add `__meta_kubernetes_endpointslice_label*` and `__meta_kubernetes_endpointslice_annotation*` labels for `role: endpointslice` targets in [kubernetes_sd_config](https://prometheus.io/docs/prometheus/latest/configuration/configuration/#kubernetes_sd_config) to be consistent with other `role` values. See [this issue](https://github.com/prometheus/prometheus/issues/10284). * BUGFIX: return proper results from `highestMax()` function at [Graphite render API](https://docs.victoriametrics.com/#graphite-render-api-usage). Previously it was incorrectly returning timeseries with min peaks instead of max peaks. * BUGFIX: properly limit indexdb cache sizes. Previously they could exceed values set via `-memory.allowedPercent` and/or `-memory.allowedBytes` when `indexdb` contained many data parts. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/2007). diff --git a/lib/promscrape/discovery/kubernetes/endpoints.go b/lib/promscrape/discovery/kubernetes/endpoints.go index a9ddc6ecc3..f011c0c45c 100644 --- a/lib/promscrape/discovery/kubernetes/endpoints.go +++ b/lib/promscrape/discovery/kubernetes/endpoints.go @@ -164,6 +164,7 @@ func getEndpointLabelsForAddressAndPort(podPortsSeen map[*Pod][]int, eps *Endpoi if svc != nil { svc.appendCommonLabels(m) } + // See https://github.com/prometheus/prometheus/issues/10284 eps.Metadata.registerLabelsAndAnnotations("__meta_kubernetes_endpoints", m) if ea.TargetRef.Kind != "Pod" || p == nil { return m diff --git a/lib/promscrape/discovery/kubernetes/endpoints_test.go b/lib/promscrape/discovery/kubernetes/endpoints_test.go index f26fe405cf..4687784d7e 100644 --- a/lib/promscrape/discovery/kubernetes/endpoints_test.go +++ b/lib/promscrape/discovery/kubernetes/endpoints_test.go @@ -168,13 +168,13 @@ func TestGetEndpointLabels(t *testing.T) { } var gw groupWatcher gw.m = map[string]*urlWatcher{ - "pod": &urlWatcher{ + "pod": { role: "pod", objectsByKey: map[string]object{ "default/test-pod": &pod, }, }, - "service": &urlWatcher{ + "service": { role: "service", objectsByKey: map[string]object{ "default/test-eps": &svc, @@ -224,7 +224,7 @@ func TestGetEndpointLabels(t *testing.T) { }) f("1 port from endpoint and 1 from pod", testArgs{ - containerPorts: map[string][]ContainerPort{"metrics": []ContainerPort{{ + containerPorts: map[string][]ContainerPort{"metrics": {{ Name: "http-metrics", ContainerPort: 8428, }}}, @@ -276,7 +276,7 @@ func TestGetEndpointLabels(t *testing.T) { }) f("1 port from endpoint", testArgs{ - containerPorts: map[string][]ContainerPort{"metrics": []ContainerPort{{ + containerPorts: map[string][]ContainerPort{"metrics": {{ Name: "web", ContainerPort: 8428, }}}, diff --git a/lib/promscrape/discovery/kubernetes/endpointslice.go b/lib/promscrape/discovery/kubernetes/endpointslice.go index 727edd2fcb..620b03e059 100644 --- a/lib/promscrape/discovery/kubernetes/endpointslice.go +++ b/lib/promscrape/discovery/kubernetes/endpointslice.go @@ -98,6 +98,8 @@ func getEndpointSliceLabelsForAddressAndPort(podPortsSeen map[*Pod][]int, addr s if svc != nil { svc.appendCommonLabels(m) } + // See https://github.com/prometheus/prometheus/issues/10284 + eps.Metadata.registerLabelsAndAnnotations("__meta_kubernetes_endpointslice", m) if ea.TargetRef.Kind != "Pod" || p == nil { return m } diff --git a/lib/promscrape/discovery/kubernetes/endpointslice_test.go b/lib/promscrape/discovery/kubernetes/endpointslice_test.go index f647695f47..a09f158419 100644 --- a/lib/promscrape/discovery/kubernetes/endpointslice_test.go +++ b/lib/promscrape/discovery/kubernetes/endpointslice_test.go @@ -137,32 +137,9 @@ func TestParseEndpointSliceListSuccess(t *testing.T) { "topology": { "kubernetes.io/hostname": "kind-control-plane" } - }, - { - "addresses": [ - "10.244.0.4" - ], - "conditions": { - "ready": true - }, - "targetRef": { - "kind": "Pod", - "namespace": "kube-system", - "name": "coredns-66bff467f8-kpbhk", - "uid": "db38d8b4-847a-4e82-874c-fe444fba2718", - "resourceVersion": "576" - }, - "topology": { - "kubernetes.io/hostname": "kind-control-plane" - } } ], "ports": [ - { - "name": "dns-tcp", - "protocol": "TCP", - "port": 53 - }, { "name": "metrics", "protocol": "TCP", @@ -189,99 +166,57 @@ func TestParseEndpointSliceListSuccess(t *testing.T) { } sortedLabelss := getSortedLabelss(objectsByKey) expectedLabelss := [][]prompbmarshal.Label{ - discoveryutils.GetSortedLabels(map[string]string{ - "__address__": "172.18.0.2:6443", - "__meta_kubernetes_endpointslice_address_type": "IPv4", - "__meta_kubernetes_endpointslice_endpoint_conditions_ready": "true", - "__meta_kubernetes_endpointslice_name": "kubernetes", - "__meta_kubernetes_endpointslice_port": "6443", - "__meta_kubernetes_endpointslice_port_name": "https", - "__meta_kubernetes_endpointslice_port_protocol": "TCP", - "__meta_kubernetes_namespace": "default", - }), discoveryutils.GetSortedLabels(map[string]string{ "__address__": "10.244.0.3:53", - "__meta_kubernetes_endpointslice_address_target_kind": "Pod", - "__meta_kubernetes_endpointslice_address_target_name": "coredns-66bff467f8-z8czk", - "__meta_kubernetes_endpointslice_address_type": "IPv4", - "__meta_kubernetes_endpointslice_endpoint_conditions_ready": "true", - "__meta_kubernetes_endpointslice_endpoint_topology_kubernetes_io_hostname": "kind-control-plane", - "__meta_kubernetes_endpointslice_endpoint_topology_present_kubernetes_io_hostname": "true", - "__meta_kubernetes_endpointslice_name": "kube-dns-22mvb", - "__meta_kubernetes_endpointslice_port": "53", - "__meta_kubernetes_endpointslice_port_name": "dns-tcp", - "__meta_kubernetes_endpointslice_port_protocol": "TCP", - "__meta_kubernetes_namespace": "kube-system", + "__meta_kubernetes_endpointslice_address_target_kind": "Pod", + "__meta_kubernetes_endpointslice_address_target_name": "coredns-66bff467f8-z8czk", + "__meta_kubernetes_endpointslice_address_type": "IPv4", + "__meta_kubernetes_endpointslice_annotation_endpoints_kubernetes_io_last_change_trigger_time": "2020-09-07T14:28:35Z", + "__meta_kubernetes_endpointslice_annotationpresent_endpoints_kubernetes_io_last_change_trigger_time": "true", + "__meta_kubernetes_endpointslice_endpoint_conditions_ready": "true", + "__meta_kubernetes_endpointslice_endpoint_topology_kubernetes_io_hostname": "kind-control-plane", + "__meta_kubernetes_endpointslice_endpoint_topology_present_kubernetes_io_hostname": "true", + "__meta_kubernetes_endpointslice_label_endpointslice_kubernetes_io_managed_by": "endpointslice-controller.k8s.io", + "__meta_kubernetes_endpointslice_label_kubernetes_io_service_name": "kube-dns", + "__meta_kubernetes_endpointslice_labelpresent_endpointslice_kubernetes_io_managed_by": "true", + "__meta_kubernetes_endpointslice_labelpresent_kubernetes_io_service_name": "true", + "__meta_kubernetes_endpointslice_name": "kube-dns-22mvb", + "__meta_kubernetes_endpointslice_port": "53", + "__meta_kubernetes_endpointslice_port_name": "dns", + "__meta_kubernetes_endpointslice_port_protocol": "UDP", + "__meta_kubernetes_namespace": "kube-system", }), discoveryutils.GetSortedLabels(map[string]string{ "__address__": "10.244.0.3:9153", - "__meta_kubernetes_endpointslice_address_target_kind": "Pod", - "__meta_kubernetes_endpointslice_address_target_name": "coredns-66bff467f8-z8czk", - "__meta_kubernetes_endpointslice_address_type": "IPv4", - "__meta_kubernetes_endpointslice_endpoint_conditions_ready": "true", - "__meta_kubernetes_endpointslice_endpoint_topology_kubernetes_io_hostname": "kind-control-plane", - "__meta_kubernetes_endpointslice_endpoint_topology_present_kubernetes_io_hostname": "true", - "__meta_kubernetes_endpointslice_name": "kube-dns-22mvb", - "__meta_kubernetes_endpointslice_port": "9153", - "__meta_kubernetes_endpointslice_port_name": "metrics", - "__meta_kubernetes_endpointslice_port_protocol": "TCP", - "__meta_kubernetes_namespace": "kube-system", + "__meta_kubernetes_endpointslice_address_target_kind": "Pod", + "__meta_kubernetes_endpointslice_address_target_name": "coredns-66bff467f8-z8czk", + "__meta_kubernetes_endpointslice_address_type": "IPv4", + "__meta_kubernetes_endpointslice_annotation_endpoints_kubernetes_io_last_change_trigger_time": "2020-09-07T14:28:35Z", + "__meta_kubernetes_endpointslice_annotationpresent_endpoints_kubernetes_io_last_change_trigger_time": "true", + "__meta_kubernetes_endpointslice_endpoint_conditions_ready": "true", + "__meta_kubernetes_endpointslice_endpoint_topology_kubernetes_io_hostname": "kind-control-plane", + "__meta_kubernetes_endpointslice_endpoint_topology_present_kubernetes_io_hostname": "true", + "__meta_kubernetes_endpointslice_label_endpointslice_kubernetes_io_managed_by": "endpointslice-controller.k8s.io", + "__meta_kubernetes_endpointslice_label_kubernetes_io_service_name": "kube-dns", + "__meta_kubernetes_endpointslice_labelpresent_endpointslice_kubernetes_io_managed_by": "true", + "__meta_kubernetes_endpointslice_labelpresent_kubernetes_io_service_name": "true", + "__meta_kubernetes_endpointslice_name": "kube-dns-22mvb", + "__meta_kubernetes_endpointslice_port": "9153", + "__meta_kubernetes_endpointslice_port_name": "metrics", + "__meta_kubernetes_endpointslice_port_protocol": "TCP", + "__meta_kubernetes_namespace": "kube-system", }), discoveryutils.GetSortedLabels(map[string]string{ - "__address__": "10.244.0.3:53", - "__meta_kubernetes_endpointslice_address_target_kind": "Pod", - "__meta_kubernetes_endpointslice_address_target_name": "coredns-66bff467f8-z8czk", - "__meta_kubernetes_endpointslice_address_type": "IPv4", - "__meta_kubernetes_endpointslice_endpoint_conditions_ready": "true", - "__meta_kubernetes_endpointslice_endpoint_topology_kubernetes_io_hostname": "kind-control-plane", - "__meta_kubernetes_endpointslice_endpoint_topology_present_kubernetes_io_hostname": "true", - "__meta_kubernetes_endpointslice_name": "kube-dns-22mvb", - "__meta_kubernetes_endpointslice_port": "53", - "__meta_kubernetes_endpointslice_port_name": "dns", - "__meta_kubernetes_endpointslice_port_protocol": "UDP", - "__meta_kubernetes_namespace": "kube-system", - }), - discoveryutils.GetSortedLabels(map[string]string{ - "__address__": "10.244.0.4:53", - "__meta_kubernetes_endpointslice_address_target_kind": "Pod", - "__meta_kubernetes_endpointslice_address_target_name": "coredns-66bff467f8-kpbhk", - "__meta_kubernetes_endpointslice_address_type": "IPv4", - "__meta_kubernetes_endpointslice_endpoint_conditions_ready": "true", - "__meta_kubernetes_endpointslice_endpoint_topology_kubernetes_io_hostname": "kind-control-plane", - "__meta_kubernetes_endpointslice_endpoint_topology_present_kubernetes_io_hostname": "true", - "__meta_kubernetes_endpointslice_name": "kube-dns-22mvb", - "__meta_kubernetes_endpointslice_port": "53", - "__meta_kubernetes_endpointslice_port_name": "dns-tcp", - "__meta_kubernetes_endpointslice_port_protocol": "TCP", - "__meta_kubernetes_namespace": "kube-system", - }), - discoveryutils.GetSortedLabels(map[string]string{ - "__address__": "10.244.0.4:9153", - "__meta_kubernetes_endpointslice_address_target_kind": "Pod", - "__meta_kubernetes_endpointslice_address_target_name": "coredns-66bff467f8-kpbhk", - "__meta_kubernetes_endpointslice_address_type": "IPv4", - "__meta_kubernetes_endpointslice_endpoint_conditions_ready": "true", - "__meta_kubernetes_endpointslice_endpoint_topology_kubernetes_io_hostname": "kind-control-plane", - "__meta_kubernetes_endpointslice_endpoint_topology_present_kubernetes_io_hostname": "true", - "__meta_kubernetes_endpointslice_name": "kube-dns-22mvb", - "__meta_kubernetes_endpointslice_port": "9153", - "__meta_kubernetes_endpointslice_port_name": "metrics", - "__meta_kubernetes_endpointslice_port_protocol": "TCP", - "__meta_kubernetes_namespace": "kube-system", - }), - discoveryutils.GetSortedLabels(map[string]string{ - "__address__": "10.244.0.4:53", - "__meta_kubernetes_endpointslice_address_target_kind": "Pod", - "__meta_kubernetes_endpointslice_address_target_name": "coredns-66bff467f8-kpbhk", - "__meta_kubernetes_endpointslice_address_type": "IPv4", - "__meta_kubernetes_endpointslice_endpoint_conditions_ready": "true", - "__meta_kubernetes_endpointslice_endpoint_topology_kubernetes_io_hostname": "kind-control-plane", - "__meta_kubernetes_endpointslice_endpoint_topology_present_kubernetes_io_hostname": "true", - "__meta_kubernetes_endpointslice_name": "kube-dns-22mvb", - "__meta_kubernetes_endpointslice_port": "53", - "__meta_kubernetes_endpointslice_port_name": "dns", - "__meta_kubernetes_endpointslice_port_protocol": "UDP", - "__meta_kubernetes_namespace": "kube-system", + "__address__": "172.18.0.2:6443", + "__meta_kubernetes_endpointslice_address_type": "IPv4", + "__meta_kubernetes_endpointslice_endpoint_conditions_ready": "true", + "__meta_kubernetes_endpointslice_label_kubernetes_io_service_name": "kubernetes", + "__meta_kubernetes_endpointslice_labelpresent_kubernetes_io_service_name": "true", + "__meta_kubernetes_endpointslice_name": "kubernetes", + "__meta_kubernetes_endpointslice_port": "6443", + "__meta_kubernetes_endpointslice_port_name": "https", + "__meta_kubernetes_endpointslice_port_protocol": "TCP", + "__meta_kubernetes_namespace": "default", }), } if !areEqualLabelss(sortedLabelss, expectedLabelss) {