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

dedup #193

Closed
wants to merge 12 commits into from
Closed

dedup #193

wants to merge 12 commits into from

Conversation

pm100
Copy link

@pm100 pm100 commented Oct 8, 2020

new PR for dedup.

@pm100 pm100 changed the title init commit dedup Oct 8, 2020
@estk
Copy link
Owner

estk commented Oct 10, 2020

Cool, looks pretty good. The biggest issue here is that this should be implemented as a filter. Other than that below are some nit picks.

  • There are some formatting and spelling mistakes in the comments. In particular Doc comments need no newline separator before the entity they document.
  • DedupResult needs a doc comment
  • The say method should be more descriptive, maybe summary
  • I would like to see a message printed to the log that we are doing deduping:
INFO foobar
INFO deduplicating previous message that is repeated 
INFO deduplicated previous message output x times 

@pm100
Copy link
Author

pm100 commented Oct 10, 2020

well I tried to implement as a filter given that that has a lot of advantages but could not work out how to make a filter generate extra messages, which it needs to do in this case. If you have a proposal of how to do that then please let me know.

I will fix the other points

@estk
Copy link
Owner

estk commented Oct 11, 2020

Ah I see that about the filter! Ok well thats fine, lets just put the dedup behind a feature flag then since it will rarely be used.

}
],
"settings": {}
}
Copy link
Owner

Choose a reason for hiding this comment

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

lets .gitignore this file, idk what that is

Copy link
Owner

Choose a reason for hiding this comment

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

I think you need to git rm --cached this file to remove it from the changeset

.file_static(None)
.line(None)
.build(),
)
Copy link
Owner

Choose a reason for hiding this comment

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

instead of calling these encode fns in the if else branches can we just return the msg and call the encode after in one place? Seems like a lot of repeated lines

Copy link
Author

Choose a reason for hiding this comment

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

tried that, format_args is amazingly hard to refactor

Copy link
Owner

Choose a reason for hiding this comment

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

I was thinking something like this

let args = if n == 1 {
  format_args!("last message repeated, suppressing dups")
} else {
  format_args!("last message repeated {} times", n)
};
encoder.encode(
    w,
    &Record::builder()
        .args(args)
        .level(record.level())
        .target(record.target())
        .module_path_static(None)
        .file_static(None)
        .line(None)
        .build(),
)

src/append/dedup.rs Outdated Show resolved Hide resolved
src/append/mod.rs Outdated Show resolved Hide resolved
count: i32,
last: String,
}
#[derive(PartialEq)]
Copy link
Owner

Choose a reason for hiding this comment

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

Newline above, comments first, then derives then struct decl please

use log::Record;

const REPEAT_COUNT: i32 = 1000;
/// dedup object to be used by deduping appender.
Copy link
Owner

Choose a reason for hiding this comment

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

Newline above please

src/append/file.rs Outdated Show resolved Hide resolved
@estk
Copy link
Owner

estk commented Oct 11, 2020

Looking good, a few more nits, need to feature flag dedup and we're in business

@pm100
Copy link
Author

pm100 commented Oct 12, 2020

rust 1.38 doesnt allow #cfg on an if statement. I am reluctant to fix this in code because its gonna be real ugly (reminder its in all appenders)

Thats why CI is failing

rust-lang/rust#69201

well I fixed it but its kinda ugly

        #[cfg(feature = "dedup")]
        let _ = {
            if let Some(dedup) = config.dedup {
                appender = appender.dedup(dedup);
            }
        };

@@ -52,6 +58,14 @@ impl fmt::Debug for FileAppender {
impl Append for FileAppender {
fn append(&self, record: &Record) -> Result<(), Box<dyn Error + Sync + Send>> {
let mut file = self.file.lock();
#[cfg(feature = "dedup")]
let _ = {
Copy link
Owner

Choose a reason for hiding this comment

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

you dont need the let _ =

@@ -150,6 +187,12 @@ impl Deserialize for FileAppenderDeserializer {
if let Some(append) = config.append {
appender = appender.append(append);
}
#[cfg(feature = "dedup")]
let _ = {
Copy link
Owner

Choose a reason for hiding this comment

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

you can remove the let _ =

@estk
Copy link
Owner

estk commented Dec 16, 2020

This is looking great, there's a few tasks left. Do you have tests for this?

@estk estk added the WIP Work In Progress label Dec 16, 2020
@estk
Copy link
Owner

estk commented Apr 30, 2022

closing stale

@estk estk closed this Apr 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
WIP Work In Progress
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants