diff --git a/userspace/falco/app/actions/process_events.cpp b/userspace/falco/app/actions/process_events.cpp index 00e44293..3a4b46a7 100644 --- a/userspace/falco/app/actions/process_events.cpp +++ b/userspace/falco/app/actions/process_events.cpp @@ -491,8 +491,9 @@ falco::app::run_result falco::app::actions::process_events(falco::app::state& s) } if(s.enabled_sources.size() == 1) { - // Since the inspector is now opened, we can enable prometheus metrics - s.webserver.enable_prometheus_metrics(s); + if(s.on_inspectors_opened != nullptr) { + s.on_inspectors_opened(); + } // optimization: with only one source we don't spawn additional threads process_inspector_events(s, @@ -523,9 +524,8 @@ falco::app::run_result falco::app::actions::process_events(falco::app::state& s) break; } } - if(s.enabled_sources.size() > 1) { - // Since all inspectors are now opened, we can enable prometheus metrics - s.webserver.enable_prometheus_metrics(s); + if(s.enabled_sources.size() > 1 && s.on_inspectors_opened != nullptr) { + s.on_inspectors_opened(); } // wait for event processing to terminate for all sources diff --git a/userspace/falco/app/actions/start_webserver.cpp b/userspace/falco/app/actions/start_webserver.cpp index ce725b76..45ed980f 100644 --- a/userspace/falco/app/actions/start_webserver.cpp +++ b/userspace/falco/app/actions/start_webserver.cpp @@ -44,6 +44,7 @@ falco::app::run_result falco::app::actions::start_webserver(falco::app::state& s std::to_string(webserver_config.m_listen_port) + ssl_option + "\n"); state.webserver.start(state, webserver_config); + state.on_inspectors_opened = [&state]() { state.webserver.enable_prometheus_metrics(state); }; #endif return run_result::ok(); } diff --git a/userspace/falco/app/state.h b/userspace/falco/app/state.h index a5281c65..1b1338bb 100644 --- a/userspace/falco/app/state.h +++ b/userspace/falco/app/state.h @@ -116,6 +116,9 @@ struct state { falco_webserver webserver; #endif + // Set by start_webserver to start prometheus metrics + // once all inspectors are opened. + std::function on_inspectors_opened = nullptr; inline bool is_capture_mode() const { return config->m_engine_mode == engine_kind_t::REPLAY; }