Skip to content

Commit 81ecc8c

Browse files
JAVA-3046: Extend RequestTracker interface for observability
Co-authored-by: Andrew Tolbert <[email protected]>
1 parent d5a79a7 commit 81ecc8c

File tree

15 files changed

+986
-213
lines changed

15 files changed

+986
-213
lines changed

core/src/main/java/com/datastax/dse/driver/internal/core/cql/continuous/ContinuousRequestHandlerBase.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -835,7 +835,7 @@ private void processResultResponse(@NonNull Result result, @Nullable Frame frame
835835
assert lock.isHeldByCurrentThread();
836836
try {
837837
ExecutionInfo executionInfo =
838-
createExecutionInfo().withServerResponse(result, frame).build();
838+
createExecutionInfo(null).withServerResponse(result, frame).build();
839839
if (result instanceof Rows) {
840840
DseRowsMetadata rowsMetadata = (DseRowsMetadata) ((Rows) result).getMetadata();
841841
if (columnDefinitions == null) {
@@ -1460,7 +1460,7 @@ private void trackNodeError(
14601460
latencyNanos,
14611461
executionProfile,
14621462
node,
1463-
createExecutionInfo().withServerResponse(frame).build(),
1463+
createExecutionInfo(error).withServerResponse(frame).build(),
14641464
logPrefix);
14651465
}
14661466
}
@@ -1614,12 +1614,13 @@ private void completeResultSetFuture(
16141614
}
16151615

16161616
@NonNull
1617-
private DefaultExecutionInfo.Builder createExecutionInfo() {
1617+
private DefaultExecutionInfo.Builder createExecutionInfo(Throwable error) {
16181618
return DefaultExecutionInfo.builder(
16191619
statement,
16201620
node,
16211621
startedSpeculativeExecutionsCount.get(),
16221622
executionIndex,
1623+
error,
16231624
errors,
16241625
session,
16251626
context,

core/src/main/java/com/datastax/dse/driver/internal/core/graph/GraphRequestHandler.java

+2
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,7 @@ private void setFinalResult(
336336
callback.node,
337337
startedSpeculativeExecutionsCount.get(),
338338
callback.execution,
339+
null,
339340
errors,
340341
session,
341342
context,
@@ -457,6 +458,7 @@ private void setFinalError(
457458
node,
458459
startedSpeculativeExecutionsCount.get(),
459460
execution,
461+
error,
460462
errors,
461463
session,
462464
context,

core/src/main/java/com/datastax/oss/driver/api/core/cql/ExecutionInfo.java

+5
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,11 @@ default DriverExecutionProfile getExecutionProfile() {
120120
@NonNull
121121
List<Map.Entry<Node, Throwable>> getErrors();
122122

123+
@Nullable
124+
default Throwable getDriverError() {
125+
return null;
126+
}
127+
123128
/**
124129
* The paging state of the query, in its raw form.
125130
*

core/src/main/java/com/datastax/oss/driver/api/core/tracker/RequestTracker.java

+28
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,33 @@
3636
*/
3737
public interface RequestTracker extends AutoCloseable {
3838

39+
/**
40+
* Invoked each time new request is created.
41+
*
42+
* @param request the request to be executed
43+
* @param executionProfile the execution profile of this request
44+
* @param requestLogPrefix the dedicated log prefix for this request
45+
*/
46+
default void onRequestCreated(
47+
@NonNull Request request,
48+
@NonNull DriverExecutionProfile executionProfile,
49+
@NonNull String requestLogPrefix) {}
50+
51+
/**
52+
* Invoked each time a new request is created and sent to next node. Due to retry policy, this
53+
* method can be triggered multiple times while processing one logical request.
54+
*
55+
* @param request the request to be executed
56+
* @param executionProfile the execution profile of this request
57+
* @param node the node which will receive the request
58+
* @param requestLogPrefix the dedicated log prefix for this request
59+
*/
60+
default void onRequestCreatedForNode(
61+
@NonNull Request request,
62+
@NonNull DriverExecutionProfile executionProfile,
63+
@NonNull Node node,
64+
@NonNull String requestLogPrefix) {}
65+
3966
/**
4067
* Invoked each time a request succeeds.
4168
*
@@ -71,6 +98,7 @@ default void onSuccess(
7198
default void onError(
7299
@NonNull Request request,
73100
@NonNull Throwable error,
101+
// TODO: Shall we expose start and end timestamp so that users do not need to call nanoTime()?
74102
long latencyNanos,
75103
@NonNull DriverExecutionProfile executionProfile,
76104
@Nullable Node node,

core/src/main/java/com/datastax/oss/driver/internal/core/cql/Conversions.java

+5
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
import com.datastax.oss.protocol.internal.ProtocolConstants;
7575
import com.datastax.oss.protocol.internal.request.Batch;
7676
import com.datastax.oss.protocol.internal.request.Execute;
77+
import com.datastax.oss.protocol.internal.request.Prepare;
7778
import com.datastax.oss.protocol.internal.request.Query;
7879
import com.datastax.oss.protocol.internal.request.query.QueryOptions;
7980
import com.datastax.oss.protocol.internal.response.Error;
@@ -359,6 +360,10 @@ public static ColumnDefinitions getResultDefinitions(
359360
}
360361
}
361362

363+
public static PrepareRequest toPrepareRequest(Prepare request) {
364+
return new DefaultPrepareRequest(SimpleStatement.newInstance(request.cqlQuery));
365+
}
366+
362367
public static DefaultPreparedStatement toPreparedStatement(
363368
Prepared response, PrepareRequest request, InternalDriverContext context) {
364369
ColumnDefinitions variableDefinitions =

0 commit comments

Comments
 (0)