Skip to content

Commit

Permalink
Merge branch 'develop' into docs/1064-middleware-factory
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Brewer authored Jun 7, 2022
2 parents ed84f65 + 9d8dd1b commit 156909f
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 9 deletions.
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,23 @@ All notable changes to this project will be documented in this file.

This project follows [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) format for changes and adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## 1.26.1 - 2022-06-07
### Bug Fixes

* **metrics:** raise SchemaValidationError for >8 metric dimensions ([#1240](https://github.com/awslabs/aws-lambda-powertools-python/issues/1240))

### Documentation

* **governance:** link roadmap and maintainers doc
* **maintainers:** initial maintainers playbook ([#1222](https://github.com/awslabs/aws-lambda-powertools-python/issues/1222))
* **roadmap:** use pinned pause issue instead

### Maintenance

* **deps-dev:** bump mypy from 0.950 to 0.960 ([#1224](https://github.com/awslabs/aws-lambda-powertools-python/issues/1224))
* **deps-dev:** bump mypy-boto3-secretsmanager from 1.23.0.post1 to 1.23.8 ([#1225](https://github.com/awslabs/aws-lambda-powertools-python/issues/1225))


## 1.26.0 - 2022-05-20

### Bug Fixes
Expand Down
3 changes: 2 additions & 1 deletion aws_lambda_powertools/metrics/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,8 @@ def serialize_metric_set(
metadata = self.metadata_set

if self.service and not self.dimension_set.get("service"):
self.dimension_set["service"] = self.service
# self.service won't be a float
self.add_dimension(name="service", value=self.service) # type: ignore[arg-type]

if len(metrics) == 0:
raise SchemaValidationError("Must contain at least one metric.")
Expand Down
10 changes: 5 additions & 5 deletions docs/core/metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ If you're new to Amazon CloudWatch, there are two terminologies you must be awar

Metric has two global settings that will be used across all metrics emitted:

Setting | Description | Environment variable | Constructor parameter
------------------------------------------------- | ------------------------------------------------- | ------------------------------------------------- | -------------------------------------------------
**Metric namespace** | Logical container where all metrics will be placed e.g. `ServerlessAirline` | `POWERTOOLS_METRICS_NAMESPACE` | `namespace`
**Service** | Optionally, sets **service** metric dimension across all metrics e.g. `payment` | `POWERTOOLS_SERVICE_NAME` | `service`
| Setting | Description | Environment variable | Constructor parameter |
| -------------------- | ------------------------------------------------------------------------------- | ------------------------------ | --------------------- |
| **Metric namespace** | Logical container where all metrics will be placed e.g. `ServerlessAirline` | `POWERTOOLS_METRICS_NAMESPACE` | `namespace` |
| **Service** | Optionally, sets **service** metric dimension across all metrics e.g. `payment` | `POWERTOOLS_SERVICE_NAME` | `service` |

???+ tip
Use your application or main service as the metric namespace to easily group all metrics.
Expand Down Expand Up @@ -191,7 +191,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 9 dimensions
* Maximum of 8 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
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "aws_lambda_powertools"
version = "1.26.0"
version = "1.26.1"
description = "A suite of utilities for AWS Lambda functions to ease adopting best practices such as tracing, structured logging, custom metrics, batching, idempotency, feature flags, and more."
authors = ["Amazon Web Services"]
include = ["aws_lambda_powertools/py.typed", "THIRD-PARTY-LICENSES"]
Expand Down
6 changes: 4 additions & 2 deletions tests/functional/test_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,9 +319,11 @@ def test_schema_no_metrics(service, namespace):
my_metrics.serialize_metric_set()


def test_exceed_number_of_dimensions(metric, namespace):
def test_exceed_number_of_dimensions(metric, namespace, monkeypatch):
# GIVEN we we have more dimensions than CloudWatch supports
dimensions = [{"name": f"test_{i}", "value": "test"} for i in range(11)]
# and that service dimension is injected like a user-defined dimension (N+1)
monkeypatch.setenv("POWERTOOLS_SERVICE_NAME", "test_service")
dimensions = [{"name": f"test_{i}", "value": "test"} for i in range(9)]

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

0 comments on commit 156909f

Please sign in to comment.