Class MetricAttributesData
java.lang.Object
com.linkedin.venice.stats.metrics.MetricAttributesData
A holder class that contains OpenTelemetry
Attributes and optionally a LongAdder
for each of that attributes for high-throughput metric recording scenarios.
This class is used by MetricEntityState subclasses to cache both the attributes
and the accumulator for MetricType.ASYNC_COUNTER_FOR_HIGH_PERF_CASES metrics. For other metric types,
only the attributes are used and the adder remains null.
The LongAdder provides high-throughput recording capability by minimizing contention
across threads. The accumulated value is read during OpenTelemetry's metric collection callback
via sumThenReset().
-
Constructor Summary
ConstructorsConstructorDescriptionMetricAttributesData(io.opentelemetry.api.common.Attributes attributes) Creates a MetricAttributesData with only attributes (for non-ASYNC_COUNTER_FOR_HIGH_PERF_CASES metrics).MetricAttributesData(io.opentelemetry.api.common.Attributes attributes, boolean createAdder) Creates a MetricAttributesData with attributes and optionally a LongAdder. -
Method Summary
Modifier and TypeMethodDescriptionvoidadd(long value) Adds the given value to the internal LongAdder.io.opentelemetry.api.common.AttributesReturns the OpenTelemetry attributes.booleanhasAdder()Returns whether this holder has a LongAdder for high-throughput recording.longReturns the current sum and resets the adder to zero.
-
Constructor Details
-
MetricAttributesData
public MetricAttributesData(io.opentelemetry.api.common.Attributes attributes) Creates a MetricAttributesData with only attributes (for non-ASYNC_COUNTER_FOR_HIGH_PERF_CASES metrics).- Parameters:
attributes- the OpenTelemetry attributes for this metric dimension combination
-
MetricAttributesData
public MetricAttributesData(io.opentelemetry.api.common.Attributes attributes, boolean createAdder) Creates a MetricAttributesData with attributes and optionally a LongAdder.- Parameters:
attributes- the OpenTelemetry attributes for this metric dimension combinationcreateAdder- if true, creates a LongAdder for high-throughput recording
-
-
Method Details
-
getAttributes
public io.opentelemetry.api.common.Attributes getAttributes()Returns the OpenTelemetry attributes. -
hasAdder
public boolean hasAdder()Returns whether this holder has a LongAdder for high-throughput recording. -
add
public void add(long value) Adds the given value to the internal LongAdder. This is a fast operation optimized for high contention scenarios. Only call this for ASYNC_COUNTER_FOR_HIGH_PERF_CASES metrics where adder is guaranteed non-null.- Parameters:
value- the value to add
-
sumThenReset
public long sumThenReset()Returns the current sum and resets the adder to zero. This is typically called during OpenTelemetry's metric collection callback. Only call this for ASYNC_COUNTER_FOR_HIGH_PERF_CASES metrics where adder is guaranteed non-null.- Returns:
- the sum before reset
-