diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/metrics/_internal/_view_instrument_match.py b/opentelemetry-sdk/src/opentelemetry/sdk/metrics/_internal/_view_instrument_match.py index b527f0e5df5..700be3d5c35 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/metrics/_internal/_view_instrument_match.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/metrics/_internal/_view_instrument_match.py @@ -52,12 +52,14 @@ def __init__( ) if not isinstance(self._view._aggregation, DefaultAggregation): self._aggregation = self._view._aggregation._create_aggregation( - self._instrument, None, 0 + self._instrument, None, self._view._exemplar_reservoir_factory, 0 ) else: self._aggregation = self._instrument_class_aggregation[ self._instrument.__class__ - ]._create_aggregation(self._instrument, None, 0) + ]._create_aggregation( + self._instrument, None, self._view._exemplar_reservoir_factory, 0 + ) def conflicts(self, other: "_ViewInstrumentMatch") -> bool: # pylint: disable=protected-access diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/metrics/_internal/view.py b/opentelemetry-sdk/src/opentelemetry/sdk/metrics/_internal/view.py index 625796ba854..9cbf602c6f6 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/metrics/_internal/view.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/metrics/_internal/view.py @@ -34,7 +34,7 @@ _logger = getLogger(__name__) -def _default_reservoir_factory(aggregationType: Type[_Aggregation]) -> ExemplarReservoirFactory: +def default_reservoir_factory(aggregationType: Type[_Aggregation]) -> ExemplarReservoirFactory: """Default reservoir factory per aggregation.""" if issubclass(aggregationType, _ExplicitBucketHistogramAggregation): return AlignedHistogramBucketExemplarReservoir @@ -154,7 +154,7 @@ def __init__( self._description = description self._attribute_keys = attribute_keys self._aggregation = aggregation or self._default_aggregation - self._exemplar_reservoir_factory = exemplar_reservoir_factory or _default_reservoir_factory + self._exemplar_reservoir_factory = exemplar_reservoir_factory or default_reservoir_factory # pylint: disable=too-many-return-statements # pylint: disable=too-many-branches diff --git a/opentelemetry-sdk/tests/metrics/test_aggregation.py b/opentelemetry-sdk/tests/metrics/test_aggregation.py index 7ea463ec8a8..af687d49051 100644 --- a/opentelemetry-sdk/tests/metrics/test_aggregation.py +++ b/opentelemetry-sdk/tests/metrics/test_aggregation.py @@ -15,11 +15,12 @@ # pylint: disable=protected-access from math import inf -from time import sleep +from time import sleep, time_ns from typing import Union from unittest import TestCase from unittest.mock import Mock +from opentelemetry.context import Context from opentelemetry.sdk.metrics._internal.aggregation import ( _ExplicitBucketHistogramAggregation, _LastValueAggregation, @@ -35,6 +36,7 @@ _UpDownCounter, ) from opentelemetry.sdk.metrics._internal.measurement import Measurement +from opentelemetry.sdk.metrics._internal.view import default_reservoir_factory from opentelemetry.sdk.metrics.export import ( AggregationTemporality, NumberDataPoint, @@ -48,10 +50,10 @@ from opentelemetry.util.types import Attributes -def measurement( - value: Union[int, float], attributes: Attributes = None -) -> Measurement: - return Measurement(value, instrument=Mock(), attributes=attributes) +def measurement(value: Union[int, float], attributes: Attributes = None) -> Measurement: + return Measurement( + value, time_ns(), instrument=Mock(), context=Context(), attributes=attributes + ) class TestSynchronousSumAggregation(TestCase): @@ -61,7 +63,11 @@ def test_aggregate_delta(self): """ synchronous_sum_aggregation = _SumAggregation( - Mock(), True, AggregationTemporality.DELTA, 0 + Mock(), + True, + AggregationTemporality.DELTA, + 0, + default_reservoir_factory(_SumAggregation), ) synchronous_sum_aggregation.aggregate(measurement(1)) @@ -71,7 +77,11 @@ def test_aggregate_delta(self): self.assertEqual(synchronous_sum_aggregation._value, 6) synchronous_sum_aggregation = _SumAggregation( - Mock(), True, AggregationTemporality.DELTA, 0 + Mock(), + True, + AggregationTemporality.DELTA, + 0, + default_reservoir_factory(_SumAggregation), ) synchronous_sum_aggregation.aggregate(measurement(1)) @@ -86,7 +96,11 @@ def test_aggregate_cumulative(self): """ synchronous_sum_aggregation = _SumAggregation( - Mock(), True, AggregationTemporality.CUMULATIVE, 0 + Mock(), + True, + AggregationTemporality.CUMULATIVE, + 0, + default_reservoir_factory(_SumAggregation), ) synchronous_sum_aggregation.aggregate(measurement(1)) @@ -96,7 +110,11 @@ def test_aggregate_cumulative(self): self.assertEqual(synchronous_sum_aggregation._value, 6) synchronous_sum_aggregation = _SumAggregation( - Mock(), True, AggregationTemporality.CUMULATIVE, 0 + Mock(), + True, + AggregationTemporality.CUMULATIVE, + 0, + default_reservoir_factory(_SumAggregation), ) synchronous_sum_aggregation.aggregate(measurement(1)) @@ -111,7 +129,11 @@ def test_collect_delta(self): """ synchronous_sum_aggregation = _SumAggregation( - Mock(), True, AggregationTemporality.DELTA, 0 + Mock(), + True, + AggregationTemporality.DELTA, + 0, + default_reservoir_factory(_SumAggregation), ) synchronous_sum_aggregation.aggregate(measurement(1)) @@ -137,15 +159,17 @@ def test_collect_delta(self): ) synchronous_sum_aggregation = _SumAggregation( - Mock(), True, AggregationTemporality.DELTA, 0 + Mock(), + True, + AggregationTemporality.DELTA, + 0, + default_reservoir_factory(_SumAggregation), ) synchronous_sum_aggregation.aggregate(measurement(1)) # 1 is used here directly to simulate the instant the first # collection process starts. - first_sum = synchronous_sum_aggregation.collect( - AggregationTemporality.DELTA, 1 - ) + first_sum = synchronous_sum_aggregation.collect(AggregationTemporality.DELTA, 1) self.assertEqual(first_sum.value, 1) @@ -168,21 +192,21 @@ def test_collect_cumulative(self): """ sum_aggregation = _SumAggregation( - Mock(), True, AggregationTemporality.CUMULATIVE, 0 + Mock(), + True, + AggregationTemporality.CUMULATIVE, + 0, + default_reservoir_factory(_SumAggregation), ) sum_aggregation.aggregate(measurement(1)) - first_sum = sum_aggregation.collect( - AggregationTemporality.CUMULATIVE, 1 - ) + first_sum = sum_aggregation.collect(AggregationTemporality.CUMULATIVE, 1) self.assertEqual(first_sum.value, 1) # should have been reset after first collect sum_aggregation.aggregate(measurement(1)) - second_sum = sum_aggregation.collect( - AggregationTemporality.CUMULATIVE, 1 - ) + second_sum = sum_aggregation.collect(AggregationTemporality.CUMULATIVE, 1) self.assertEqual(second_sum.value, 1) @@ -191,9 +215,7 @@ def test_collect_cumulative(self): ) # if no point seen for a whole interval, should return None - third_sum = sum_aggregation.collect( - AggregationTemporality.CUMULATIVE, 1 - ) + third_sum = sum_aggregation.collect(AggregationTemporality.CUMULATIVE, 1) self.assertIsNone(third_sum) @@ -204,7 +226,9 @@ def test_aggregate(self): temporality """ - last_value_aggregation = _LastValueAggregation(Mock()) + last_value_aggregation = _LastValueAggregation( + Mock(), default_reservoir_factory(_LastValueAggregation) + ) last_value_aggregation.aggregate(measurement(1)) self.assertEqual(last_value_aggregation._value, 1) @@ -220,12 +244,12 @@ def test_collect(self): `LastValueAggregation` collects number data points """ - last_value_aggregation = _LastValueAggregation(Mock()) + last_value_aggregation = _LastValueAggregation( + Mock(), default_reservoir_factory(_LastValueAggregation) + ) self.assertIsNone( - last_value_aggregation.collect( - AggregationTemporality.CUMULATIVE, 1 - ) + last_value_aggregation.collect(AggregationTemporality.CUMULATIVE, 1) ) last_value_aggregation.aggregate(measurement(1)) @@ -274,13 +298,12 @@ def test_aggregate(self): Test `ExplicitBucketHistogramAggregation with custom boundaries """ - explicit_bucket_histogram_aggregation = ( - _ExplicitBucketHistogramAggregation( - Mock(), - AggregationTemporality.DELTA, - 0, - boundaries=[0, 2, 4], - ) + explicit_bucket_histogram_aggregation = _ExplicitBucketHistogramAggregation( + Mock(), + AggregationTemporality.DELTA, + 0, + default_reservoir_factory(_ExplicitBucketHistogramAggregation), + boundaries=[0, 2, 4], ) explicit_bucket_histogram_aggregation.aggregate(measurement(-1)) @@ -314,10 +337,11 @@ def test_min_max(self): maximum value in the population """ - explicit_bucket_histogram_aggregation = ( - _ExplicitBucketHistogramAggregation( - Mock(), AggregationTemporality.CUMULATIVE, 0 - ) + explicit_bucket_histogram_aggregation = _ExplicitBucketHistogramAggregation( + Mock(), + AggregationTemporality.CUMULATIVE, + 0, + default_reservoir_factory(_ExplicitBucketHistogramAggregation), ) explicit_bucket_histogram_aggregation.aggregate(measurement(-1)) @@ -329,13 +353,12 @@ def test_min_max(self): self.assertEqual(explicit_bucket_histogram_aggregation._min, -1) self.assertEqual(explicit_bucket_histogram_aggregation._max, 9999) - explicit_bucket_histogram_aggregation = ( - _ExplicitBucketHistogramAggregation( - Mock(), - AggregationTemporality.CUMULATIVE, - 0, - record_min_max=False, - ) + explicit_bucket_histogram_aggregation = _ExplicitBucketHistogramAggregation( + Mock(), + AggregationTemporality.CUMULATIVE, + 0, + default_reservoir_factory(_ExplicitBucketHistogramAggregation), + record_min_max=False, ) explicit_bucket_histogram_aggregation.aggregate(measurement(-1)) @@ -352,13 +375,12 @@ def test_collect(self): `_ExplicitBucketHistogramAggregation` collects sum metric points """ - explicit_bucket_histogram_aggregation = ( - _ExplicitBucketHistogramAggregation( - Mock(), - AggregationTemporality.DELTA, - 0, - boundaries=[0, 1, 2], - ) + explicit_bucket_histogram_aggregation = _ExplicitBucketHistogramAggregation( + Mock(), + AggregationTemporality.DELTA, + 0, + default_reservoir_factory(_ExplicitBucketHistogramAggregation), + boundaries=[0, 1, 2], ) explicit_bucket_histogram_aggregation.aggregate(measurement(1)) @@ -392,7 +414,10 @@ def test_collect(self): def test_boundaries(self): self.assertEqual( _ExplicitBucketHistogramAggregation( - Mock(), AggregationTemporality.CUMULATIVE, 0 + Mock(), + AggregationTemporality.CUMULATIVE, + 0, + default_reservoir_factory(_ExplicitBucketHistogramAggregation), )._boundaries, ( 0.0, @@ -418,19 +443,25 @@ class TestAggregationFactory(TestCase): def test_sum_factory(self): counter = _Counter("name", Mock(), Mock()) factory = SumAggregation() - aggregation = factory._create_aggregation(counter, Mock(), 0) + aggregation = factory._create_aggregation( + counter, Mock(), default_reservoir_factory, 0 + ) self.assertIsInstance(aggregation, _SumAggregation) self.assertTrue(aggregation._instrument_is_monotonic) self.assertEqual( aggregation._instrument_aggregation_temporality, AggregationTemporality.DELTA, ) - aggregation2 = factory._create_aggregation(counter, Mock(), 0) + aggregation2 = factory._create_aggregation( + counter, Mock(), default_reservoir_factory, 0 + ) self.assertNotEqual(aggregation, aggregation2) counter = _UpDownCounter("name", Mock(), Mock()) factory = SumAggregation() - aggregation = factory._create_aggregation(counter, Mock(), 0) + aggregation = factory._create_aggregation( + counter, Mock(), default_reservoir_factory, 0 + ) self.assertIsInstance(aggregation, _SumAggregation) self.assertFalse(aggregation._instrument_is_monotonic) self.assertEqual( @@ -440,7 +471,9 @@ def test_sum_factory(self): counter = _ObservableCounter("name", Mock(), Mock(), None) factory = SumAggregation() - aggregation = factory._create_aggregation(counter, Mock(), 0) + aggregation = factory._create_aggregation( + counter, Mock(), default_reservoir_factory, 0 + ) self.assertIsInstance(aggregation, _SumAggregation) self.assertTrue(aggregation._instrument_is_monotonic) self.assertEqual( @@ -457,19 +490,27 @@ def test_explicit_bucket_histogram_factory(self): ), record_min_max=False, ) - aggregation = factory._create_aggregation(histo, Mock(), 0) + aggregation = factory._create_aggregation( + histo, Mock(), default_reservoir_factory, 0 + ) self.assertIsInstance(aggregation, _ExplicitBucketHistogramAggregation) self.assertFalse(aggregation._record_min_max) self.assertEqual(aggregation._boundaries, (0.0, 5.0)) - aggregation2 = factory._create_aggregation(histo, Mock(), 0) + aggregation2 = factory._create_aggregation( + histo, Mock(), default_reservoir_factory, 0 + ) self.assertNotEqual(aggregation, aggregation2) def test_last_value_factory(self): counter = _Counter("name", Mock(), Mock()) factory = LastValueAggregation() - aggregation = factory._create_aggregation(counter, Mock(), 0) + aggregation = factory._create_aggregation( + counter, Mock(), default_reservoir_factory, 0 + ) self.assertIsInstance(aggregation, _LastValueAggregation) - aggregation2 = factory._create_aggregation(counter, Mock(), 0) + aggregation2 = factory._create_aggregation( + counter, Mock(), default_reservoir_factory, 0 + ) self.assertNotEqual(aggregation, aggregation2) @@ -479,9 +520,8 @@ def setUpClass(cls): cls.default_aggregation = DefaultAggregation() def test_counter(self): - aggregation = self.default_aggregation._create_aggregation( - _Counter("name", Mock(), Mock()), Mock(), 0 + _Counter("name", Mock(), Mock()), Mock(), default_reservoir_factory, 0 ) self.assertIsInstance(aggregation, _SumAggregation) self.assertTrue(aggregation._instrument_is_monotonic) @@ -491,9 +531,8 @@ def test_counter(self): ) def test_up_down_counter(self): - aggregation = self.default_aggregation._create_aggregation( - _UpDownCounter("name", Mock(), Mock()), Mock(), 0 + _UpDownCounter("name", Mock(), Mock()), Mock(), default_reservoir_factory, 0 ) self.assertIsInstance(aggregation, _SumAggregation) self.assertFalse(aggregation._instrument_is_monotonic) @@ -503,10 +542,10 @@ def test_up_down_counter(self): ) def test_observable_counter(self): - aggregation = self.default_aggregation._create_aggregation( _ObservableCounter("name", Mock(), Mock(), callbacks=[Mock()]), Mock(), + default_reservoir_factory, 0, ) self.assertIsInstance(aggregation, _SumAggregation) @@ -517,12 +556,10 @@ def test_observable_counter(self): ) def test_observable_up_down_counter(self): - aggregation = self.default_aggregation._create_aggregation( - _ObservableUpDownCounter( - "name", Mock(), Mock(), callbacks=[Mock()] - ), + _ObservableUpDownCounter("name", Mock(), Mock(), callbacks=[Mock()]), Mock(), + default_reservoir_factory, 0, ) self.assertIsInstance(aggregation, _SumAggregation) @@ -533,7 +570,6 @@ def test_observable_up_down_counter(self): ) def test_histogram(self): - aggregation = self.default_aggregation._create_aggregation( _Histogram( "name", @@ -541,12 +577,12 @@ def test_histogram(self): Mock(), ), Mock(), + default_reservoir_factory, 0, ) self.assertIsInstance(aggregation, _ExplicitBucketHistogramAggregation) def test_gauge(self): - aggregation = self.default_aggregation._create_aggregation( _Gauge( "name", @@ -554,12 +590,12 @@ def test_gauge(self): Mock(), ), Mock(), + default_reservoir_factory, 0, ) self.assertIsInstance(aggregation, _LastValueAggregation) def test_observable_gauge(self): - aggregation = self.default_aggregation._create_aggregation( _ObservableGauge( "name", @@ -568,6 +604,7 @@ def test_observable_gauge(self): callbacks=[Mock()], ), Mock(), + default_reservoir_factory, 0, ) self.assertIsInstance(aggregation, _LastValueAggregation) diff --git a/opentelemetry-sdk/tests/metrics/test_instrument.py b/opentelemetry-sdk/tests/metrics/test_instrument.py index d4a2ddf5094..ba260e10719 100644 --- a/opentelemetry-sdk/tests/metrics/test_instrument.py +++ b/opentelemetry-sdk/tests/metrics/test_instrument.py @@ -15,9 +15,11 @@ # pylint: disable=no-self-use from logging import WARNING +# from time import time_ns from unittest import TestCase -from unittest.mock import Mock +from unittest.mock import Mock, patch +from opentelemetry.context import Context from opentelemetry.metrics import Observation from opentelemetry.metrics._internal.instrument import CallbackOptions from opentelemetry.sdk.metrics import ( @@ -39,6 +41,7 @@ _UpDownCounter, ) from opentelemetry.sdk.metrics._internal.measurement import Measurement +from opentelemetry.sdk.metrics._internal.view import default_reservoir_factory class TestCounter(TestCase): @@ -85,21 +88,23 @@ def test_disallow_direct_up_down_counter_creation(self): TEST_ATTRIBUTES = {"foo": "bar"} +TEST_CONTEXT = Context() +TEST_TIMESTAMP = 1_000_000_000 def callable_callback_0(options: CallbackOptions): return [ - Observation(1, attributes=TEST_ATTRIBUTES), - Observation(2, attributes=TEST_ATTRIBUTES), - Observation(3, attributes=TEST_ATTRIBUTES), + Observation(1, attributes=TEST_ATTRIBUTES, context=TEST_CONTEXT), + Observation(2, attributes=TEST_ATTRIBUTES, context=TEST_CONTEXT), + Observation(3, attributes=TEST_ATTRIBUTES, context=TEST_CONTEXT), ] def callable_callback_1(options: CallbackOptions): return [ - Observation(4, attributes=TEST_ATTRIBUTES), - Observation(5, attributes=TEST_ATTRIBUTES), - Observation(6, attributes=TEST_ATTRIBUTES), + Observation(4, attributes=TEST_ATTRIBUTES, context=TEST_CONTEXT), + Observation(5, attributes=TEST_ATTRIBUTES, context=TEST_CONTEXT), + Observation(6, attributes=TEST_ATTRIBUTES, context=TEST_CONTEXT), ] @@ -107,9 +112,9 @@ def generator_callback_0(): options = yield assert isinstance(options, CallbackOptions) options = yield [ - Observation(1, attributes=TEST_ATTRIBUTES), - Observation(2, attributes=TEST_ATTRIBUTES), - Observation(3, attributes=TEST_ATTRIBUTES), + Observation(1, attributes=TEST_ATTRIBUTES, context=TEST_CONTEXT), + Observation(2, attributes=TEST_ATTRIBUTES, context=TEST_CONTEXT), + Observation(3, attributes=TEST_ATTRIBUTES, context=TEST_CONTEXT), ] assert isinstance(options, CallbackOptions) @@ -118,13 +123,14 @@ def generator_callback_1(): options = yield assert isinstance(options, CallbackOptions) options = yield [ - Observation(4, attributes=TEST_ATTRIBUTES), - Observation(5, attributes=TEST_ATTRIBUTES), - Observation(6, attributes=TEST_ATTRIBUTES), + Observation(4, attributes=TEST_ATTRIBUTES, context=TEST_CONTEXT), + Observation(5, attributes=TEST_ATTRIBUTES, context=TEST_CONTEXT), + Observation(6, attributes=TEST_ATTRIBUTES, context=TEST_CONTEXT), ] assert isinstance(options, CallbackOptions) +@patch("opentelemetry.sdk.metrics._internal.instrument.time_ns", Mock(return_value=TEST_TIMESTAMP)) class TestObservableGauge(TestCase): def testname(self): self.assertEqual(_ObservableGauge("name", Mock(), Mock()).name, "name") @@ -135,19 +141,30 @@ def test_callable_callback_0(self): "name", Mock(), Mock(), [callable_callback_0] ) - self.assertEqual( - list(observable_gauge.callback(CallbackOptions())), + assert list(observable_gauge.callback(CallbackOptions())) == ( [ Measurement( - 1, instrument=observable_gauge, attributes=TEST_ATTRIBUTES + 1, + TEST_TIMESTAMP, + instrument=observable_gauge, + context=TEST_CONTEXT, + attributes=TEST_ATTRIBUTES, ), Measurement( - 2, instrument=observable_gauge, attributes=TEST_ATTRIBUTES + 2, + TEST_TIMESTAMP, + instrument=observable_gauge, + context=TEST_CONTEXT, + attributes=TEST_ATTRIBUTES, ), Measurement( - 3, instrument=observable_gauge, attributes=TEST_ATTRIBUTES + 3, + TEST_TIMESTAMP, + instrument=observable_gauge, + context=TEST_CONTEXT, + attributes=TEST_ATTRIBUTES, ), - ], + ] ) def test_callable_multiple_callable_callback(self): @@ -159,22 +176,46 @@ def test_callable_multiple_callable_callback(self): list(observable_gauge.callback(CallbackOptions())), [ Measurement( - 1, instrument=observable_gauge, attributes=TEST_ATTRIBUTES + 1, + TEST_TIMESTAMP, + instrument=observable_gauge, + context=TEST_CONTEXT, + attributes=TEST_ATTRIBUTES, ), Measurement( - 2, instrument=observable_gauge, attributes=TEST_ATTRIBUTES + 2, + TEST_TIMESTAMP, + instrument=observable_gauge, + context=TEST_CONTEXT, + attributes=TEST_ATTRIBUTES, ), Measurement( - 3, instrument=observable_gauge, attributes=TEST_ATTRIBUTES + 3, + TEST_TIMESTAMP, + instrument=observable_gauge, + context=TEST_CONTEXT, + attributes=TEST_ATTRIBUTES, ), Measurement( - 4, instrument=observable_gauge, attributes=TEST_ATTRIBUTES + 4, + TEST_TIMESTAMP, + instrument=observable_gauge, + context=TEST_CONTEXT, + attributes=TEST_ATTRIBUTES, ), Measurement( - 5, instrument=observable_gauge, attributes=TEST_ATTRIBUTES + 5, + TEST_TIMESTAMP, + instrument=observable_gauge, + context=TEST_CONTEXT, + attributes=TEST_ATTRIBUTES, ), Measurement( - 6, instrument=observable_gauge, attributes=TEST_ATTRIBUTES + 6, + TEST_TIMESTAMP, + instrument=observable_gauge, + context=TEST_CONTEXT, + attributes=TEST_ATTRIBUTES, ), ], ) @@ -188,13 +229,25 @@ def test_generator_callback_0(self): list(observable_gauge.callback(CallbackOptions())), [ Measurement( - 1, instrument=observable_gauge, attributes=TEST_ATTRIBUTES + 1, + TEST_TIMESTAMP, + instrument=observable_gauge, + context=TEST_CONTEXT, + attributes=TEST_ATTRIBUTES, ), Measurement( - 2, instrument=observable_gauge, attributes=TEST_ATTRIBUTES + 2, + TEST_TIMESTAMP, + instrument=observable_gauge, + context=TEST_CONTEXT, + attributes=TEST_ATTRIBUTES, ), Measurement( - 3, instrument=observable_gauge, attributes=TEST_ATTRIBUTES + 3, + TEST_TIMESTAMP, + instrument=observable_gauge, + context=TEST_CONTEXT, + attributes=TEST_ATTRIBUTES, ), ], ) @@ -211,22 +264,46 @@ def test_generator_multiple_generator_callback(self): list(observable_gauge.callback(CallbackOptions())), [ Measurement( - 1, instrument=observable_gauge, attributes=TEST_ATTRIBUTES + 1, + TEST_TIMESTAMP, + instrument=observable_gauge, + context=TEST_CONTEXT, + attributes=TEST_ATTRIBUTES, ), Measurement( - 2, instrument=observable_gauge, attributes=TEST_ATTRIBUTES + 2, + TEST_TIMESTAMP, + instrument=observable_gauge, + context=TEST_CONTEXT, + attributes=TEST_ATTRIBUTES, ), Measurement( - 3, instrument=observable_gauge, attributes=TEST_ATTRIBUTES + 3, + TEST_TIMESTAMP, + instrument=observable_gauge, + context=TEST_CONTEXT, + attributes=TEST_ATTRIBUTES, ), Measurement( - 4, instrument=observable_gauge, attributes=TEST_ATTRIBUTES + 4, + TEST_TIMESTAMP, + instrument=observable_gauge, + context=TEST_CONTEXT, + attributes=TEST_ATTRIBUTES, ), Measurement( - 5, instrument=observable_gauge, attributes=TEST_ATTRIBUTES + 5, + TEST_TIMESTAMP, + instrument=observable_gauge, + context=TEST_CONTEXT, + attributes=TEST_ATTRIBUTES, ), Measurement( - 6, instrument=observable_gauge, attributes=TEST_ATTRIBUTES + 6, + TEST_TIMESTAMP, + instrument=observable_gauge, + context=TEST_CONTEXT, + attributes=TEST_ATTRIBUTES, ), ], ) @@ -237,6 +314,7 @@ def test_disallow_direct_observable_gauge_creation(self): ObservableGauge("name", Mock(), Mock()) +@patch("opentelemetry.sdk.metrics._internal.instrument.time_ns", Mock(return_value=TEST_TIMESTAMP)) class TestObservableCounter(TestCase): def test_callable_callback_0(self): observable_counter = _ObservableCounter( @@ -248,17 +326,23 @@ def test_callable_callback_0(self): [ Measurement( 1, + TEST_TIMESTAMP, instrument=observable_counter, + context=TEST_CONTEXT, attributes=TEST_ATTRIBUTES, ), Measurement( 2, + TEST_TIMESTAMP, instrument=observable_counter, + context=TEST_CONTEXT, attributes=TEST_ATTRIBUTES, ), Measurement( 3, + TEST_TIMESTAMP, instrument=observable_counter, + context=TEST_CONTEXT, attributes=TEST_ATTRIBUTES, ), ], @@ -274,17 +358,23 @@ def test_generator_callback_0(self): [ Measurement( 1, + TEST_TIMESTAMP, instrument=observable_counter, + context=TEST_CONTEXT, attributes=TEST_ATTRIBUTES, ), Measurement( 2, + TEST_TIMESTAMP, instrument=observable_counter, + context=TEST_CONTEXT, attributes=TEST_ATTRIBUTES, ), Measurement( 3, + TEST_TIMESTAMP, instrument=observable_counter, + context=TEST_CONTEXT, attributes=TEST_ATTRIBUTES, ), ], @@ -313,6 +403,7 @@ def test_disallow_direct_counter_creation(self): _SDKGauge("name", Mock(), Mock()) +@patch("opentelemetry.sdk.metrics._internal.instrument.time_ns", Mock(return_value=TEST_TIMESTAMP)) class TestObservableUpDownCounter(TestCase): def test_callable_callback_0(self): observable_up_down_counter = _ObservableUpDownCounter( @@ -324,17 +415,23 @@ def test_callable_callback_0(self): [ Measurement( 1, + TEST_TIMESTAMP, instrument=observable_up_down_counter, + context=TEST_CONTEXT, attributes=TEST_ATTRIBUTES, ), Measurement( 2, + TEST_TIMESTAMP, instrument=observable_up_down_counter, + context=TEST_CONTEXT, attributes=TEST_ATTRIBUTES, ), Measurement( 3, + TEST_TIMESTAMP, instrument=observable_up_down_counter, + context=TEST_CONTEXT, attributes=TEST_ATTRIBUTES, ), ], @@ -350,17 +447,23 @@ def test_generator_callback_0(self): [ Measurement( 1, + TEST_TIMESTAMP, instrument=observable_up_down_counter, + context=TEST_CONTEXT, attributes=TEST_ATTRIBUTES, ), Measurement( 2, + TEST_TIMESTAMP, instrument=observable_up_down_counter, + context=TEST_CONTEXT, attributes=TEST_ATTRIBUTES, ), Measurement( 3, + TEST_TIMESTAMP, instrument=observable_up_down_counter, + context=TEST_CONTEXT, attributes=TEST_ATTRIBUTES, ), ], diff --git a/opentelemetry-sdk/tests/metrics/test_measurement_consumer.py b/opentelemetry-sdk/tests/metrics/test_measurement_consumer.py index 91a49955b70..bedffaaeff0 100644 --- a/opentelemetry-sdk/tests/metrics/test_measurement_consumer.py +++ b/opentelemetry-sdk/tests/metrics/test_measurement_consumer.py @@ -43,6 +43,7 @@ def test_creates_metric_reader_storages(self, MockMetricReaderStorage): reader_mocks = [Mock() for _ in range(5)] SynchronousMeasurementConsumer( SdkConfiguration( + exemplar_filter=Mock(), resource=Mock(), metric_readers=reader_mocks, views=Mock(), @@ -59,6 +60,7 @@ def test_measurements_passed_to_each_reader_storage( consumer = SynchronousMeasurementConsumer( SdkConfiguration( + exemplar_filter=Mock(should_sample=Mock(return_value=False)), resource=Mock(), metric_readers=reader_mocks, views=Mock(), @@ -69,7 +71,7 @@ def test_measurements_passed_to_each_reader_storage( for rs_mock in reader_storage_mocks: rs_mock.consume_measurement.assert_called_once_with( - measurement_mock + measurement_mock, False ) def test_collect_passed_to_reader_stage(self, MockMetricReaderStorage): @@ -80,6 +82,7 @@ def test_collect_passed_to_reader_stage(self, MockMetricReaderStorage): consumer = SynchronousMeasurementConsumer( SdkConfiguration( + exemplar_filter=Mock(), resource=Mock(), metric_readers=reader_mocks, views=Mock(), @@ -98,6 +101,7 @@ def test_collect_calls_async_instruments(self, MockMetricReaderStorage): MockMetricReaderStorage.return_value = reader_storage_mock consumer = SynchronousMeasurementConsumer( SdkConfiguration( + exemplar_filter=Mock(), resource=Mock(), metric_readers=[reader_mock], views=Mock(), @@ -125,6 +129,7 @@ def test_collect_timeout(self, MockMetricReaderStorage): MockMetricReaderStorage.return_value = reader_storage_mock consumer = SynchronousMeasurementConsumer( SdkConfiguration( + exemplar_filter=Mock(), resource=Mock(), metric_readers=[reader_mock], views=Mock(), @@ -157,6 +162,7 @@ def test_collect_deadline( MockMetricReaderStorage.return_value = reader_storage_mock consumer = SynchronousMeasurementConsumer( SdkConfiguration( + exemplar_filter=Mock(), resource=Mock(), metric_readers=[reader_mock], views=Mock(), diff --git a/opentelemetry-sdk/tests/metrics/test_metric_reader_storage.py b/opentelemetry-sdk/tests/metrics/test_metric_reader_storage.py index 2aac9874659..ecf46c4c44b 100644 --- a/opentelemetry-sdk/tests/metrics/test_metric_reader_storage.py +++ b/opentelemetry-sdk/tests/metrics/test_metric_reader_storage.py @@ -15,8 +15,10 @@ # pylint: disable=protected-access,invalid-name from logging import WARNING +from time import time_ns from unittest.mock import MagicMock, Mock, patch +from opentelemetry.context import Context from opentelemetry.sdk.metrics._internal.aggregation import ( _LastValueAggregation, ) @@ -75,6 +77,7 @@ def test_creates_view_instrument_matches( view2 = mock_view_matching("view_2", instrument1, instrument2) storage = MetricReaderStorage( SdkConfiguration( + exemplar_filter=Mock(), resource=Mock(), metric_readers=(), views=(view1, view2), @@ -89,21 +92,21 @@ def test_creates_view_instrument_matches( # instrument1 matches view1 and view2, so should create two # ViewInstrumentMatch objects - storage.consume_measurement(Measurement(1, instrument1)) + storage.consume_measurement(Measurement(1, time_ns(), instrument1, Context())) self.assertEqual( len(MockViewInstrumentMatch.call_args_list), 2, MockViewInstrumentMatch.mock_calls, ) # they should only be created the first time the instrument is seen - storage.consume_measurement(Measurement(1, instrument1)) + storage.consume_measurement(Measurement(1, time_ns(), instrument1, Context())) self.assertEqual(len(MockViewInstrumentMatch.call_args_list), 2) # instrument2 matches view2, so should create a single # ViewInstrumentMatch MockViewInstrumentMatch.call_args_list.clear() with self.assertLogs(level=WARNING): - storage.consume_measurement(Measurement(1, instrument2)) + storage.consume_measurement(Measurement(1, time_ns(), instrument2, Context())) self.assertEqual(len(MockViewInstrumentMatch.call_args_list), 1) @patch( @@ -113,9 +116,9 @@ def test_creates_view_instrument_matches( def test_forwards_calls_to_view_instrument_match( self, MockViewInstrumentMatch: Mock ): - view_instrument_match1 = Mock(_aggregation=_LastValueAggregation({})) - view_instrument_match2 = Mock(_aggregation=_LastValueAggregation({})) - view_instrument_match3 = Mock(_aggregation=_LastValueAggregation({})) + view_instrument_match1 = Mock(_aggregation=_LastValueAggregation({}, Mock())) + view_instrument_match2 = Mock(_aggregation=_LastValueAggregation({}, Mock())) + view_instrument_match3 = Mock(_aggregation=_LastValueAggregation({}, Mock())) MockViewInstrumentMatch.side_effect = [ view_instrument_match1, view_instrument_match2, @@ -129,6 +132,7 @@ def test_forwards_calls_to_view_instrument_match( storage = MetricReaderStorage( SdkConfiguration( + exemplar_filter=Mock(), resource=Mock(), metric_readers=(), views=(view1, view2), @@ -143,21 +147,21 @@ def test_forwards_calls_to_view_instrument_match( # Measurements from an instrument should be passed on to each # ViewInstrumentMatch objects created for that instrument - measurement = Measurement(1, instrument1) + measurement = Measurement(1, time_ns(), instrument1, Context()) storage.consume_measurement(measurement) view_instrument_match1.consume_measurement.assert_called_once_with( - measurement + measurement, True ) view_instrument_match2.consume_measurement.assert_called_once_with( - measurement + measurement, True ) view_instrument_match3.consume_measurement.assert_not_called() - measurement = Measurement(1, instrument2) + measurement = Measurement(1, time_ns(), instrument2, Context()) with self.assertLogs(level=WARNING): storage.consume_measurement(measurement) view_instrument_match3.consume_measurement.assert_called_once_with( - measurement + measurement, True ) # collect() should call collect on all of its _ViewInstrumentMatch @@ -238,6 +242,7 @@ def test_race_concurrent_measurements(self, MockViewInstrumentMatch: Mock): view1 = mock_view_matching(instrument1) storage = MetricReaderStorage( SdkConfiguration( + exemplar_filter=Mock(), resource=Mock(), metric_readers=(), views=(view1,), @@ -251,7 +256,7 @@ def test_race_concurrent_measurements(self, MockViewInstrumentMatch: Mock): ) def send_measurement(): - storage.consume_measurement(Measurement(1, instrument1)) + storage.consume_measurement(Measurement(1, time_ns(), instrument1, Context())) # race sending many measurements concurrently self.run_with_many_threads(send_measurement) @@ -270,6 +275,7 @@ def test_default_view_enabled(self, MockViewInstrumentMatch: Mock): storage = MetricReaderStorage( SdkConfiguration( + exemplar_filter=Mock(), resource=Mock(), metric_readers=(), views=(), @@ -282,17 +288,17 @@ def test_default_view_enabled(self, MockViewInstrumentMatch: Mock): MagicMock(**{"__getitem__.return_value": DefaultAggregation()}), ) - storage.consume_measurement(Measurement(1, instrument1)) + storage.consume_measurement(Measurement(1, time_ns(), instrument1, Context())) self.assertEqual( len(MockViewInstrumentMatch.call_args_list), 1, MockViewInstrumentMatch.mock_calls, ) - storage.consume_measurement(Measurement(1, instrument1)) + storage.consume_measurement(Measurement(1, time_ns(), instrument1, Context())) self.assertEqual(len(MockViewInstrumentMatch.call_args_list), 1) MockViewInstrumentMatch.call_args_list.clear() - storage.consume_measurement(Measurement(1, instrument2)) + storage.consume_measurement(Measurement(1, time_ns(), instrument2, Context())) self.assertEqual(len(MockViewInstrumentMatch.call_args_list), 1) def test_drop_aggregation(self): @@ -300,6 +306,7 @@ def test_drop_aggregation(self): counter = _Counter("name", Mock(), Mock()) metric_reader_storage = MetricReaderStorage( SdkConfiguration( + exemplar_filter=Mock(), resource=Mock(), metric_readers=(), views=( @@ -315,7 +322,7 @@ def test_drop_aggregation(self): ), MagicMock(**{"__getitem__.return_value": DefaultAggregation()}), ) - metric_reader_storage.consume_measurement(Measurement(1, counter)) + metric_reader_storage.consume_measurement(Measurement(1, time_ns(), counter, Context())) self.assertIsNone(metric_reader_storage.collect()) @@ -326,6 +333,7 @@ def test_same_collection_start(self): metric_reader_storage = MetricReaderStorage( SdkConfiguration( + exemplar_filter=Mock(), resource=Mock(), metric_readers=(), views=(View(instrument_name="name"),), @@ -338,9 +346,9 @@ def test_same_collection_start(self): MagicMock(**{"__getitem__.return_value": DefaultAggregation()}), ) - metric_reader_storage.consume_measurement(Measurement(1, counter)) + metric_reader_storage.consume_measurement(Measurement(1, time_ns(), counter, Context())) metric_reader_storage.consume_measurement( - Measurement(1, up_down_counter) + Measurement(1, time_ns(), up_down_counter, Context()) ) actual = metric_reader_storage.collect() @@ -371,6 +379,7 @@ def test_conflicting_view_configuration(self): ) metric_reader_storage = MetricReaderStorage( SdkConfiguration( + exemplar_filter=Mock(), resource=Mock(), metric_readers=(), views=( @@ -390,7 +399,7 @@ def test_conflicting_view_configuration(self): with self.assertLogs(level=WARNING): metric_reader_storage.consume_measurement( - Measurement(1, observable_counter) + Measurement(1, time_ns(), observable_counter, Context()) ) self.assertIs( @@ -419,6 +428,7 @@ def test_view_instrument_match_conflict_0(self): ) metric_reader_storage = MetricReaderStorage( SdkConfiguration( + exemplar_filter=Mock(), resource=Mock(), metric_readers=(), views=( @@ -437,12 +447,12 @@ def test_view_instrument_match_conflict_0(self): with self.assertRaises(AssertionError): with self.assertLogs(level=WARNING): metric_reader_storage.consume_measurement( - Measurement(1, observable_counter_0) + Measurement(1, time_ns(), observable_counter_0, Context()) ) with self.assertLogs(level=WARNING) as log: metric_reader_storage.consume_measurement( - Measurement(1, observable_counter_1) + Measurement(1, time_ns(), observable_counter_1, Context()) ) self.assertIn( @@ -476,6 +486,7 @@ def test_view_instrument_match_conflict_1(self): ) metric_reader_storage = MetricReaderStorage( SdkConfiguration( + exemplar_filter=Mock(), resource=Mock(), metric_readers=(), views=( @@ -494,12 +505,12 @@ def test_view_instrument_match_conflict_1(self): with self.assertRaises(AssertionError): with self.assertLogs(level=WARNING): metric_reader_storage.consume_measurement( - Measurement(1, observable_counter_foo) + Measurement(1, time_ns(), observable_counter_foo, Context()) ) with self.assertLogs(level=WARNING) as log: metric_reader_storage.consume_measurement( - Measurement(1, observable_counter_bar) + Measurement(1, time_ns(), observable_counter_bar, Context()) ) self.assertIn( @@ -509,7 +520,7 @@ def test_view_instrument_match_conflict_1(self): with self.assertLogs(level=WARNING) as log: metric_reader_storage.consume_measurement( - Measurement(1, observable_counter_baz) + Measurement(1, time_ns(), observable_counter_baz, Context()) ) self.assertIn( @@ -544,6 +555,7 @@ def test_view_instrument_match_conflict_2(self): metric_reader_storage = MetricReaderStorage( SdkConfiguration( + exemplar_filter=Mock(), resource=Mock(), metric_readers=(), views=( @@ -562,13 +574,13 @@ def test_view_instrument_match_conflict_2(self): with self.assertRaises(AssertionError): with self.assertLogs(level=WARNING): metric_reader_storage.consume_measurement( - Measurement(1, observable_counter_foo) + Measurement(1, time_ns(), observable_counter_foo, Context()) ) with self.assertRaises(AssertionError): with self.assertLogs(level=WARNING): metric_reader_storage.consume_measurement( - Measurement(1, observable_counter_bar) + Measurement(1, time_ns(), observable_counter_bar, Context()) ) def test_view_instrument_match_conflict_3(self): @@ -592,6 +604,7 @@ def test_view_instrument_match_conflict_3(self): metric_reader_storage = MetricReaderStorage( SdkConfiguration( + exemplar_filter=Mock(), resource=Mock(), metric_readers=(), views=( @@ -610,13 +623,13 @@ def test_view_instrument_match_conflict_3(self): with self.assertRaises(AssertionError): with self.assertLogs(level=WARNING): metric_reader_storage.consume_measurement( - Measurement(1, counter_bar) + Measurement(1, time_ns(), counter_bar, Context()) ) with self.assertRaises(AssertionError): with self.assertLogs(level=WARNING): metric_reader_storage.consume_measurement( - Measurement(1, observable_counter_baz) + Measurement(1, time_ns(), observable_counter_baz, Context()) ) def test_view_instrument_match_conflict_4(self): @@ -640,6 +653,7 @@ def test_view_instrument_match_conflict_4(self): metric_reader_storage = MetricReaderStorage( SdkConfiguration( + exemplar_filter=Mock(), resource=Mock(), metric_readers=(), views=( @@ -658,13 +672,13 @@ def test_view_instrument_match_conflict_4(self): with self.assertRaises(AssertionError): with self.assertLogs(level=WARNING): metric_reader_storage.consume_measurement( - Measurement(1, counter_bar) + Measurement(1, time_ns(), counter_bar, Context()) ) with self.assertRaises(AssertionError): with self.assertLogs(level=WARNING): metric_reader_storage.consume_measurement( - Measurement(1, up_down_counter_baz) + Measurement(1, time_ns(), up_down_counter_baz, Context()) ) def test_view_instrument_match_conflict_5(self): @@ -686,6 +700,7 @@ def test_view_instrument_match_conflict_5(self): ) metric_reader_storage = MetricReaderStorage( SdkConfiguration( + exemplar_filter=Mock(), resource=Mock(), metric_readers=(), views=( @@ -704,13 +719,13 @@ def test_view_instrument_match_conflict_5(self): with self.assertRaises(AssertionError): with self.assertLogs(level=WARNING): metric_reader_storage.consume_measurement( - Measurement(1, observable_counter_0) + Measurement(1, time_ns(), observable_counter_0, Context()) ) with self.assertRaises(AssertionError): with self.assertLogs(level=WARNING): metric_reader_storage.consume_measurement( - Measurement(1, observable_counter_1) + Measurement(1, time_ns(), observable_counter_1, Context()) ) def test_view_instrument_match_conflict_6(self): @@ -740,6 +755,7 @@ def test_view_instrument_match_conflict_6(self): ) metric_reader_storage = MetricReaderStorage( SdkConfiguration( + exemplar_filter=Mock(), resource=Mock(), metric_readers=(), views=( @@ -759,19 +775,19 @@ def test_view_instrument_match_conflict_6(self): with self.assertRaises(AssertionError): with self.assertLogs(level=WARNING): metric_reader_storage.consume_measurement( - Measurement(1, observable_counter) + Measurement(1, time_ns(), observable_counter, Context()) ) with self.assertRaises(AssertionError): with self.assertLogs(level=WARNING): metric_reader_storage.consume_measurement( - Measurement(1, histogram) + Measurement(1, time_ns(), histogram, Context()) ) with self.assertRaises(AssertionError): with self.assertLogs(level=WARNING): metric_reader_storage.consume_measurement( - Measurement(1, gauge) + Measurement(1, time_ns(), gauge, Context()) ) def test_view_instrument_match_conflict_7(self): @@ -794,6 +810,7 @@ def test_view_instrument_match_conflict_7(self): ) metric_reader_storage = MetricReaderStorage( SdkConfiguration( + exemplar_filter=Mock(), resource=Mock(), metric_readers=(), views=( @@ -812,12 +829,12 @@ def test_view_instrument_match_conflict_7(self): with self.assertRaises(AssertionError): with self.assertLogs(level=WARNING): metric_reader_storage.consume_measurement( - Measurement(1, observable_counter_0) + Measurement(1, time_ns(), observable_counter_0, Context()) ) with self.assertLogs(level=WARNING) as log: metric_reader_storage.consume_measurement( - Measurement(1, observable_counter_1) + Measurement(1, time_ns(), observable_counter_1, Context()) ) self.assertIn( @@ -848,6 +865,7 @@ def test_view_instrument_match_conflict_8(self): ) metric_reader_storage = MetricReaderStorage( SdkConfiguration( + exemplar_filter=Mock(), resource=Mock(), metric_readers=(), views=( @@ -870,12 +888,12 @@ def test_view_instrument_match_conflict_8(self): with self.assertRaises(AssertionError): with self.assertLogs(level=WARNING): metric_reader_storage.consume_measurement( - Measurement(1, up_down_counter) + Measurement(1, time_ns(), up_down_counter, Context()) ) with self.assertLogs(level=WARNING) as log: metric_reader_storage.consume_measurement( - Measurement(1, histogram) + Measurement(1, time_ns(), histogram, Context()) ) self.assertIn( diff --git a/opentelemetry-sdk/tests/metrics/test_view_instrument_match.py b/opentelemetry-sdk/tests/metrics/test_view_instrument_match.py index f4d2d02351a..41526c6d3a0 100644 --- a/opentelemetry-sdk/tests/metrics/test_view_instrument_match.py +++ b/opentelemetry-sdk/tests/metrics/test_view_instrument_match.py @@ -14,9 +14,11 @@ # pylint: disable=protected-access +from time import time_ns from unittest import TestCase from unittest.mock import MagicMock, Mock +from opentelemetry.context import Context from opentelemetry.sdk.metrics._internal._view_instrument_match import ( _ViewInstrumentMatch, ) @@ -49,6 +51,7 @@ def setUpClass(cls): cls.mock_resource = Mock() cls.mock_instrumentation_scope = Mock() cls.sdk_configuration = SdkConfiguration( + exemplar_filter=Mock(), resource=cls.mock_resource, metric_readers=[], views=[], @@ -73,7 +76,9 @@ def test_consume_measurement(self): view_instrument_match.consume_measurement( Measurement( value=0, + time_unix_nano=time_ns(), instrument=instrument1, + context=Context(), attributes={"c": "d", "f": "g"}, ) ) @@ -85,7 +90,9 @@ def test_consume_measurement(self): view_instrument_match.consume_measurement( Measurement( value=0, + time_unix_nano=time_ns(), instrument=instrument1, + context=Context(), attributes={"w": "x", "y": "z"}, ) ) @@ -114,7 +121,9 @@ def test_consume_measurement(self): view_instrument_match.consume_measurement( Measurement( value=0, + time_unix_nano=time_ns(), instrument=instrument1, + context=Context(), attributes={"c": "d", "f": "g"}, ) ) @@ -142,7 +151,13 @@ def test_consume_measurement(self): ), ) view_instrument_match.consume_measurement( - Measurement(value=0, instrument=instrument1, attributes=None) + Measurement( + value=0, + time_unix_nano=time_ns(), + instrument=instrument1, + context=Context(), + attributes=None + ) ) self.assertEqual( view_instrument_match._attributes_aggregation, @@ -166,7 +181,10 @@ def test_consume_measurement(self): ), ) view_instrument_match.consume_measurement( - Measurement(value=0, instrument=instrument1, attributes=None) + Measurement(value=0, + time_unix_nano=time_ns(), + instrument=instrument1, + context=Context(), attributes=None) ) self.assertIsInstance( view_instrument_match._attributes_aggregation[frozenset({})], @@ -198,7 +216,9 @@ def test_collect(self): view_instrument_match.consume_measurement( Measurement( value=0, + time_unix_nano=time_ns(), instrument=Mock(name="instrument1"), + context=Context(), attributes={"c": "d", "f": "g"}, ) ) @@ -254,28 +274,36 @@ def test_data_point_check(self): view_instrument_match.consume_measurement( Measurement( value=0, + time_unix_nano=time_ns(), instrument=Mock(name="instrument1"), + context=Context(), attributes={"c": "d", "f": "g"}, ) ) view_instrument_match.consume_measurement( Measurement( value=0, + time_unix_nano=time_ns(), instrument=Mock(name="instrument1"), + context=Context(), attributes={"h": "i", "j": "k"}, ) ) view_instrument_match.consume_measurement( Measurement( value=0, + time_unix_nano=time_ns(), instrument=Mock(name="instrument1"), + context=Context(), attributes={"l": "m", "n": "o"}, ) ) view_instrument_match.consume_measurement( Measurement( value=0, + time_unix_nano=time_ns(), instrument=Mock(name="instrument1"), + context=Context(), attributes={"p": "q", "r": "s"}, ) ) @@ -309,7 +337,9 @@ def test_setting_aggregation(self): view_instrument_match.consume_measurement( Measurement( value=0, + time_unix_nano=time_ns(), instrument=Mock(name="instrument1"), + context=Context(), attributes={"c": "d", "f": "g"}, ) )