@cryptotaxi247 / netdata-1 / commits / ce2e30838

fix(cgroups.plugin): improve check for uninitialized containers in k8s (#12912)

Ilya Mashchenko committed May 16, 2022 at 10:38 UTC ce2e3083856bb8e080f4808e06286f023c313a97
1 file changed +24 -2
collectors/cgroups.plugin/sys_fs_cgroup.c
+24 -2
@@ -91,6 +91,8 @@ static SIMPLE_PATTERN *search_cgroup_paths = NULL;
91 static SIMPLE_PATTERN *enabled_cgroup_renames = NULL;
92 static SIMPLE_PATTERN *systemd_services_cgroups = NULL;
93
94 +static SIMPLE_PATTERN *entrypoint_parent_process_comm = NULL;
95 +
96 static char *cgroups_rename_script = NULL;
97 static char *cgroups_network_interface_script = NULL;
98
@@ -918,6 +920,10 @@ static inline int matches_search_cgroup_paths(const char *dir) {
920 return simple_pattern_matches(search_cgroup_paths, dir);
921 }
922
923 +static inline int matches_entrypoint_parent_process_comm(const char *comm) {
924 + return simple_pattern_matches(entrypoint_parent_process_comm, comm);
925 +}
926 +
927 static inline int is_cgroup_systemd_service(struct cgroup *cg) {
928 return (cg->options & CGROUP_OPTIONS_SYSTEM_SLICE_SERVICE);
929 }
@@ -2567,6 +2573,16 @@ static inline void discovery_find_all_cgroups_v2() {
2573 }
2574 }
2575
2576 +static int is_digits_only(const char *s) {
2577 + do {
2578 + if (!isdigit(*s++)) {
2579 + return 0;
2580 + }
2581 + } while (*s);
2582 +
2583 + return 1;
2584 +}
2585 +
2586 static inline void discovery_process_first_time_seen_cgroup(struct cgroup *cg) {
2587 if (!cg->first_time_seen) {
2588 return;
@@ -2577,8 +2593,8 @@ static inline void discovery_process_first_time_seen_cgroup(struct cgroup *cg) {
2593
2594 if (is_inside_k8s && !k8s_get_container_first_proc_comm(cg->id, comm)) {
2595 // container initialization may take some time when CPU % is high
2580 - // TODO: not sure run-level 2 is enough (just came across this problem on an AWS K8s cluster)
2581 - if (!strcmp(comm, "runc:[2:INIT]")) {
2596 + // seen on GKE: comm is '6' before 'runc:[2:INIT]' (dunno if it could be another number)
2597 + if (is_digits_only(comm) || matches_entrypoint_parent_process_comm(comm)) {
2598 cg->first_time_seen = 1;
2599 return;
2600 }
@@ -2728,6 +2744,12 @@ void cgroup_discovery_worker(void *ptr)
2744 worker_register_job_name(WORKER_DISCOVERY_SHARE, "share");
2745 worker_register_job_name(WORKER_DISCOVERY_LOCK, "lock");
2746
2747 + entrypoint_parent_process_comm = simple_pattern_create(
2748 + " runc:[* " // http://terenceli.github.io/%E6%8A%80%E6%9C%AF/2021/12/28/runc-internals-3)
2749 + " exe ", // https://github.com/falcosecurity/falco/blob/9d41b0a151b83693929d3a9c84f7c5c85d070d3a/rules/falco_rules.yaml#L1961
2750 + NULL,
2751 + SIMPLE_PATTERN_EXACT);
2752 +
2753 while (!netdata_exit) {
2754 worker_is_idle();
2755