Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename Measure to ValueRecorder #761

Merged
merged 7 commits into from
Jun 2, 2020
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/examples/basic_meter/basic_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import time

from opentelemetry import metrics
from opentelemetry.sdk.metrics import Counter, Measure, MeterProvider
from opentelemetry.sdk.metrics import Counter, MeterProvider, ValueRecorder
from opentelemetry.sdk.metrics.export import ConsoleMetricsExporter
from opentelemetry.sdk.metrics.export.controller import PushController

Expand Down Expand Up @@ -80,7 +80,7 @@ def usage(argv):
description="size of requests",
unit="1",
value_type=int,
metric_type=Measure,
metric_type=ValueRecorder,
label_keys=("environment",),
)

Expand Down
4 changes: 2 additions & 2 deletions docs/examples/basic_meter/calling_conventions.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import time

from opentelemetry import metrics
from opentelemetry.sdk.metrics import Counter, Measure, MeterProvider
from opentelemetry.sdk.metrics import Counter, MeterProvider, ValueRecorder
from opentelemetry.sdk.metrics.export import ConsoleMetricsExporter
from opentelemetry.sdk.metrics.export.controller import PushController

Expand All @@ -43,7 +43,7 @@
description="size of requests",
unit="1",
value_type=int,
metric_type=Measure,
metric_type=ValueRecorder,
label_keys=("environment",),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
from opentelemetry.ext.opencensusexporter import metrics_exporter
from opentelemetry.sdk.metrics import (
Counter,
Measure,
MeterProvider,
ValueRecorder,
get_labels_as_key,
)
from opentelemetry.sdk.metrics.export import (
Expand Down Expand Up @@ -76,7 +76,7 @@ def test_get_collector_metric_type(self):
)
self.assertIs(result, metrics_pb2.MetricDescriptor.CUMULATIVE_DOUBLE)
result = metrics_exporter.get_collector_metric_type(
Measure("testName", "testDescription", "unit", None, None)
ValueRecorder("testName", "testDescription", "unit", None, None)
)
self.assertIs(result, metrics_pb2.MetricDescriptor.UNSPECIFIED)

