Temporary fix for cgroup renaming (#11775)
Vladimir Kobal committed
Nov 11, 2021 at 20:09 UTC
5bf1cffc4063235711a44d3ae9c8715f68de22b1
2 files changed
+14
-10
collectors/cgroups.plugin/cgroup-name.sh.in
-2
@@ -161,8 +161,6 @@ function k8s_get_kubepod_name() {
161
local clean_id="$id"
162
clean_id=${clean_id//.slice/}
163
clean_id=${clean_id//.scope/}
164
- clean_id=${clean_id//-slice/}
165
- clean_id=${clean_id//-scope/}
164
165
local name pod_uid cntr_id
166
if [[ $clean_id == "kubepods" ]]; then
collectors/cgroups.plugin/sys_fs_cgroup.c
+14
-8
@@ -663,6 +663,7 @@ struct cgroup {
663
char enabled; // enabled in the config
664
665
char pending_renames;
666
+ char *intermediate_id; // TODO: remove it when the renaming script is fixed
667
668
char *id;
669
uint32_t hash;
@@ -1367,13 +1368,16 @@ static inline char *cgroup_chart_id_strdupz(const char *s) {
1368
char *r = strdupz(s);
1369
netdata_fix_chart_id(r);
1370
1371
+ return r;
1372
+}
1373
+
1374
+// TODO: move the code to cgroup_chart_id_strdupz() when the renaming script is fixed
1375
+static inline void substitute_dots_in_id(char *s) {
1376
// dots are used to distinguish chart type and id in streaming, so we should replace them
1371
- for (char *d = r; *d; d++) {
1377
+ for (char *d = s; *d; d++) {
1378
if (*d == '.')
1379
*d = '-';
1380
}
1375
-
1376
- return r;
1381
}
1382
1383
char *parse_k8s_data(struct label **labels, char *data)
@@ -1411,7 +1415,8 @@ static inline void cgroup_get_chart_name(struct cgroup *cg) {
1415
pid_t cgroup_pid;
1416
char command[CGROUP_CHARTID_LINE_MAX + 1];
1417
1414
- snprintfz(command, CGROUP_CHARTID_LINE_MAX, "exec %s '%s'", cgroups_rename_script, cg->chart_id);
1418
+ // TODO: use cg->id when the renaming script is fixed
1419
+ snprintfz(command, CGROUP_CHARTID_LINE_MAX, "exec %s '%s'", cgroups_rename_script, cg->intermediate_id);
1420
1421
debug(D_CGROUP, "executing command \"%s\" for cgroup '%s'", command, cg->chart_id);
1422
FILE *fp = mypopen(command, &cgroup_pid);
@@ -1448,6 +1453,7 @@ static inline void cgroup_get_chart_name(struct cgroup *cg) {
1453
1454
freez(cg->chart_id);
1455
cg->chart_id = cgroup_chart_id_strdupz(name);
1456
+ substitute_dots_in_id(cg->chart_id);
1457
cg->hash_chart = simple_hash(cg->chart_id);
1458
}
1459
}
@@ -1474,7 +1480,10 @@ static inline struct cgroup *cgroup_add(const char *id) {
1480
1481
cg->chart_title = cgroup_title_strdupz(id);
1482
1483
+ cg->intermediate_id = cgroup_chart_id_strdupz(id);
1484
+
1485
cg->chart_id = cgroup_chart_id_strdupz(id);
1486
+ substitute_dots_in_id(cg->chart_id);
1487
cg->hash_chart = simple_hash(cg->chart_id);
1488
1489
if(cgroup_use_unified_cgroups) cg->options |= CGROUP_OPTIONS_IS_UNIFIED;
@@ -1515,10 +1524,6 @@ static inline struct cgroup *cgroup_add(const char *id) {
1524
strncpy(buffer, cg->id, CGROUP_CHARTID_LINE_MAX);
1525
char *s = buffer;
1526
1518
- //freez(cg->chart_id);
1519
- //cg->chart_id = cgroup_chart_id_strdupz(s);
1520
- //cg->hash_chart = simple_hash(cg->chart_id);
1521
-
1527
// skip to the last slash
1528
size_t len = strlen(s);
1529
while(len--) if(unlikely(s[len] == '/')) break;
@@ -1642,6 +1647,7 @@ static inline void cgroup_free(struct cgroup *cg) {
1647
free_pressure(&cg->memory_pressure);
1648
1649
freez(cg->id);
1650
+ freez(cg->intermediate_id);
1651
freez(cg->chart_id);
1652
freez(cg->chart_title);
1653