Class AsyncMetricEntityStateOneEnum<E extends Enum<E> & VeniceDimensionInterface>

java.lang.Object
com.linkedin.venice.stats.metrics.AsyncMetricEntityStateOneEnum<E>

public class AsyncMetricEntityStateOneEnum<E extends Enum<E> & VeniceDimensionInterface> extends Object
Async state wrapper for a metric with one enum dimension (MetricType.ASYNC_GAUGE or MetricType.ASYNC_DOUBLE_GAUGE).

Two-callback contract (enforces cardinality control)

This class registers exactly ONE OTel observable gauge per metric entity. The caller provides:
  1. AsyncMetricResolvers.LiveStateResolverOneEnum — maps an enum value to its backing state, or null when the combo is dormant. The null return is the liveness signal: the SDK never sees an attribute set for a dormant combo, so the cardinality cap is only charged for combos that actually have data.
  2. AsyncMetricResolvers.ValueResolverOneEnum — reads the numeric value from the resolved state. Only invoked when AsyncMetricResolvers.LiveStateResolverOneEnum.resolve(E) returned non-null.
Splitting the two phases forces the caller to think about liveness: there is no path from "combo" to "value" that skips the state resolution, so it is impossible to accidentally emit a dormant attribute set.

Attribute sets are precomputed once per enum value at construction and cached. Per-collection cost is O(|E|) liveStateResolver calls plus one measurement.record(...) per emitted combo.

  • Method Details

    • create

      public static <E extends Enum<E> & VeniceDimensionInterface, S> AsyncMetricEntityStateOneEnum<E> create(MetricEntity metricEntity, VeniceOpenTelemetryMetricsRepository otelRepository, Map<VeniceMetricsDimensions,String> baseDimensionsMap, Class<E> enumTypeClass, AsyncMetricResolvers.LiveStateResolverOneEnum<E,S> liveStateResolver, AsyncMetricResolvers.ValueResolverOneEnum<S,E> valueResolver)
      Creates a state wrapper and registers a single multi-emit observable gauge. On every collection the SDK invokes the callback, which for each enum value:
      • calls liveStateResolver.resolve(enumValue) — if null, skips this combo for this cycle;
      • otherwise calls valueResolver.extractValue(state, enumValue) and emits a data point with the precomputed attributes.

      When OTel is disabled, no registration happens and neither callback is invoked.

      Type Parameters:
      S - the state type returned by liveStateResolver. Can be any reference type (wrapper, task, counter, etc.) — the infra never inspects it beyond null-check.
    • emitOpenTelemetryMetrics

      public boolean emitOpenTelemetryMetrics()
    • getAttributesByEnum

      public EnumMap<E,io.opentelemetry.api.common.Attributes> getAttributesByEnum()
      Visible for testing — the cached attributes per enum value, or null if OTel is disabled.
    • getInstrument

      public Object getInstrument()
      Visible for testing — the underlying SDK instrument handle, or null if OTel disabled.