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

subscriber: fix level hint not considering value filters #907

Merged
merged 1 commit into from
Aug 10, 2020

Conversation

hawkw
Copy link
Member

@hawkw hawkw commented Aug 8, 2020

This fixes an issue with EnvFilter's max_level_hint not considering
that span field value filters may enable any span, regardless of the
level enabled inside that span. This is because the field value must be
recorded to be known.

We may wish to change this behavior to only check spans up to the
selected level, but this isn't what it does currently. This branch fixes
the wrong max level hint.

This bug was not caught due to an issue where hinting was too permissive
(#906), but fixing that bug uncovers this issue. A subsequent PR fixing
hint calculation introduces new test failures without this change.

Signed-off-by: Eliza Weisman eliza@buoyant.io

@hawkw hawkw added kind/bug Something isn't working crate/subscriber Related to the `tracing-subscriber` crate labels Aug 8, 2020
@hawkw hawkw requested a review from a team as a code owner August 8, 2020 19:52
@hawkw hawkw self-assigned this Aug 8, 2020
This fixes an issue with `EnvFilter`'s `max_level_hint` not considering
that span field value filters may enable *any* span, regardless of the
level enabled inside that span. This is because the field value must be
recorded to be known.

We may wish to change this behavior to only check spans up to the
selected level, but this isn't what it does currently. This branch fixes
the wrong max level hint.

This bug was not caught due to an issue where hinting was too
permissive, but fixing that bug uncovers this issue.

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
Copy link
Collaborator

@yaahc yaahc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like a subset of the other PR, definitely LGTM

@hawkw
Copy link
Member Author

hawkw commented Aug 10, 2020

looks like a subset of the other PR, definitely LGTM

yup, #908 depends on this, since fixing that bug uncovered this bug.

@hawkw hawkw merged commit 579f772 into master Aug 10, 2020
@hawkw hawkw deleted the eliza/fix-field-filter-hints branch August 10, 2020 18:30
hawkw added a commit that referenced this pull request Aug 10, 2020
## Motivation

Currently, when rebuilding the interest cache, the max level is
calculated by tracking a max level, and comparing it with each active
`Subscriber`'s max level hint, and setting the max value to the hint if
the hint is higher than the current value.

This is correct. However, the max level in this calculation starts at
`TRACE`. This means that regardless of what any subscriber returns for
its hint, after rebuilding the interest cache, the max level will
*always* be `TRACE`. This is wrong — it means that the fast path will
not be taken in may cases where it *should* be.

The max level calculation was started at `TRACE` rather than `OFF`,
because when this code was written with it starting at `OFF`, all the
tests broke, because the test subscribers don't provide hints. This was
the incorrect solution to that problem, however. This caused the tests
to break because we were *ignoring* all `None` hints, and not changing
the current max value when a subscriber returns `None`. This means that
if all subscribers returned `None` for their max level hint, the max
would remain `OFF`. However, what we *should* have done is assume that
if a subscriber doesn't provide a hint, it won't be filtering based on
levels, and assume that the max level is `TRACE` for that subscriber.

Whoopsie!

## Solution

Now, the max level should be calculated correctly for subscribers that
*do* provide hints, and should still be `TRACE` if a subscriber does not
have a hint.

I've also added new tests to ensure that the global max level filter is
used when provided, by asserting that `enabled` is not called with spans
that would be excluded by the max level. These tests fail on master, but
pass after this change.

Additionally, note that fixing this bug revealed a separate issue in
`tracing-subscriber`'s implementation of `max_level_hint` for
`EnvFilter`. When the `EnvFilter` includes directives that filter on
span field values, it will enable all spans with fields with that name,
so that events *within* the span can be enabled up to the filtering
directive's level. This may not be the ideal behavior, but it's what
we're doing currently, and we have tests for it. Therefore, it was
necessary to change the `max_level_hint` implementation to take this
into account by always returning `TRACE` when there are field value
filters. 

That means that this branch requires #907 order for the
`tracing-subscriber` tests to pass.

Fixes: #906 

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
hawkw added a commit that referenced this pull request Aug 11, 2020
Fixed

- **env-filter**: Incorrect max level hint when filters involving span
  field values are in use (#907)
- **registry**: Fixed inconsistent span stacks when multiple registries
  are in use on the same thread (#901)

Changed

- **env-filter**: `regex` dependency enables fewer unused feature flags
  (#899)

Thanks to @bdonlan and @jeromegn for contributing to this release!
hawkw added a commit that referenced this pull request Aug 11, 2020
### Fixed

- **env-filter**: Incorrect max level hint when filters involving span
  field values are in use (#907)
- **registry**: Fixed inconsistent span stacks when multiple registries
  are in use on the same thread (#901)

### Changed

- **env-filter**: `regex` dependency enables fewer unused feature flags
  (#899)

Thanks to @bdonlan and @jeromegn for contributing to this release!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
crate/subscriber Related to the `tracing-subscriber` crate kind/bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants