-
Notifications
You must be signed in to change notification settings - Fork 345
Conversation
could we add a readme at the module level briefly explaining what each example represents? |
Instead of just moving them into this repo as "examples", do we want to take this opportunity to start some form of conformance test suite? Could be based on these examples initially and changed over time if necessary to ensure testing all aspects of the API. |
These examples could evolve into
some day. |
I agree on this point with @malafeev - I think at this time they are a testbed for such changes, and not much of actual tests (and thus the listing of specific use cases there, and not the common ones). |
I like the idea @objectiser; I'd like to see us build out a test harness for tracers to verify that they conform to the spec properly. Perhaps durning or after the release candidate process we can work on this? The immediate concern that examples were created to solve is that we need a place to discuss the API using code. If we encounter a usecase during the release candidate process where we feel the API is incomplete or ambiguous, we need a way to record this fact for all to see. So this is about "correctness of the API" itself as opposed to "correctness of an implementation of the API". Personally, I think we can continue to push and change this example/test code as patch versions to the API, so we don't need to get it perfect on the first shot and can merge this in. If that approach is problematic, we should leave it in ot-contrib until we work it out. |
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.
I did a partial review. I would like to see more comments, why something is bad and something good.
Could we get rid of all unnecessary waits/sleeps and joins with magic constants? It is just a distraction.
opentracing-examples/pom.xml
Outdated
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.jayway.awaitility</groupId> |
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.
Use new version https://mvnrepository.com/artifact/org.awaitility/awaitility/3.0.0 (it's under slightly different groupId/artifactId)
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.
Please define version in properties
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.
done
</dependency> | ||
|
||
<dependency> | ||
<groupId>ch.qos.logback</groupId> |
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.
can we use just System.out.print()
for simplicity?
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.
yes, but I wanted to print thread name, time, don't use ugly string concatenation...
} | ||
} | ||
if (found.size() > 1) { | ||
throw new RuntimeException("Ups, it's too much"); |
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.
A more meaningful message would be good
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.
IllegalArgumentException
is more suitable for this
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.
done
ActiveSpan activeSpan = continuation.activate(); | ||
|
||
try { | ||
TimeUnit.SECONDS.sleep(1); |
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.
Is this necessary? Just leave a comment in the middle that it wraps some logic.
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.
added commend
import static org.hamcrest.core.IsEqual.equalTo; | ||
import static org.junit.Assert.assertEquals; | ||
|
||
public class TestCallback { |
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.
Could you please use the Test
suffix like it is in other tests in this repo?
} | ||
|
||
assertNotEquals(finished.get(0).context().traceId(), finished.get(1).context().traceId()); | ||
assertEquals(finished.get(0).parentId(), finished.get(1).parentId()); |
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.
I think that these two last lines are distracting. I would rather see asset on 0
it's more explicit.
} | ||
|
||
|
||
public Future<Object> send(final Object message) { |
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.
nit: return String
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.
done
} | ||
|
||
/** | ||
* Solution is bad because parent is per client (we don't have better choice) |
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.
Explain it better, that happened, why it is bad
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.
done
|
||
for (int i = 0; i < 2; i++) { | ||
assertEquals(true, spans.get(2).finishMicros() >= spans.get(i).finishMicros()); | ||
assertEquals(spans.get(2).context().traceId(), spans.get(i).context().traceId()); |
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.
nit: create TestUtils.assertSameTrace(List<MockSpan>)
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.
done
opentracing-examples/README.md
Outdated
|
||
Examples of common instrumentation patterns: | ||
|
||
- **activate_deactivate** - callbacks finish at some time. |
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.
Could we create some categories? e.g. one related to client-server other to callbacks and order them from the simplest to more complex use cases?
@malafeev I have a meta request. Could you please clean the sources:
|
opentracing-examples/pom.xml
Outdated
<dependency> | ||
<groupId>ch.qos.logback</groupId> | ||
<artifactId>logback-classic</artifactId> | ||
<version>1.2.3</version> |
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.
Define versions in parent pom
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.
ok
import java.util.concurrent.TimeUnit; | ||
|
||
/** | ||
* Callback which executed at some time. We don't know when it is started, when it is |
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.
I think this comment is misleading. It depends on how the callback is executed.
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.
Idea is to show case when callback is executed at some time and we don't know when it is started, completed, no status.
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.
My point is that this comment is at wrong place.
public void test() throws Exception { | ||
Thread entryThread = entryThread(); | ||
entryThread.start(); | ||
entryThread.join(10_000); |
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.
Why this magic number?Applies to a lot of places in this PR.
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.
That thread will end, no need to specify max wait time
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.
ok
private int getTestTagsCount(MockSpan mockSpan) { | ||
Map<String, Object> tags = mockSpan.tags(); | ||
int tagCounter = 0; | ||
for (String tagKey : tags.keySet()) { |
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.
nit: mockSpan.tags().keySet()
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.
ok
assertEquals(parentSpan.context().spanId(), spans.get(i).parentId()); | ||
} | ||
|
||
assertNull(tracer.activeSpan()); |
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.
This is just redundant noise. Are you trying to test active span source in MockTracer works?
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.
maybe client activated span and not deactivated? better to test than assume.
} | ||
|
||
private static MockSpan getOneByOperationName(List<MockSpan> spans, String name) { | ||
List<MockSpan> found = new ArrayList<>(); |
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.
you don't need a list to do this.
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.
done
} | ||
} | ||
if (found.size() > 1) { | ||
throw new RuntimeException("Ups, it's too much"); |
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.
IllegalArgument ex is better
try (ActiveSpan childSpan1 = tracer.buildSpan("task1").startActive()) { | ||
sleep(55); | ||
} | ||
span.capture(); // Workaround, prevent parentSpan from being finished here. |
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.
This is anti-pattern. Do we want to have anti-patterns in examples? There should be continuation create for each runnable. e.g. https://paste.fedoraproject.org/paste/SvU3kpGwJbMqP2HTI6mi9A
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.
The idea for this test sample was to have a 'master' Span whose lifetime is not tied to any children - hence we couldn't pass a Continuation
, as creating them would increment the refcount for them.
Then again, another option to prevent this usage would be to simply have them create a Continuation
and don't close the 'master' ActiveSpan
(which, I think, you will definitely prefer ;) )
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.
These examples need more explanatory comments. Especially for this anti-patterns, explain why it is written like it is.
// Alternative to calling makeActive() is to pass it manually to asChildOf() for each created Span. | ||
try (ActiveSpan span = tracer.makeActive(parentSpan)) { | ||
try (ActiveSpan childSpan1 = tracer.buildSpan("task1").startActive()) { | ||
sleep(55); |
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.
you don't really need a sleep here
opentracing-examples/README.md
Outdated
- **late_span_finish** - late parent span finish | ||
- **listener_per_request** - one listener per request | ||
- **multiple_callbacks** - multiple callbacks | ||
- **nested_callbacks** - nested callbacks |
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.
Create a section for async/callbacks. Better comments would be appreciated.
multiple_callbacks - multiple callbacks`. e.g. how it differs from nested ones.
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.
(thanks!)
@@ -0,0 +1,14 @@ | |||
# OpenTracing-Java examples |
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.
We need a "Why does this exist" sort of thing... Could just be ## Module purpose
or whatever. My TL;DR is (1) something to test API changes against, (2) something to look at for common instrumentation patterns, (3) something to use for Tracer regression testing.
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.
... oh, and let's make a pointer in the main OT-Java README, too.
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 be pointer under "Development" section?
import static org.hamcrest.core.IsEqual.equalTo; | ||
import static org.junit.Assert.assertEquals; | ||
|
||
public class TestScheduledActions { |
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.
Could you please rename test classes to align with naming convention used in this repo. All other test files are named WhateverTest
@pavolloffay @malafeev is this good enough to merge at this point? There are people waiting to add more test cases. If it's just style tweaks and documentation left to work on, can we merge and do that as subsequent PRs? |
I think it could be merged although more explanations should be added to examples. |
Yes, it looks better and cleaner, however, I still think it needs more comments. let's not block others and merge this. |
move examples from https://github.com/opentracing-contrib/java-examples to be part of
opentracing-java