Alert on frequent network errors (#7410)

* Introduce is_frequent util

* Add dirty warn_if_frequent! implementation

* Add freq

* Fix order in condition

* Update

* Update docs

* Fix

* Remove old impl

* Fix errors

* Add wif to av-distr

* Add wif to col prot

* Rename

* Add wif to state-distr

* Address review comments

* Change Freq implementation

* Remove the zero division check

* Make rate explicit

* Fix typo

* Update rate constant

* Introduce explicit rates

* Update docs

* Split errors freq

* Downgrade coarsetime
This commit is contained in:
Andrei Eres
2023-07-17 14:05:57 +02:00
committed by GitHub
parent dd7d2f924b
commit 174f23d1cc
12 changed files with 268 additions and 15 deletions
+21
View File
@@ -43,6 +43,27 @@ pub fn warn(item: proc_macro::TokenStream) -> proc_macro::TokenStream {
gum(item, Level::Warn)
}
/// Print a warning or debug level message depending on their frequency
#[proc_macro]
pub fn warn_if_frequent(item: proc_macro::TokenStream) -> proc_macro::TokenStream {
let ArgsIfFrequent { freq, max_rate, rest } = parse2(item.into()).unwrap();
let freq_expr = freq.expr;
let max_rate_expr = max_rate.expr;
let debug: proc_macro2::TokenStream = gum(rest.clone().into(), Level::Debug).into();
let warn: proc_macro2::TokenStream = gum(rest.into(), Level::Warn).into();
let stream = quote! {
if #freq_expr .is_frequent(#max_rate_expr) {
#warn
} else {
#debug
}
};
stream.into()
}
/// Print a info level message.
#[proc_macro]
pub fn info(item: proc_macro::TokenStream) -> proc_macro::TokenStream {