diff --git a/test/falco_test.py b/test/falco_test.py index 5c084d10..63cf7b2b 100644 --- a/test/falco_test.py +++ b/test/falco_test.py @@ -40,6 +40,8 @@ class FalcoTest(Test): build_type = "debug" if build_type == "debug" else "release" build_dir = os.path.join('/build', build_type) + if not os.path.exists(build_dir): + build_dir = '../build' self.falcodir = self.params.get('falcodir', '/', default=os.path.join(self.basedir, build_dir)) self.stdout_is = self.params.get('stdout_is', '*', default='') diff --git a/userspace/falco/falco.cpp b/userspace/falco/falco.cpp index d335653f..0620754a 100644 --- a/userspace/falco/falco.cpp +++ b/userspace/falco/falco.cpp @@ -258,8 +258,10 @@ uint64_t do_inspect(falco_engine *engine, } // Module check settings - utils::timer t; - t.reset(); + // utils::timer t; + // t.reset(); + + uint64_t now = 0; uint64_t frequency = config.m_module_check_frequency; auto num_failures = 0; @@ -273,24 +275,24 @@ uint64_t do_inspect(falco_engine *engine, // while(true) { - // Check module every x seconds - if(t.seconds_elapsed() > frequency) { - // Check module is present and loaded with exponential backoff (eg., 100, 200, 400, ...) - // When module is missing or unloaded, try to insert it - // Retries at most times - // Stops early if module is found - auto found = utils::retry(max_attempts, ini_delay, max_delay, utils::module_predicate, utils::has_module, verbose, true); + // // Check module every x seconds + // if(t.seconds_elapsed() > frequency) { + // // Check module is present and loaded with exponential backoff (eg., 100, 200, 400, ...) + // // When module is missing or unloaded, try to insert it + // // Retries at most times + // // Stops early if module is found + // auto found = utils::retry(max_attempts, ini_delay, max_delay, utils::module_predicate, utils::has_module, verbose, true); - // Count how many intervals the module is missing, reset counter when module has been found - num_failures = found ? 0 : num_failures + 1; - // Stop falco if module is missing from checks - if (num_failures >= max_failures) { - result = EXIT_FAILURE; - break; - } - // Reset timer - t.reset(); - } + // // Count how many intervals the module is missing, reset counter when module has been found + // num_failures = found ? 0 : num_failures + 1; + // // Stop falco if module is missing from checks + // if (num_failures >= max_failures) { + // result = EXIT_FAILURE; + // break; + // } + // // Reset timer + // t.reset(); + // } rc = inspector->next(&ev); @@ -325,10 +327,11 @@ uint64_t do_inspect(falco_engine *engine, throw sinsp_exception(inspector->getlasterr().c_str()); } - if (duration_start == 0) + if(duration_start == 0) { duration_start = ev->get_ts(); - } else if(duration_to_tot_ns > 0) + } + else if(duration_to_tot_ns > 0) { if(ev->get_ts() - duration_start >= duration_to_tot_ns) { @@ -336,6 +339,25 @@ uint64_t do_inspect(falco_engine *engine, } } + if((ev->get_ts() - now) >= (frequency*ONE_SECOND_IN_NS)) + { + // Check module is present and loaded with exponential backoff (eg., 100, 200, 400, ...) + // When module is missing or unloaded, try to insert it + // Retries at most times + // Stops early if module is found + auto found = utils::retry(max_attempts, ini_delay, max_delay, utils::module_predicate, utils::has_module, verbose, true); + + // Count how many intervals the module is missing, reset counter when module has been found + num_failures = found ? 0 : num_failures + 1; + // Stop falco if module is missing from checks + if (num_failures >= max_failures) { + result = EXIT_FAILURE; + break; + } + // Reset + now = ev->get_ts(); + } + if(!sdropmgr.process_event(inspector, ev)) { result = EXIT_FAILURE; diff --git a/userspace/falco/retry.h b/userspace/falco/retry.h index fba1552a..221b10ad 100644 --- a/userspace/falco/retry.h +++ b/userspace/falco/retry.h @@ -30,7 +30,7 @@ template< typename Predicate, typename Callable, typename... Args, - // figure out what the callable returns + // figure out the callable return type typename R = std::decay_t>, // require that Predicate is actually a Predicate std::enable_if_t, bool>::value, int> = 0> @@ -64,6 +64,7 @@ R retry(int max_retries, std::ostringstream message; message << "Waiting " << delay << "ms ... \n"; falco_logger::log(LOG_INFO, message.str()); + // Blocking for `delay` ms std::this_thread::sleep_for(std::chrono::milliseconds(delay)); retries++; }