Skip to content

Commit

Permalink
Ensure tz-aware timestamps in response
Browse files Browse the repository at this point in the history
The API response contains only tz-naive UTC timestamps, which are
converted to tz-aware timestamps to avoid misinterpretation.

Signed-off-by: cwasicki <[email protected]>
  • Loading branch information
cwasicki committed Dec 9, 2024
1 parent 42fcfec commit c743618
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/frequenz/client/reporting/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from collections import namedtuple
from collections.abc import AsyncIterator, Iterable, Iterator
from dataclasses import dataclass
from datetime import datetime, timedelta
from datetime import datetime, timedelta, timezone
from typing import cast

import grpc.aio as grpcaio
Expand Down Expand Up @@ -90,6 +90,9 @@ def __iter__(self) -> Iterator[MetricSample]:
cid = cdata.component_id
for msample in cdata.metric_samples:
ts = msample.sampled_at.ToDatetime()
# Ensure tz-aware timestamps,
# as the API returns tz-naive UTC timestamps
ts = ts.replace(tzinfo=timezone.utc)
met = Metric.from_proto(msample.metric).name
value = (
msample.value.simple_metric.value
Expand Down

0 comments on commit c743618

Please sign in to comment.