From 5d35cda8dc24f7695372e10c6aa0d6c82ec358e1 Mon Sep 17 00:00:00 2001 From: Jason Dellaluce Date: Fri, 19 May 2023 15:54:10 +0000 Subject: [PATCH] update(userspace): minor polishing Signed-off-by: Jason Dellaluce --- userspace/engine/falco_metrics.cpp | 1 - userspace/falco/app/actions/load_config.cpp | 2 +- userspace/falco/app/actions/process_events.cpp | 5 +++++ userspace/falco/stats_writer.cpp | 4 ++-- userspace/falco/stats_writer.h | 3 ++- 5 files changed, 10 insertions(+), 5 deletions(-) diff --git a/userspace/engine/falco_metrics.cpp b/userspace/engine/falco_metrics.cpp index 0783db1e..02368057 100644 --- a/userspace/engine/falco_metrics.cpp +++ b/userspace/engine/falco_metrics.cpp @@ -70,7 +70,6 @@ uint64_t parse_metrics_interval(std::string interval_str) { /* todo: deprecate for Falco 0.36. */ interval = std::stoull(interval_str, nullptr, 0); - std::cerr << "Metrics interval was passed as numeric value without Prometheus time unit, this option will no longer be supported starting Falco 0.36" << std::endl; } /* Option 2: Passing a Prometheus time duration. * https://prometheus.io/docs/prometheus/latest/querying/basics/#time-durations diff --git a/userspace/falco/app/actions/load_config.cpp b/userspace/falco/app/actions/load_config.cpp index b48197d9..6f153081 100644 --- a/userspace/falco/app/actions/load_config.cpp +++ b/userspace/falco/app/actions/load_config.cpp @@ -27,7 +27,7 @@ static void apply_deprecated_options( { if (!opts.stats_output_file.empty() || !opts.stats_interval.empty()) { - falco_logger::log(LOG_WARNING, "Options '-s' and '--stats-interval' are deprecated, metrics must be configured in the config file"); + falco_logger::log(LOG_WARNING, "Options '-s' and '--stats-interval' will be deprecated in the future, metrics must be configured through config file"); if (!opts.stats_output_file.empty()) { cfg->m_metrics_enabled = true; diff --git a/userspace/falco/app/actions/process_events.cpp b/userspace/falco/app/actions/process_events.cpp index 25adc231..1a0be7b1 100644 --- a/userspace/falco/app/actions/process_events.cpp +++ b/userspace/falco/app/actions/process_events.cpp @@ -412,6 +412,11 @@ static falco::app::run_result init_stats_writer( return falco::app::run_result::fatal("Metrics interval must have a minimum value of 100ms"); } + if(std::all_of(config->m_metrics_interval_str.begin(), config->m_metrics_interval_str.end(), ::isdigit)) + { + falco_logger::log(LOG_WARNING, "Metrics interval was passed as numeric value without Prometheus time unit, this option will be deprecated in the future"); + } + if (config->m_metrics_enabled && !sw->has_output()) { falco_logger::log(LOG_WARNING, "Metrics are enabled with no output configured, no snapshot will be collected"); diff --git a/userspace/falco/stats_writer.cpp b/userspace/falco/stats_writer.cpp index f2b41ac9..b1c5e5cf 100644 --- a/userspace/falco/stats_writer.cpp +++ b/userspace/falco/stats_writer.cpp @@ -163,9 +163,8 @@ void stats_writer::worker() noexcept { std::string rule = "Falco internal: metrics snapshot"; std::string msg = "Falco metrics snapshot"; - uint64_t ts = 0; // todo: pass timestamp in message std::map fields = {m.output_fields.begin(), m.output_fields.end()}; - m_outputs->handle_msg(ts, falco_common::PRIORITY_INFORMATIONAL, msg, rule, fields); + m_outputs->handle_msg(m.ts, falco_common::PRIORITY_INFORMATIONAL, msg, rule, fields); } if (use_file) @@ -369,6 +368,7 @@ void stats_writer::collector::collect(const std::shared_ptr& inspector, c /* Send message in the queue */ stats_writer::msg msg; + msg.ts = now; msg.source = src; msg.output_fields = std::move(output_fields); m_writer->push(msg); diff --git a/userspace/falco/stats_writer.h b/userspace/falco/stats_writer.h index ebb40355..3c07db16 100644 --- a/userspace/falco/stats_writer.h +++ b/userspace/falco/stats_writer.h @@ -125,13 +125,14 @@ public: private: struct msg { - msg(): stop(false) {} + msg(): stop(false), ts(0) {} msg(msg&&) = default; msg& operator = (msg&&) = default; msg(const msg&) = default; msg& operator = (const msg&) = default; bool stop; + uint64_t ts; std::string source; std::unordered_map output_fields; };