Skip to content
This repository has been archived by the owner on May 23, 2023. It is now read-only.

add isRegistered boolean to GlobalTracer #321

Merged
merged 4 commits into from
Dec 10, 2018

Conversation

MikeGoldsmith
Copy link
Member

  • add isRegistered boolean
  • set isRegistered when Registering a tracer
  • add unit test to verify registering a NoopTracer set the isRegistered bool
  • move resetTracer logic to GlobalTracer as private function instead of test utility for easier reusability

Ported from C# fix where the bug was originally reported in
opentracing/opentracing-csharp#113

- add isRegistered boolean
- set isRegistered when Registering a tracer
- add unit test to verify registering a NoopTracer set the isRegistered bool

- move resetTracer logic to GlobalTracer as private function instead of test utility for easier reusability
@coveralls
Copy link

coveralls commented Nov 28, 2018

Coverage Status

Coverage increased (+0.1%) to 75.258% when pulling 4784d09 on MikeGoldsmith:global-tracer-bool into 76d7b8d on opentracing:master.

Copy link
Member

@austinlparker austinlparker left a comment

Choose a reason for hiding this comment

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

👍

Copy link
Member

@yurishkuro yurishkuro left a comment

Choose a reason for hiding this comment

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

This introduces a race condition between two independent volatile vars.

Also, wasn't there a ticket where this enhancement was repeatedly voted down?

@austinlparker
Copy link
Member

@yurishkuro do you know where the ticket you're referencing is? I'm unfamiliar with it.

Copy link
Contributor

@sjoerdtalsma sjoerdtalsma left a comment

Choose a reason for hiding this comment

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

See #288 for discussion on the reset functionality

* </dependency>
* </code></pre>
*/
public class GlobalTracerTestUtil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Removing this class breaks backward compatibility for folks using the test-jar dependency!

Copy link
Member Author

Choose a reason for hiding this comment

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

I can revert this change, it's not essential to the fix. I should be able to update the isRegistered boolean in the same way the tracer is reset to a NoopTracer.

Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of updating two variables, have you considered a constant UNREGISTERED_TRACER and check with == if a tracer was registered?

@MikeGoldsmith
Copy link
Member Author

@yurishkuro doesn't the synchronized keyword on registerIfAbsent ensure both the tracer and boolean are updated in a thread-safe way?

@yurishkuro
Copy link
Member

@MikeGoldsmith GitHib mobile wasn't showing that part - looks good.

@@ -59,6 +59,11 @@ public static void setGlobalTracerUnconditionally(Tracer tracer) {
globalTracerField.setAccessible(true);
globalTracerField.set(null, tracer);
globalTracerField.setAccessible(false);

Field isRegisteredField = GlobalTracer.class.getDeclaredField("isRegistered");
Copy link
Contributor

Choose a reason for hiding this comment

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

This does something that is not according to the method name.
Setting unconditionally would intuitively leave isRegistered to true.
Resetting should clear it though.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I agree with @sjoerdtalsma - IHMO resetting should be the only one touching isRegistered (an alternative would be to receive a isRegistered parameter, but it's probably not something needed at the moment, and thus could be added later if needed).

@MikeGoldsmith
Copy link
Member Author

@sjoerdtalsma Sorry for the delay in addressing your comments.

I've updated resetGlobalTracer and setGlobalTracerUnconditionally to correctly manage the isRegistered property.

@carlosalberto
Copy link
Collaborator

Hey @MikeGoldsmith

Left a comment but overall this looks good ;)

@sjoerdtalsma
Copy link
Contributor

I think discarding the boolean (as it's just state) and replacing that with an == comparison with a unique no-op constant tracer gets you what you want (ability to set the NoopTracer) and reduces the complexity of your solution.

I won't object this PR though.

@MikeGoldsmith MikeGoldsmith merged commit b7c5ba0 into opentracing:master Dec 10, 2018
@MikeGoldsmith MikeGoldsmith deleted the global-tracer-bool branch December 10, 2018 15:29
@austinlparker austinlparker mentioned this pull request Dec 10, 2018
public static synchronized boolean isRegistered() {
return !(GlobalTracer.tracer instanceof NoopTracer);
}
public static synchronized boolean isRegistered() { return isRegistered; }
Copy link
Contributor

Choose a reason for hiding this comment

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

Since isRegistered is volatile, we can remove the synchronized here.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants