update(userspace): minor polishing

Signed-off-by: Jason Dellaluce <jasondellaluce@gmail.com>
This commit is contained in:
Jason Dellaluce 2023-05-19 15:54:10 +00:00 committed by poiana
parent f117d5273c
commit 5d35cda8dc
5 changed files with 10 additions and 5 deletions

View File

@ -70,7 +70,6 @@ uint64_t parse_metrics_interval(std::string interval_str)
{ {
/* todo: deprecate for Falco 0.36. */ /* todo: deprecate for Falco 0.36. */
interval = std::stoull(interval_str, nullptr, 0); 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. /* Option 2: Passing a Prometheus time duration.
* https://prometheus.io/docs/prometheus/latest/querying/basics/#time-durations * https://prometheus.io/docs/prometheus/latest/querying/basics/#time-durations

View File

@ -27,7 +27,7 @@ static void apply_deprecated_options(
{ {
if (!opts.stats_output_file.empty() || !opts.stats_interval.empty()) 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()) if (!opts.stats_output_file.empty())
{ {
cfg->m_metrics_enabled = true; cfg->m_metrics_enabled = true;

View File

@ -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"); 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()) 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"); falco_logger::log(LOG_WARNING, "Metrics are enabled with no output configured, no snapshot will be collected");

View File

@ -163,9 +163,8 @@ void stats_writer::worker() noexcept
{ {
std::string rule = "Falco internal: metrics snapshot"; std::string rule = "Falco internal: metrics snapshot";
std::string msg = "Falco metrics snapshot"; std::string msg = "Falco metrics snapshot";
uint64_t ts = 0; // todo: pass timestamp in message
std::map<std::string,std::string> fields = {m.output_fields.begin(), m.output_fields.end()}; std::map<std::string,std::string> 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) if (use_file)
@ -369,6 +368,7 @@ void stats_writer::collector::collect(const std::shared_ptr<sinsp>& inspector, c
/* Send message in the queue */ /* Send message in the queue */
stats_writer::msg msg; stats_writer::msg msg;
msg.ts = now;
msg.source = src; msg.source = src;
msg.output_fields = std::move(output_fields); msg.output_fields = std::move(output_fields);
m_writer->push(msg); m_writer->push(msg);

View File

@ -125,13 +125,14 @@ public:
private: private:
struct msg struct msg
{ {
msg(): stop(false) {} msg(): stop(false), ts(0) {}
msg(msg&&) = default; msg(msg&&) = default;
msg& operator = (msg&&) = default; msg& operator = (msg&&) = default;
msg(const msg&) = default; msg(const msg&) = default;
msg& operator = (const msg&) = default; msg& operator = (const msg&) = default;
bool stop; bool stop;
uint64_t ts;
std::string source; std::string source;
std::unordered_map<std::string, std::string> output_fields; std::unordered_map<std::string, std::string> output_fields;
}; };