Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(starknet_sequencer_infra): add dynamic logging util fn #2328

Closed
wants to merge 1 commit into from

Conversation

@reviewable-StarkWare
Copy link

This change is Reviewable

Copy link

Benchmark movements:
tree_computation_flow performance regressed!
tree_computation_flow time: [34.744 ms 35.257 ms 35.876 ms]
change: [+2.0039% +3.5715% +5.2905%] (p = 0.00 < 0.05)
Performance has regressed.
Found 13 outliers among 100 measurements (13.00%)
3 (3.00%) low mild
3 (3.00%) high mild
7 (7.00%) high severe

full_committer_flow performance improved 😺
full_committer_flow time: [30.367 ms 30.422 ms 30.480 ms]
change: [-3.3226% -2.9437% -2.6104%] (p = 0.00 < 0.05)
Performance has improved.
Found 4 outliers among 100 measurements (4.00%)
3 (3.00%) high mild
1 (1.00%) high severe

Copy link

codecov bot commented Nov 28, 2024

Codecov Report

Attention: Patch coverage is 0% with 14 lines in your changes missing coverage. Please review.

Project coverage is 77.55%. Comparing base (e3165c4) to head (7967122).
Report is 672 commits behind head on main.

Files with missing lines Patch % Lines
crates/infra_utils/src/tracing.rs 0.00% 14 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main    #2328       +/-   ##
===========================================
+ Coverage   40.10%   77.55%   +37.44%     
===========================================
  Files          26      388      +362     
  Lines        1895    41126    +39231     
  Branches     1895    41126    +39231     
===========================================
+ Hits          760    31895    +31135     
- Misses       1100     6978     +5878     
- Partials       35     2253     +2218     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Itay-Tsabary-Starkware Itay-Tsabary-Starkware changed the base branch from spr/main/4d0abfb5 to main November 28, 2024 12:03
@Itay-Tsabary-Starkware Itay-Tsabary-Starkware changed the base branch from main to spr/main/4d0abfb5 November 28, 2024 12:03
Copy link

Benchmark movements:
tree_computation_flow performance improved 😺
tree_computation_flow time: [33.597 ms 33.628 ms 33.663 ms]
change: [-4.1108% -2.5955% -1.2684%] (p = 0.00 < 0.05)
Performance has improved.
Found 10 outliers among 100 measurements (10.00%)
5 (5.00%) high mild
5 (5.00%) high severe

full_committer_flow performance improved 😺
full_committer_flow time: [29.403 ms 29.449 ms 29.499 ms]
change: [-2.9366% -2.7469% -2.5410%] (p = 0.00 < 0.05)
Performance has improved.
Found 6 outliers among 100 measurements (6.00%)
4 (4.00%) high mild
2 (2.00%) high severe

@Itay-Tsabary-Starkware Itay-Tsabary-Starkware changed the base branch from spr/main/4d0abfb5 to main November 28, 2024 14:56
Copy link

Benchmark movements:
tree_computation_flow performance regressed!
tree_computation_flow time: [35.315 ms 35.807 ms 36.383 ms]
change: [+1.3919% +2.9894% +4.9688%] (p = 0.00 < 0.05)
Performance has regressed.
Found 7 outliers among 100 measurements (7.00%)
7 (7.00%) high severe

@Itay-Tsabary-Starkware Itay-Tsabary-Starkware force-pushed the spr/main/9ffe9fbe branch 2 times, most recently from 3074675 to e3aeefe Compare December 1, 2024 11:19
@Itay-Tsabary-Starkware Itay-Tsabary-Starkware changed the title chore(infra): add dynamic logging util fn chore(starknet_sequencer_infra): add dynamic logging util fn Dec 1, 2024
@Itay-Tsabary-Starkware Itay-Tsabary-Starkware force-pushed the spr/main/9ffe9fbe branch 2 times, most recently from cfe3da9 to 1c04622 Compare December 2, 2024 08:32
@Itay-Tsabary-Starkware Itay-Tsabary-Starkware force-pushed the spr/main/9ffe9fbe branch 2 times, most recently from f6705a7 to 397d1e8 Compare December 2, 2024 13:00
Copy link
Contributor

