Class MetricAttributesData

java.lang.Object
com.linkedin.venice.stats.metrics.MetricAttributesData

public class MetricAttributesData extends Object
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 observable counter metrics (MetricType.ASYNC_COUNTER_FOR_HIGH_PERF_CASES and MetricType.ASYNC_UP_DOWN_COUNTER_FOR_HIGH_PERF_CASES). 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

    Constructors
    Constructor
    Description
    MetricAttributesData(io.opentelemetry.api.common.Attributes attributes)
    Creates a MetricAttributesData with only attributes (for non-observable-counter metrics).
    MetricAttributesData(io.opentelemetry.api.common.Attributes attributes, boolean createAdder)
    Creates a MetricAttributesData with attributes and optionally a LongAdder.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    add(long value)
    Adds the given value to the internal LongAdder.
    io.opentelemetry.api.common.Attributes
    Returns the OpenTelemetry attributes.
    boolean
    Returns whether this holder has a LongAdder for high-throughput recording.
    long
    Returns the current sum and resets the adder to zero.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • MetricAttributesData

      public MetricAttributesData(io.opentelemetry.api.common.Attributes attributes)
      Creates a MetricAttributesData with only attributes (for non-observable-counter 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 combination
      createAdder - 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 observable counter 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 observable counter metrics where adder is guaranteed non-null.
      Returns:
      the sum before reset