diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 8f7ab34976..ac5bc17d7c 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -19,6 +19,7 @@ The following tip changes can be tested by building VictoriaMetrics components f * FEATURE: [VictoriaMetrics cluster](https://docs.victoriametrics.com/Cluster-VictoriaMetrics.html): improve performance for heavy queries on systems with many CPU cores. * FEATURE: [vmagent](https://docs.victoriametrics.com/vmagent.html): add support for MX record types in [dns_sd_configs](https://docs.victoriametrics.com/sd_configs.html#dns_sd_configs) in the same way as Prometheus 2.38 [does](https://github.com/prometheus/prometheus/pull/10099). +* FEATURE: [vmagent](https://docs.victoriametrics.com/vmagent.html): add `__meta_kubernetes_service_port_number` meta-label for `role: service` in [kubernetes_sd_configs](https://docs.victoriametrics.com/sd_configs.html#kubernetes_sd_configs) in the same way as Prometheus 2.38 [does](https://github.com/prometheus/prometheus/pull/11002). * FEATURE: [vmalert](https://docs.victoriametrics.com/vmalert.html): add `toTime()` template function in the same way as Prometheus 2.38 [does](https://github.com/prometheus/prometheus/pull/10993). See [these docs](https://prometheus.io/docs/prometheus/latest/configuration/template_reference/#numbers). * BUGFIX: prevent from excess CPU usage when the storage enters [read-only mode](https://docs.victoriametrics.com/Cluster-VictoriaMetrics.html#readonly-mode). diff --git a/docs/sd_configs.md b/docs/sd_configs.md index f3281e5caf..7844517f74 100644 --- a/docs/sd_configs.md +++ b/docs/sd_configs.md @@ -756,6 +756,7 @@ One of the following `role` types can be configured to discover targets: * `__meta_kubernetes_service_labelpresent_`: "true" for each label of the service object. * `__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_number`: Service port number 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. diff --git a/lib/promscrape/discovery/kubernetes/service.go b/lib/promscrape/discovery/kubernetes/service.go index b74bd26532..77956d76bc 100644 --- a/lib/promscrape/discovery/kubernetes/service.go +++ b/lib/promscrape/discovery/kubernetes/service.go @@ -4,6 +4,7 @@ import ( "encoding/json" "fmt" "io" + "strconv" "github.com/VictoriaMetrics/VictoriaMetrics/lib/promscrape/discoveryutils" ) @@ -79,6 +80,7 @@ func (s *Service) getTargetLabels(gw *groupWatcher) []map[string]string { m := map[string]string{ "__address__": addr, "__meta_kubernetes_service_port_name": sp.Name, + "__meta_kubernetes_service_port_number": strconv.Itoa(sp.Port), "__meta_kubernetes_service_port_protocol": sp.Protocol, } s.appendCommonLabels(m) diff --git a/lib/promscrape/discovery/kubernetes/service_test.go b/lib/promscrape/discovery/kubernetes/service_test.go index 050b2f70ed..d4ff4949f6 100644 --- a/lib/promscrape/discovery/kubernetes/service_test.go +++ b/lib/promscrape/discovery/kubernetes/service_test.go @@ -107,6 +107,7 @@ func TestParseServiceListSuccess(t *testing.T) { "__meta_kubernetes_service_name": "kube-dns", "__meta_kubernetes_service_type": "ClusterIP", "__meta_kubernetes_service_port_name": "dns", + "__meta_kubernetes_service_port_number": "53", "__meta_kubernetes_service_port_protocol": "UDP", "__meta_kubernetes_service_cluster_ip": "10.96.0.10", @@ -130,6 +131,7 @@ func TestParseServiceListSuccess(t *testing.T) { "__meta_kubernetes_service_name": "kube-dns", "__meta_kubernetes_service_type": "ClusterIP", "__meta_kubernetes_service_port_name": "dns-tcp", + "__meta_kubernetes_service_port_number": "53", "__meta_kubernetes_service_port_protocol": "TCP", "__meta_kubernetes_service_cluster_ip": "10.96.0.10", @@ -153,6 +155,7 @@ func TestParseServiceListSuccess(t *testing.T) { "__meta_kubernetes_service_name": "kube-dns", "__meta_kubernetes_service_type": "ClusterIP", "__meta_kubernetes_service_port_name": "metrics", + "__meta_kubernetes_service_port_number": "9153", "__meta_kubernetes_service_port_protocol": "TCP", "__meta_kubernetes_service_cluster_ip": "10.96.0.10",