Skip to content

Commit c75a59b

Browse files
JAVA-3046: Extend RequestTracker interface for observability
Co-authored-by: Andrew Tolbert <6889771+tolbertam@users.noreply.github.com>
1 parent 495fdda commit c75a59b

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -834,7 +834,7 @@ private void processResultResponse(@NonNull Result result, @Nullable Frame frame
834834
assert lock.isHeldByCurrentThread();
835835
try {
836836
ExecutionInfo executionInfo =
837-
createExecutionInfo().withServerResponse(result, frame).build();
837+
createExecutionInfo(null).withServerResponse(result, frame).build();
838838
if (result instanceof Rows) {
839839
DseRowsMetadata rowsMetadata = (DseRowsMetadata) ((Rows) result).getMetadata();
840840
if (columnDefinitions == null) {
@@ -1459,7 +1459,7 @@ private void trackNodeError(
14591459
latencyNanos,
14601460
executionProfile,
14611461
node,
1462-
createExecutionInfo().withServerResponse(frame).build(),
1462+
createExecutionInfo(error).withServerResponse(frame).build(),
14631463
logPrefix);
14641464
}
14651465
}
@@ -1613,12 +1613,13 @@ private void completeResultSetFuture(
16131613
}
16141614

16151615
@NonNull
1616-
private DefaultExecutionInfo.Builder createExecutionInfo() {
1616+
private DefaultExecutionInfo.Builder createExecutionInfo(Throwable error) {
16171617
return DefaultExecutionInfo.builder(
16181618
statement,
16191619
node,
16201620
startedSpeculativeExecutionsCount.get(),
16211621
executionIndex,
1622+
error,
16221623
errors,
16231624
session,
16241625
context,

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@ private void setFinalResult(
335335
callback.node,
336336
startedSpeculativeExecutionsCount.get(),
337337
callback.execution,
338+
null,
338339
errors,
339340
session,
340341
context,
@@ -456,6 +457,7 @@ private void setFinalError(
456457
node,
457458
startedSpeculativeExecutionsCount.get(),
458459
execution,
460+
error,
459461
errors,
460462
session,
461463
context,

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

Lines changed: 5 additions & 0 deletions
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

Lines changed: 28 additions & 0 deletions
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

Lines changed: 5 additions & 0 deletions
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)