Skip to content

Commit b1aa148

Browse files
committed
chore(metrics): test dimensions limit with service set
1 parent 9097f90 commit b1aa148

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

Diff for: tests/functional/test_metrics.py

+13
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,19 @@ def test_exceed_number_of_dimensions(metric, namespace):
331331
my_metric.add_dimension(**dimension)
332332

333333

334+
def test_exceed_number_of_dimensions_with_service(metric, namespace, monkeypatch):
335+
# GIVEN we have service set and add more dimensions than CloudWatch supports (N+1)
336+
monkeypatch.setenv("POWERTOOLS_SERVICE_NAME", "test_service")
337+
dimensions = [{"name": f"test_{i}", "value": "test"} for i in range(9)]
338+
339+
# WHEN we attempt to serialize them into a valid EMF object
340+
# THEN it should fail validation and raise SchemaValidationError
341+
with pytest.raises(SchemaValidationError, match="Maximum number of dimensions exceeded.*"):
342+
with single_metric(**metric, namespace=namespace) as my_metric:
343+
for dimension in dimensions:
344+
my_metric.add_dimension(**dimension)
345+
346+
334347
def test_log_metrics_during_exception(capsys, metric, dimension, namespace):
335348
# GIVEN Metrics is initialized
336349
my_metrics = Metrics(namespace=namespace)

0 commit comments

Comments
 (0)