-
Notifications
You must be signed in to change notification settings - Fork 207
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
Validate tracing for actors #1154
Draft
artursouza
wants to merge
4
commits into
dapr:master
Choose a base branch
from
artursouza:actor_tracing
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+157
−25
Draft
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
124 changes: 124 additions & 0 deletions
124
sdk-tests/src/test/java/io/dapr/it/actors/ActorTracingIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
package io.dapr.it.actors; | ||
|
||
import com.jayway.jsonpath.DocumentContext; | ||
import com.jayway.jsonpath.JsonPath; | ||
import io.dapr.actors.ActorId; | ||
import io.dapr.actors.client.ActorProxyBuilder; | ||
import io.dapr.client.DaprClient; | ||
import io.dapr.it.BaseIT; | ||
import io.dapr.it.actors.app.MyActor; | ||
import io.dapr.it.actors.app.MyActorService; | ||
import io.dapr.it.tracing.http.OpenTelemetryConfig; | ||
import io.opentelemetry.api.OpenTelemetry; | ||
import io.opentelemetry.api.trace.Span; | ||
import io.opentelemetry.api.trace.SpanKind; | ||
import io.opentelemetry.api.trace.Tracer; | ||
import io.opentelemetry.context.Scope; | ||
import net.minidev.json.JSONArray; | ||
import okhttp3.HttpUrl; | ||
import okhttp3.OkHttpClient; | ||
import okhttp3.Request; | ||
import okhttp3.Response; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.UUID; | ||
|
||
import static io.dapr.it.tracing.OpenTelemetry.createOpenTelemetry; | ||
import static io.dapr.it.tracing.OpenTelemetry.getReactorContext; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
public class ActorTracingIT extends BaseIT { | ||
|
||
@Test | ||
public void testInvoke() throws Exception { | ||
var run = startDaprApp( | ||
ActorTracingIT.class.getSimpleName()+"Server", | ||
MyActorService.SUCCESS_MESSAGE, | ||
MyActorService.class, | ||
true, | ||
60000); | ||
var clientRun = startDaprApp( | ||
ActorTracingIT.class.getSimpleName()+"Client", | ||
60000); | ||
|
||
OpenTelemetry openTelemetry = createOpenTelemetry(); | ||
Tracer tracer = openTelemetry.getTracer(OpenTelemetryConfig.TRACER_NAME); | ||
String spanName = UUID.randomUUID().toString(); | ||
Span span = tracer.spanBuilder(spanName).setSpanKind(SpanKind.CLIENT).startSpan(); | ||
|
||
try (DaprClient client = run.newDaprClientBuilder().build()) { | ||
MyActor myActor = | ||
new ActorProxyBuilder<>( | ||
"MyActorTest", | ||
MyActor.class, | ||
clientRun.newActorClient()).build(new ActorId("123456")); | ||
try (Scope scope = span.makeCurrent()) { | ||
client.waitForSidecar(10000).block(); | ||
myActor.say("hello world") | ||
.contextWrite(getReactorContext(openTelemetry)) | ||
.block(); | ||
} | ||
} finally { | ||
span.end(); | ||
} | ||
|
||
Validation.validateGrandChild( | ||
spanName, | ||
"/dapr.proto.runtime.v1.dapr/invokeactor", | ||
"callactor/myactortest/say"); | ||
} | ||
|
||
private static final class Validation { | ||
|
||
private static final OkHttpClient HTTP_CLIENT = new OkHttpClient(); | ||
|
||
/** | ||
* JSON Path for main span Id. | ||
*/ | ||
public static final String JSONPATH_MAIN_SPAN_ID = "$..[?(@.name == \"%s\")]['id']"; | ||
|
||
/** | ||
* JSON Path for child span. | ||
*/ | ||
public static final String JSONPATH_PARENT_SPAN_ID = | ||
"$..[?(@.parentId=='%s' && @.name=='%s')]['id']"; | ||
|
||
public static void validateGrandChild(String grandParentSpanName, String parentSpanName, String grandChildSpanName) throws Exception { | ||
// Must wait for some time to make sure Zipkin receives all spans. | ||
Thread.sleep(10000); | ||
HttpUrl.Builder urlBuilder = new HttpUrl.Builder(); | ||
urlBuilder.scheme("http") | ||
.host("localhost") | ||
.port(9411) | ||
.addPathSegments("api/v2/traces") | ||
.addQueryParameter("limit", "100"); | ||
Request.Builder requestBuilder = new Request.Builder() | ||
.url(urlBuilder.build()); | ||
requestBuilder.method("GET", null); | ||
|
||
Request request = requestBuilder.build(); | ||
|
||
Response response = HTTP_CLIENT.newCall(request).execute(); | ||
DocumentContext documentContext = JsonPath.parse(response.body().string()); | ||
String grandParentSpanId = readOne(documentContext, String.format(JSONPATH_MAIN_SPAN_ID, grandParentSpanName)).toString(); | ||
assertNotNull(grandParentSpanId); | ||
|
||
String parentSpanId = readOne(documentContext, String.format(JSONPATH_PARENT_SPAN_ID, grandParentSpanId, parentSpanName)) | ||
.toString(); | ||
assertNotNull(parentSpanId); | ||
|
||
String grandChildSpanId = readOne(documentContext, String.format(JSONPATH_PARENT_SPAN_ID, parentSpanId, grandChildSpanName)) | ||
.toString(); | ||
assertNotNull(grandChildSpanId); | ||
} | ||
|
||
private static Object readOne(DocumentContext documentContext, String path) { | ||
JSONArray arr = documentContext.read(path); | ||
assertTrue(arr.size() > 0); | ||
|
||
return arr.get(0); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 an example showing how the client app should invoke actors and tracing headers to work.