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 ;
@@ -914,7 +915,7 @@ public void sendResponse(RestResponse response) {
914915 private static final class ResourceHandlingHttpChannel extends DelegatingRestChannel {
915916 private final CircuitBreakerService circuitBreakerService ;
916917 private final int contentLength ;
917- private final MethodHandlers methodHandlers ;
918+ private final HttpRouteStatsTracker statsTracker ;
918919 private final long startTime ;
919920 private final AtomicBoolean closed = new AtomicBoolean ();
920921
@@ -927,7 +928,7 @@ private static final class ResourceHandlingHttpChannel extends DelegatingRestCha
927928 super (delegate );
928929 this .circuitBreakerService = circuitBreakerService ;
929930 this .contentLength = contentLength ;
930- this .methodHandlers = methodHandlers ;
931+ this .statsTracker = methodHandlers . statsTracker () ;
931932 this .startTime = rawRelativeTimeInMillis ();
932933 }
933934
@@ -936,12 +937,12 @@ public void sendResponse(RestResponse response) {
936937 boolean success = false ;
937938 try {
938939 close ();
939- methodHandlers .addRequestStats (contentLength );
940- methodHandlers .addResponseTime (rawRelativeTimeInMillis () - startTime );
940+ statsTracker .addRequestStats (contentLength );
941+ statsTracker .addResponseTime (rawRelativeTimeInMillis () - startTime );
941942 if (response .isChunked () == false ) {
942- methodHandlers .addResponseStats (response .content ().length ());
943+ statsTracker .addResponseStats (response .content ().length ());
943944 } else {
944- final var responseLengthRecorder = new ResponseLengthRecorder (methodHandlers );
945+ final var responseLengthRecorder = new ResponseLengthRecorder (statsTracker );
945946 final var headers = response .getHeaders ();
946947 response = RestResponse .chunked (
947948 response .status (),
@@ -976,23 +977,23 @@ private void close() {
976977 }
977978 }
978979
979- private static class ResponseLengthRecorder extends AtomicReference <MethodHandlers > implements Releasable {
980+ private static class ResponseLengthRecorder extends AtomicReference <HttpRouteStatsTracker > implements Releasable {
980981 private long responseLength ;
981982
982- private ResponseLengthRecorder (MethodHandlers methodHandlers ) {
983- super (methodHandlers );
983+ private ResponseLengthRecorder (HttpRouteStatsTracker routeStatsTracker ) {
984+ super (routeStatsTracker );
984985 }
985986
986987 @ Override
987988 public void close () {
988989 // closed just before sending the last chunk, and also when the whole RestResponse is closed since the client might abort the
989990 // connection before we send the last chunk, in which case we won't have recorded the response in the
990991 // stats yet; thus we need run-once semantics here:
991- final var methodHandlers = getAndSet (null );
992- if (methodHandlers != null ) {
992+ final var routeStatsTracker = getAndSet (null );
993+ if (routeStatsTracker != null ) {
993994 // if we started sending chunks then we're closed on the transport worker, no need for sync
994995 assert responseLength == 0L || Transports .assertTransportThread ();
995- methodHandlers .addResponseStats (responseLength );
996+ routeStatsTracker .addResponseStats (responseLength );
996997 }
997998 }
998999
0 commit comments