Skip to content

Commit

Permalink
Add deprecation warning for non-specified interval_ms.
Browse files Browse the repository at this point in the history
  • Loading branch information
a-feld committed Jun 2, 2020
1 parent 291524f commit dcf4bc6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
27 changes: 23 additions & 4 deletions src/newrelic_telemetry_sdk/metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
import warnings


DEFAULT = object()


class Metric(dict):
"""Base Metric type
Expand All @@ -40,7 +43,14 @@ def __init__(self, name, value, tags=None, interval_ms=None, end_time_ms=None):
self["name"] = name
self["value"] = value

if interval_ms is not None:
if interval_ms is DEFAULT:
warnings.warn(
"interval_ms will be required for CountMetric and "
"SummaryMetric in a future SDK release.",
DeprecationWarning,
)
interval = 0
elif interval_ms is not None:
interval = self["interval.ms"] = int(interval_ms)
else:
interval = 0
Expand Down Expand Up @@ -156,12 +166,13 @@ class CountMetric(Metric):
Usage::
>>> from newrelic_telemetry_sdk import CountMetric
>>> metric = CountMetric('response_status', 0, tags={'code': 200})
>>> metric = CountMetric('response_status', 0,
... tags={'code': 200}, interval_ms=1)
>>> metric.value
0
"""

def __init__(self, name, value, tags=None, interval_ms=None, end_time_ms=None):
def __init__(self, name, value, tags=None, interval_ms=DEFAULT, end_time_ms=None):
super(CountMetric, self).__init__(name, value, tags, interval_ms, end_time_ms)

self["type"] = "count"
Expand Down Expand Up @@ -204,7 +215,15 @@ class SummaryMetric(Metric):
"""

def __init__(
self, name, count, sum, min, max, tags=None, interval_ms=None, end_time_ms=None
self,
name,
count,
sum,
min,
max,
tags=None,
interval_ms=DEFAULT,
end_time_ms=None,
):
value = {"count": count, "sum": sum, "min": min, "max": max}
super(SummaryMetric, self).__init__(name, value, tags, interval_ms, end_time_ms)
Expand Down
2 changes: 2 additions & 0 deletions tests/test_metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def test_metric_defaults(method, freeze_time):
assert "interval.ms" not in metric


@pytest.mark.filterwarnings("ignore:.*interval_ms.*:DeprecationWarning")
def test_count_metric_defaults(freeze_time):
metric = CountMetric("name", 0)
assert metric["type"] == "count"
Expand All @@ -45,6 +46,7 @@ def test_count_metric_defaults(freeze_time):
assert "interval.ms" not in metric


@pytest.mark.filterwarnings("ignore:.*interval_ms.*:DeprecationWarning")
def test_summary_metric_defaults(freeze_time):
metric = SummaryMetric("name", 0, 0, 0, 0)
assert metric["type"] == "summary"
Expand Down

0 comments on commit dcf4bc6

Please sign in to comment.