3636import org .elasticsearch .core .TimeValue ;
3737import org .elasticsearch .http .HttpHeadersValidationException ;
3838import org .elasticsearch .http .HttpRouteStats ;
39+ import org .elasticsearch .http .HttpRouteStatsTracker ;
3940import org .elasticsearch .http .HttpServerTransport ;
4041import org .elasticsearch .indices .breaker .CircuitBreakerService ;
4142import org .elasticsearch .rest .RestHandler .Route ;
@@ -879,7 +880,7 @@ public void sendResponse(RestResponse response) {
879880 private static final class ResourceHandlingHttpChannel extends DelegatingRestChannel {
880881 private final CircuitBreakerService circuitBreakerService ;
881882 private final int contentLength ;
882- private final MethodHandlers methodHandlers ;
883+ private final HttpRouteStatsTracker statsTracker ;
883884 private final long startTime ;
884885 private final AtomicBoolean closed = new AtomicBoolean ();
885886
@@ -892,7 +893,7 @@ private static final class ResourceHandlingHttpChannel extends DelegatingRestCha
892893 super (delegate );
893894 this .circuitBreakerService = circuitBreakerService ;
894895 this .contentLength = contentLength ;
895- this .methodHandlers = methodHandlers ;
896+ this .statsTracker = methodHandlers . statsTracker () ;
896897 this .startTime = rawRelativeTimeInMillis ();
897898 }
898899
@@ -901,12 +902,12 @@ public void sendResponse(RestResponse response) {
901902 boolean success = false ;
902903 try {
903904 close ();
904- methodHandlers .addRequestStats (contentLength );
905- methodHandlers .addResponseTime (rawRelativeTimeInMillis () - startTime );
905+ statsTracker .addRequestStats (contentLength );
906+ statsTracker .addResponseTime (rawRelativeTimeInMillis () - startTime );
906907 if (response .isChunked () == false ) {
907- methodHandlers .addResponseStats (response .content ().length ());
908+ statsTracker .addResponseStats (response .content ().length ());
908909 } else {
909- final var responseLengthRecorder = new ResponseLengthRecorder (methodHandlers );
910+ final var responseLengthRecorder = new ResponseLengthRecorder (statsTracker );
910911 final var headers = response .getHeaders ();
911912 response = RestResponse .chunked (
912913 response .status (),
@@ -941,23 +942,23 @@ private void close() {
941942 }
942943 }
943944
944- private static class ResponseLengthRecorder extends AtomicReference <MethodHandlers > implements Releasable {
945+ private static class ResponseLengthRecorder extends AtomicReference <HttpRouteStatsTracker > implements Releasable {
945946 private long responseLength ;
946947
947- private ResponseLengthRecorder (MethodHandlers methodHandlers ) {
948- super (methodHandlers );
948+ private ResponseLengthRecorder (HttpRouteStatsTracker routeStatsTracker ) {
949+ super (routeStatsTracker );
949950 }
950951
951952 @ Override
952953 public void close () {
953954 // closed just before sending the last chunk, and also when the whole RestResponse is closed since the client might abort the
954955 // connection before we send the last chunk, in which case we won't have recorded the response in the
955956 // stats yet; thus we need run-once semantics here:
956- final var methodHandlers = getAndSet (null );
957- if (methodHandlers != null ) {
957+ final var routeStatsTracker = getAndSet (null );
958+ if (routeStatsTracker != null ) {
958959 // if we started sending chunks then we're closed on the transport worker, no need for sync
959960 assert responseLength == 0L || Transports .assertTransportThread ();
960- methodHandlers .addResponseStats (responseLength );
961+ routeStatsTracker .addResponseStats (responseLength );
961962 }
962963 }
963964
0 commit comments