fix max_level_hint for empty cases for Option/Vec Subscribe impls#2195
fix max_level_hint for empty cases for Option/Vec Subscribe impls#2195hawkw merged 10 commits intotokio-rs:masterfrom
Conversation
06e6efe to
734bcd0
Compare
hawkw
left a comment
There was a problem hiding this comment.
some minor nits on the tests etc, but the fix looks correct to me
| use super::*; | ||
| use tracing::Collect; | ||
|
|
||
| // This test is just used to compare to the tests below | ||
| #[test] | ||
| fn just_layer() { | ||
| let info = subscriber::named("info") | ||
| .run() | ||
| .with_filter(LevelFilter::INFO) | ||
| .boxed(); | ||
|
|
||
| let collector = tracing_subscriber::registry().with(info); | ||
| assert_eq!(collector.max_level_hint(), Some(LevelFilter::INFO)); | ||
| } | ||
|
|
||
| #[test] | ||
| fn layer_and_option_layer() { | ||
| let info = subscriber::named("info") | ||
| .run() | ||
| .with_filter(LevelFilter::INFO) | ||
| .boxed(); | ||
|
|
||
| let debug = subscriber::named("debug") | ||
| .run() | ||
| .with_filter(LevelFilter::DEBUG) | ||
| .boxed(); | ||
|
|
||
| let mut collector = tracing_subscriber::registry().with(info).with(Some(debug)); | ||
| assert_eq!(collector.max_level_hint(), Some(LevelFilter::DEBUG)); | ||
|
|
||
| let error = subscriber::named("error") | ||
| .run() | ||
| .with_filter(LevelFilter::ERROR) | ||
| .boxed(); | ||
| // None means the other layer takes control | ||
| collector = tracing_subscriber::registry().with(error).with(None); | ||
| assert_eq!(collector.max_level_hint(), Some(LevelFilter::ERROR)); | ||
| } | ||
|
|
||
| #[test] | ||
| fn just_option_layer() { | ||
| // Just a None means everything is off | ||
| let collector = tracing_subscriber::registry().with(None::<ExpectSubscriber>); | ||
| assert_eq!(collector.max_level_hint(), Some(LevelFilter::OFF)); | ||
| } |
There was a problem hiding this comment.
we should probably have the same tests for the Subscribe implementation for Option, as well as the Filter impl.
There was a problem hiding this comment.
There isn't a filter impl is there? I can move these tests out of this directory
There was a problem hiding this comment.
yeah, i misspoke: there isn't a Filter impl for Option<impl Filter>, but some of these tests do also exercise per-layer filtering, because they use with_filter on the inner subscribers. thus, those tests do need to be in this test module because of feature flagging. however, we could have other tests in a different module that don't use with_filter, and instead use the Layer impl for LevelFilter...
There was a problem hiding this comment.
ooh, I like the Layer impl of LevelFilter, let me push that up!
…ls (#2195) ## Motivation These are incorrect: currently, when you have a `None` layer, the `None` hint it returns causes the default `TRACE` to win, which is inaccurate. Similarly, `Vec` should default to `OFF` if it has no `Layer`s in it ## Solution Change the default hints to `Some(OFF)` Co-authored-by: Eliza Weisman <eliza@buoyant.io>
…ls (#2195) ## Motivation These are incorrect: currently, when you have a `None` layer, the `None` hint it returns causes the default `TRACE` to win, which is inaccurate. Similarly, `Vec` should default to `OFF` if it has no `Layer`s in it ## Solution Change the default hints to `Some(OFF)` Co-authored-by: Eliza Weisman <eliza@buoyant.io>
# 0.3.14 (Jul 1, 2022) This release fixes multiple filtering bugs in the `Layer` implementations for `Option<impl Layer>` and `Vec<impl Layer>`. ### Fixed - **layer**: `Layer::event_enabled` implementation for `Option<impl Layer<S>>` returning `false` when the `Option` is `None`, disabling all events globally ([#2193]) - **layer**: `Layer::max_level_hint` implementation for `Option<impl Layer<S>>` incorrectly disabling max level filtering when the option is `None` ([#2195]) - **layer**: `Layer::max_level_hint` implementation for `Vec<impl Layer<S>>` returning `LevelFilter::ERROR` rather than `LevelFilter::OFF` when the `Vec` is empty ([#2195]) Thanks to @CAD97 and @guswynn for contributing to this release! [#2193]: #2193 [#2195]: #2195
# 0.3.14 (Jul 1, 2022) This release fixes multiple filtering bugs in the `Layer` implementations for `Option<impl Layer>` and `Vec<impl Layer>`. ### Fixed - **layer**: `Layer::event_enabled` implementation for `Option<impl Layer<S>>` returning `false` when the `Option` is `None`, disabling all events globally ([#2193]) - **layer**: `Layer::max_level_hint` implementation for `Option<impl Layer<S>>` incorrectly disabling max level filtering when the option is `None` ([#2195]) - **layer**: `Layer::max_level_hint` implementation for `Vec<impl Layer<S>>` returning `LevelFilter::ERROR` rather than `LevelFilter::OFF` when the `Vec` is empty ([#2195]) Thanks to @CAD97 and @guswynn for contributing to this release! [#2193]: #2193 [#2195]: #2195
…ls (tokio-rs#2195) ## Motivation These are incorrect: currently, when you have a `None` layer, the `None` hint it returns causes the default `TRACE` to win, which is inaccurate. Similarly, `Vec` should default to `OFF` if it has no `Layer`s in it ## Solution Change the default hints to `Some(OFF)` Co-authored-by: Eliza Weisman <eliza@buoyant.io>
# 0.3.14 (Jul 1, 2022) This release fixes multiple filtering bugs in the `Layer` implementations for `Option<impl Layer>` and `Vec<impl Layer>`. ### Fixed - **layer**: `Layer::event_enabled` implementation for `Option<impl Layer<S>>` returning `false` when the `Option` is `None`, disabling all events globally ([tokio-rs#2193]) - **layer**: `Layer::max_level_hint` implementation for `Option<impl Layer<S>>` incorrectly disabling max level filtering when the option is `None` ([tokio-rs#2195]) - **layer**: `Layer::max_level_hint` implementation for `Vec<impl Layer<S>>` returning `LevelFilter::ERROR` rather than `LevelFilter::OFF` when the `Vec` is empty ([tokio-rs#2195]) Thanks to @CAD97 and @guswynn for contributing to this release! [tokio-rs#2193]: tokio-rs#2193 [tokio-rs#2195]: tokio-rs#2195
Motivation
These are incorrect; Currently, when you have a
Nonelayer, theNonehint it returns causes the defaultTRACEto win, which is inaccurate. Similarly,Vecshould default toOFFif it has noSubscribes in itSolution
Change the defaults hints to
Some(OFF)