|
4 | 4 | #include "utl/Logger.h" |
5 | 5 |
|
6 | 6 | #include <algorithm> |
| 7 | +#include <atomic> |
7 | 8 | #include <cstdint> |
8 | 9 | #include <cstring> |
9 | 10 | #include <fstream> |
|
21 | 22 | #else |
22 | 23 | #include "spdlog/pattern_formatter.h" |
23 | 24 | #endif |
| 25 | +#include "spdlog/common.h" |
24 | 26 | #include "spdlog/sinks/basic_file_sink.h" |
25 | 27 | #include "spdlog/sinks/ostream_sink.h" |
26 | 28 | #include "spdlog/sinks/stdout_color_sinks.h" |
@@ -58,6 +60,12 @@ Logger::Logger(const char* log_filename, const char* metrics_filename) |
58 | 60 | } |
59 | 61 | } |
60 | 62 |
|
| 63 | + for (auto& levels : message_levels_) { |
| 64 | + for (auto& level : levels) { |
| 65 | + level.store(spdlog::level::off, std::memory_order_relaxed); |
| 66 | + } |
| 67 | + } |
| 68 | + |
61 | 69 | prometheus_registry_ = std::make_shared<PrometheusRegistry>(); |
62 | 70 | } |
63 | 71 |
|
@@ -178,11 +186,34 @@ void Logger::flushMetrics() |
178 | 186 | } |
179 | 187 | } |
180 | 188 |
|
| 189 | +void Logger::addWarningMetrics() |
| 190 | +{ |
| 191 | + // Add metrics for non-zero warnings |
| 192 | + int warning_type_cnt = 0; |
| 193 | + for (int i = 0; i < ToolId::SIZE; ++i) { |
| 194 | + for (int j = 0; j <= max_message_id; ++j) { |
| 195 | + if (message_counters_[i][j] > 0 |
| 196 | + && message_levels_[i][j] == spdlog::level::warn) { |
| 197 | + warning_type_cnt++; |
| 198 | + log_metric( |
| 199 | + // NOLINTNEXTLINE(misc-include-cleaner) |
| 200 | + fmt::format("flow__warnings__count:{}-{}", tool_names_[i], j), |
| 201 | + std::to_string(message_counters_[i][j])); |
| 202 | + } |
| 203 | + } |
| 204 | + } |
| 205 | + |
| 206 | + // Add a metric to report the number of unique warning types |
| 207 | + log_metric("flow__warnings__type_count", std::to_string(warning_type_cnt)); |
| 208 | +} |
| 209 | + |
181 | 210 | void Logger::finalizeMetrics() |
182 | 211 | { |
183 | 212 | log_metric("flow__warnings__count", std::to_string(warning_count_)); |
184 | 213 | log_metric("flow__errors__count", std::to_string(error_count_)); |
185 | 214 |
|
| 215 | + addWarningMetrics(); |
| 216 | + |
186 | 217 | for (MetricsPolicy policy : metrics_policies_) { |
187 | 218 | policy.applyPolicy(metrics_entries_); |
188 | 219 | } |
|
0 commit comments