| | import pytest |
| |
|
| | from aws_lambda_powertools.metrics.exceptions import SchemaValidationError |
| | from aws_lambda_powertools.metrics.provider.datadog import DatadogMetrics |
| | from aws_lambda_powertools.metrics.provider.datadog.warnings import DatadogDataValidationWarning |
| |
|
| |
|
| | def test_get_namespace_property(namespace): |
| | |
| | my_metrics = DatadogMetrics(namespace=namespace) |
| |
|
| | |
| | |
| | assert my_metrics.namespace == namespace |
| |
|
| |
|
| | def test_set_namespace_property(namespace): |
| | |
| | my_metrics = DatadogMetrics() |
| |
|
| | |
| | my_metrics.namespace = namespace |
| |
|
| | |
| | assert my_metrics.namespace == namespace |
| |
|
| |
|
| | def test_default_tags_across_instances(): |
| | |
| | my_metrics = DatadogMetrics() |
| | my_metrics.set_default_tags(environment="test", log_group="/lambda/test") |
| |
|
| | |
| | same_metrics = DatadogMetrics() |
| |
|
| | |
| | assert "environment" in same_metrics.default_tags |
| |
|
| |
|
| | def test_invalid_datadog_metric_name(): |
| | metrics = DatadogMetrics() |
| |
|
| | |
| | metric_name_1 = "1_metric" |
| | metric_name_2 = "metric_ç" |
| | metric_name_3 = "".join(["x" for _ in range(201)]) |
| |
|
| | |
| | |
| | with pytest.raises(SchemaValidationError, match="Invalid metric name.*"): |
| | metrics.add_metric(name=metric_name_1, value=1) |
| |
|
| | with pytest.raises(SchemaValidationError, match="Invalid metric name.*"): |
| | metrics.add_metric(name=metric_name_2, value=1) |
| |
|
| | with pytest.raises(SchemaValidationError, match="Invalid metric name.*"): |
| | metrics.add_metric(name=metric_name_3, value=1) |
| |
|
| |
|
| | def test_invalid_datadog_metric_tag(): |
| | metrics = DatadogMetrics() |
| |
|
| | |
| | metric_tag_1 = "".join(["x" for _ in range(201)]) |
| |
|
| | |
| | |
| | with pytest.warns(DatadogDataValidationWarning): |
| | metrics.add_metric(name="metric_2", value=1, tag1=metric_tag_1) |
| |
|