Class OpenTelemetryDataTestUtils

java.lang.Object
com.linkedin.venice.utils.OpenTelemetryDataTestUtils

public abstract class OpenTelemetryDataTestUtils extends Object
  • Constructor Details

    • OpenTelemetryDataTestUtils

      public OpenTelemetryDataTestUtils()
  • Method Details

    • getLongPointDataFromSum

      public static io.opentelemetry.sdk.metrics.data.LongPointData getLongPointDataFromSum(Collection<io.opentelemetry.sdk.metrics.data.MetricData> metricsData, String metricName, String prefix, io.opentelemetry.api.common.Attributes expectedAttributes)
    • getLongPointDataFromGauge

      public static io.opentelemetry.sdk.metrics.data.LongPointData getLongPointDataFromGauge(Collection<io.opentelemetry.sdk.metrics.data.MetricData> metricsData, String metricName, String prefix, io.opentelemetry.api.common.Attributes expectedAttributes)
    • getLongPointDataFromGaugeIfPresent

      public static io.opentelemetry.sdk.metrics.data.LongPointData getLongPointDataFromGaugeIfPresent(Collection<io.opentelemetry.sdk.metrics.data.MetricData> metricsData, String metricName, String prefix, io.opentelemetry.api.common.Attributes expectedAttributes)
      Null-safe variant of getLongPointDataFromGauge(java.util.Collection<io.opentelemetry.sdk.metrics.data.MetricData>, java.lang.String, java.lang.String, io.opentelemetry.api.common.Attributes): returns null when either the metric is absent from the collection or no data point matches expectedAttributes. Useful for asserting that a particular attribute set was not emitted this collection cycle.
    • getExponentialHistogramPointData

      public static io.opentelemetry.sdk.metrics.data.ExponentialHistogramPointData getExponentialHistogramPointData(Collection<io.opentelemetry.sdk.metrics.data.MetricData> metricsData, String metricName, String prefix, io.opentelemetry.api.common.Attributes expectedAttributes)
    • getHistogramPointData

      public static io.opentelemetry.sdk.metrics.data.HistogramPointData getHistogramPointData(Collection<io.opentelemetry.sdk.metrics.data.MetricData> metricsData, String metricName, String prefix, io.opentelemetry.api.common.Attributes expectedAttributes)
    • validateLongPointDataFromCounter

      public static void validateLongPointDataFromCounter(io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader inMemoryMetricReader, long expectedValue, io.opentelemetry.api.common.Attributes expectedAttributes, String metricName, String metricPrefix)
    • validateLongPointDataFromCounterAtLeast

      public static void validateLongPointDataFromCounterAtLeast(io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader inMemoryMetricReader, long expectedMinValue, io.opentelemetry.api.common.Attributes expectedAttributes, String metricName, String metricPrefix)
      Validate counter value is at least the expected minimum. Use this in integration tests where the exact count is non-deterministic (e.g., TopicCleanupService may delete additional topics beyond those the test explicitly tracks).
    • validateLongPointDataFromGauge

      public static void validateLongPointDataFromGauge(io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader inMemoryMetricReader, long expectedValue, io.opentelemetry.api.common.Attributes expectedAttributes, String metricName, String metricPrefix)
    • validateDoublePointDataFromGauge

      public static void validateDoublePointDataFromGauge(io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader inMemoryMetricReader, double expectedValue, double tolerance, io.opentelemetry.api.common.Attributes expectedAttributes, String metricName, String metricPrefix)
    • validateExponentialHistogramPointData

      public static void validateExponentialHistogramPointData(io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader inMemoryMetricReader, double expectedMin, double expectedMax, long expectedCount, double expectedSum, io.opentelemetry.api.common.Attributes expectedAttributes, String metricName, String metricPrefix)
    • validateExponentialHistogramPointDataForLatency

      public static void validateExponentialHistogramPointDataForLatency(io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader inMemoryMetricReader, long expectedCount, io.opentelemetry.api.common.Attributes expectedAttributes, String metricName, String metricPrefix)
      Validate ExponentialHistogramPointData for latency metrics where min, max, and sum are not known but are > 0.
    • validateExponentialHistogramPointDataAtLeast

      public static void validateExponentialHistogramPointDataAtLeast(io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader inMemoryMetricReader, long expectedMinCount, io.opentelemetry.api.common.Attributes expectedAttributes, String metricName, String metricPrefix)
      Validate ExponentialHistogramPointData has at least expectedMinCount entries with sum > 0. Use this in integration tests where the exact count is non-deterministic.
    • validateHistogramPointData

      public static void validateHistogramPointData(io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader inMemoryMetricReader, double expectedMin, double expectedMax, long expectedCount, double expectedSum, io.opentelemetry.api.common.Attributes expectedAttributes, String metricName, String metricPrefix)
    • validateObservableCounterValue

      public static void validateObservableCounterValue(io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader inMemoryMetricReader, long expectedValue, io.opentelemetry.api.common.Attributes expectedAttributes, String metricName, String metricPrefix)
      Validate observable counter value for a specific attribute combination. Observable counters report as Sum data in OpenTelemetry.
    • validateAnySumDataPointAtLeast

      public static void validateAnySumDataPointAtLeast(io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader inMemoryMetricReader, long minValue, String metricName, String metricPrefix)
      Validate that at least one Sum (counter) data point exists with value >= minValue, across all attribute combinations. Use this in integration tests where the exact attributes are non-deterministic (e.g., replica type depends on leader election).

      Note: When validating multiple metrics, prefer collecting once via reader.collectAllMetrics() and calling the Collection<MetricData> overload to avoid draining async counter adders between calls.

    • validateAnySumDataPointAtLeast

      public static void validateAnySumDataPointAtLeast(Collection<io.opentelemetry.sdk.metrics.data.MetricData> metricsData, long minValue, String metricName, String metricPrefix)
    • validateAnyGaugeDataPointAtLeast

      public static void validateAnyGaugeDataPointAtLeast(io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader inMemoryMetricReader, long minValue, String metricName, String metricPrefix)
      Validate that at least one Gauge data point exists with value >= minValue, across all attribute combinations. Use this in integration tests where the exact attributes are non-deterministic.

      Note: When validating multiple metrics, prefer collecting once via reader.collectAllMetrics() and calling the Collection<MetricData> overload to avoid draining async counter adders between calls.

    • validateAnyGaugeDataPointAtLeast

      public static void validateAnyGaugeDataPointAtLeast(Collection<io.opentelemetry.sdk.metrics.data.MetricData> metricsData, long minValue, String metricName, String metricPrefix)
    • validateAnyDoubleGaugeDataPointAtLeast

      public static void validateAnyDoubleGaugeDataPointAtLeast(io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader inMemoryMetricReader, double minValue, String metricName, String metricPrefix)
    • assertNoLongSumDataForAttributes

      public static void assertNoLongSumDataForAttributes(Collection<io.opentelemetry.sdk.metrics.data.MetricData> metricsData, String metricName, String metricPrefix, io.opentelemetry.api.common.Attributes expectedAttributes)
      Assert that no Sum (counter) data point exists for the given metric name and attributes. If the metric is not present at all, this passes (no data = no counter data). If attributes is null, asserts that no data points exist at all for the metric.
    • validateAsyncCounterDeltaMultiCollection

      public static void validateAsyncCounterDeltaMultiCollection(io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader deltaReader, String metricName, String metricPrefix, io.opentelemetry.api.common.Attributes expectedAttributes, LongConsumer recordFn, long[] valuesPerPeriod)
      Validates that a monotonic async counter (ASYNC_COUNTER_FOR_HIGH_PERF_CASES) produces correct strictly-positive deltas under DELTA temporality across multiple collection intervals. All valuesPerPeriod must be strictly positive.

      This is the key regression test for the sumThenReset() to sum() fix. With DELTA temporality, the OTel SDK computes currentObservation - lastObservation. If the callback reports deltas (sumThenReset()), the SDK computes delta-of-delta which goes negative when traffic decreases. With cumulative observations (sum()), the SDK correctly computes the real delta for each period.

      For ASYNC_UP_DOWN_COUNTER_FOR_HIGH_PERF_CASES, use validateAsyncUpDownCounterDeltaMultiCollection(io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader, java.lang.String, java.lang.String, io.opentelemetry.api.common.Attributes, java.util.function.LongConsumer, long[]) instead.

    • validateAsyncUpDownCounterDeltaMultiCollection

      public static void validateAsyncUpDownCounterDeltaMultiCollection(io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader deltaReader, String metricName, String metricPrefix, io.opentelemetry.api.common.Attributes expectedAttributes, LongConsumer recordFn, long[] valuesPerPeriod)
      Validates that an ASYNC_UP_DOWN_COUNTER_FOR_HIGH_PERF_CASES metric produces correct deltas under DELTA temporality. Unlike monotonic counters, deltas can be negative.
    • validateAsyncCounterCumulativeMultiCollection

      public static void validateAsyncCounterCumulativeMultiCollection(io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader cumulativeReader, String metricName, String metricPrefix, io.opentelemetry.api.common.Attributes expectedAttributes, LongConsumer recordFn, long[] valuesPerPeriod)
      Validates that a monotonic async counter (ASYNC_COUNTER_FOR_HIGH_PERF_CASES) produces monotonically non-decreasing cumulative values across multiple collection intervals.

      For ASYNC_UP_DOWN_COUNTER_FOR_HIGH_PERF_CASES, use validateAsyncUpDownCounterCumulativeMultiCollection(io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader, java.lang.String, java.lang.String, io.opentelemetry.api.common.Attributes, java.util.function.LongConsumer, long[]) instead.

    • validateAsyncUpDownCounterCumulativeMultiCollection

      public static void validateAsyncUpDownCounterCumulativeMultiCollection(io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader cumulativeReader, String metricName, String metricPrefix, io.opentelemetry.api.common.Attributes expectedAttributes, LongConsumer recordFn, long[] valuesPerPeriod)
      Validates that an ASYNC_UP_DOWN_COUNTER_FOR_HIGH_PERF_CASES metric produces correct cumulative values. Unlike monotonic counters, the cumulative value can decrease.
    • validateAsyncCounterMultiCollection

      public static void validateAsyncCounterMultiCollection(String metricPrefix, Collection<MetricEntity> metricEntities, String metricName, io.opentelemetry.api.common.Attributes expectedAttributes, Function<VeniceMetricsRepository,LongConsumer> statsFactory, long[] valuesPerPeriod)
      Convenience overload for monotonic async counters (ASYNC_COUNTER_FOR_HIGH_PERF_CASES) that handles reader and repository lifecycle. Validates both DELTA and CUMULATIVE temporality.

      For ASYNC_UP_DOWN_COUNTER_FOR_HIGH_PERF_CASES, use validateAsyncUpDownCounterMultiCollection(java.lang.String, java.util.Collection<com.linkedin.venice.stats.metrics.MetricEntity>, java.lang.String, io.opentelemetry.api.common.Attributes, java.util.function.Function<com.linkedin.venice.stats.VeniceMetricsRepository, java.util.function.LongConsumer>, long[]) instead.

    • validateAsyncUpDownCounterMultiCollection

      public static void validateAsyncUpDownCounterMultiCollection(String metricPrefix, Collection<MetricEntity> metricEntities, String metricName, io.opentelemetry.api.common.Attributes expectedAttributes, Function<VeniceMetricsRepository,LongConsumer> statsFactory, long[] valuesPerPeriod)
      Convenience overload for ASYNC_UP_DOWN_COUNTER_FOR_HIGH_PERF_CASES that handles reader and repository lifecycle. Validates both DELTA and CUMULATIVE temporality. Values can be positive or negative.