Class HttpTransportTimer

java.lang.Object
io.netty.channel.ChannelHandlerAdapter
io.netty.channel.ChannelInboundHandlerAdapter
io.netty.channel.ChannelDuplexHandler
org.mockserver.netty.connection.HttpTransportTimer
All Implemented Interfaces:
io.netty.channel.ChannelHandler, io.netty.channel.ChannelInboundHandler, io.netty.channel.ChannelOutboundHandler

public final class HttpTransportTimer extends io.netty.channel.ChannelDuplexHandler
Times each HTTP/1.1 exchange on a connection for mock_server_request_transport_duration_seconds: from the request head being decoded to the write of the last part of its response completing on the socket. Unlike the handler timer it includes aggregation, event-loop hand-off of a response written from another thread, encoding, and a slow reader holding the write back.

Installed after HttpServerCodec, ahead of every handler that aggregates or answers, one instance per connection, only when metrics are enabled. Requests are paired with responses in arrival order, as HTTP/1.1 requires, so pipelined requests are timed separately. A 1xx response other than 101 precedes the real response and ends nothing; a 101 turns the connection into a WebSocket and the timer removes itself. An exchange that ends without a LastHttpContent passing through (a raw-bytes HttpError, an abandoned exchange, a final 1xx) is announced by HttpExchangeEndedEvent: its start is dropped unrecorded, so later exchanges on that keep-alive connection are still timed from their own start.

With its read marker added before the codec, it also times the span before that start for mock_server_request_read_to_decode_duration_seconds: from the read that delivered a request's first bytes (the first read after the previous request's last content was decoded, or the read that decoded it when the next request follows in the same bytes) to the head being decoded. That covers the handlers before the codec, the decode, a head split across reads, and pipelined requests ahead of it in the same read being handled first.

  • Nested Class Summary

    Nested classes/interfaces inherited from interface io.netty.channel.ChannelHandler

    io.netty.channel.ChannelHandler.Sharable
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    channelRead(io.netty.channel.ChannelHandlerContext ctx, Object msg)
     
    io.netty.channel.ChannelHandler
    The handler to add before the HTTP server codec, so the read-to-decode span starts at the read.
    static void
    removeFrom(io.netty.channel.ChannelPipeline pipeline)
    Removes the timer and its read marker, if present, for when the connection stops carrying HTTP/1.1.
    void
    userEventTriggered(io.netty.channel.ChannelHandlerContext ctx, Object evt)
     
    void
    write(io.netty.channel.ChannelHandlerContext ctx, Object msg, io.netty.channel.ChannelPromise promise)
     

    Methods inherited from class io.netty.channel.ChannelDuplexHandler

    bind, close, connect, deregister, disconnect, flush, read

    Methods inherited from class io.netty.channel.ChannelInboundHandlerAdapter

    channelActive, channelInactive, channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChanged, exceptionCaught

    Methods inherited from class io.netty.channel.ChannelHandlerAdapter

    ensureNotSharable, handlerAdded, handlerRemoved, isSharable

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface io.netty.channel.ChannelHandler

    handlerAdded, handlerRemoved
  • Constructor Details

    • HttpTransportTimer

      public HttpTransportTimer()
  • Method Details

    • readMarker

      public io.netty.channel.ChannelHandler readMarker()
      The handler to add before the HTTP server codec, so the read-to-decode span starts at the read.
    • removeFrom

      public static void removeFrom(io.netty.channel.ChannelPipeline pipeline)
      Removes the timer and its read marker, if present, for when the connection stops carrying HTTP/1.1.
    • channelRead

      public void channelRead(io.netty.channel.ChannelHandlerContext ctx, Object msg)
      Specified by:
      channelRead in interface io.netty.channel.ChannelInboundHandler
      Overrides:
      channelRead in class io.netty.channel.ChannelInboundHandlerAdapter
    • userEventTriggered

      public void userEventTriggered(io.netty.channel.ChannelHandlerContext ctx, Object evt)
      Specified by:
      userEventTriggered in interface io.netty.channel.ChannelInboundHandler
      Overrides:
      userEventTriggered in class io.netty.channel.ChannelInboundHandlerAdapter
    • write

      public void write(io.netty.channel.ChannelHandlerContext ctx, Object msg, io.netty.channel.ChannelPromise promise)
      Specified by:
      write in interface io.netty.channel.ChannelOutboundHandler
      Overrides:
      write in class io.netty.channel.ChannelDuplexHandler