-
Notifications
You must be signed in to change notification settings - Fork 683
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
subscriber: added builder for filter Directive #3018
base: master
Are you sure you want to change the base?
subscriber: added builder for filter Directive #3018
Conversation
Motivation ---------- 1. There are some filters which can not be created with the current Directive string repr syntax, like e.g. the strings `bool`, `1` or `2.3` or values containing characters including but not limited to `}],` (for some of this there are partial fixes in other PRS). Furthermore updating the syntax the accommodate this is always a potential braking change, one which also can be subtle to detect. 2. Sometimes there is need to create `Directives` programmatically, e.g. from a different kind of logging config or to set more complicated defaults. 3. We might want to add other matching capabilities in the future which might not be re presentable in the string syntax (or at least entail a braking change). Like e.g. matching fields regex, matching based on `dyn Value`, a field matching the string `true` and boolean `true` at the same time, etc. By allowing programmatic creation of `Directive`s we allow downstream users to work around existing issues, experiment with solution to such issues in external crates and in addition set the foundation for adding future matching capabilities in the future. Solution -------- - adds `Directive::builder()` / `DirectiveBuilder` - `ValueMatch` is now public, but wrapped to that we can freely extend and change it without braking changes Workaround For: tokio-rs#1584, tokio-rs#1181 Fixes: tokio-rs#2507, tokio-rs#404 Refs: tokio-rs#1584, tokio-rs#1181
61bdbd8
to
0c5d313
Compare
@@ -0,0 +1,102 @@ | |||
use core::fmt::Debug; |
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.
❓ Should env/directive.rs
be moved to env/directive/mod.rs
?
|
||
// ==== impl Builder ==== | ||
|
||
impl Builder { |
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.
❗ Currently we could add all of this methods directly onto Directive
but as idk. if that will be the case in the future I added a builder.
#[derive(Debug, Clone)] | ||
#[repr(transparent)] | ||
pub struct ValueMatch { | ||
inner: ValueMatchInternal, |
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.
For building directives this needs to be a public type in some form, the reason why I choose a wrapper instead of #[non_exhaustive]
is:
- like #[non_exhaustive] we can add variants
- but we also can fully change the internal representation
- and we don't want to expose
MatchDebug
andMatchPattern
- through we could give them a public interface, too
- we wan to prevent people from creating a
F64(f64::NAN)
I still could change it to a pub #[non_exhaustive]
enum if desired.
@@ -55,12 +68,113 @@ pub(crate) enum ValueMatch { | |||
Pat(Box<MatchPattern>), | |||
} | |||
|
|||
// === impl ValueMatch === |
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.
Preferably I would have added this block just above the ==== impl ValueMatchInternal ====
block but that would have introduced many more line changes as some existing impl where outside of their section.
} | ||
} | ||
} | ||
|
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.
Pulled up so that after this PR all impl ValueMatch
are under the same ==== impl ValueMatch ===
section.
Motivation
There are some filters which can not be created with the current Directive string repr syntax, like e.g. the strings
bool
,1
or2.3
or values containing characters including but not limited to}],
(for some of this there are partial fixes in other PRS). Furthermore updating the syntax the accommodate this is always a potential braking change, one which also can be subtle to detect.Sometimes there is need to create
Directives
programmatically, e.g. from a different kind of logging config or to set more complicated defaults.We might want to add other matching capabilities in the future which might not be re presentable in the string syntax (or at least entail a braking change). Like e.g. matching fields regex, matching based on
dyn Value
, a field matching the stringtrue
and booleantrue
at the same time, etc.By allowing programmatic creation of
Directive
s we allow downstream users to work around existing issues, experiment with solution to such issues in external crates and in addition set the foundation for adding future matching capabilities in the future.Solution
Directive::builder()
/DirectiveBuilder
ValueMatch
is now public as we need it in the builder. But we wrapped the current implementation instead of exposing it so that we can freely change/extend it in the future.Cavets
Display <=> FromStr
round trip worksOut of Scope
Directives
is by usingEnvFilter::add_directive
, which means there always is "some" parsed or default directive in theEnvFilter
before we can add our directives. We could e.g. implFromIterator<Directive>
forEnvFilter
or allow adding directives instead of parsing for building the builder. But that is outside of the scope of this PR.Workaround For: #1584, #1181
Fixes: #2507, #404
Refs: #1584, #1181