cgroups: remove pod_uid and container_id labels in k8s (#15216)
Ilya Mashchenko committed
Jun 20, 2023 at 19:47 UTC
3cbcaeabab73a88d73182bc0157af599bbc16b0e
1 file changed
+19
collectors/cgroups.plugin/cgroup-name.sh
+19
@@ -132,6 +132,22 @@ function add_lbl_prefix() {
132
echo "${new_labels:0:-1}" # trim last ','
133
}
134
135
+function remove_lbl() {
136
+ local orig_labels lbl_name
137
+ orig_labels="${1}"
138
+ lbl_name="${2}"
139
+
140
+ IFS=, read -ra labels <<< "$orig_labels"
141
+
142
+ local new_labels
143
+ for l in "${labels[@]}"; do
144
+ IFS="=" read -r lname lval <<< "$l"
145
+ [ "$lbl_name" != "$lname" ] && new_labels+="${l},"
146
+ done
147
+
148
+ echo "${new_labels:0:-1}" # trim last ','
149
+}
150
+
151
function k8s_is_pause_container() {
152
local cgroup_path="${1}"
153
@@ -385,6 +401,8 @@ function k8s_get_kubepod_name() {
401
name+="_$(get_lbl_val "$labels" namespace)"
402
name+="_$(get_lbl_val "$labels" pod_name)"
403
name+="_$(get_lbl_val "$labels" container_name)"
404
+ labels=$(remove_lbl "$labels" "container_id")
405
+ labels=$(remove_lbl "$labels" "pod_uid")
406
labels=$(add_lbl_prefix "$labels" "k8s_")
407
name+=" $labels"
408
else
@@ -400,6 +418,7 @@ function k8s_get_kubepod_name() {
418
name="pod"
419
name+="_$(get_lbl_val "$labels" namespace)"
420
name+="_$(get_lbl_val "$labels" pod_name)"
421
+ labels=$(remove_lbl "$labels" "pod_uid")
422
labels=$(add_lbl_prefix "$labels" "k8s_")
423
name+=" $labels"
424
else