Class RestRequestMetricsTracker


  • public class RestRequestMetricsTracker
    extends java.lang.Object
    Construct to support end-to-end metrics tracking based on request type. Usually accompanies a single RestRequest i.e. there is a one-to-one mapping b/w a RestRequest and a RestRequestMetricsTracker instance.

    A brief description of how the tracker works :- 1. When an object of type RestRequest (request) is instantiated, it is also expected to be associated with a unique instance of RestRequestMetricsTracker (tracker). This unique instance is returned on every call to RestRequest.getMetricsTracker(). Therefore there is one-to-one mapping between an instance of RestRequest and an instance of RestRequestMetricsTracker. 2. When the tracker is instantiated, the type of the request is usually not available. Therefore, the RestRequestMetrics (metrics) object associated with the tracker tracks "unknown" requests. 3. As the request passes through the NIO framework and the scaling framework, metrics associated with these layers are tracked and stored but not updated in the metrics object. 4. When the request reaches the RestRequestService, it is usually identified as a specific type and a custom metrics object that tracks that specific type of request is "injected" into the tracker associated with the request. 5. When the response for the request is complete and the request is "closed", the metrics that are stored are updated in the metrics object (injected or default).

    • Constructor Detail

      • RestRequestMetricsTracker

        public RestRequestMetricsTracker()
    • Method Detail

      • markFailure

        public void markFailure()
        Marks that the request is failed so that metrics can be tracked.
      • markUnsatisfied

        public void markUnsatisfied()
        Marks that the request is unsatisfied so that metrics can be tracked.
      • isSatisfied

        public boolean isSatisfied()
        Return whether the rest request is satisfied or not.
        Returns:
        true if request is satisfied.
      • setResponseStatus

        public void setResponseStatus​(ResponseStatus responseStatus)
        Parameters:
        responseStatus - the ResponseStatus to be used for certain count metrics.
      • injectMetrics

        public void injectMetrics​(RestRequestMetrics restRequestMetrics)
        Injects a RestRequestMetrics that can be used to track the metrics of the RestRequest that this instance of RestRequestMetricsTracker is attached to.
        Parameters:
        restRequestMetrics - the RestRequestMetrics instance to use to track the metrics of the RestRequest that this instance of RestRequestMetricsTracker is attached to.
      • injectContainerMetrics

        public void injectContainerMetrics​(ContainerMetrics containerMetrics)
      • recordMetrics

        public void recordMetrics()
        Records the metrics.

        This method is expected to called when the RestRequest, that this instance of RestRequestMetricsTracker is attached to, finishes.
      • getRoundTripTimeInMs

        public long getRoundTripTimeInMs()
        Returns:
        round trip time of this request in milliseconds
      • getTimeToFirstByteInMs

        public long getTimeToFirstByteInMs()
        Returns:
        time to first byte of this request in milliseconds