Skip to content

Commit b70450e

Browse files
authored
api/sdk: Rename CounterAggregator -> SumAggregator (open-telemetry#816)
Enables broader usage of the aggregator, across multiple counter types.
1 parent 0b823a1 commit b70450e

File tree

9 files changed

+77
-77
lines changed

9 files changed

+77
-77
lines changed

ext/opentelemetry-exporter-cloud-monitoring/src/opentelemetry/exporter/cloud_monitoring/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
MetricsExporter,
1313
MetricsExportResult,
1414
)
15-
from opentelemetry.sdk.metrics.export.aggregate import CounterAggregator
15+
from opentelemetry.sdk.metrics.export.aggregate import SumAggregator
1616

1717
logger = logging.getLogger(__name__)
1818
MAX_BATCH_WRITE = 200
@@ -97,7 +97,7 @@ def _get_metric_descriptor(
9797
logger.warning(
9898
"Label value %s is not a string, bool or integer", value
9999
)
100-
if isinstance(record.aggregator, CounterAggregator):
100+
if isinstance(record.aggregator, SumAggregator):
101101
descriptor["metric_kind"] = MetricDescriptor.MetricKind.GAUGE
102102
else:
103103
logger.warning(

ext/opentelemetry-exporter-cloud-monitoring/tests/test_cloud_monitoring.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
CloudMonitoringMetricsExporter,
2626
)
2727
from opentelemetry.sdk.metrics.export import MetricRecord
28-
from opentelemetry.sdk.metrics.export.aggregate import CounterAggregator
28+
from opentelemetry.sdk.metrics.export.aggregate import SumAggregator
2929

3030

3131
class UnsupportedAggregator:
@@ -114,7 +114,7 @@ def test_get_metric_descriptor(self):
114114
)
115115

116116
record = MetricRecord(
117-
MockMetric(), (("label1", "value1"),), CounterAggregator(),
117+
MockMetric(), (("label1", "value1"),), SumAggregator(),
118118
)
119119
metric_descriptor = exporter._get_metric_descriptor(record)
120120
client.create_metric_descriptor.assert_called_with(
@@ -149,7 +149,7 @@ def test_get_metric_descriptor(self):
149149
("label3", 3),
150150
("label4", False),
151151
),
152-
CounterAggregator(),
152+
SumAggregator(),
153153
)
154154
)
155155
client.create_metric_descriptor.assert_called_with(
@@ -204,20 +204,20 @@ def test_export(self):
204204
}
205205
)
206206

207-
counter_one = CounterAggregator()
208-
counter_one.checkpoint = 1
209-
counter_one.last_update_timestamp = (WRITE_INTERVAL + 1) * 1e9
207+
sum_agg_one = SumAggregator()
208+
sum_agg_one.checkpoint = 1
209+
sum_agg_one.last_update_timestamp = (WRITE_INTERVAL + 1) * 1e9
210210
exporter.export(
211211
[
212212
MetricRecord(
213213
MockMetric(),
214214
(("label1", "value1"), ("label2", 1),),
215-
counter_one,
215+
sum_agg_one,
216216
),
217217
MetricRecord(
218218
MockMetric(),
219219
(("label1", "value2"), ("label2", 2),),
220-
counter_one,
220+
sum_agg_one,
221221
),
222222
]
223223
)
@@ -245,33 +245,33 @@ def test_export(self):
245245
# Attempting to export too soon after another export with the exact
246246
# same labels leads to it being dropped
247247

248-
counter_two = CounterAggregator()
249-
counter_two.checkpoint = 1
250-
counter_two.last_update_timestamp = (WRITE_INTERVAL + 2) * 1e9
248+
sum_agg_two = SumAggregator()
249+
sum_agg_two.checkpoint = 1
250+
sum_agg_two.last_update_timestamp = (WRITE_INTERVAL + 2) * 1e9
251251
exporter.export(
252252
[
253253
MetricRecord(
254254
MockMetric(),
255255
(("label1", "value1"), ("label2", 1),),
256-
counter_two,
256+
sum_agg_two,
257257
),
258258
MetricRecord(
259259
MockMetric(),
260260
(("label1", "value2"), ("label2", 2),),
261-
counter_two,
261+
sum_agg_two,
262262
),
263263
]
264264
)
265265
self.assertEqual(client.create_time_series.call_count, 1)
266266

267267
# But exporting with different labels is fine
268-
counter_two.checkpoint = 2
268+
sum_agg_two.checkpoint = 2
269269
exporter.export(
270270
[
271271
MetricRecord(
272272
MockMetric(),
273273
(("label1", "changed_label"), ("label2", 2),),
274-
counter_two,
274+
sum_agg_two,
275275
),
276276
]
277277
)

