mirror of
https://github.com/falcosecurity/falco.git
synced 2025-07-15 07:22:05 +00:00
fix(userspace/falco): only enable prometheus metrics once all inspectors have been opened.
Signed-off-by: Federico Di Pierro <nierro92@gmail.com>
This commit is contained in:
parent
b94cda0b12
commit
d6fc8c63e5
@ -491,6 +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);
|
||||
|
||||
// optimization: with only one source we don't spawn additional threads
|
||||
process_inspector_events(s,
|
||||
src_info->inspector,
|
||||
@ -520,6 +523,10 @@ 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);
|
||||
}
|
||||
|
||||
// wait for event processing to terminate for all sources
|
||||
// if a thread terminates with an error, we trigger the app termination
|
||||
|
@ -58,12 +58,6 @@ void falco_webserver::start(const falco::app::state &state,
|
||||
res.set_content(versions_json_str, "application/json");
|
||||
});
|
||||
|
||||
if(state.config->m_metrics_enabled && webserver_config.m_prometheus_metrics_enabled) {
|
||||
m_server->Get("/metrics", [&state](const httplib::Request &, httplib::Response &res) {
|
||||
res.set_content(falco_metrics::to_text_prometheus(state),
|
||||
falco_metrics::content_type_prometheus);
|
||||
});
|
||||
}
|
||||
// run server in a separate thread
|
||||
if(!m_server->is_valid()) {
|
||||
m_server = nullptr;
|
||||
@ -106,3 +100,13 @@ void falco_webserver::stop() {
|
||||
m_running = false;
|
||||
}
|
||||
}
|
||||
|
||||
void falco_webserver::enable_prometheus_metrics(const falco::app::state &state) {
|
||||
if(state.config->m_metrics_enabled &&
|
||||
state.config->m_webserver_config.m_prometheus_metrics_enabled) {
|
||||
m_server->Get("/metrics", [&state](const httplib::Request &, httplib::Response &res) {
|
||||
res.set_content(falco_metrics::to_text_prometheus(state),
|
||||
falco_metrics::content_type_prometheus);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -40,6 +40,7 @@ public:
|
||||
virtual void start(const falco::app::state& state,
|
||||
const falco_configuration::webserver_config& webserver_config);
|
||||
virtual void stop();
|
||||
virtual void enable_prometheus_metrics(const falco::app::state& state);
|
||||
|
||||
private:
|
||||
bool m_running = false;
|
||||
|
Loading…
Reference in New Issue
Block a user