Skip to content

Commit c29e0dd

Browse files
committed
Fix pylint errors
1 parent e8aa164 commit c29e0dd

File tree

5 files changed

+45
-42
lines changed

5 files changed

+45
-42
lines changed

opentelemetry-sdk/src/opentelemetry/sdk/metrics/_internal/aggregation.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ def aggregate(
105105
measurement: Measurement to aggregate
106106
should_sample_exemplar: Whether the measurement should be sampled by the exemplars reservoir or not.
107107
"""
108-
pass
109108

110109
@abstractmethod
111110
def collect(

opentelemetry-sdk/src/opentelemetry/sdk/metrics/_internal/exemplar/exemplar_reservoir.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def offer(
107107

108108
self.__offered = True
109109

110-
def collect(self, point_attributes: Attributes) -> Exemplar | None:
110+
def collect(self, point_attributes: Attributes) -> Optional[Exemplar]:
111111
"""May return an Exemplar and resets the bucket for the next sampling period."""
112112
if not self.__offered:
113113
return None
@@ -232,11 +232,9 @@ def _find_bucket_index(
232232
Raises:
233233
BucketIndexError: If no bucket index can be found.
234234
"""
235-
pass
236235

237236
def _reset(self) -> None:
238237
"""Reset the reservoir by resetting any stateful logic after a collection cycle."""
239-
pass
240238

241239

242240
class SimpleFixedSizeExemplarReservoir(FixedSizeExemplarReservoirABC):
@@ -309,9 +307,9 @@ def _find_bucket_index(
309307
attributes: Attributes,
310308
context: Context,
311309
) -> int:
312-
for i, boundary in enumerate(self._boundaries):
310+
for index, boundary in enumerate(self._boundaries):
313311
if value <= boundary:
314-
return i
312+
return index
315313
return len(self._boundaries)
316314

317315

opentelemetry-sdk/src/opentelemetry/sdk/metrics/_internal/view.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@
3535

3636

3737
def _default_reservoir_factory(
38-
aggregationType: Type[_Aggregation],
38+
aggregation_type: Type[_Aggregation],
3939
) -> ExemplarReservoirBuilder:
4040
"""Default reservoir factory per aggregation."""
41-
if issubclass(aggregationType, _ExplicitBucketHistogramAggregation):
41+
if issubclass(aggregation_type, _ExplicitBucketHistogramAggregation):
4242
return AlignedHistogramBucketExemplarReservoir
43-
elif issubclass(aggregationType, _ExponentialBucketHistogramAggregation):
43+
if issubclass(aggregation_type, _ExponentialBucketHistogramAggregation):
4444
return SimpleFixedSizeExemplarReservoir
4545
return SimpleFixedSizeExemplarReservoir
4646

opentelemetry-sdk/tests/metrics/test_aggregation.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -704,15 +704,12 @@ def test_collection_simple_fixed_size_reservoir_with_default_reservoir(
704704

705705
def test_collection_aligned_histogram_bucket_reservoir(self):
706706
boundaries = [5.0, 10.0, 20.0]
707-
exemplar_reservoir_factory = (
708-
lambda: AlignedHistogramBucketExemplarReservoir(boundaries)
709-
)
710707
synchronous_sum_aggregation = _SumAggregation(
711708
Mock(),
712709
True,
713710
AggregationTemporality.DELTA,
714711
0,
715-
exemplar_reservoir_factory,
712+
lambda: AlignedHistogramBucketExemplarReservoir(boundaries),
716713
)
717714

718715
synchronous_sum_aggregation.aggregate(measurement(2.0))

opentelemetry-sdk/tests/metrics/test_view_instrument_match.py

Lines changed: 38 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -52,18 +52,18 @@ def generalized_reservoir_factory(
5252
size: int = 1, boundaries: Sequence[float] = None
5353
) -> Callable[[Type[_Aggregation]], ExemplarReservoirBuilder]:
5454
def factory(
55-
aggregationType: Type[_Aggregation],
55+
aggregation_type: Type[_Aggregation],
5656
) -> ExemplarReservoirBuilder:
57-
if issubclass(aggregationType, _ExplicitBucketHistogramAggregation):
57+
if issubclass(aggregation_type, _ExplicitBucketHistogramAggregation):
5858
return lambda **kwargs: AlignedHistogramBucketExemplarReservoir(
5959
boundaries=boundaries or [],
6060
**{k: v for k, v in kwargs.items() if k != "boundaries"},
6161
)
62-
else:
63-
return lambda **kwargs: SimpleFixedSizeExemplarReservoir(
64-
size=size,
65-
**{k: v for k, v in kwargs.items() if k != "size"},
66-
)
62+
63+
return lambda **kwargs: SimpleFixedSizeExemplarReservoir(
64+
size=size,
65+
**{k: v for k, v in kwargs.items() if k != "size"},
66+
)
6767

6868
return factory
6969

@@ -288,7 +288,11 @@ def test_collect_resets_start_time_unix_nano(self, mock_time_ns):
288288
# +1 call to _create_aggregation
289289
view_instrument_match.consume_measurement(
290290
Measurement(
291-
value=0, instrument=instrument, attributes={"foo": "bar0"}
291+
value=0,
292+
time_unix_nano=time_ns(),
293+
instrument=instrument,
294+
attributes={"foo": "bar0"},
295+
context=Context(),
292296
)
293297
)
294298
view_instrument_match._view._aggregation._create_aggregation.assert_called_with(
@@ -304,7 +308,11 @@ def test_collect_resets_start_time_unix_nano(self, mock_time_ns):
304308
# +1 call to _create_aggregation
305309
view_instrument_match.consume_measurement(
306310
Measurement(
307-
value=0, instrument=instrument, attributes={"foo": "bar1"}
311+
value=0,
312+
time_unix_nano=time_ns(),
313+
instrument=instrument,
314+
attributes={"foo": "bar1"},
315+
context=Context(),
308316
)
309317
)
310318
view_instrument_match._view._aggregation._create_aggregation.assert_called_with(
@@ -322,7 +330,11 @@ def test_collect_resets_start_time_unix_nano(self, mock_time_ns):
322330
# +1 call to create_aggregation
323331
view_instrument_match.consume_measurement(
324332
Measurement(
325-
value=0, instrument=instrument, attributes={"foo": "bar"}
333+
value=0,
334+
time_unix_nano=time_ns(),
335+
instrument=instrument,
336+
attributes={"foo": "bar"},
337+
context=Context(),
326338
)
327339
)
328340
view_instrument_match._view._aggregation._create_aggregation.assert_called_with(
@@ -331,12 +343,20 @@ def test_collect_resets_start_time_unix_nano(self, mock_time_ns):
331343
# No new calls to _create_aggregation because attributes remain the same
332344
view_instrument_match.consume_measurement(
333345
Measurement(
334-
value=0, instrument=instrument, attributes={"foo": "bar"}
346+
value=0,
347+
time_unix_nano=time_ns(),
348+
instrument=instrument,
349+
attributes={"foo": "bar"},
350+
context=Context(),
335351
)
336352
)
337353
view_instrument_match.consume_measurement(
338354
Measurement(
339-
value=0, instrument=instrument, attributes={"foo": "bar"}
355+
value=0,
356+
time_unix_nano=time_ns(),
357+
instrument=instrument,
358+
attributes={"foo": "bar"},
359+
context=Context(),
340360
)
341361
)
342362
# In total we have 5 calls for _create_aggregation
@@ -520,8 +540,8 @@ def test_consume_measurement_with_custom_reservoir_factory(self):
520540
)
521541
)
522542

523-
data_points = view_instrument_match.collect(
524-
AggregationTemporality.CUMULATIVE, 0
543+
data_points = list(
544+
view_instrument_match.collect(AggregationTemporality.CUMULATIVE, 0)
525545
)
526546

527547
# Ensure only one data point is collected
@@ -577,8 +597,8 @@ def test_consume_measurement_with_exemplars(self):
577597
)
578598

579599
# Collect the data points
580-
data_points = view_instrument_match.collect(
581-
AggregationTemporality.CUMULATIVE, 0
600+
data_points = list(
601+
view_instrument_match.collect(AggregationTemporality.CUMULATIVE, 0)
582602
)
583603

584604
# Ensure only one data point is collected
@@ -660,19 +680,9 @@ def test_consume_measurement_with_custom_reservoir_factory(self):
660680
)
661681
)
662682

663-
# view_instrument_match.consume_measurement(
664-
# Measurement(
665-
# value=30.0, # Should go into the outliners bucket
666-
# time_unix_nano=time_ns(),
667-
# instrument=instrument1,
668-
# context=Context(),
669-
# attributes={"attribute3": "value3"},
670-
# )
671-
# )
672-
673683
# Collect the data points
674-
data_points = view_instrument_match.collect(
675-
AggregationTemporality.CUMULATIVE, 0
684+
data_points = list(
685+
view_instrument_match.collect(AggregationTemporality.CUMULATIVE, 0)
676686
)
677687

678688
# Ensure three data points are collected, one for each bucket
@@ -692,4 +702,3 @@ def test_consume_measurement_with_custom_reservoir_factory(self):
692702
self.assertEqual(
693703
data_points[2].exemplars[0].value, 15.0
694704
) # Third bucket
695-
# self.assertEqual(data_points[2].exemplars[0].value, 30.0) # Outliner bucket

0 commit comments

Comments
 (0)