@lev-starkware lev-starkware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 0 of 4 files reviewed, 2 unresolved discussions (waiting on @Itay-Tsabary-Starkware)


crates/infra_utils/src/tracing.rs line 4 at r1 (raw file):

/// Dynamically set tracing level of a message.
pub struct DynamicLogger {

Why this is DynamicLogger?
Your previous version, As I remember, could log every message with a different TraceLevel


crates/infra_utils/src/tracing.rs line 23 at r1 (raw file):

        };

        match self.level {

I understand that 'match' is quite effective, but it doesn't seem pretty.

I would suggest another solution but its up to you

Code snippet:

use tracing::{debug, error, info, trace, warn}; 

pub struct DynamicLogger {
    base_msg: Option<String>,
    log_message_fn: Box<dyn Fn(&str)>,
}

impl DynamicLogger {
    fn new(base_msg: Option<String>, log_message_fn: Box<dyn Fn(&str)>) -> Self {
        Self { base_msg, log_message_fn }
    }

    fn log_message(&self, msg: &str) {
        let message = match &self.base_msg {
            Some(base_msg) => format!("{}: {}", base_msg, msg),
            None => msg.to_string(),
        };
        (self.log_message_fn)(&message);
    }
}

pub enum TraceLevel {
    Trace,
    Debug,
    Info,
    Warn,
    Error,
}

pub fn create_logger(base_msg: Option<String>, level: TraceLevel) -> DynamicLogger {
    let log_fn: Box<dyn Fn(&str)> = match level {
        TraceLevel::Trace => Box::new(|msg| trace!("{}", msg)),
        TraceLevel::Debug => Box::new(|msg| debug!("{}", msg)),
        TraceLevel::Info => Box::new(|msg| info!("{}", msg)),
        TraceLevel::Warn => Box::new(|msg| warn!("{}", msg)),
        TraceLevel::Error => Box::new(|msg| error!("{}", msg)),
    };

    DynamicLogger::new(base_msg, log_fn)
}

Copy link
Contributor Author

@Itay-Tsabary-Starkware Itay-Tsabary-Starkware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 0 of 4 files reviewed, 1 unresolved discussion (waiting on @lev-starkware)


crates/infra_utils/src/tracing.rs line 4 at r1 (raw file):

Previously, lev-starkware wrote…

Why this is DynamicLogger?
Your previous version, As I remember, could log every message with a different TraceLevel

It determines the logging level at runtime and not at compile time.
Happy to take name suggestions.

Copy link
Contributor

@lev-starkware lev-starkware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 3 of 4 files at r1, 1 of 1 files at r3, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @Itay-Tsabary-Starkware)


crates/infra_utils/src/tracing.rs line 4 at r1 (raw file):

Previously, Itay-Tsabary-Starkware wrote…

It determines the logging level at runtime and not at compile time.
Happy to take name suggestions.

AdaptiveLogger, FlexibleLogger, and my favorite CustomLogger?

Copy link
Contributor Author

@Itay-Tsabary-Starkware Itay-Tsabary-Starkware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @lev-starkware)


crates/infra_utils/src/tracing.rs line 4 at r1 (raw file):

Previously, lev-starkware wrote…

AdaptiveLogger, FlexibleLogger, and my favorite CustomLogger?

Added a refactor in #2424

Copy link
Contributor

@lev-starkware lev-starkware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @Itay-Tsabary-Starkware)

@Itay-Tsabary-Starkware
Copy link
Contributor Author

✓ Commit merged in pull request #2424

@github-actions github-actions bot locked and limited conversation to collaborators Dec 5, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants