lib/promscrape/discovery/kubernetes: add __meta_kubernetes_pod_container_image label in the same way as Prometheus 2.38 does

See https://github.com/prometheus/prometheus/pull/11034
This commit is contained in:
Aliaksandr Valialkin 2022-08-15 01:18:21 +03:00
parent 2fb63dda83
commit 1a00c9ef03
No known key found for this signature in database
GPG key ID: A72BEC6CD3D0DED1
6 changed files with 19 additions and 2 deletions

View file

@ -20,6 +20,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: [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 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: [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: [vmagent](https://docs.victoriametrics.com/vmagent.html): add `__meta_kubernetes_pod_container_image` meta-label for `role: pod` 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/11034).
* 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). * 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). * BUGFIX: prevent from excess CPU usage when the storage enters [read-only mode](https://docs.victoriametrics.com/Cluster-VictoriaMetrics.html#readonly-mode).

View file

@ -776,6 +776,7 @@ One of the following `role` types can be configured to discover targets:
* `__meta_kubernetes_pod_annotation_<annotationname>`: Each annotation from the pod object. * `__meta_kubernetes_pod_annotation_<annotationname>`: Each annotation from the pod object.
* `__meta_kubernetes_pod_annotationpresent_<annotationname>`: "true" for each annotation from the pod object. * `__meta_kubernetes_pod_annotationpresent_<annotationname>`: "true" for each annotation from the pod object.
* `__meta_kubernetes_pod_container_init`: "true" if the container is an InitContainer * `__meta_kubernetes_pod_container_init`: "true" if the container is an InitContainer
* `__meta_kubernetes_pod_container_image`: Container image the target address points to.
* `__meta_kubernetes_pod_container_name`: Name of the container the target address points to. * `__meta_kubernetes_pod_container_name`: Name of the container the target address points to.
* `__meta_kubernetes_pod_container_port_name`: Name of the container port. * `__meta_kubernetes_pod_container_port_name`: Name of the container port.
* `__meta_kubernetes_pod_container_port_number`: Number of the container port. * `__meta_kubernetes_pod_container_port_number`: Number of the container port.

View file

@ -184,7 +184,11 @@ func TestGetEndpointsLabels(t *testing.T) {
}, },
} }
for cn, ports := range args.containerPorts { for cn, ports := range args.containerPorts {
pod.Spec.Containers = append(pod.Spec.Containers, Container{Name: cn, Ports: ports}) pod.Spec.Containers = append(pod.Spec.Containers, Container{
Name: cn,
Image: "test-image",
Ports: ports,
})
} }
var gw groupWatcher var gw groupWatcher
gw.m = map[string]*urlWatcher{ gw.m = map[string]*urlWatcher{
@ -298,6 +302,7 @@ func TestGetEndpointsLabels(t *testing.T) {
"__meta_kubernetes_node_label_node_label": "xyz", "__meta_kubernetes_node_label_node_label": "xyz",
"__meta_kubernetes_node_labelpresent_node_label": "true", "__meta_kubernetes_node_labelpresent_node_label": "true",
"__meta_kubernetes_node_name": "test-node", "__meta_kubernetes_node_name": "test-node",
"__meta_kubernetes_pod_container_image": "test-image",
"__meta_kubernetes_pod_container_name": "metrics", "__meta_kubernetes_pod_container_name": "metrics",
"__meta_kubernetes_pod_container_port_name": "http-metrics", "__meta_kubernetes_pod_container_port_name": "http-metrics",
"__meta_kubernetes_pod_container_port_number": "8428", "__meta_kubernetes_pod_container_port_number": "8428",
@ -343,6 +348,7 @@ func TestGetEndpointsLabels(t *testing.T) {
"__meta_kubernetes_node_label_node_label": "xyz", "__meta_kubernetes_node_label_node_label": "xyz",
"__meta_kubernetes_node_labelpresent_node_label": "true", "__meta_kubernetes_node_labelpresent_node_label": "true",
"__meta_kubernetes_node_name": "test-node", "__meta_kubernetes_node_name": "test-node",
"__meta_kubernetes_pod_container_image": "test-image",
"__meta_kubernetes_pod_container_name": "metrics", "__meta_kubernetes_pod_container_name": "metrics",
"__meta_kubernetes_pod_container_port_name": "web", "__meta_kubernetes_pod_container_port_name": "web",
"__meta_kubernetes_pod_container_port_number": "8428", "__meta_kubernetes_pod_container_port_number": "8428",

View file

@ -304,7 +304,11 @@ func TestGetEndpointsliceLabels(t *testing.T) {
}, },
} }
for cn, ports := range args.containerPorts { for cn, ports := range args.containerPorts {
pod.Spec.Containers = append(pod.Spec.Containers, Container{Name: cn, Ports: ports}) pod.Spec.Containers = append(pod.Spec.Containers, Container{
Name: cn,
Image: "test-image",
Ports: ports,
})
} }
var gw groupWatcher var gw groupWatcher
gw.m = map[string]*urlWatcher{ gw.m = map[string]*urlWatcher{
@ -432,6 +436,7 @@ func TestGetEndpointsliceLabels(t *testing.T) {
"__meta_kubernetes_node_label_node_label": "xyz", "__meta_kubernetes_node_label_node_label": "xyz",
"__meta_kubernetes_node_labelpresent_node_label": "true", "__meta_kubernetes_node_labelpresent_node_label": "true",
"__meta_kubernetes_node_name": "test-node", "__meta_kubernetes_node_name": "test-node",
"__meta_kubernetes_pod_container_image": "test-image",
"__meta_kubernetes_pod_container_name": "metrics", "__meta_kubernetes_pod_container_name": "metrics",
"__meta_kubernetes_pod_container_port_name": "http-metrics", "__meta_kubernetes_pod_container_port_name": "http-metrics",
"__meta_kubernetes_pod_container_port_number": "8428", "__meta_kubernetes_pod_container_port_number": "8428",
@ -484,6 +489,7 @@ func TestGetEndpointsliceLabels(t *testing.T) {
"__meta_kubernetes_node_label_node_label": "xyz", "__meta_kubernetes_node_label_node_label": "xyz",
"__meta_kubernetes_node_labelpresent_node_label": "true", "__meta_kubernetes_node_labelpresent_node_label": "true",
"__meta_kubernetes_node_name": "test-node", "__meta_kubernetes_node_name": "test-node",
"__meta_kubernetes_pod_container_image": "test-image",
"__meta_kubernetes_pod_container_name": "metrics", "__meta_kubernetes_pod_container_name": "metrics",
"__meta_kubernetes_pod_container_port_name": "web", "__meta_kubernetes_pod_container_port_name": "web",
"__meta_kubernetes_pod_container_port_number": "8428", "__meta_kubernetes_pod_container_port_number": "8428",

View file

@ -66,6 +66,7 @@ type PodSpec struct {
// See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.17/#container-v1-core // See https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.17/#container-v1-core
type Container struct { type Container struct {
Name string Name string
Image string
Ports []ContainerPort Ports []ContainerPort
} }
@ -135,6 +136,7 @@ func appendPodLabelsInternal(ms []map[string]string, gw *groupWatcher, p *Pod, c
} }
func (p *Pod) appendContainerLabels(m map[string]string, c Container, cp *ContainerPort) { func (p *Pod) appendContainerLabels(m map[string]string, c Container, cp *ContainerPort) {
m["__meta_kubernetes_pod_container_image"] = c.Image
m["__meta_kubernetes_pod_container_name"] = c.Name m["__meta_kubernetes_pod_container_name"] = c.Name
if cp != nil { if cp != nil {
m["__meta_kubernetes_pod_container_port_name"] = cp.Name m["__meta_kubernetes_pod_container_port_name"] = cp.Name

View file

@ -249,6 +249,7 @@ func TestParsePodListSuccess(t *testing.T) {
"__meta_kubernetes_node_name": "test-node", "__meta_kubernetes_node_name": "test-node",
"__meta_kubernetes_pod_name": "etcd-m01", "__meta_kubernetes_pod_name": "etcd-m01",
"__meta_kubernetes_pod_ip": "172.17.0.2", "__meta_kubernetes_pod_ip": "172.17.0.2",
"__meta_kubernetes_pod_container_image": "k8s.gcr.io/etcd:3.4.3-0",
"__meta_kubernetes_pod_container_name": "etcd", "__meta_kubernetes_pod_container_name": "etcd",
"__meta_kubernetes_pod_container_port_name": "foobar", "__meta_kubernetes_pod_container_port_name": "foobar",
"__meta_kubernetes_pod_container_port_number": "1234", "__meta_kubernetes_pod_container_port_number": "1234",