Skip to content

Commit

Permalink
Use datetime.now(utc) in MetricDatum
Browse files Browse the repository at this point in the history
datetime.utcnow() is deprecated as of Python 3.12, and its use will
raise a DeprecationWarning. Since warnings are treated as errors, this
results in test failures under Python 3.12. Switch to using
datetime.now() with a timezone.utc parameter.
  • Loading branch information
s-t-e-v-e-n-k committed Feb 8, 2024
1 parent 027ffc0 commit aca3d4d
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions samtranslator/metrics/metrics.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
"""
Helper classes to publish metrics
"""

import logging
from abc import ABC, abstractmethod
from datetime import datetime
from datetime import datetime, timezone
from typing import Any, Dict, List, Optional, TypedDict, Union

from samtranslator.internal.deprecation_control import deprecated
Expand Down Expand Up @@ -114,7 +115,7 @@ def __init__(
self.value = value
self.unit = unit
self.dimensions = dimensions if dimensions else []
self.timestamp = timestamp if timestamp else datetime.utcnow()
self.timestamp = timestamp if timestamp else datetime.now(timezone.utc)

def get_metric_data(self) -> Dict[str, Any]:
return {
Expand Down

0 comments on commit aca3d4d

Please sign in to comment.