Skip to content

Commit

Permalink
fix type
Browse files Browse the repository at this point in the history
  • Loading branch information
lzchen committed Sep 26, 2019
1 parent 4b03cb7 commit cedcd1e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 16 deletions.
9 changes: 5 additions & 4 deletions opentelemetry-api/src/opentelemetry/metrics/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,17 @@ class DefaultMetricHandle:


class CounterHandle:
def add(self, value: Type[_ValueT]) -> None:
def add(self, value: _ValueT) -> None:
"""Increases the value of the handle by ``value``"""


class GaugeHandle:
def set(self, value: Type[_ValueT]) -> None:
def set(self, value: _ValueT) -> None:
"""Sets the current value of the handle to ``value``."""


class MeasureHandle:
def record(self, value: Type[_ValueT]) -> None:
def record(self, value: _ValueT) -> None:
"""Records the given ``value`` to this handle."""


Expand Down Expand Up @@ -123,6 +123,7 @@ def get_handle(self, label_values: Tuple[str, ...]) -> "MeasureHandle":
"""Gets a `MeasureHandle` with a float value."""
return MeasureHandle()


_MetricT = TypeVar("_MetricT", Counter, Gauge, Measure)


Expand All @@ -138,7 +139,7 @@ class Meter:
def record_batch(
self,
label_values: Tuple[str, ...],
record_tuples: Tuple[Tuple["Metric", Type[_ValueT]]],
record_tuples: Tuple[Tuple["Metric", _ValueT]],
) -> None:
"""Atomically records a batch of `Metric` and value pairs.
Expand Down
3 changes: 2 additions & 1 deletion opentelemetry-api/tests/metrics/test_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ def setUp(self):
self.meter = metrics.Meter()

def test_record_batch(self):
self.meter.record_batch((), ())
counter = metrics.Counter()
self.meter.record_batch(("values"), ((counter, 1)))

def test_create_metric(self):
metric = self.meter.create_metric("", "", "", float, metrics.Counter)
Expand Down
25 changes: 14 additions & 11 deletions opentelemetry-sdk/src/opentelemetry/sdk/metrics/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@

class BaseHandle:
def __init__(
self, value_type: metrics_api._ValueT, enabled: bool, monotonic: bool
self,
value_type: Type[metrics_api._ValueT],
enabled: bool,
monotonic: bool,
):
self.data = 0
self.value_type = value_type
Expand Down Expand Up @@ -84,7 +87,7 @@ def __init__(
name: str,
description: str,
unit: str,
value_type: metrics_api._ValueT,
value_type: Type[metrics_api._ValueT],
label_keys: Tuple[str, ...] = None,
enabled: bool = True,
monotonic: bool = False,
Expand All @@ -98,13 +101,13 @@ def __init__(
self.monotonic = monotonic
self.handles = {}

def get_handle(
self, label_values: Tuple[str, ...]
) -> BaseHandle:
def get_handle(self, label_values: Tuple[str, ...]) -> BaseHandle:
"""See `opentelemetry.metrics.Metric.get_handle`."""
handle = self.handles.get(label_values)
if not handle:
handle = self.__class__.HANDLE_TYPE(self.value_type, self.enabled, self.monotonic)
handle = self.__class__.HANDLE_TYPE(
self.value_type, self.enabled, self.monotonic
)
self.handles[label_values] = handle
return handle

Expand All @@ -124,7 +127,7 @@ def __init__(
name: str,
description: str,
unit: str,
value_type: metrics_api._ValueT,
value_type: Type[metrics_api._ValueT],
label_keys: Tuple[str, ...] = None,
enabled: bool = True,
monotonic: bool = True,
Expand Down Expand Up @@ -154,7 +157,7 @@ def __init__(
name: str,
description: str,
unit: str,
value_type: metrics_api._ValueT,
value_type: Type[metrics_api._ValueT],
label_keys: Tuple[str, ...] = None,
enabled: bool = True,
monotonic: bool = False,
Expand Down Expand Up @@ -184,7 +187,7 @@ def __init__(
name: str,
description: str,
unit: str,
value_type: metrics_api._ValueT,
value_type: Type[metrics_api._ValueT],
label_keys: Tuple[str, ...] = None,
enabled: bool = False,
monotonic: bool = False,
Expand Down Expand Up @@ -217,8 +220,8 @@ def create_metric(
name: str,
description: str,
unit: str,
value_type: metrics_api._ValueT,
metric_type: metrics_api._MetricT,
value_type: Type[metrics_api._ValueT],
metric_type: Type[metrics_api._MetricT],
label_keys: Tuple[str, ...] = None,
enabled: bool = True,
monotonic: bool = False,
Expand Down

0 comments on commit cedcd1e

Please sign in to comment.