Skip to content

Commit

Permalink
cleanup(metrics): simplify some logic
Browse files Browse the repository at this point in the history
Co-authored-by: Samuel Gaist <samuel.gaist@idiap.ch>
Signed-off-by: Melissa Kilby <melissa.kilby.oss@gmail.com>
  • Loading branch information
incertum and sgaist committed May 16, 2024
1 parent 3d3e566 commit ea01751
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
5 changes: 3 additions & 2 deletions userspace/falco/falco_metrics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@ std::string falco_metrics::to_text(const falco::app::state& state)

prometheus_metrics_converter.convert_metric_to_unit_convention(metric);
prometheus_text += prometheus_metrics_converter.convert_metric_to_text_prometheus(metric, "falcosecurity", "falco");
for (size_t i = 0; i < rule_stats_manager.get_by_rule_id().size(); i++)
const std::vector<std::unique_ptr<std::atomic<uint64_t>>>& rules_by_id = rule_stats_manager.get_by_rule_id();
for (size_t i = 0; i < rules_by_id.size(); i++)
{
auto rule = rules.at(i);
std::string rules_metric_name = "rules." + rule->name;
Expand All @@ -176,7 +177,7 @@ std::string falco_metrics::to_text(const falco::app::state& state)
METRIC_VALUE_TYPE_U64,
METRIC_VALUE_UNIT_COUNT,
METRIC_VALUE_METRIC_TYPE_MONOTONIC,
rule_stats_manager.get_by_rule_id()[i]->load());
rules_by_id[i]->load());
prometheus_metrics_converter.convert_metric_to_unit_convention(metric);
const std::map<std::string, std::string>& const_labels = {
{"priority", std::to_string(rule->priority)},
Expand Down
8 changes: 5 additions & 3 deletions userspace/falco/stats_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -384,14 +384,16 @@ void stats_writer::collector::get_metrics_output_fields_additional(
const stats_manager& rule_stats_manager = m_writer->m_engine->get_rule_stats_manager();
const indexed_vector<falco_rule>& rules = m_writer->m_engine->get_rules();
output_fields["falco.rules.matches_total"] = rule_stats_manager.get_total().load();
for (size_t i = 0; i < rule_stats_manager.get_by_rule_id().size(); i++)
const std::vector<std::unique_ptr<std::atomic<uint64_t>>>& rules_by_id = rule_stats_manager.get_by_rule_id();
for (size_t i = 0; i < rules_by_id.size(); i++)
{
auto rule_count = rule_stats_manager.get_by_rule_id()[i]->load();
auto rule_count = rules_by_id[i]->load();
if (rule_count == 0 && !m_writer->m_config->m_metrics_include_empty_values)
{
continue;
}
std::string rules_metric_name = "falco.rules." + rules.at(i)->name;
auto rule = rules.at(i);
std::string rules_metric_name = "falco.rules." + rule->name;
output_fields[rules_metric_name] = rule_count;
}
}
Expand Down

0 comments on commit ea01751

Please sign in to comment.