Skip to content

Commit 211b482

Browse files
authored
Additional checks during cgroup discovery (#21148)
Limit cgroup discovery to a maximum number of entries and log a warning if exceeded
1 parent a8cdc7b commit 211b482

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/collectors/cgroups.plugin/cgroup-discovery.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -823,7 +823,7 @@ static inline void discovery_share_cgroups_with_ebpf() {
823823
}
824824
sem_wait(shm_mutex_cgroup_ebpf);
825825

826-
for (cg = cgroup_root, count = 0; cg; cg = cg->next, count++) {
826+
for (cg = cgroup_root, count = 0; cg && count < cgroup_root_max; cg = cg->next, count++) {
827827
netdata_ebpf_cgroup_shm_body_t *ptr = &shm_cgroup_ebpf.body[count];
828828
char *prefix = (is_cgroup_systemd_service(cg)) ? services_chart_id_prefix : cgroup_chart_id_prefix;
829829
snprintfz(ptr->name, CGROUP_EBPF_NAME_SHARED_LENGTH - 1, "%s%s", prefix, cg->chart_id);
@@ -843,6 +843,13 @@ static inline void discovery_share_cgroups_with_ebpf() {
843843
netdata_log_debug(D_CGROUP, "cgroup shared: NAME=%s, ENABLED=%d", ptr->name, ptr->enabled);
844844
}
845845

846+
if (unlikely(cg != NULL)) {
847+
nd_log_limit_static_global_var(erl, 3600, 0);
848+
nd_log_limit(&erl, NDLS_COLLECTORS, NDLP_WARNING,
849+
"CGROUP: shared memory buffer full (%d cgroups). Some cgroups were not shared with eBPF.",
850+
cgroup_root_max);
851+
}
852+
846853
shm_cgroup_ebpf.header->cgroup_root_count = count;
847854
sem_post(shm_mutex_cgroup_ebpf);
848855
}

0 commit comments

Comments
 (0)