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

Refactoring in ContextContainer and implementation #10

Merged
merged 3 commits into from
Jun 1, 2022

Conversation

rstoyanchev
Copy link
Collaborator

@rstoyanchev rstoyanchev commented Jun 1, 2022

See commit messages for details:

  • Rename SimpleContextContainer to DefaultContextContainer and make it public
  • Remove ContextAccessorLoader and ThreadLocalAccessorLoader in favor of configuring instances of those directly on DefaultContextContainer
  • Remove NOOP constants and implementations in favor of IllegalStateException while also provide explicit method to restore or return null.
  • Rename ContextContainerPropagator to ContextContainerAdapter.

Rename SimpleContextContainer to DefaultContextContainer.

Drop ContextAccessorLoader and ThreadLocalAccessorLoader in favor of
configuring instances of those directly on DefaultContextContainer.
The layers above (e.g. Web Framework, GraphQL transport, etc.) have
the responsibility to know what accessors should be used, and therefore
ContextContainer should be directly configurable. In other words it
cannot be a global mechanism like ServiceLoader.
If a ContextContainerPropagator isn't found, it should be an
IllegalStateException. It means we don't know how to save to a specific
external context, and something is wrong. Or otherwise it would
silently not propagate.

If a ContextContainer isn't present, there are several cases.
- the code expects a ContextContainer and therefore needs to check
  through the isNoop() method anyway to protect itself, but it might
  forget to do so.
- the code expects there may or may not be a ContextContainer, but
  wants to start a new one if not found. Here it also needs to check
  isNoop(), but if it doesn't do so, it could even lead to errors in
  code that expects an actual ContextContainer and not a noop.
- only code that expects there may or may not be a ContextContainer and
  doesn't care either way benefits; arguably though a noop lurking
  always has the potential of causing side effects and surprises.

For ContextContainerPropagator, we now always throw
IllegalStateException if there isn't a compatible one registered.

For ContextContainer, restoreFrom raises ISE while separately there
is a restoreIfPresentFrom that returns null if not found.
Ordering of methods in DefaultContextContainer consistent with the
order in ContextContainer.

Rename ContextContainerPropagator to ContextContainerAdapter.
@marcingrzejszczak marcingrzejszczak added this to the 1.0.0-M3 milestone Jun 1, 2022
@marcingrzejszczak marcingrzejszczak merged commit 306ba5c into micrometer-metrics:main Jun 1, 2022
@rstoyanchev rstoyanchev deleted the refactoring branch June 16, 2022 13:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change enhancement A general enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants