Skip to content

Commit

Permalink
Check data point before yielding
Browse files Browse the repository at this point in the history
  • Loading branch information
ocelotl committed Jun 7, 2022
1 parent 928d333 commit 2c29e1e
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ def collect(

with self._lock:
for aggregation in self._attributes_aggregation.values():
yield aggregation.collect(
data_point = aggregation.collect(
aggregation_temporality, collection_start_nanos
)
if data_point is not None:
yield data_point
72 changes: 72 additions & 0 deletions opentelemetry-sdk/tests/metrics/test_view_instrument_match.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,78 @@ def test_collect(self):
self.assertEqual(number_data_point.attributes, {"c": "d"})
self.assertEqual(number_data_point.value, 0)

def test_data_point_check(self):
instrument1 = Counter(
"instrument1",
Mock(),
Mock(),
description="description",
unit="unit",
)
instrument1.instrumentation_scope = self.mock_instrumentation_scope

view_instrument_match = _ViewInstrumentMatch(
view=View(
instrument_name="instrument1",
name="name",
aggregation=DefaultAggregation(),
),
instrument=instrument1,
instrument_class_aggregation=MagicMock(
**{
"__getitem__.return_value": Mock(
**{
"_create_aggregation.return_value": Mock(
**{
"collect.side_effect": [
Mock(),
Mock(),
None,
Mock(),
]
}
)
}
)
}
),
)

view_instrument_match.consume_measurement(
Measurement(
value=0,
instrument=Mock(name="instrument1"),
attributes={"c": "d", "f": "g"},
)
)
view_instrument_match.consume_measurement(
Measurement(
value=0,
instrument=Mock(name="instrument1"),
attributes={"h": "i", "j": "k"},
)
)
view_instrument_match.consume_measurement(
Measurement(
value=0,
instrument=Mock(name="instrument1"),
attributes={"l": "m", "n": "o"},
)
)
view_instrument_match.consume_measurement(
Measurement(
value=0,
instrument=Mock(name="instrument1"),
attributes={"p": "q", "r": "s"},
)
)

result = view_instrument_match.collect(
AggregationTemporality.CUMULATIVE, 0
)

self.assertEqual(len(list(result)), 3)

def test_setting_aggregation(self):
instrument1 = Counter(
name="instrument1",
Expand Down

0 comments on commit 2c29e1e

Please sign in to comment.