Skip to content

Commit 8c167ea

Browse files
committed
Added new metrics for warnings.
- *__flow__warnings__type_count: the number of unique warning types - *__flow__warnings__count:<TOOL>-<ID> Signed-off-by: Jaehyun Kim <jhkim@precisioninno.com>
1 parent 5ba8849 commit 8c167ea

2 files changed

Lines changed: 35 additions & 0 deletions

File tree

src/utl/include/utl/Logger.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ class Logger
279279
const Args&... args)
280280
{
281281
assert(id >= 0 && id <= max_message_id);
282+
message_levels_[tool][id].store(level, std::memory_order_relaxed);
282283
auto& counter = message_counters_[tool][id];
283284
auto count = counter++;
284285
if (count < max_message_print) {
@@ -319,6 +320,9 @@ class Logger
319320

320321
void flushMetrics();
321322
void finalizeMetrics();
323+
// Add new metric for each non-zero warning. It also counts the number of
324+
// unique warning types.
325+
void addWarningMetrics();
322326

323327
void setRedirectSink(std::ostream& sink_stream, bool keep_sinks = false);
324328
void restoreFromRedirect();
@@ -359,6 +363,9 @@ class Logger
359363
// from multiple threads without locks.
360364
using MessageCounter = std::array<std::atomic_int16_t, max_message_id + 1>;
361365
std::array<MessageCounter, ToolId::SIZE> message_counters_;
366+
using MessageLevel
367+
= std::array<std::atomic<spdlog::level::level_enum>, max_message_id + 1>;
368+
std::array<MessageLevel, ToolId::SIZE> message_levels_;
362369
std::array<DebugGroups, ToolId::SIZE> debug_group_level_;
363370
bool debug_on_{false};
364371
std::atomic_int warning_count_{0};

src/utl/src/Logger.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ Logger::Logger(const char* log_filename, const char* metrics_filename)
5858
}
5959
}
6060

61+
for (auto& levels : message_levels_) {
62+
for (auto& level : levels) {
63+
level.store(spdlog::level::off, std::memory_order_relaxed);
64+
}
65+
}
66+
6167
prometheus_registry_ = std::make_shared<PrometheusRegistry>();
6268
}
6369

@@ -178,11 +184,33 @@ void Logger::flushMetrics()
178184
}
179185
}
180186

187+
void Logger::addWarningMetrics()
188+
{
189+
// Add metrics for non-zero warnings
190+
int warning_type_cnt = 0;
191+
for (int i = 0; i < ToolId::SIZE; ++i) {
192+
for (int j = 0; j <= max_message_id; ++j) {
193+
if (message_counters_[i][j] > 0
194+
&& message_levels_[i][j] == spdlog::level::warn) {
195+
warning_type_cnt++;
196+
log_metric(
197+
fmt::format("flow__warnings__count:{}-{}", tool_names_[i], j),
198+
std::to_string(message_counters_[i][j]));
199+
}
200+
}
201+
}
202+
203+
// Add a metric to report the number of unique warning types
204+
log_metric("flow__warnings__type_count", std::to_string(warning_type_cnt));
205+
}
206+
181207
void Logger::finalizeMetrics()
182208
{
183209
log_metric("flow__warnings__count", std::to_string(warning_count_));
184210
log_metric("flow__errors__count", std::to_string(error_count_));
185211

212+
addWarningMetrics();
213+
186214
for (MetricsPolicy policy : metrics_policies_) {
187215
policy.applyPolicy(metrics_entries_);
188216
}

0 commit comments

Comments
 (0)