Skip to content

Commit

Permalink
add metrics counters for warn! and info! logs (#13552)
Browse files Browse the repository at this point in the history
* add metrics counters for warn! and info! logs

* move info/warn/err counting out of macro into handler thread
  • Loading branch information
brianolson authored Jun 21, 2024
1 parent 8f3e991 commit 43d709c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
9 changes: 8 additions & 1 deletion crates/aptos-logger/src/aptos_logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ use crate::{
sample,
sample::SampleRate,
telemetry_log_writer::{TelemetryLog, TelemetryLogWriter},
Event, Filter, Key, Level, LevelFilter, Metadata,
Event, Filter, Key, Level, LevelFilter, Metadata, ERROR_LOG_COUNT, INFO_LOG_COUNT,
WARN_LOG_COUNT,
};
use aptos_infallible::RwLock;
use backtrace::Backtrace;
Expand Down Expand Up @@ -604,6 +605,12 @@ impl LoggerService {
match event {
LoggerServiceEvent::LogEntry(entry) => {
PROCESSED_STRUCT_LOG_COUNT.inc();
match entry.metadata.level() {
Level::Error => ERROR_LOG_COUNT.inc(),
Level::Warn => WARN_LOG_COUNT.inc(),
Level::Info => INFO_LOG_COUNT.inc(),
_ => {},
}

if let Some(printer) = &mut self.printer {
if self
Expand Down
6 changes: 5 additions & 1 deletion crates/aptos-logger/src/counters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,13 @@ pub static PROCESSED_STRUCT_LOG_COUNT: Lazy<IntCounter> = Lazy::new(|| {
.unwrap()
});

/// Count of error!() logs
/// Counts of logs
pub static ERROR_LOG_COUNT: Lazy<IntCounter> =
Lazy::new(|| register_int_counter!("aptos_error_log_count", "Count of error!() logs").unwrap());
pub static WARN_LOG_COUNT: Lazy<IntCounter> =
Lazy::new(|| register_int_counter!("aptos_warn_log_count", "Count of warn!() logs").unwrap());
pub static INFO_LOG_COUNT: Lazy<IntCounter> =
Lazy::new(|| register_int_counter!("aptos_info_log_count", "Count of info!() logs").unwrap());

/// Metric for when we fail to log during sending to the queue
pub static STRUCT_LOG_QUEUE_ERROR_COUNT: Lazy<IntCounter> = Lazy::new(|| {
Expand Down
2 changes: 1 addition & 1 deletion crates/aptos-logger/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,4 @@ pub use metadata::{Level, Metadata};
pub use security::SecurityEvent;

mod counters;
pub use counters::ERROR_LOG_COUNT;
pub use counters::{ERROR_LOG_COUNT, INFO_LOG_COUNT, WARN_LOG_COUNT};
4 changes: 0 additions & 4 deletions crates/aptos-logger/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,6 @@ macro_rules! log {
concat!(file!(), ':', line!()),
);

if METADATA.level() == $crate::Level::Error {
$crate::ERROR_LOG_COUNT.inc();
}

if METADATA.enabled() {
$crate::Event::dispatch(
&METADATA,
Expand Down

0 comments on commit 43d709c

Please sign in to comment.