Package io.pravega.common.tracing
Class RequestTracker
- java.lang.Object
-
- io.pravega.common.tracing.RequestTracker
-
public final class RequestTracker extends java.lang.ObjectThis class is a helper for multiple classes to get the client-generated id for a request (requestId) based on the available information of the request itself (requestDescriptor) in multiple methods. The objective is to cache such requestDescriptor and requestId pairs to allow classes within a component (Controller, Segment Store) to also log the client-generated ids, making it easier to trace the lifecycle of a request across multiple logs.
-
-
Constructor Summary
Constructors Constructor Description RequestTracker(boolean tracingEnabled)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static java.lang.StringbuildRequestDescriptor(java.lang.String... requestInfo)Creates a request descriptor or key to locate the client request id.longgetNumDescriptors()Returns the number of descriptors in the cache.longgetRequestIdFor(java.lang.String requestDescriptor)Retrieves the requestId associated to a request descriptor by means of usinggetRequestTagFor(String...).longgetRequestIdFor(java.lang.String... requestInfo)Retrieves a request id associated to a request descriptor.RequestTaggetRequestTagFor(java.lang.String requestDescriptor)Retrieves aRequestTagobject formed by a request descriptor and request id.RequestTaggetRequestTagFor(java.lang.String... requestInfo)Retrieves aRequestTagobject formed by a request descriptor and request id by means of using methodgetRequestTagFor(String...).RequestTaginitializeAndTrackRequestTag(long requestId, java.lang.String... requestInfo)This method first attempts to load aRequestTagfrom a request that is assumed to exist.booleanisTracingEnabled()voidtrackRequest(RequestTag requestTag)Adds a request descriptor and request id pair in the cache based on an inputRequestTagobject by overloading {trackRequest(String, long)}.voidtrackRequest(java.lang.String requestDescriptor, long requestId)Adds a request descriptor and request id pair in the cache if tracing is enabled.longuntrackRequest(RequestTag requestTag)Remove a request id from an associated request descriptor within aRequestTagobject by overloading {untrackRequest(String)}.longuntrackRequest(java.lang.String requestDescriptor)Removes and returns a request id from an associated request descriptor.
-
-
-
Method Detail
-
buildRequestDescriptor
public static java.lang.String buildRequestDescriptor(java.lang.String... requestInfo)
Creates a request descriptor or key to locate the client request id.- Parameters:
requestInfo- Fields to form the request descriptor.- Returns:
- Request descriptor.
-
getRequestTagFor
public RequestTag getRequestTagFor(java.lang.String... requestInfo)
Retrieves aRequestTagobject formed by a request descriptor and request id by means of using methodgetRequestTagFor(String...). In addition, this method transforms a set of input string parameters into a single request descriptor.- Parameters:
requestInfo- Fields to form the request descriptor.- Returns:
- Request descriptor and request id pair embedded in a
RequestTagobject.
-
getRequestTagFor
public RequestTag getRequestTagFor(java.lang.String requestDescriptor)
Retrieves aRequestTagobject formed by a request descriptor and request id. If the request descriptor does not exist or tracing is disabled, a newRequestTagobject with a default request id is returned. In the case of concurrent requests with the same descriptor, multiple request ids will be associated to that request descriptor. The policy adopted is to retrieve the first one that was stored in the cache. Given that tracing is applied to idempotent operations, this allows us to consistently trace the operation that actually changes the state of the system. The rest of concurrent operations will be rejected and their response will be logged with a different requestId, as an indicator that another client request was ongoing. For more information, we refer to this PDP: https://github.com/pravega/pravega/wiki/PDP-31:-End-to-end-Request-Tags- Parameters:
requestDescriptor- Request descriptor as a single string.- Returns:
- Request descriptor and request id pair embedded in a
RequestTagobject.
-
getRequestIdFor
public long getRequestIdFor(java.lang.String... requestInfo)
Retrieves a request id associated to a request descriptor. This method overloadsgetRequestTagFor(String)by transforming a set of input string parameters into a single request descriptor.- Parameters:
requestInfo- Fields to form the request descriptor.- Returns:
- Request descriptor and request id pair embedded in a RequestTag object.
-
getRequestIdFor
public long getRequestIdFor(java.lang.String requestDescriptor)
Retrieves the requestId associated to a request descriptor by means of usinggetRequestTagFor(String...).- Parameters:
requestDescriptor- Request descriptor as a single string.- Returns:
- Request id associated to the given descriptor.
-
trackRequest
public void trackRequest(RequestTag requestTag)
Adds a request descriptor and request id pair in the cache based on an inputRequestTagobject by overloading {trackRequest(String, long)}.- Parameters:
requestTag- Request tag to be cached for further tracing.
-
trackRequest
public void trackRequest(java.lang.String requestDescriptor, long requestId)Adds a request descriptor and request id pair in the cache if tracing is enabled. In the case of tracking a request with an existing descriptor, this method adds the request id to the list associated to the descriptor.- Parameters:
requestDescriptor- Request descriptor as a single string.requestId- Request id associated to the given descriptor.
-
untrackRequest
public long untrackRequest(RequestTag requestTag)
Remove a request id from an associated request descriptor within aRequestTagobject by overloading {untrackRequest(String)}.- Parameters:
requestTag- Request tag to remove from cache.- Returns:
- Request id removed from cache.
-
untrackRequest
public long untrackRequest(java.lang.String requestDescriptor)
Removes and returns a request id from an associated request descriptor. If the request descriptor does not exist or tracing is disabled, a default request id is returned. In the case that there is only one request id, the whole entry is evicted from cache. If there are multiple request ids for a given descriptor, the last request id in the list is deleted from the cache.- Parameters:
requestDescriptor- Request tag to remove from cache.- Returns:
- Request id removed from cache.
-
initializeAndTrackRequestTag
public RequestTag initializeAndTrackRequestTag(long requestId, java.lang.String... requestInfo)
This method first attempts to load aRequestTagfrom a request that is assumed to exist. However, if we work with clients or channels that do not attach tags to requests, then we initialize and track the request at the server side. In the worst case, we will have the ability of tracking a request from the server entry point onwards.- Parameters:
requestId- Alternative request id in the case there is no request id in headers.requestInfo- Alternative descriptor to identify the call in the case there is no descriptor in headers.- Returns:
- Request tag formed either from request headers or from arguments given.
-
getNumDescriptors
public long getNumDescriptors()
Returns the number of descriptors in the cache.- Returns:
- Number of request descriptors in the cache.
-
isTracingEnabled
public boolean isTracingEnabled()
-
-