ext/opentelemetry-ext-opencensusexporter/tests/test_otcollector_metrics_exporter.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def test_get_collector_metric_type(self):
8181
self.assertIs(result, metrics_pb2.MetricDescriptor.UNSPECIFIED)
8282

8383
def test_get_collector_point(self):
84-
aggregator = aggregate.CounterAggregator()
84+
aggregator = aggregate.SumAggregator()
8585
int_counter = self._meter.create_metric(
8686
"testName", "testDescription", "unit", int, Counter
8787
)
@@ -122,7 +122,7 @@ def test_export(self):
122122
"testname", "testdesc", "unit", int, Counter, ["environment"]
123123
)
124124
record = MetricRecord(
125-
test_metric, self._key_labels, aggregate.CounterAggregator(),
125+
test_metric, self._key_labels, aggregate.SumAggregator(),
126126
)
127127

128128
result = collector_exporter.export([record])
@@ -144,7 +144,7 @@ def test_translate_to_collector(self):
144144
test_metric = self._meter.create_metric(
145145
"testname", "testdesc", "unit", int, Counter, ["environment"]
146146
)
147-
aggregator = aggregate.CounterAggregator()
147+
aggregator = aggregate.SumAggregator()
148148
aggregator.update(123)
149149
aggregator.take_checkpoint()
150150
record = MetricRecord(test_metric, self._key_labels, aggregator,)

ext/opentelemetry-ext-prometheus/tests/test_prometheus_exporter.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
from opentelemetry.metrics import get_meter_provider, set_meter_provider
2525
from opentelemetry.sdk import metrics
2626
from opentelemetry.sdk.metrics.export import MetricRecord, MetricsExportResult
27-
from opentelemetry.sdk.metrics.export.aggregate import CounterAggregator
27+
from opentelemetry.sdk.metrics.export.aggregate import SumAggregator
2828

2929

3030
class TestPrometheusMetricExporter(unittest.TestCase):
@@ -67,7 +67,7 @@ def test_shutdown(self):
6767
def test_export(self):
6868
with self._registry_register_patch:
6969
record = MetricRecord(
70-
self._test_metric, self._labels_key, CounterAggregator(),
70+
self._test_metric, self._labels_key, SumAggregator(),
7171
)
7272
exporter = PrometheusMetricsExporter()
7373
result = exporter.export([record])
@@ -87,7 +87,7 @@ def test_counter_to_prometheus(self):
8787
)
8888
labels = {"environment@": "staging", "os": "Windows"}
8989
key_labels = metrics.get_labels_as_key(labels)
90-
aggregator = CounterAggregator()
90+
aggregator = SumAggregator()
9191
aggregator.update(123)
9292
aggregator.take_checkpoint()
9393
record = MetricRecord(metric, key_labels, aggregator)

opentelemetry-sdk/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
## Unreleased
44

5+
- Rename CounterAggregator -> SumAggregator
6+
([#816](https://github.com/open-telemetry/opentelemetry-python/pull/816))
7+
58
## 0.9b0
69

710
Released 2020-06-10

opentelemetry-sdk/src/opentelemetry/sdk/metrics/export/aggregate.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def merge(self, other):
4343
"""Combines two aggregator values."""
4444

4545

46-
class CounterAggregator(Aggregator):
46+
class SumAggregator(Aggregator):
4747
"""Aggregator for Counter metrics."""
4848

4949
def __init__(self):

opentelemetry-sdk/src/opentelemetry/sdk/metrics/export/batcher.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@
2727
from opentelemetry.sdk.metrics.export import MetricRecord
2828
from opentelemetry.sdk.metrics.export.aggregate import (
2929
Aggregator,
30-
CounterAggregator,
3130
LastValueAggregator,
3231
MinMaxSumCountAggregator,
32+
SumAggregator,
3333
ValueObserverAggregator,
3434
)
3535

@@ -57,15 +57,15 @@ def aggregator_for(self, instrument_type: Type[InstrumentT]) -> Aggregator:
5757
"""
5858
# pylint:disable=R0201
5959
if issubclass(instrument_type, (Counter, UpDownCounter)):
60-
return CounterAggregator()
60+
return SumAggregator()
6161
if issubclass(instrument_type, (SumObserver, UpDownSumObserver)):
6262
return LastValueAggregator()
6363
if issubclass(instrument_type, ValueRecorder):
6464
return MinMaxSumCountAggregator()
6565
if issubclass(instrument_type, ValueObserver):
6666
return ValueObserverAggregator()
6767
# TODO: Add other aggregators
68-
return CounterAggregator()
68+
return SumAggregator()
6969

7070
def checkpoint_set(self) -> Sequence[MetricRecord]:
7171
"""Returns a list of MetricRecords used for exporting.

0 commit comments

Comments
 (0)