Skip to content

Commit

Permalink
Strip empty chars
Browse files Browse the repository at this point in the history
  • Loading branch information
leandrodamascena committed Nov 12, 2024
1 parent 1f103e4 commit 8744555
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ def add_dimension(self, name: str, value: str) -> None:
f"Maximum number of dimensions exceeded ({MAX_DIMENSIONS}): Unable to add dimension {name}.",
)

if not name or not value:
if not name.strip() or not value.strip():
warnings.warn(
f"The dimension {name} doesn't meet the requirements and won't be added. "
"Ensure the dimension name and value are non empty strings",
Expand Down
4 changes: 3 additions & 1 deletion docs/core/metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ If you're new to Amazon CloudWatch, there are five terminologies you must be awa
* **Resolution**. It's a value representing the storage resolution for the corresponding metric. Metrics can be either Standard or High resolution. Read more [here](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/publishingMetrics.html#high-resolution-metrics){target="_blank"}.

<figure>
<img src="../../media/metrics_terminology.png" />
<img src="../../media/metrics_terminology.png" alt="Terminology" />
<figcaption>Metric terminology, visually explained</figcaption>
</figure>

Expand Down Expand Up @@ -131,6 +131,8 @@ If you'd like to remove them at some point, you can use `clear_default_dimension
--8<-- "examples/metrics/src/set_default_dimensions_log_metrics.py"
```

**Note:** Dimensions with empty values will not be included.

### Changing default timestamp

When creating metrics, we use the current timestamp. If you want to change the timestamp of all the metrics you create, utilize the `set_timestamp` function. You can specify a datetime object or an integer representing an epoch timestamp in milliseconds.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1053,7 +1053,7 @@ def test_add_dimensions_with_empty_value(namespace, capsys, metric):

# WHEN we try to add a dimension with empty value
with pytest.warns(UserWarning, match=f"The dimension {my_dimension} doesn't meet the requirements *"):
my_metrics.add_dimension(name="my_empty_dimension", value="")
my_metrics.add_dimension(name="my_empty_dimension", value=" ")

my_metrics.add_metric(**metric)
my_metrics.flush_metrics()
Expand Down

0 comments on commit 8744555

Please sign in to comment.