Package com.github.ambry.rest
Class RestRequestMetricsTracker
- java.lang.Object
-
- com.github.ambry.rest.RestRequestMetricsTracker
-
public class RestRequestMetricsTracker extends java.lang.Object
Construct to support end-to-end metrics tracking based on request type. Usually accompanies a singleRestRequest
i.e. there is a one-to-one mapping b/w aRestRequest
and a RestRequestMetricsTracker instance. A brief description of how the tracker works :- 1. When an object of typeRestRequest
(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 toRestRequest.getMetricsTracker()
. Therefore there is one-to-one mapping between an instance ofRestRequest
and an instance of RestRequestMetricsTracker. 2. When the tracker is instantiated, the type of the request is usually not available. Therefore, theRestRequestMetrics
(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 theRestRequestService
, 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).
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
RestRequestMetricsTracker.NioMetricsTracker
Tracker for updating NIO related metrics.static class
RestRequestMetricsTracker.ScalingMetricsTracker
Helper for updating scaling related metrics.
-
Field Summary
Fields Modifier and Type Field Description protected static java.lang.String
DEFAULT_REQUEST_TYPE
RestRequestMetricsTracker.NioMetricsTracker
nioMetricsTracker
NIO related metrics tracker instance.RestRequestMetricsTracker.ScalingMetricsTracker
scalingMetricsTracker
Scaling related metrics tracker instance.
-
Constructor Summary
Constructors Constructor Description RestRequestMetricsTracker()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ContainerMetrics
getContainerMetrics()
long
getRoundTripTimeInMs()
long
getTimeToFirstByteInMs()
void
injectContainerMetrics(ContainerMetrics containerMetrics)
void
injectMetrics(RestRequestMetrics restRequestMetrics)
Injects aRestRequestMetrics
that can be used to track the metrics of theRestRequest
that this instance of RestRequestMetricsTracker is attached to.boolean
isSatisfied()
Return whether the rest request is satisfied or not.void
markFailure()
Marks that the request is failed so that metrics can be tracked.void
markUnsatisfied()
Marks that the request is unsatisfied so that metrics can be tracked.void
recordMetrics()
Records the metrics.static void
setDefaults(com.codahale.metrics.MetricRegistry metricRegistry)
Creates a defaultRestRequestMetrics
in caseinjectMetrics(RestRequestMetrics)
is never called on an instance ofRestRequestMetricsTracker
.void
setResponseStatus(ResponseStatus responseStatus)
-
-
-
Field Detail
-
DEFAULT_REQUEST_TYPE
protected static final java.lang.String DEFAULT_REQUEST_TYPE
- See Also:
- Constant Field Values
-
nioMetricsTracker
public final RestRequestMetricsTracker.NioMetricsTracker nioMetricsTracker
NIO related metrics tracker instance.
-
scalingMetricsTracker
public final RestRequestMetricsTracker.ScalingMetricsTracker scalingMetricsTracker
Scaling related metrics tracker instance.
-
-
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
- theResponseStatus
to be used for certain count metrics.
-
injectMetrics
public void injectMetrics(RestRequestMetrics restRequestMetrics)
Injects aRestRequestMetrics
that can be used to track the metrics of theRestRequest
that this instance of RestRequestMetricsTracker is attached to.- Parameters:
restRequestMetrics
- theRestRequestMetrics
instance to use to track the metrics of theRestRequest
that this instance of RestRequestMetricsTracker is attached to.
-
injectContainerMetrics
public void injectContainerMetrics(ContainerMetrics containerMetrics)
-
getContainerMetrics
public ContainerMetrics getContainerMetrics()
-
recordMetrics
public void recordMetrics()
Records the metrics. This method is expected to called when theRestRequest
, that this instance ofRestRequestMetricsTracker
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
-
setDefaults
public static void setDefaults(com.codahale.metrics.MetricRegistry metricRegistry)
Creates a defaultRestRequestMetrics
in caseinjectMetrics(RestRequestMetrics)
is never called on an instance ofRestRequestMetricsTracker
.- Parameters:
metricRegistry
- theMetricRegistry
to use to register the created metrics.
-
-