Fix disabled apps (ebpf.plugin) (#13044)
thiagoftsm committed
Jun 1, 2022 at 08:33 UTC
a16fbcef1649b898617239dd108c8515618c3488
5 files changed
+40
-2
collectors/ebpf.plugin/ebpf.c
+22
-2
@@ -1082,11 +1082,33 @@ int ebpf_start_pthread_variables()
1082
return 0;
1083
}
1084
1085
+/**
1086
+ * Am I collecting PIDs?
1087
+ *
1088
+ * Test if eBPF plugin needs to collect PID information.
1089
+ *
1090
+ * @return It returns 1 if at least one thread needs to collect the data, or zero otherwise.
1091
+ */
1092
+static inline uint32_t ebpf_am_i_collect_pids()
1093
+{
1094
+ uint32_t ret = 0;
1095
+ int i;
1096
+ for (i = 0; ebpf_modules[i].thread_name; i++) {
1097
+ ret |= ebpf_modules[i].cgroup_charts | ebpf_modules[i].apps_charts;
1098
+ }
1099
+
1100
+ return ret;
1101
+}
1102
+
1103
/**
1104
* Allocate the vectors used for all threads.
1105
*/
1106
static void ebpf_allocate_common_vectors()
1107
{
1108
+ if (unlikely(!ebpf_am_i_collect_pids())) {
1109
+ return;
1110
+ }
1111
+
1112
all_pids = callocz((size_t)pid_max, sizeof(struct pid_stat *));
1113
global_process_stat = callocz((size_t)ebpf_nprocs, sizeof(ebpf_process_stat_t));
1114
}
@@ -1427,8 +1449,6 @@ void set_global_variables()
1449
1450
/**
1451
* Load collector config
1430
- *
1431
- * @param lmode the mode that will be used for them.
1452
*/
1453
static inline void ebpf_load_thread_config()
1454
{
collectors/ebpf.plugin/ebpf_apps.c
+3
@@ -1091,6 +1091,9 @@ static inline void aggregate_pid_on_target(struct target *w, struct pid_stat *p,
1091
*/
1092
void collect_data_for_all_processes(int tbl_pid_stats_fd)
1093
{
1094
+ if (unlikely(!all_pids))
1095
+ return;
1096
+
1097
struct pid_stat *pids = root_of_pids; // global list of all processes running
1098
while (pids) {
1099
if (pids->updated_twice) {
collectors/ebpf.plugin/ebpf_oomkill.c
+9
@@ -377,6 +377,15 @@ void *ebpf_oomkill_thread(void *ptr)
377
ebpf_module_t *em = (ebpf_module_t *)ptr;
378
em->maps = oomkill_maps;
379
380
+ if (unlikely(!all_pids || !em->apps_charts)) {
381
+ // When we are not running integration with apps, we won't fill necessary variables for this thread to run, so
382
+ // we need to disable it.
383
+ if (em->enabled)
384
+ info("Disabling OOMKILL thread, because apps integration is completely disabled.");
385
+
386
+ em->enabled = 0;
387
+ }
388
+
389
if (!em->enabled) {
390
goto endoomkill;
391
}
collectors/ebpf.plugin/ebpf_process.c
+3
@@ -579,6 +579,9 @@ void ebpf_process_create_apps_charts(struct ebpf_module *em, void *ptr)
579
*/
580
static void ebpf_create_apps_charts(struct target *root)
581
{
582
+ if (unlikely(!all_pids))
583
+ return;
584
+
585
struct target *w;
586
int newly_added = 0;
587
libnetdata/ebpf/ebpf.c
+3
@@ -971,6 +971,9 @@ void ebpf_update_module_using_config(ebpf_module_t *modules)
971
modules->apps_charts = appconfig_get_boolean(modules->cfg, EBPF_GLOBAL_SECTION, EBPF_CFG_APPLICATION,
972
modules->apps_charts);
973
974
+ modules->cgroup_charts = appconfig_get_boolean(modules->cfg, EBPF_GLOBAL_SECTION, EBPF_CFG_CGROUP,
975
+ modules->cgroup_charts);
976
+
977
modules->pid_map_size = (uint32_t)appconfig_get_number(modules->cfg, EBPF_GLOBAL_SECTION, EBPF_CFG_PID_SIZE,
978
modules->pid_map_size);
979