Class OpenTelemetryDataTestUtils
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidassertNoLongSumDataForAttributes(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.static io.opentelemetry.sdk.metrics.data.ExponentialHistogramPointDatagetExponentialHistogramPointData(Collection<io.opentelemetry.sdk.metrics.data.MetricData> metricsData, String metricName, String prefix, io.opentelemetry.api.common.Attributes expectedAttributes) static io.opentelemetry.sdk.metrics.data.HistogramPointDatagetHistogramPointData(Collection<io.opentelemetry.sdk.metrics.data.MetricData> metricsData, String metricName, String prefix, io.opentelemetry.api.common.Attributes expectedAttributes) static io.opentelemetry.sdk.metrics.data.LongPointDatagetLongPointDataFromGauge(Collection<io.opentelemetry.sdk.metrics.data.MetricData> metricsData, String metricName, String prefix, io.opentelemetry.api.common.Attributes expectedAttributes) static io.opentelemetry.sdk.metrics.data.LongPointDatagetLongPointDataFromGaugeIfPresent(Collection<io.opentelemetry.sdk.metrics.data.MetricData> metricsData, String metricName, String prefix, io.opentelemetry.api.common.Attributes expectedAttributes) Null-safe variant ofgetLongPointDataFromGauge(java.util.Collection<io.opentelemetry.sdk.metrics.data.MetricData>, java.lang.String, java.lang.String, io.opentelemetry.api.common.Attributes): returnsnullwhen either the metric is absent from the collection or no data point matchesexpectedAttributes.static io.opentelemetry.sdk.metrics.data.LongPointDatagetLongPointDataFromSum(Collection<io.opentelemetry.sdk.metrics.data.MetricData> metricsData, String metricName, String prefix, io.opentelemetry.api.common.Attributes expectedAttributes) static voidvalidateAnyDoubleGaugeDataPointAtLeast(io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader inMemoryMetricReader, double minValue, String metricName, String metricPrefix) static voidvalidateAnyGaugeDataPointAtLeast(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.static voidvalidateAnyGaugeDataPointAtLeast(Collection<io.opentelemetry.sdk.metrics.data.MetricData> metricsData, long minValue, String metricName, String metricPrefix) static voidvalidateAnySumDataPointAtLeast(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.static voidvalidateAnySumDataPointAtLeast(Collection<io.opentelemetry.sdk.metrics.data.MetricData> metricsData, long minValue, String metricName, String metricPrefix) static voidvalidateAsyncCounterCumulativeMultiCollection(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.static voidvalidateAsyncCounterDeltaMultiCollection(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.static voidvalidateAsyncCounterMultiCollection(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.static voidvalidateAsyncUpDownCounterCumulativeMultiCollection(io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader cumulativeReader, String metricName, String metricPrefix, io.opentelemetry.api.common.Attributes expectedAttributes, LongConsumer recordFn, long[] valuesPerPeriod) Validates that anASYNC_UP_DOWN_COUNTER_FOR_HIGH_PERF_CASESmetric produces correct cumulative values.static voidvalidateAsyncUpDownCounterDeltaMultiCollection(io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader deltaReader, String metricName, String metricPrefix, io.opentelemetry.api.common.Attributes expectedAttributes, LongConsumer recordFn, long[] valuesPerPeriod) Validates that anASYNC_UP_DOWN_COUNTER_FOR_HIGH_PERF_CASESmetric produces correct deltas under DELTA temporality.static voidvalidateAsyncUpDownCounterMultiCollection(String metricPrefix, Collection<MetricEntity> metricEntities, String metricName, io.opentelemetry.api.common.Attributes expectedAttributes, Function<VeniceMetricsRepository, LongConsumer> statsFactory, long[] valuesPerPeriod) Convenience overload forASYNC_UP_DOWN_COUNTER_FOR_HIGH_PERF_CASESthat handles reader and repository lifecycle.static voidvalidateDoublePointDataFromGauge(io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader inMemoryMetricReader, double expectedValue, double tolerance, io.opentelemetry.api.common.Attributes expectedAttributes, String metricName, String metricPrefix) static voidvalidateExponentialHistogramPointData(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) static voidvalidateExponentialHistogramPointDataAtLeast(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.static voidvalidateExponentialHistogramPointDataForLatency(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.static voidvalidateHistogramPointData(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) static voidvalidateLongPointDataFromCounter(io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader inMemoryMetricReader, long expectedValue, io.opentelemetry.api.common.Attributes expectedAttributes, String metricName, String metricPrefix) static voidvalidateLongPointDataFromCounterAtLeast(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.static voidvalidateLongPointDataFromGauge(io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader inMemoryMetricReader, long expectedValue, io.opentelemetry.api.common.Attributes expectedAttributes, String metricName, String metricPrefix) static voidvalidateObservableCounterValue(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.
-
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 ofgetLongPointDataFromGauge(java.util.Collection<io.opentelemetry.sdk.metrics.data.MetricData>, java.lang.String, java.lang.String, io.opentelemetry.api.common.Attributes): returnsnullwhen either the metric is absent from the collection or no data point matchesexpectedAttributes. 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
-
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
-
validateDoublePointDataFromGauge
-
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 theCollection<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 theCollection<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
-
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. AllvaluesPerPeriodmust be strictly positive.This is the key regression test for the
sumThenReset()tosum()fix. With DELTA temporality, the OTel SDK computescurrentObservation - 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, usevalidateAsyncUpDownCounterDeltaMultiCollection(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 anASYNC_UP_DOWN_COUNTER_FOR_HIGH_PERF_CASESmetric 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, usevalidateAsyncUpDownCounterCumulativeMultiCollection(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 anASYNC_UP_DOWN_COUNTER_FOR_HIGH_PERF_CASESmetric 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, usevalidateAsyncUpDownCounterMultiCollection(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 forASYNC_UP_DOWN_COUNTER_FOR_HIGH_PERF_CASESthat handles reader and repository lifecycle. Validates both DELTA and CUMULATIVE temporality. Values can be positive or negative.
-