-
Notifications
You must be signed in to change notification settings - Fork 16
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
feat: optional console log message filter #241
Conversation
0fa1eed
to
1014e37
Compare
…and 'ConsoleFilter'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot @rvanasa for this PR and the changes regarding to logging. I have one more comment regarding the mix of test logic with the productive code, but otherwise looks good to me!
src/logs/mod.rs
Outdated
#[cfg(test)] | ||
DISPLAYED_LOG_ENTRIES.with_borrow_mut(|entries| entries.push(entry.clone())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mixing test code with productive code is usually not a good idea and I think here you actually don't need it, so I would remove this and the declaration L24-27.
Here is an alternative of how it could look like in the test file src/logs/tests.rs
:
...
declare_log_buffer!(name = TEST_BUF, capacity = 1000);
const TEST: PrintProxySink = PrintProxySink(&Priority::Debug, &TEST_BUF);
...
#[test]
fn should_show_all() {
set_console_filter(ConsoleFilter::ShowAll);
log!(TEST, "ABC");
log!(TEST, "123");
log!(TEST, "!@#");
assert_eq!(get_messages(), vec!["ABC", "123", "!@#"]);
}
...
fn get_messages() -> Vec<String> {
export(&TEST_BUF)
.into_iter()
.map(|entry| entry.message)
.collect()
}
Does-it make sense?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem I'm running into with this approach is that the messages are always added to the buffer regardless of the filter, which only affects whether the messages are printed to the console.
The simplest solution would be to change the logic so that the console messages are the same as the logs. I also looked into intercepting the println!()
output, but compared to this, it seemed cleaner to add the DISPLAYED_LOG_ENTRIES
data structure to simulate this in a more controlled way. A third option could be to call ConsoleFilter::is_valid()
(now renamed try_is_valid()
) directly instead of going through a PrintProxySink
. Do you have a preference for any of these solutions or something else?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the messages are always added to the buffer regardless of the filter, which only affects whether the messages are printed to the console.
good point, I missed this. I should have tried with more tests :)
The simplest solution would be to change the logic so that the console messages are the same as the logs.
I have the impression this would indeed the simplest. I guess for this it would then maybe make sense to rename ConsoleFilter
to something like LogFilter
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
src/types.rs
Outdated
pub fn is_match(&self, value: &str) -> bool { | ||
Regex::new(&self.0) | ||
.map(|regex| regex.is_match(value)) | ||
.unwrap_or(false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I think we should panic in case the regex is not valid instead of just silently returning false
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose we can do this because it's only used in the local replica. Updated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose we can do this because it's only used in the local replica.
By local replica you mean running locally in dfx? If yes, I think we can and should also do this even if we were to use that feature productively. This could only be set during an upgrade and so if the regex is wrong then the panic will revert the upgrade which is IMO the correct thing to do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that makes sense. This is now implemented.
Remove all productive dependencies on the [IC repository](https://github.com/dfinity/ic/tree/master): 1. `ic-canisters-http-types`: is removed and the corresponding types (`HttpRequest` and `HttpResponse`) were copied over since they amount to a few lines of code. 2. `ic-crypto-sha3`: is replaced by `ic-sha3`, available on [crates.io](https://crates.io/crates/ic-sha3). 3. `ic-ethereum-types` is replaced by a crate of the same name available on[ crates.io](https://crates.io/crates/ic-ethereum-types). 4. `ic-nervous-system-common`: is removed since it was only used to serve metrics. The only remaining productive dependency from the IC repository is `ic-canister-log` and will be removed by #241.
…ic-eth-rpc into optional-logs-2
We should make sure this is properly documented with a new release. Do we expect projects that deploy their own evm rpc canister to only deploy the latest release as well? |
For sure. I'll work with @gregorydemay and @jessiemongeon1 on making sure the documentation is updated for the new changes.
We can recommend this, although the previous version should continue working as well. |
what about deploying |
If I understand the question correctly, this is a work in progress since it requires an NNS proposal. We also want to give a window of time for developers to migrate to the new version before redeploying. |
Documentation PR: dfinity/portal#3575 |
what i meant was should we advise projects not to deploy from |
Haha, okay, I see what you're saying. Yes, that is what we should recommend. |
Resolves #201 by adding an optional
consoleFilter
install arg.Show all log messages (default):
dfx deploy evm_rpc --argument "(record { consoleFilter = opt variant { ShowAll } })"
Hide all log messages:
dfx deploy evm_rpc --argument "(record { consoleFilter = opt variant { HideAll } })"
Only show
INFO ...
messages:Hide
TRACE_HTTP ...
messages:Only show messages related to
eth_getLogs
:Note that
ShowPattern
andHidePattern
accept regular expressions and are evaluated using theregex
crate.