Skip to content

Commit

Permalink
resolve comments
Browse files Browse the repository at this point in the history
  • Loading branch information
wcy-fdu committed Jun 13, 2023
1 parent 71910d6 commit c426bb4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
10 changes: 6 additions & 4 deletions src/common/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,24 +49,26 @@ impl Atomic for TrAdderAtomic {

pub type TrAdderGauge = GenericGauge<TrAdderAtomic>;

pub struct CustomLayer {
/// [`MetricsLayer`] is a struct used for monitoring the frequency of certain specific logs and
/// counting them using Prometheus metrics. Currently, it is used to monitor the frequency of retry
/// occurrences of aws sdk.
pub struct MetricsLayer {
pub aws_sdk_retry_counts: GenericCounter<AtomicU64>,
}

impl<S> Layer<S> for CustomLayer
impl<S> Layer<S> for MetricsLayer
where
S: Subscriber + for<'a> LookupSpan<'a>,
{
fn on_event(&self, _event: &tracing::Event<'_>, _ctx: Context<'_, S>) {
// Currently one retry will only generate one debug log,
// so we can monitor the number of retry only through the metadata target.
// Refer to <https://docs.rs/aws-smithy-client/0.55.3/src/aws_smithy_client/retry.rs.html>

self.aws_sdk_retry_counts.inc();
}
}

impl CustomLayer {
impl MetricsLayer {
pub fn new(registry: Registry) -> Self {
let aws_sdk_retry_counts = register_int_counter_with_registry!(
"aws_sdk_retry_counts",
Expand Down
4 changes: 2 additions & 2 deletions src/utils/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use std::path::PathBuf;
use std::time::Duration;

use futures::Future;
use risingwave_common::metrics::CustomLayer;
use risingwave_common::metrics::MetricsLayer;
use tracing::Level;
use tracing_subscriber::filter::{Directive, Targets};
use tracing_subscriber::layer::SubscriberExt;
Expand Down Expand Up @@ -282,7 +282,7 @@ pub fn init_risingwave_logger(settings: LoggerSettings, registry: prometheus::Re

let filter = filter::Targets::new().with_target("aws_smithy_client::retry", Level::DEBUG);

layers.push(Box::new(CustomLayer::new(registry).with_filter(filter)));
layers.push(Box::new(MetricsLayer::new(registry).with_filter(filter)));
tracing_subscriber::registry().with(layers).init();

// TODO: add file-appender tracing subscriber in the future
Expand Down

0 comments on commit c426bb4

Please sign in to comment.