Skip to content

Commit 84a6eb2

Browse files
committed
Support secret to sign requests to reporting client
- Includes various naming updates that come with the new reporting client version. - Replaced deprecated `MetricSample` imports. - Updated tests to use string-based component IDs and numeric state values due to `MetricSample` now being stronly typed. Signed-off-by: cyiallou - Costas <[email protected]>
1 parent 478e4bc commit 84a6eb2

File tree

4 files changed

+38
-38
lines changed

4 files changed

+38
-38
lines changed

RELEASE_NOTES.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
## Upgrading
88

9-
<!-- Here goes notes on how to upgrade from previous versions, including deprecations and what they should be replaced with -->
9+
- The reporting API client version is updated to `>= 0.18.0, < 0.19.0`.
1010

1111
## New Features
1212

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ classifiers = [
2727
requires-python = ">= 3.11, < 4"
2828
dependencies = [
2929
"typing-extensions >= 4.6.1, < 5",
30-
"frequenz-client-reporting>=0.13.0, < 1",
30+
"frequenz-client-reporting >= 0.18.0, < 0.19.0",
3131
"frequenz-client-common >= 0.3.0, < 0.4",
3232
]
3333
dynamic = ["version"]

src/frequenz/reporting/_reporting.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
from frequenz.client.common.metric import Metric
1212
from frequenz.client.reporting import ReportingApiClient
13-
from frequenz.client.reporting._client import MetricSample
13+
from frequenz.client.reporting._types import MetricSample
1414

1515
CumulativeEnergy = namedtuple(
1616
"CumulativeEnergy", ["start_time", "end_time", "consumption", "production"]
@@ -49,11 +49,11 @@ async def cumulative_energy(
4949

5050
metric_samples = [
5151
sample
52-
async for sample in client.list_microgrid_components_data(
52+
async for sample in client.receive_microgrid_components_data(
5353
microgrid_components=[(microgrid_id, [component_id])],
5454
metrics=metric,
55-
start_dt=start_time,
56-
end_dt=end_time,
55+
start_time=start_time,
56+
end_time=end_time,
5757
resampling_period=resampling_period,
5858
)
5959
]
@@ -101,22 +101,22 @@ async def cumulative_energy(
101101
# Fetch energy consumption and production metrics separately
102102
consumption_samples = [
103103
sample
104-
async for sample in client.list_microgrid_components_data(
104+
async for sample in client.receive_microgrid_components_data(
105105
microgrid_components=[(microgrid_id, [component_id])],
106106
metrics=Metric.AC_ACTIVE_ENERGY_CONSUMED,
107-
start_dt=start_time,
108-
end_dt=end_time,
107+
start_time=start_time,
108+
end_time=end_time,
109109
resampling_period=resampling_period,
110110
)
111111
]
112112

113113
production_samples = [
114114
sample
115-
async for sample in client.list_microgrid_components_data(
115+
async for sample in client.receive_microgrid_components_data(
116116
microgrid_components=[(microgrid_id, [component_id])],
117117
metrics=Metric.AC_ACTIVE_ENERGY_DELIVERED,
118-
start_dt=start_time,
119-
end_dt=end_time,
118+
start_time=start_time,
119+
end_time=end_time,
120120
resampling_period=resampling_period,
121121
)
122122
]
@@ -350,11 +350,11 @@ async def _fetch_component_data(
350350
"""
351351
return [
352352
sample
353-
async for sample in client.list_microgrid_components_data(
353+
async for sample in client.receive_microgrid_components_data(
354354
microgrid_components=microgrid_components,
355355
metrics=metrics,
356-
start_dt=start_time,
357-
end_dt=end_time,
356+
start_time=start_time,
357+
end_time=end_time,
358358
resampling_period=resampling_period,
359359
include_states=include_states,
360360
include_bounds=include_bounds,

tests/test_frequenz_reporting.py

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from typing import Any
77

88
import pytest
9-
from frequenz.client.reporting._client import MetricSample
9+
from frequenz.client.reporting._types import MetricSample
1010

1111
from frequenz.reporting import delete_me
1212
from frequenz.reporting._reporting import extract_state_durations
@@ -23,8 +23,8 @@
2323
{
2424
"description": "No matching metrics",
2525
"samples": [
26-
MetricSample(datetime(2023, 1, 1, 0, 0), 1, 101, "temperature", 25),
27-
MetricSample(datetime(2023, 1, 1, 1, 0), 1, 101, "humidity", 60),
26+
MetricSample(datetime(2023, 1, 1, 0, 0), 1, "101", "temperature", 25),
27+
MetricSample(datetime(2023, 1, 1, 1, 0), 1, "101", "humidity", 60),
2828
],
2929
"alert_states": [1],
3030
"include_warnings": True,
@@ -34,23 +34,23 @@
3434
{
3535
"description": "Single state change",
3636
"samples": [
37-
MetricSample(datetime(2023, 1, 1, 0, 0), 1, 101, "state", 0),
38-
MetricSample(datetime(2023, 1, 1, 1, 0), 1, 101, "state", 1),
37+
MetricSample(datetime(2023, 1, 1, 0, 0), 1, "101", "state", 0),
38+
MetricSample(datetime(2023, 1, 1, 1, 0), 1, "101", "state", 1),
3939
],
4040
"alert_states": [1],
4141
"include_warnings": True,
4242
"expected_all_states": [
4343
{
4444
"microgrid_id": 1,
45-
"component_id": 101,
45+
"component_id": "101",
4646
"state_type": "state",
4747
"state_value": 0,
4848
"start_time": datetime(2023, 1, 1, 0, 0),
4949
"end_time": datetime(2023, 1, 1, 1, 0),
5050
},
5151
{
5252
"microgrid_id": 1,
53-
"component_id": 101,
53+
"component_id": "101",
5454
"state_type": "state",
5555
"state_value": 1,
5656
"start_time": datetime(2023, 1, 1, 1, 0),
@@ -60,7 +60,7 @@
6060
"expected_alert_records": [
6161
{
6262
"microgrid_id": 1,
63-
"component_id": 101,
63+
"component_id": "101",
6464
"state_type": "state",
6565
"state_value": 1,
6666
"start_time": datetime(2023, 1, 1, 1, 0),
@@ -71,26 +71,26 @@
7171
{
7272
"description": "Warnings and errors included",
7373
"samples": [
74-
MetricSample(datetime(2023, 1, 2, 0, 0), 3, 303, "state", 0),
75-
MetricSample(datetime(2023, 1, 2, 0, 30), 3, 303, "warning", "W1"),
76-
MetricSample(datetime(2023, 1, 2, 1, 0), 3, 303, "state", 1),
77-
MetricSample(datetime(2023, 1, 2, 1, 30), 3, 303, "error", "E1"),
74+
MetricSample(datetime(2023, 1, 2, 0, 0), 3, "303", "state", 0),
75+
MetricSample(datetime(2023, 1, 2, 0, 30), 3, "303", "warning", 10),
76+
MetricSample(datetime(2023, 1, 2, 1, 0), 3, "303", "state", 1),
77+
MetricSample(datetime(2023, 1, 2, 1, 30), 3, "303", "error", 20),
7878
],
7979
"alert_states": [1],
8080
"include_warnings": True,
8181
"expected_all_states": [
8282
# State transitions
8383
{
8484
"microgrid_id": 3,
85-
"component_id": 303,
85+
"component_id": "303",
8686
"state_type": "state",
8787
"state_value": 0,
8888
"start_time": datetime(2023, 1, 2, 0, 0),
8989
"end_time": datetime(2023, 1, 2, 1, 0),
9090
},
9191
{
9292
"microgrid_id": 3,
93-
"component_id": 303,
93+
"component_id": "303",
9494
"state_type": "state",
9595
"state_value": 1,
9696
"start_time": datetime(2023, 1, 2, 1, 0),
@@ -99,43 +99,43 @@
9999
# Warning transitions
100100
{
101101
"microgrid_id": 3,
102-
"component_id": 303,
102+
"component_id": "303",
103103
"state_type": "warning",
104-
"state_value": "W1",
104+
"state_value": 10,
105105
"start_time": datetime(2023, 1, 2, 0, 30),
106106
"end_time": None,
107107
},
108108
# Error transitions
109109
{
110110
"microgrid_id": 3,
111-
"component_id": 303,
111+
"component_id": "303",
112112
"state_type": "error",
113-
"state_value": "E1",
113+
"state_value": 20,
114114
"start_time": datetime(2023, 1, 2, 1, 30),
115115
"end_time": None,
116116
},
117117
],
118118
"expected_alert_records": [
119119
{
120120
"microgrid_id": 3,
121-
"component_id": 303,
121+
"component_id": "303",
122122
"state_type": "warning",
123-
"state_value": "W1",
123+
"state_value": 10,
124124
"start_time": datetime(2023, 1, 2, 0, 30),
125125
"end_time": None,
126126
},
127127
{
128128
"microgrid_id": 3,
129-
"component_id": 303,
129+
"component_id": "303",
130130
"state_type": "error",
131-
"state_value": "E1",
131+
"state_value": 20,
132132
"start_time": datetime(2023, 1, 2, 1, 30),
133133
"end_time": None,
134134
},
135135
# State alert
136136
{
137137
"microgrid_id": 3,
138-
"component_id": 303,
138+
"component_id": "303",
139139
"state_type": "state",
140140
"state_value": 1,
141141
"start_time": datetime(2023, 1, 2, 1, 0),

0 commit comments

Comments
 (0)