Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,16 @@

## Summary

> **Warning:** This client is compatible *only* with Reporting API `v1alpha10` or later.
> Using with services that use an older API version **will cause failures**.
<!-- Here goes a general summary of what this release is about -->

## Upgrading

* Breaking change to reporting API v1alpha10.
* Switch to new `metrics` package from client-common.
<!-- Here goes notes on how to upgrade from previous versions, including deprecations and what they should be replaced with -->

## New Features

<!-- Here goes the main new features and examples or instructions on how to use them -->

## Bug Fixes

<!-- Here goes notable bug fixes that are worth a special mention or explanation -->
* Fix default value of formula-aggregated metrics when no data was sent.
28 changes: 22 additions & 6 deletions src/frequenz/client/reporting/_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

"""Types for the Reporting API client."""

import math
from collections.abc import Iterable, Iterator
from dataclasses import dataclass
from datetime import datetime
Expand Down Expand Up @@ -180,10 +181,25 @@ class AggregatedMetric:

def sample(self) -> MetricSample:
"""Return the aggregated metric sample."""
return MetricSample(
timestamp=datetime_from_proto(self._data_pb.sample.sample_time),
microgrid_id=self._data_pb.aggregation_config.microgrid_id,
component_id=self._data_pb.aggregation_config.aggregation_formula,
metric=Metric(self._data_pb.aggregation_config.metric).name,
value=self._data_pb.sample.sample.value,
config = self._data_pb.aggregation_config
sample = self._data_pb.sample

timestamp = datetime_from_proto(sample.sample_time)
microgrid_id = config.microgrid_id
component_id = config.aggregation_formula
metric = Metric(config.metric).name
# Ignoring this verification results in
# values of zero if the field is not set.
if sample.HasField("sample") and sample.sample.HasField("value"):
value = sample.sample.value
else:
value = math.nan

ret = MetricSample(
timestamp=timestamp,
microgrid_id=microgrid_id,
component_id=component_id,
metric=metric,
value=value,
)
return ret