Expand All @@ -88,8 +88,8 @@ def test_get_collector_point(self):
float_counter = self._meter.create_metric(
"testName", "testDescription", "unit", float, Counter
)
measure = self._meter.create_metric(
"testName", "testDescription", "unit", float, Measure
valuerecorder = self._meter.create_metric(
"testName", "testDescription", "unit", float, ValueRecorder
)
result = metrics_exporter.get_collector_point(
MetricRecord(aggregator, self._key_labels, int_counter)
Expand All @@ -106,7 +106,7 @@ def test_get_collector_point(self):
self.assertRaises(
TypeError,
metrics_exporter.get_collector_point(
MetricRecord(aggregator, self._key_labels, measure)
MetricRecord(aggregator, self._key_labels, valuerecorder)
),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
UnknownMetricFamily,
)

from opentelemetry.metrics import Counter, Measure, Metric
from opentelemetry.metrics import Counter, Metric, ValueRecorder
from opentelemetry.sdk.metrics.export import (
MetricRecord,
MetricsExporter,
Expand Down Expand Up @@ -164,7 +164,7 @@ def _translate_to_prometheus(self, metric_record: MetricRecord):
labels=label_values, value=metric_record.aggregator.checkpoint
)
# TODO: Add support for histograms when supported in OT
elif isinstance(metric_record.metric, Measure):
elif isinstance(metric_record.metric, ValueRecorder):
prometheus_metric = UnknownMetricFamily(
name=metric_name,
documentation=metric_record.metric.description,
Expand Down
3 changes: 3 additions & 0 deletions opentelemetry-api/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## Unreleased

- Rename Measure to ValueRecorder in metrics
([#761](https://github.com/open-telemetry/opentelemetry-python/pull/761))

## 0.8b0

Released 2020-05-27
Expand Down
55 changes: 22 additions & 33 deletions opentelemetry-api/src/opentelemetry/metrics/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,13 @@
The `Meter` class is used to construct `Metric` s to record raw statistics
as well as metrics with predefined aggregation.

`Meter` s can be obtained via the `MeterProvider`, corresponding to the name
of the instrumenting library and (optionally) a version.

See the `metrics api`_ spec for terminology and context clarification.

.. _metrics api:
https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/api-metrics.md

.. versionadded:: 0.1.0
.. versionchanged:: 0.5.0
``meter_provider`` was replaced by `get_meter_provider`,
``set_preferred_meter_provider_implementation`` was replaced by
`set_meter_provider`.
Comment on lines -27 to -31
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may well make sense to lose the version comments until we're out of beta, but why do it in this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CHANGELOG.md contains a lot more information than the version comments (some missed API changes related to metrics). Instead of updating in multiple places, we can just refer to that file.

https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/metrics/api.md
"""
import abc
from logging import getLogger
Expand All @@ -54,7 +51,7 @@ def add(self, value: ValueT) -> None:
"""

def record(self, value: ValueT) -> None:
"""No-op implementation of `BoundMeasure` record.
"""No-op implementation of `BoundValueRecorder` record.

Args:
value: The value to record to the bound metric instrument.
Expand All @@ -73,12 +70,12 @@ def add(self, value: ValueT) -> None:
"""


class BoundMeasure:
class BoundValueRecorder:
def record(self, value: ValueT) -> None:
"""Records the given ``value`` to this bound measure.
"""Records the given ``value`` to this bound valuerecorder.

Args:
value: The value to record to the bound measure.
value: The value to record to the bound valuerecorder.
"""


Expand All @@ -94,12 +91,7 @@ def bind(self, labels: Dict[str, str]) -> "object":
"""Gets a bound metric instrument.

Bound metric instruments are useful to reduce the cost of repeatedly
recording a metric with a pre-defined set of label values. All metric
kinds (counter, measure) support declaring a set of required label
keys. The values corresponding to these keys should be specified in
every bound metric instrument. "Unspecified" label values, in cases
where a bound metric instrument is requested but a value was not
provided are permitted.
recording a metric with a pre-defined set of label values.

Args:
labels: Labels to associate with the bound instrument.
Expand All @@ -126,10 +118,10 @@ def add(self, value: ValueT, labels: Dict[str, str]) -> None:
"""

def record(self, value: ValueT, labels: Dict[str, str]) -> None:
"""No-op implementation of `Measure` record.
"""No-op implementation of `ValueRecorder` record.

Args:
value: The value to record to this measure metric.
value: The value to record to this valuerecorder metric.
labels: Labels to associate with the bound instrument.
"""

Expand All @@ -150,21 +142,18 @@ def add(self, value: ValueT, labels: Dict[str, str]) -> None:
"""


class Measure(Metric):
"""A measure type metric that represent raw stats that are recorded.

Measure metrics represent raw statistics that are recorded.
"""
class ValueRecorder(Metric):
"""A valuerecorder type metric that represent raw stats."""

def bind(self, labels: Dict[str, str]) -> "BoundMeasure":
"""Gets a `BoundMeasure`."""
return BoundMeasure()
def bind(self, labels: Dict[str, str]) -> "BoundValueRecorder":
"""Gets a `BoundValueRecorder`."""
return BoundValueRecorder()

def record(self, value: ValueT, labels: Dict[str, str]) -> None:
"""Records the ``value`` to the measure.
"""Records the ``value`` to the valuerecorder.

Args:
value: The value to record to this measure metric.
value: The value to record to this valuerecorder metric.
labels: Labels to associate with the bound instrument.
"""

Expand Down Expand Up @@ -251,17 +240,17 @@ def get_meter(
return DefaultMeter()


MetricT = TypeVar("MetricT", Counter, Measure, Observer)
MetricT = TypeVar("MetricT", Counter, ValueRecorder, Observer)
ObserverCallbackT = Callable[[Observer], None]


# pylint: disable=unused-argument
class Meter(abc.ABC):
"""An interface to allow the recording of metrics.

`Metric` s are used for recording pre-defined aggregation (counter),
or raw values (measure) in which the aggregation and labels
for the exported metric are deferred.
`Metric` s or metric instruments, are devices used for capturing raw
measurements. Each metric instrument supports a single method, each with
fixed interpretation to capture measurements.
"""

@abc.abstractmethod
Expand Down
20 changes: 10 additions & 10 deletions opentelemetry-api/tests/metrics/test_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ def test_counter_add(self):
counter = metrics.Counter()
counter.add(1, {})

def test_measure(self):
measure = metrics.Measure()
bound_measure = measure.bind({})
self.assertIsInstance(bound_measure, metrics.BoundMeasure)
def test_valuerecorder(self):
valuerecorder = metrics.ValueRecorder()
bound_valuerecorder = valuerecorder.bind({})
self.assertIsInstance(bound_valuerecorder, metrics.BoundValueRecorder)

def test_measure_record(self):
measure = metrics.Measure()
measure.record(1, {})
def test_valuerecorder_record(self):
valuerecorder = metrics.ValueRecorder()
valuerecorder.record(1, {})

def test_default_bound_metric(self):
bound_instrument = metrics.DefaultBoundInstrument()
Expand All @@ -52,9 +52,9 @@ def test_bound_counter(self):
bound_counter = metrics.BoundCounter()
bound_counter.add(1)

def test_bound_measure(self):
bound_measure = metrics.BoundMeasure()
bound_measure.record(1)
def test_bound_valuerecorder(self):
bound_valuerecorder = metrics.BoundValueRecorder()
bound_valuerecorder.record(1)

def test_observer(self):
observer = metrics.DefaultObserver()
Expand Down
3 changes: 3 additions & 0 deletions opentelemetry-sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## Unreleased

- Rename Measure to ValueRecorder in metrics
([#761](https://github.com/open-telemetry/opentelemetry-python/pull/761))

## 0.8b0

Released 2020-05-27
Expand Down
12 changes: 6 additions & 6 deletions opentelemetry-sdk/src/opentelemetry/sdk/metrics/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ def add(self, value: metrics_api.ValueT) -> None:
self.update(value)


class BoundMeasure(metrics_api.BoundMeasure, BaseBoundInstrument):
class BoundValueRecorder(metrics_api.BoundValueRecorder, BaseBoundInstrument):
def record(self, value: metrics_api.ValueT) -> None:
"""See `opentelemetry.metrics.BoundMeasure.record`."""
"""See `opentelemetry.metrics.BoundValueRecorder.record`."""
if self._validate_update(value):
self.update(value)

Expand Down Expand Up @@ -174,15 +174,15 @@ def add(self, value: metrics_api.ValueT, labels: Dict[str, str]) -> None:
UPDATE_FUNCTION = add


class Measure(Metric, metrics_api.Measure):
"""See `opentelemetry.metrics.Measure`."""
class ValueRecorder(Metric, metrics_api.ValueRecorder):
"""See `opentelemetry.metrics.ValueRecorder`."""

BOUND_INSTR_TYPE = BoundMeasure
BOUND_INSTR_TYPE = BoundValueRecorder

def record(
self, value: metrics_api.ValueT, labels: Dict[str, str]
) -> None:
"""See `opentelemetry.metrics.Measure.record`."""
"""See `opentelemetry.metrics.ValueRecorder.record`."""
bound_intrument = self.bind(labels)
bound_intrument.record(value)
bound_intrument.release()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def merge(self, other):


class MinMaxSumCountAggregator(Aggregator):
"""Agregator for Measure metrics that keeps min, max, sum and count."""
"""Aggregator for ValueRecorder metrics that keeps min, max, sum, count."""

_TYPE = namedtuple("minmaxsumcount", "min max sum count")
_EMPTY = _TYPE(None, None, None, 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import abc
from typing import Sequence, Type

from opentelemetry.metrics import Counter, Measure, MetricT, Observer
from opentelemetry.metrics import Counter, MetricT, Observer, ValueRecorder
from opentelemetry.sdk.metrics.export import MetricRecord
from opentelemetry.sdk.metrics.export.aggregate import (
Aggregator,
Expand Down Expand Up @@ -49,7 +49,7 @@ def aggregator_for(self, metric_type: Type[MetricT]) -> Aggregator:
# pylint:disable=R0201
if issubclass(metric_type, Counter):
return CounterAggregator()
if issubclass(metric_type, Measure):
if issubclass(metric_type, ValueRecorder):
return MinMaxSumCountAggregator()
if issubclass(metric_type, Observer):
return ObserverAggregator()
Expand Down
Loading