Class CallMetricRecorder
- java.lang.Object
-
- io.grpc.services.CallMetricRecorder
-
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/6012") @ThreadSafe public final class CallMetricRecorder extends java.lang.Object
Utility to record call metrics for load-balancing. One instance per call.
-
-
Field Summary
Fields Modifier and Type Field Description private double
applicationUtilizationMetric
(package private) static Context.Key<CallMetricRecorder>
CONTEXT_KEY
private double
cpuUtilizationMetric
private boolean
disabled
private double
eps
private double
memoryUtilizationMetric
private java.util.concurrent.atomic.AtomicReference<java.util.concurrent.ConcurrentHashMap<java.lang.String,java.lang.Double>>
namedMetrics
private static CallMetricRecorder
NOOP
private double
qps
private java.util.concurrent.atomic.AtomicReference<java.util.concurrent.ConcurrentHashMap<java.lang.String,java.lang.Double>>
requestCostMetrics
private java.util.concurrent.atomic.AtomicReference<java.util.concurrent.ConcurrentHashMap<java.lang.String,java.lang.Double>>
utilizationMetrics
-
Constructor Summary
Constructors Constructor Description CallMetricRecorder()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description private CallMetricRecorder
disable()
Turn this recorder into a no-op one.(package private) java.util.Map<java.lang.String,java.lang.Double>
finalizeAndDump()
Returns all request cost metric values.(package private) MetricReport
finalizeAndDump2()
Returns all save metric values.static CallMetricRecorder
getCurrent()
Returns the call metric recorder attached to the currentContext
.(package private) boolean
isDisabled()
CallMetricRecorder
recordApplicationUtilizationMetric(double value)
Records a call metric measurement for application specific utilization in the range [0, inf).CallMetricRecorder
recordCallMetric(java.lang.String name, double value)
Deprecated.userecordRequestCostMetric(java.lang.String, double)
instead.CallMetricRecorder
recordCpuUtilizationMetric(double value)
Records a call metric measurement for CPU utilization in the range [0, inf).CallMetricRecorder
recordEpsMetric(double value)
Records a call metric measurement for errors per second (eps) in the range [0, inf).CallMetricRecorder
recordMemoryUtilizationMetric(double value)
Records a call metric measurement for memory utilization in the range [0, 1].CallMetricRecorder
recordNamedMetric(java.lang.String name, double value)
Records an application-specific opaque custom metric measurement.CallMetricRecorder
recordQpsMetric(double value)
Records a call metric measurement for queries per second (qps) in the range [0, inf).CallMetricRecorder
recordRequestCostMetric(java.lang.String name, double value)
Records a call metric measurement for request cost.CallMetricRecorder
recordUtilizationMetric(java.lang.String name, double value)
Records a call metric measurement for utilization in the range [0, 1].
-
-
-
Field Detail
-
NOOP
private static final CallMetricRecorder NOOP
-
CONTEXT_KEY
static final Context.Key<CallMetricRecorder> CONTEXT_KEY
-
utilizationMetrics
private final java.util.concurrent.atomic.AtomicReference<java.util.concurrent.ConcurrentHashMap<java.lang.String,java.lang.Double>> utilizationMetrics
-
requestCostMetrics
private final java.util.concurrent.atomic.AtomicReference<java.util.concurrent.ConcurrentHashMap<java.lang.String,java.lang.Double>> requestCostMetrics
-
namedMetrics
private final java.util.concurrent.atomic.AtomicReference<java.util.concurrent.ConcurrentHashMap<java.lang.String,java.lang.Double>> namedMetrics
-
cpuUtilizationMetric
private double cpuUtilizationMetric
-
applicationUtilizationMetric
private double applicationUtilizationMetric
-
memoryUtilizationMetric
private double memoryUtilizationMetric
-
qps
private double qps
-
eps
private double eps
-
disabled
private volatile boolean disabled
-
-
Method Detail
-
getCurrent
public static CallMetricRecorder getCurrent()
Returns the call metric recorder attached to the currentContext
. If there is none, returns a no-op recorder.IMPORTANT:It returns the recorder specifically for the current RPC call. DO NOT save the returned object or share it between different RPC calls.
IMPORTANT:It must be called under the
Context
under which the RPC handler was called. If it is called from a different thread, the Context must be propagated to the same thread, e.g., withContext.wrap(Runnable)
.- Since:
- 1.23.0
-
recordUtilizationMetric
public CallMetricRecorder recordUtilizationMetric(java.lang.String name, double value)
Records a call metric measurement for utilization in the range [0, 1]. Values outside the valid range are ignored. If RPC has already finished, this method is no-op.A latter record will overwrite its former name-sakes.
- Returns:
- this recorder object
- Since:
- 1.23.0
-
recordCallMetric
@Deprecated @InlineMe(replacement="this.recordRequestCostMetric(name, value)") public CallMetricRecorder recordCallMetric(java.lang.String name, double value)
Deprecated.userecordRequestCostMetric(java.lang.String, double)
instead. This method will be removed in the future.Records a call metric measurement for request cost. If RPC has already finished, this method is no-op.A latter record will overwrite its former name-sakes.
- Returns:
- this recorder object
- Since:
- 1.47.0
-
recordRequestCostMetric
public CallMetricRecorder recordRequestCostMetric(java.lang.String name, double value)
Records a call metric measurement for request cost. If RPC has already finished, this method is no-op.A latter record will overwrite its former name-sakes.
- Returns:
- this recorder object
- Since:
- 1.48.1
-
recordNamedMetric
public CallMetricRecorder recordNamedMetric(java.lang.String name, double value)
Records an application-specific opaque custom metric measurement. If RPC has already finished, this method is no-op.A latter record will overwrite its former name-sakes.
- Returns:
- this recorder object
-
recordCpuUtilizationMetric
public CallMetricRecorder recordCpuUtilizationMetric(double value)
Records a call metric measurement for CPU utilization in the range [0, inf). Values outside the valid range are ignored. If RPC has already finished, this method is no-op.A latter record will overwrite its former name-sakes.
- Returns:
- this recorder object
- Since:
- 1.47.0
-
recordApplicationUtilizationMetric
public CallMetricRecorder recordApplicationUtilizationMetric(double value)
Records a call metric measurement for application specific utilization in the range [0, inf). Values outside the valid range are ignored. If RPC has already finished, this method is no-op.A latter record will overwrite its former name-sakes.
- Returns:
- this recorder object
-
recordMemoryUtilizationMetric
public CallMetricRecorder recordMemoryUtilizationMetric(double value)
Records a call metric measurement for memory utilization in the range [0, 1]. Values outside the valid range are ignored. If RPC has already finished, this method is no-op.A latter record will overwrite its former name-sakes.
- Returns:
- this recorder object
- Since:
- 1.47.0
-
recordQpsMetric
public CallMetricRecorder recordQpsMetric(double value)
Records a call metric measurement for queries per second (qps) in the range [0, inf). Values outside the valid range are ignored. If RPC has already finished, this method is no-op.A latter record will overwrite its former name-sakes.
- Returns:
- this recorder object
- Since:
- 1.54.0
-
recordEpsMetric
public CallMetricRecorder recordEpsMetric(double value)
Records a call metric measurement for errors per second (eps) in the range [0, inf). Values outside the valid range are ignored. If RPC has already finished, this method is no-op.A latter record will overwrite its former name-sakes.
- Returns:
- this recorder object
-
finalizeAndDump
java.util.Map<java.lang.String,java.lang.Double> finalizeAndDump()
Returns all request cost metric values. No more metric values will be recorded after this method is called. Calling this method multiple times returns the same collection of metric values.- Returns:
- a map containing all saved metric name-value pairs.
-
finalizeAndDump2
MetricReport finalizeAndDump2()
Returns all save metric values. No more metric values will be recorded after this method is called. Calling this method multiple times returns the same collection of metric values.- Returns:
- a per-request ORCA reports containing all saved metrics.
-
isDisabled
boolean isDisabled()
-
disable
private CallMetricRecorder disable()
Turn this recorder into a no-op one.
-
-