Class StoreVersionOtelStats

java.lang.Object
com.linkedin.davinci.stats.StoreVersionOtelStats
All Implemented Interfaces:
StoreDataChangedListener, Closeable, AutoCloseable

public class StoreVersionOtelStats extends Object implements StoreDataChangedListener, Closeable
Registers OTel ASYNC_GAUGE callbacks per store for the current and future version numbers.

Metric: store.version with dimensions CLUSTER_NAME, STORE_NAME, and VERSION_ROLE. Only CURRENT and FUTURE are emitted — backup version number is not tracked.

This class implements StoreDataChangedListener and should be registered once per process on the metadata repository via register(ReadOnlyStoreRepository). Per-store state is created lazily on first store change and bounded by the number of distinct store names ever observed by the process (entries are not removed on deletion — see cleanup limitation below).

Cleanup limitation: the OTel SDK does support per-instrument deregistration via ObservableLongGauge.close(), but the current Venice wrapper (AsyncMetricEntityStateBase) doesn't surface the SDK instrument handle, so callbacks remain registered until the MetricsRepository is closed. On store deletion, version info is reset to OtelVersionedStatsUtils.VersionInfo.NON_EXISTING rather than removed — see handleStoreDeleted(java.lang.String) for why removing the map entry is unsafe given the current wrapper.

  • Method Details

    • create

      public static StoreVersionOtelStats create(io.tehuti.metrics.MetricsRepository metricsRepository, String clusterName, ReadOnlyStoreRepository metadataRepository)
      Creates and registers a StoreVersionOtelStats listener on the given metadata repository. Initializes gauges for all pre-existing stores. This is the preferred entry point — it combines construction and registration to prevent the listener from existing in an unregistered state.
    • close

      public void close()
      Unregisters this OTel listener from the metadata repository. Idempotent.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
    • handleStoreCreated

      public void handleStoreCreated(Store store)
      Description copied from interface: StoreDataChangedListener
      Do NOT try to acquire the lock of store repository again in the implementation, otherwise a dead lock issue will happen.
      Specified by:
      handleStoreCreated in interface StoreDataChangedListener
    • handleStoreChanged

      public void handleStoreChanged(Store store)
      Specified by:
      handleStoreChanged in interface StoreDataChangedListener
    • handleStoreDeleted

      public void handleStoreDeleted(String storeName)
      Resets version info to OtelVersionedStatsUtils.VersionInfo.NON_EXISTING rather than removing the map entry. The async-gauge callback closes over the AtomicReference, which the Venice wrapper doesn't currently surface for de-registration. Removing the map entry would orphan the live callback (SDK keeps polling stale data); a subsequent re-create would register a second callback emitting under the same attributes. Resetting keeps one live callback pointed at the right state across delete→re-create cycles.
      Specified by:
      handleStoreDeleted in interface StoreDataChangedListener