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

Proposal: remove our usage of log::log_enabled! using a global Targets in ore #10441

Closed
guswynn opened this issue Feb 4, 2022 · 7 comments · Fixed by #12505
Closed

Proposal: remove our usage of log::log_enabled! using a global Targets in ore #10441

guswynn opened this issue Feb 4, 2022 · 7 comments · Fixed by #12505
Labels
C-refactoring Category: replacing or reorganizing code

Comments

@guswynn
Copy link
Contributor

guswynn commented Feb 4, 2022

(This is primarily aimed at @benesch)

The way that log::log_enabled! (and my soon-to-be-landed tracing::enabled!) work with "per-layer filtering" in tracing means that they return true if ANY layer in the subscriber stack returns true. For enabling rdkafka debug mode, we want to check if only the fmt layer is enabled for the rdkafka target. The way we currently work around this is by cloning the fmt layer's target filter onto all our tracing layers. My understanding is that a primary reason we have seen regressions in the past is because of

if log::log_enabled!(target: "librdkafka", log::Level::Debug) {
accidentally being enabled.

I suggested tokio-rs/tracing#1889 to the tracing team to create a version of enabled! that returned false if ANY of the layers were disabled, but instead they suggested that I just keep a copy of my Targets layer around and query that.

So I propose we do the following:

I think we can ALSO optionally add global EnvFilter if we really want field-level filtering, but EnvFilter only works globally, for special debugging scenarios.

Alternatives

  • We do nothing, and leave the filters on all layers
    • The tokio-console layer SHOULD already filter out spans that aren't from tokio, so it MAY work as we want it to, but I have not tested how this interacts with enabled!
  • We come up with some other way to communicate the debug state to rdkafka
@guswynn guswynn added the C-refactoring Category: replacing or reorganizing code label Feb 4, 2022
@benesch
Copy link
Member

benesch commented Feb 4, 2022

Do we not want the default enabled! behavior? Like, if the console is enabled, don't we in theory want to enable librdkafka's debug logs so that librdkafka shows up? Very willing to believe that I'm missing something.

@benesch
Copy link
Member

benesch commented Feb 4, 2022

Oh, I think I see. Setting debug=true in librdkafka is expensive because it causes a lot of extra string formatting internally, yeah? And since librdkafka is in C, the tracing magic of deferring string formatting doesn't apply. So we're looking to special case the heck out of librdkafka's debug logs.

Rather than trying to back this information out via globals and the enabled! macro, how about we add a librdkafka_debug: bool to the dataflow server configuration? And then the materialized main function can do whatever tracing-related logic it wants to determine whether that bool should be true or false.

I think downstream in rust-rdkafka it still makes sense to use the enabled! macro here, yeah? Since most folks won't have a MetricsRecorderLayer that's observing events at all levels.

@guswynn
Copy link
Contributor Author

guswynn commented Feb 4, 2022

@benesch piping that value through seems fine to me!

So the new plan is:

and then we also separately do the rdkafka cleanup by adding a tracing feature which:

  • uses tracing instead of log
  • switch to tracing::enabled!
  • remove MzClientContext

(i already have a local commit with most of this)

@guswynn
Copy link
Contributor Author

guswynn commented Feb 4, 2022

I think we will need to pipe through a tracing::Level instead of a boolean, but thats just finer details

@benesch
Copy link
Member

benesch commented Feb 4, 2022

Yeah, that sounds right to me!!

hawkw pushed a commit to tokio-rs/tracing that referenced this issue Feb 4, 2022
## Motivation

As discussed on discord, this API + `Targets` being `: Clone` makes it
easier to solve the original problem I had tried to solve in
#1889.

My plan on how to use this is in
MaterializeInc/materialize#10441 if you are
interested!

## Solution

I considered doing some macro magic to create a `Metadata` with a
callsite and empty fields and everything, to be able to called
`DirectiveSet::enabled`, but it felt cleaner and easier to reason about
the special-case-ness (`Targets` never having field filters) using a new
set of methods that do a similar thing.

For testing I opted for just a doc-test, let me know if thats fine!
@guswynn
Copy link
Contributor Author

guswynn commented Feb 4, 2022

rdkafka side: fede1024/rust-rdkafka#440

@guswynn
Copy link
Contributor Author

guswynn commented Feb 4, 2022

working on the second part: guswynn@cdafa32 requires a lot of piping values through, posting here so people can see my WIP

hawkw pushed a commit to tokio-rs/tracing that referenced this issue Mar 23, 2022
## Motivation

As discussed on discord, this API + `Targets` being `: Clone` makes it
easier to solve the original problem I had tried to solve in
#1889.

My plan on how to use this is in
MaterializeInc/materialize#10441 if you are
interested!

## Solution

I considered doing some macro magic to create a `Metadata` with a
callsite and empty fields and everything, to be able to called
`DirectiveSet::enabled`, but it felt cleaner and easier to reason about
the special-case-ness (`Targets` never having field filters) using a new
set of methods that do a similar thing.

For testing I opted for just a doc-test, let me know if thats fine!
hawkw pushed a commit to tokio-rs/tracing that referenced this issue Mar 23, 2022
## Motivation

As discussed on discord, this API + `Targets` being `: Clone` makes it
easier to solve the original problem I had tried to solve in
#1889.

My plan on how to use this is in
MaterializeInc/materialize#10441 if you are
interested!

## Solution

I considered doing some macro magic to create a `Metadata` with a
callsite and empty fields and everything, to be able to called
`DirectiveSet::enabled`, but it felt cleaner and easier to reason about
the special-case-ness (`Targets` never having field filters) using a new
set of methods that do a similar thing.

For testing I opted for just a doc-test, let me know if thats fine!
hawkw pushed a commit to tokio-rs/tracing that referenced this issue Mar 24, 2022
## Motivation

As discussed on discord, this API + `Targets` being `: Clone` makes it
easier to solve the original problem I had tried to solve in
#1889.

My plan on how to use this is in
MaterializeInc/materialize#10441 if you are
interested!

## Solution

I considered doing some macro magic to create a `Metadata` with a
callsite and empty fields and everything, to be able to called
`DirectiveSet::enabled`, but it felt cleaner and easier to reason about
the special-case-ness (`Targets` never having field filters) using a new
set of methods that do a similar thing.

For testing I opted for just a doc-test, let me know if thats fine!
hawkw pushed a commit to tokio-rs/tracing that referenced this issue Mar 24, 2022
## Motivation

As discussed on discord, this API + `Targets` being `: Clone` makes it
easier to solve the original problem I had tried to solve in
#1889.

My plan on how to use this is in
MaterializeInc/materialize#10441 if you are
interested!

## Solution

I considered doing some macro magic to create a `Metadata` with a
callsite and empty fields and everything, to be able to called
`DirectiveSet::enabled`, but it felt cleaner and easier to reason about
the special-case-ness (`Targets` never having field filters) using a new
set of methods that do a similar thing.

For testing I opted for just a doc-test, let me know if thats fine!
hawkw pushed a commit to tokio-rs/tracing that referenced this issue Mar 24, 2022
## Motivation

As discussed on discord, this API + `Targets` being `: Clone` makes it
easier to solve the original problem I had tried to solve in
#1889.

My plan on how to use this is in
MaterializeInc/materialize#10441 if you are
interested!

## Solution

I considered doing some macro magic to create a `Metadata` with a
callsite and empty fields and everything, to be able to called
`DirectiveSet::enabled`, but it felt cleaner and easier to reason about
the special-case-ness (`Targets` never having field filters) using a new
set of methods that do a similar thing.

For testing I opted for just a doc-test, let me know if thats fine!
hawkw pushed a commit to tokio-rs/tracing that referenced this issue Mar 24, 2022
## Motivation

As discussed on discord, this API + `Targets` being `: Clone` makes it
easier to solve the original problem I had tried to solve in
#1889.

My plan on how to use this is in
MaterializeInc/materialize#10441 if you are
interested!

## Solution

I considered doing some macro magic to create a `Metadata` with a
callsite and empty fields and everything, to be able to called
`DirectiveSet::enabled`, but it felt cleaner and easier to reason about
the special-case-ness (`Targets` never having field filters) using a new
set of methods that do a similar thing.

For testing I opted for just a doc-test, let me know if thats fine!
hawkw pushed a commit to tokio-rs/tracing that referenced this issue Mar 24, 2022
## Motivation

As discussed on discord, this API + `Targets` being `: Clone` makes it
easier to solve the original problem I had tried to solve in
#1889.

My plan on how to use this is in
MaterializeInc/materialize#10441 if you are
interested!

## Solution

I considered doing some macro magic to create a `Metadata` with a
callsite and empty fields and everything, to be able to called
`DirectiveSet::enabled`, but it felt cleaner and easier to reason about
the special-case-ness (`Targets` never having field filters) using a new
set of methods that do a similar thing.

For testing I opted for just a doc-test, let me know if thats fine!
hawkw pushed a commit to tokio-rs/tracing that referenced this issue Mar 24, 2022
## Motivation

As discussed on discord, this API + `Targets` being `: Clone` makes it
easier to solve the original problem I had tried to solve in
#1889.

My plan on how to use this is in
MaterializeInc/materialize#10441 if you are
interested!

## Solution

I considered doing some macro magic to create a `Metadata` with a
callsite and empty fields and everything, to be able to called
`DirectiveSet::enabled`, but it felt cleaner and easier to reason about
the special-case-ness (`Targets` never having field filters) using a new
set of methods that do a similar thing.

For testing I opted for just a doc-test, let me know if thats fine!
hawkw pushed a commit to tokio-rs/tracing that referenced this issue Mar 24, 2022
## Motivation

As discussed on discord, this API + `Targets` being `: Clone` makes it
easier to solve the original problem I had tried to solve in
#1889.

My plan on how to use this is in
MaterializeInc/materialize#10441 if you are
interested!

## Solution

I considered doing some macro magic to create a `Metadata` with a
callsite and empty fields and everything, to be able to called
`DirectiveSet::enabled`, but it felt cleaner and easier to reason about
the special-case-ness (`Targets` never having field filters) using a new
set of methods that do a similar thing.

For testing I opted for just a doc-test, let me know if thats fine!
hawkw pushed a commit to tokio-rs/tracing that referenced this issue Mar 24, 2022
## Motivation

As discussed on discord, this API + `Targets` being `: Clone` makes it
easier to solve the original problem I had tried to solve in
#1889.

My plan on how to use this is in
MaterializeInc/materialize#10441 if you are
interested!

## Solution

I considered doing some macro magic to create a `Metadata` with a
callsite and empty fields and everything, to be able to called
`DirectiveSet::enabled`, but it felt cleaner and easier to reason about
the special-case-ness (`Targets` never having field filters) using a new
set of methods that do a similar thing.

For testing I opted for just a doc-test, let me know if thats fine!
hawkw pushed a commit to tokio-rs/tracing that referenced this issue Mar 24, 2022
## Motivation

As discussed on discord, this API + `Targets` being `: Clone` makes it
easier to solve the original problem I had tried to solve in
#1889.

My plan on how to use this is in
MaterializeInc/materialize#10441 if you are
interested!

## Solution

I considered doing some macro magic to create a `Metadata` with a
callsite and empty fields and everything, to be able to called
`DirectiveSet::enabled`, but it felt cleaner and easier to reason about
the special-case-ness (`Targets` never having field filters) using a new
set of methods that do a similar thing.

For testing I opted for just a doc-test, let me know if thats fine!
hawkw pushed a commit to tokio-rs/tracing that referenced this issue Mar 24, 2022
## Motivation

As discussed on discord, this API + `Targets` being `: Clone` makes it
easier to solve the original problem I had tried to solve in
#1889.

My plan on how to use this is in
MaterializeInc/materialize#10441 if you are
interested!

## Solution

I considered doing some macro magic to create a `Metadata` with a
callsite and empty fields and everything, to be able to called
`DirectiveSet::enabled`, but it felt cleaner and easier to reason about
the special-case-ness (`Targets` never having field filters) using a new
set of methods that do a similar thing.

For testing I opted for just a doc-test, let me know if thats fine!
benesch pushed a commit to benesch/materialize that referenced this issue May 17, 2022
benesch pushed a commit to benesch/materialize that referenced this issue May 17, 2022
benesch added a commit to benesch/materialize that referenced this issue May 18, 2022
Supersedes MaterializeInc#10875.
Fixes MaterializeInc#10441.

Co-authored-by: Nikhil Benesch <nikhil.benesch@gmail.com>
benesch added a commit to benesch/materialize that referenced this issue May 18, 2022
Supersedes MaterializeInc#10875.
Fixes MaterializeInc#10441.

Co-authored-by: Nikhil Benesch <nikhil.benesch@gmail.com>
benesch added a commit to benesch/materialize that referenced this issue May 18, 2022
Supersedes MaterializeInc#10875.
Fixes MaterializeInc#10441.

Co-authored-by: Nikhil Benesch <nikhil.benesch@gmail.com>
benesch added a commit that referenced this issue May 18, 2022
Supersedes #10875.
Fixes #10441.

Co-authored-by: Nikhil Benesch <nikhil.benesch@gmail.com>
liuhaozhan added a commit to liuhaozhan/tracing that referenced this issue Nov 17, 2022
## Motivation

As discussed on discord, this API + `Targets` being `: Clone` makes it
easier to solve the original problem I had tried to solve in
tokio-rs/tracing#1889.

My plan on how to use this is in
MaterializeInc/materialize#10441 if you are
interested!

## Solution

I considered doing some macro magic to create a `Metadata` with a
callsite and empty fields and everything, to be able to called
`DirectiveSet::enabled`, but it felt cleaner and easier to reason about
the special-case-ness (`Targets` never having field filters) using a new
set of methods that do a similar thing.

For testing I opted for just a doc-test, let me know if thats fine!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-refactoring Category: replacing or reorganizing code
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants