@@ -198,7 +198,7 @@ public void onThrottleReady(boolean wasDelayed) {
198198 private ScheduledFuture <?> scheduleTimeout (Duration timeout ) {
199199 if (timeout .toNanos () > 0 ) {
200200 return scheduler .schedule (
201- () -> setFinalError (new DriverTimeoutException ("Query timed out after " + timeout )),
201+ () -> setFinalError (new DriverTimeoutException ("Query timed out after " + timeout ), null ),
202202 timeout .toNanos (),
203203 TimeUnit .NANOSECONDS );
204204 } else {
@@ -234,7 +234,7 @@ private void sendRequest(
234234 // We've reached the end of the query plan without finding any node to write to
235235 if (!result .isDone () && activeExecutionsCount .decrementAndGet () == 0 ) {
236236 // We're the last execution so fail the result
237- setFinalError (AllNodesFailedException .fromErrors (this .errors ));
237+ setFinalError (AllNodesFailedException .fromErrors (this .errors ), null );
238238 }
239239 } else {
240240 NodeResponseCallback nodeResponseCallback =
@@ -287,15 +287,14 @@ private void setFinalResult(
287287 if (result .complete (resultSet )) {
288288 cancelScheduledTasks ();
289289 throttler .signalSuccess (this );
290+ long latencyNanos = System .nanoTime () - startTimeNanos ;
291+ context .requestTracker ().onSuccess (statement , latencyNanos , configProfile , callback .node );
290292 session
291293 .getMetricUpdater ()
292- .updateTimer (
293- DefaultSessionMetric .CQL_REQUESTS ,
294- System .nanoTime () - startTimeNanos ,
295- TimeUnit .NANOSECONDS );
294+ .updateTimer (DefaultSessionMetric .CQL_REQUESTS , latencyNanos , TimeUnit .NANOSECONDS );
296295 }
297296 } catch (Throwable error ) {
298- setFinalError (error );
297+ setFinalError (error , callback . node );
299298 }
300299 }
301300
@@ -323,12 +322,14 @@ private ExecutionInfo buildExecutionInfo(
323322 @ Override
324323 public void onThrottleFailure (RequestThrottlingException error ) {
325324 session .getMetricUpdater ().incrementCounter (DefaultSessionMetric .THROTTLING_ERRORS );
326- setFinalError (error );
325+ setFinalError (error , null );
327326 }
328327
329- private void setFinalError (Throwable error ) {
328+ private void setFinalError (Throwable error , Node node ) {
330329 if (result .completeExceptionally (error )) {
331330 cancelScheduledTasks ();
331+ long latencyNanos = System .nanoTime () - startTimeNanos ;
332+ context .requestTracker ().onError (statement , error , latencyNanos , configProfile , node );
332333 if (error instanceof DriverTimeoutException ) {
333334 throttler .signalTimeout (this );
334335 session .getMetricUpdater ().incrementCounter (DefaultSessionMetric .CQL_CLIENT_TIMEOUTS );
@@ -380,7 +381,7 @@ public void operationComplete(Future<java.lang.Void> future) throws Exception {
380381 Throwable error = future .cause ();
381382 if (error instanceof EncoderException
382383 && error .getCause () instanceof FrameTooLongException ) {
383- setFinalError (error .getCause ());
384+ setFinalError (error .getCause (), node );
384385 } else {
385386 LOG .debug (
386387 "[{}] Failed to send request on {}, trying next node (cause: {})" ,
@@ -479,10 +480,10 @@ public void onResponse(Frame responseFrame) {
479480 LOG .debug ("[{}] Got error response, processing" , logPrefix );
480481 processErrorResponse ((Error ) responseMessage );
481482 } else {
482- setFinalError (new IllegalStateException ("Unexpected response " + responseMessage ));
483+ setFinalError (new IllegalStateException ("Unexpected response " + responseMessage ), node );
483484 }
484485 } catch (Throwable t ) {
485- setFinalError (t );
486+ setFinalError (t , node );
486487 }
487488 }
488489
@@ -524,12 +525,12 @@ private void processErrorResponse(Error errorMessage) {
524525 || prepareError instanceof FunctionFailureException
525526 || prepareError instanceof ProtocolError ) {
526527 LOG .debug ("[{}] Unrecoverable error on reprepare, rethrowing" , logPrefix );
527- setFinalError (prepareError );
528+ setFinalError (prepareError , node );
528529 return null ;
529530 }
530531 }
531532 } else if (exception instanceof RequestThrottlingException ) {
532- setFinalError (exception );
533+ setFinalError (exception , node );
533534 return null ;
534535 }
535536 recordError (node , exception );
@@ -554,7 +555,7 @@ private void processErrorResponse(Error errorMessage) {
554555 || error instanceof ProtocolError ) {
555556 LOG .debug ("[{}] Unrecoverable error, rethrowing" , logPrefix );
556557 metricUpdater .incrementCounter (DefaultNodeMetric .OTHER_ERRORS );
557- setFinalError (error );
558+ setFinalError (error , node );
558559 } else {
559560 RetryDecision decision ;
560561 if (error instanceof ReadTimeoutException ) {
@@ -634,7 +635,7 @@ private void processRetryDecision(RetryDecision decision, Throwable error) {
634635 sendRequest (null , execution , retryCount + 1 , false );
635636 break ;
636637 case RETHROW :
637- setFinalError (error );
638+ setFinalError (error , node );
638639 break ;
639640 case IGNORE :
640641 setFinalResult (Void .INSTANCE , null , true , this );
0 commit comments