mirror of
https://github.com/falcosecurity/falco.git
synced 2025-08-17 13:47:14 +00:00
cleanup(userspace): update parse_prometheus_interval
Signed-off-by: Melissa Kilby <melissa.kilby.oss@gmail.com>
This commit is contained in:
parent
9a12a93342
commit
6cdb740786
@ -61,10 +61,13 @@ TEST(FalcoUtils, parse_prometheus_interval)
|
|||||||
ASSERT_EQ(falco::utils::parse_prometheus_interval("2h5m"), 2 * 3600000UL + 5 * 60000UL);
|
ASSERT_EQ(falco::utils::parse_prometheus_interval("2h5m"), 2 * 3600000UL + 5 * 60000UL);
|
||||||
ASSERT_EQ(falco::utils::parse_prometheus_interval("2h 5m"), 2 * 3600000UL + 5 * 60000UL);
|
ASSERT_EQ(falco::utils::parse_prometheus_interval("2h 5m"), 2 * 3600000UL + 5 * 60000UL);
|
||||||
|
|
||||||
ASSERT_EQ(falco::utils::parse_prometheus_interval("200"), 200UL);
|
|
||||||
|
|
||||||
/* Invalid, non prometheus compliant time ordering will result in 0ms. */
|
/* Invalid, non prometheus compliant time ordering will result in 0ms. */
|
||||||
ASSERT_EQ(falco::utils::parse_prometheus_interval("1ms1y"), 0UL);
|
ASSERT_EQ(falco::utils::parse_prometheus_interval("1ms1y"), 0UL);
|
||||||
ASSERT_EQ(falco::utils::parse_prometheus_interval("1t1y"), 0UL);
|
ASSERT_EQ(falco::utils::parse_prometheus_interval("1t1y"), 0UL);
|
||||||
ASSERT_EQ(falco::utils::parse_prometheus_interval("1t"), 0UL);
|
ASSERT_EQ(falco::utils::parse_prometheus_interval("1t"), 0UL);
|
||||||
|
|
||||||
|
/* Deprecated option to pass a numeric value in ms without prometheus compliant time unit,
|
||||||
|
* will result in 0ms and as a result the end user will receive an error warning.
|
||||||
|
*/
|
||||||
|
ASSERT_EQ(falco::utils::parse_prometheus_interval("200"), 0UL);
|
||||||
}
|
}
|
||||||
|
@ -61,17 +61,6 @@ uint64_t parse_prometheus_interval(std::string interval_str)
|
|||||||
interval_str.erase(remove_if(interval_str.begin(), interval_str.end(), isspace), interval_str.end());
|
interval_str.erase(remove_if(interval_str.begin(), interval_str.end(), isspace), interval_str.end());
|
||||||
|
|
||||||
if(!interval_str.empty())
|
if(!interval_str.empty())
|
||||||
{
|
|
||||||
/* Option 1: Passing interval directly in ms. Will be deprecated in the future. */
|
|
||||||
if(std::all_of(interval_str.begin(), interval_str.end(), ::isdigit))
|
|
||||||
{
|
|
||||||
/* todo: deprecate for Falco 0.36. */
|
|
||||||
interval = std::stoull(interval_str, nullptr, 0);
|
|
||||||
}
|
|
||||||
/* Option 2: Passing a Prometheus compliant time duration.
|
|
||||||
* https://prometheus.io/docs/prometheus/latest/querying/basics/#time-durations
|
|
||||||
*/
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
re2::StringPiece input(interval_str);
|
re2::StringPiece input(interval_str);
|
||||||
std::string args[14];
|
std::string args[14];
|
||||||
@ -122,7 +111,6 @@ uint64_t parse_prometheus_interval(std::string interval_str)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return interval;
|
return interval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -435,7 +435,6 @@ static falco::app::run_result init_stats_writer(
|
|||||||
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");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
falco_logger::log(LOG_INFO, "Setting metrics interval to " + config->m_metrics_interval_str + ", equivalent to " + std::to_string(config->m_metrics_interval) + " (ms)\n");
|
falco_logger::log(LOG_INFO, "Setting metrics interval to " + config->m_metrics_interval_str + ", equivalent to " + std::to_string(config->m_metrics_interval) + " (ms)\n");
|
||||||
|
|
||||||
auto res = falco::app::run_result::ok();
|
auto res = falco::app::run_result::ok();
|
||||||
|
Loading…
Reference in New Issue
Block a user