Skip to content

Commit d00b926

Browse files
committed
chore: remove Metrics deprecated code
1 parent c4135cb commit d00b926

File tree

5 files changed

+44
-180
lines changed

5 files changed

+44
-180
lines changed

aws_lambda_powertools/helper/models.py

-31
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
"""
55

66
from enum import Enum
7-
from typing import Union
87

98

109
class LambdaContextModel:
@@ -100,33 +99,3 @@ class MetricUnit(Enum):
10099
GigabitsPerSecond = "Gigabits/Second"
101100
TerabitsPerSecond = "Terabits/Second"
102101
CountPerSecond = "Count/Second"
103-
104-
105-
def build_metric_unit_from_str(unit: Union[str, MetricUnit]) -> MetricUnit:
106-
"""Builds correct metric unit value from string or return Count as default
107-
108-
Parameters
109-
----------
110-
unit : str, MetricUnit
111-
metric unit
112-
113-
Returns
114-
-------
115-
MetricUnit
116-
Metric Unit enum from string value or MetricUnit.Count as a default
117-
"""
118-
if isinstance(unit, MetricUnit):
119-
return unit
120-
121-
if isinstance(unit, str):
122-
unit = unit.lower().capitalize()
123-
124-
metric_unit = None
125-
126-
try:
127-
metric_unit = MetricUnit[unit]
128-
except (TypeError, KeyError):
129-
metric_units = [units for units, _ in MetricUnit.__members__.items()]
130-
raise ValueError(f"Invalid Metric Unit - Received {unit}. Value Metric Units are {metric_units}")
131-
132-
return metric_unit

aws_lambda_powertools/metrics/__init__.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""CloudWatch Embedded Metric Format utility
22
"""
33
from ..helper.models import MetricUnit
4-
from .exceptions import MetricUnitError, MetricValueError, SchemaValidationError, UniqueNamespaceError
4+
from .exceptions import MetricUnitError, MetricValueError, SchemaValidationError
55
from .metric import single_metric
66
from .metrics import Metrics
77

@@ -12,5 +12,4 @@
1212
"MetricUnitError",
1313
"SchemaValidationError",
1414
"MetricValueError",
15-
"UniqueNamespaceError",
1615
]

aws_lambda_powertools/metrics/base.py

+1-28
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@
44
import numbers
55
import os
66
import pathlib
7-
import warnings
87
from typing import Dict, List, Union
98

109
import fastjsonschema
1110

1211
from ..helper.models import MetricUnit
13-
from .exceptions import MetricUnitError, MetricValueError, SchemaValidationError, UniqueNamespaceError
12+
from .exceptions import MetricUnitError, MetricValueError, SchemaValidationError
1413

1514
logger = logging.getLogger(__name__)
1615

@@ -45,8 +44,6 @@ class MetricManager:
4544
When metric metric isn't supported by CloudWatch
4645
MetricValueError
4746
When metric value isn't a number
48-
UniqueNamespaceError
49-
When an additional namespace is set
5047
SchemaValidationError
5148
When metric object fails EMF schema validation
5249
"""
@@ -61,30 +58,6 @@ def __init__(
6158
self._metric_units = [unit.value for unit in MetricUnit]
6259
self._metric_unit_options = list(MetricUnit.__members__)
6360

64-
def add_namespace(self, name: str):
65-
"""Adds given metric namespace
66-
67-
Example
68-
-------
69-
**Add metric namespace**
70-
71-
metric.add_namespace(name="ServerlessAirline")
72-
73-
Parameters
74-
----------
75-
name : str
76-
Metric namespace
77-
"""
78-
warnings.warn(
79-
"add_namespace method is deprecated. Pass namespace to Metrics constructor instead", DeprecationWarning
80-
)
81-
if self.namespace is not None:
82-
raise UniqueNamespaceError(
83-
f"Namespace '{self.namespace}' already set - Only one namespace is allowed across metrics"
84-
)
85-
logger.debug(f"Adding metrics namespace: {name}")
86-
self.namespace = name
87-
8861
def add_metric(self, name: str, unit: MetricUnit, value: Union[float, int]):
8962
"""Adds given metric
9063

aws_lambda_powertools/metrics/exceptions.py

-6
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,3 @@ class MetricValueError(Exception):
1414
"""When metric value isn't a valid number"""
1515

1616
pass
17-
18-
19-
class UniqueNamespaceError(Exception):
20-
"""When an additional namespace is set"""
21-
22-
pass

0 commit comments

Comments
 (0)