Skip to content

Commit

Permalink
Remove default aggregations
Browse files Browse the repository at this point in the history
  • Loading branch information
ocelotl committed Dec 13, 2021
1 parent 5bdd539 commit 370c6b2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 92 deletions.
41 changes: 5 additions & 36 deletions opentelemetry-sdk/src/opentelemetry/sdk/_metrics/instrument.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

# pylint: disable=too-many-ancestors

from abc import ABC, abstractmethod
from typing import Dict, Generator, Iterable, Union

from opentelemetry._metrics.instrument import CallbackT
Expand All @@ -30,23 +29,11 @@
ObservableUpDownCounter as APIObservableUpDownCounter,
)
from opentelemetry._metrics.instrument import UpDownCounter as APIUpDownCounter
from opentelemetry.sdk._metrics.aggregation import (
ExplicitBucketHistogramAggregation,
LastValueAggregation,
SumAggregation,
)
from opentelemetry.sdk._metrics.measurement import Measurement
from opentelemetry.sdk.util.instrumentation import InstrumentationInfo


class _Instrument(ABC):
@property
@abstractmethod
def default_aggregation(self):
pass


class _Synchronous(_Instrument):
class _Synchronous:
def __init__(
self,
instrumentation_info: InstrumentationInfo,
Expand All @@ -58,7 +45,7 @@ def __init__(
super().__init__(name, unit=unit, description=description)


class _Asynchronous(_Instrument):
class _Asynchronous:
def __init__(
self,
instrumentation_info: InstrumentationInfo,
Expand Down Expand Up @@ -86,10 +73,6 @@ def callback(self) -> CallbackT:


class Counter(_Synchronous, APICounter):
@property
def default_aggregation(self):
return SumAggregation

def add(
self, amount: Union[int, float], attributes: Dict[str, str] = None
):
Expand All @@ -98,38 +81,24 @@ def add(


class UpDownCounter(_Synchronous, APIUpDownCounter):
@property
def default_aggregation(self):
return SumAggregation

def add(
self, amount: Union[int, float], attributes: Dict[str, str] = None
):
pass


class ObservableCounter(_Asynchronous, APIObservableCounter):
@property
def default_aggregation(self):
return SumAggregation
pass


class ObservableUpDownCounter(_Asynchronous, APIObservableUpDownCounter):
@property
def default_aggregation(self):
return SumAggregation
pass


class Histogram(_Synchronous, APIHistogram):
@property
def default_aggregation(self):
return ExplicitBucketHistogramAggregation

def record(self, amount, attributes=None):
pass


class ObservableGauge(_Asynchronous, APIObservableGauge):
@property
def default_aggregation(self):
return LastValueAggregation
pass
56 changes: 0 additions & 56 deletions opentelemetry-sdk/tests/metrics/test_instrument.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,54 +15,14 @@
from unittest import TestCase
from unittest.mock import Mock

from opentelemetry.sdk._metrics.aggregation import (
ExplicitBucketHistogramAggregation,
LastValueAggregation,
SumAggregation,
)
from opentelemetry.sdk._metrics.instrument import (
Counter,
Histogram,
ObservableCounter,
ObservableGauge,
ObservableUpDownCounter,
UpDownCounter,
)


class TestCounter(TestCase):
def test_default_aggregation(self):

self.assertIs(
Counter(Mock(), "name").default_aggregation, SumAggregation
)


class TestUpDownCounter(TestCase):
def test_default_aggregation(self):

self.assertIs(
UpDownCounter(Mock(), "name").default_aggregation, SumAggregation
)


class TestHistogram(TestCase):
def test_default_aggregation(self):

self.assertIs(
Histogram(Mock(), "name").default_aggregation,
ExplicitBucketHistogramAggregation,
)


class TestObservableGauge(TestCase):
def test_default_aggregation(self):

self.assertIs(
ObservableGauge(Mock(), "name", Mock()).default_aggregation,
LastValueAggregation,
)

def test_callable_callback(self):
def callback():
return [1, 2, 3]
Expand All @@ -81,13 +41,6 @@ def callback():


class TestObservableCounter(TestCase):
def test_default_aggregation(self):

self.assertIs(
ObservableCounter(Mock(), "name", Mock()).default_aggregation,
SumAggregation,
)

def test_callable_callback(self):
def callback():
return [1, 2, 3]
Expand All @@ -106,15 +59,6 @@ def callback():


class TestObservableUpDownCounter(TestCase):
def test_default_aggregation(self):

self.assertIs(
ObservableUpDownCounter(
Mock(), "name", Mock()
).default_aggregation,
SumAggregation,
)

def test_callable_callback(self):
def callback():
return [1, 2, 3]
Expand Down

0 comments on commit 370c6b2

Please sign in to comment.