Skip to content

feat(metrics): update max user-defined dimensions from 9 to 29 #1417

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

Merged
Show file tree
Hide file tree
Changes from all 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 aws_lambda_powertools/metrics/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
logger = logging.getLogger(__name__)

MAX_METRICS = 100
MAX_DIMENSIONS = 9
MAX_DIMENSIONS = 29


class MetricUnit(Enum):
Expand Down Expand Up @@ -233,7 +233,7 @@ def add_dimension(self, name: str, value: str) -> None:
Dimension value
"""
logger.debug(f"Adding dimension: {name}:{value}")
if len(self.dimension_set) == 9:
if len(self.dimension_set) == MAX_DIMENSIONS:
raise SchemaValidationError(
f"Maximum number of dimensions exceeded ({MAX_DIMENSIONS}): Unable to add dimension {name}."
)
Expand Down
2 changes: 1 addition & 1 deletion docs/core/metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ This decorator also **validates**, **serializes**, and **flushes** all your metr
???+ tip "Tip: Metric validation"
If metrics are provided, and any of the following criteria are not met, **`SchemaValidationError`** exception will be raised:

* Maximum of 8 user-defined dimensions
* Maximum of 29 user-defined dimensions
* Namespace is set, and no more than one
* Metric units must be [supported by CloudWatch](https://docs.aws.amazon.com/AmazonCloudWatch/latest/APIReference/API_MetricDatum.html)

Expand Down
10 changes: 5 additions & 5 deletions tests/functional/test_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from aws_lambda_powertools import Metrics, single_metric
from aws_lambda_powertools.metrics import MetricUnit, MetricUnitError, MetricValueError, SchemaValidationError
from aws_lambda_powertools.metrics import metrics as metrics_global
from aws_lambda_powertools.metrics.base import MetricManager
from aws_lambda_powertools.metrics.base import MAX_DIMENSIONS, MetricManager


@pytest.fixture(scope="function", autouse=True)
Expand Down Expand Up @@ -320,8 +320,8 @@ def test_schema_no_metrics(service, namespace):


def test_exceed_number_of_dimensions(metric, namespace):
# GIVEN we have more dimensions than CloudWatch supports
dimensions = [{"name": f"test_{i}", "value": "test"} for i in range(11)]
# GIVEN we have more dimensions than CloudWatch supports (N+1)
dimensions = [{"name": f"test_{i}", "value": "test"} for i in range(MAX_DIMENSIONS + 1)]

# WHEN we attempt to serialize them into a valid EMF object
# THEN it should fail validation and raise SchemaValidationError
Expand All @@ -332,9 +332,9 @@ def test_exceed_number_of_dimensions(metric, namespace):


def test_exceed_number_of_dimensions_with_service(metric, namespace, monkeypatch):
# GIVEN we have service set and add more dimensions than CloudWatch supports (N+1)
# GIVEN we have service set and add more dimensions than CloudWatch supports (N-1)
monkeypatch.setenv("POWERTOOLS_SERVICE_NAME", "test_service")
dimensions = [{"name": f"test_{i}", "value": "test"} for i in range(9)]
dimensions = [{"name": f"test_{i}", "value": "test"} for i in range(MAX_DIMENSIONS)]

# WHEN we attempt to serialize them into a valid EMF object
# THEN it should fail validation and raise SchemaValidationError
Expand Down