Skip to content

Commit d8b8260

Browse files
authored
Revamp config management (frequenz-floss#1134)
This pull request adds a new `ConfigManager` class that takes care of the *client-side* of the `ConfigManagingActor`, providing the common tasks users of the config system need to do. The class owns the config channel and provides a convenient method to get new receivers that validate the configuration using a `dataclass` as a `marshmallow` schema, and allow filtering to receive only configuration for a specific key. The receiver also reports errors when the configuration can't be properly loaded, and avoid spurious updates when the configuration didn't change compared to the previous one. The manager also takes care of instantiating both the `ConfigManagingActor` and the `LoggingConfigUpdatingActor` and provides a utility function to wait for the first configuration to be received.
2 parents fcb7de4 + 4c87e6a commit d8b8260

File tree

11 files changed

+1582
-115
lines changed

11 files changed

+1582
-115
lines changed

RELEASE_NOTES.md

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## Summary
44

5-
<!-- Here goes a general summary of what this release is about -->
5+
This release includes a new `ConfigManager` class to simplify managing the configuration, and ships other improvements and fixes to the config system in general.
66

77
## Upgrading
88

@@ -11,7 +11,9 @@
1111
* `LoggingConfigUpdater`
1212

1313
+ Renamed to `LoggingConfigUpdatingActor` to follow the actor naming convention.
14-
+ Make all arguments to the constructor keyword-only.
14+
+ The actor must now be constructed using a `ConfigManager` instead of a receiver.
15+
+ Make all arguments to the constructor keyword-only, except for the `config_manager` argument.
16+
+ If the configuration is removed, the actor will now load back the default configuration.
1517

1618
* `LoggingConfig`
1719

@@ -31,12 +33,30 @@
3133
+ The `base_schema` argument is now keyword-only.
3234
+ The arguments forwarded to `marshmallow.Schema.load()` now must be passed explicitly via the `marshmallow_load_kwargs` argument, as a `dict`, to improve the type-checking.
3335

36+
* `ConfigManagingActor`: Raise a `ValueError` if the `config_files` argument an empty sequence.
37+
3438
## New Features
3539

36-
- `LoggingConfigUpdatingActor`
40+
- `frequenz.sdk.config`
41+
42+
- Logging was improved in general.
43+
44+
- Added documentation and user guide.
45+
46+
- `LoggingConfigUpdatingActor`
3747

38-
* Added a new `name` argument to the constructor to be able to override the actor's name.
48+
* Added a new `name` argument to the constructor to be able to override the actor's name.
49+
50+
- `ConfigManager`: Added a class to simplify managing the configuration. It takes care of instantiating the config actors and provides a convenient method for creating receivers with a lot of common functionality.
51+
52+
- `BaseConfigSchema`: Added a `marshmallow` base `Schema` that includes custom fields for `frequenz-quantities`. In the futute more commonly used fields might be added.
53+
54+
- `wait_for_first()`: Added a function to make it easy to wait for the first configuration to be received with a timeout.
55+
56+
- `ConfigManagingActor`: Allow passing a single configuration file.
3957

4058
## Bug Fixes
4159

4260
- Fix a bug in `BackgroundService` where it won't try to `self.cancel()` and `await self.wait()` if there are no internal tasks. This prevented to properly implement custom stop logic without having to redefine the `stop()` method too.
61+
62+
- Fix a bug where if a string was passed to the `ConfigManagingActor` it would be interpreted as a sequence of 1 character strings.

docs/user-guide/config.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Configuration
2+
3+
::: frequenz.sdk.config
4+
options:
5+
members: []
6+
show_bases: false
7+
show_root_heading: false
8+
show_root_toc_entry: false
9+
show_source: false

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ plugins:
119119
- https://docs.python.org/3/objects.inv
120120
- https://frequenz-floss.github.io/frequenz-channels-python/v1.1/objects.inv
121121
- https://frequenz-floss.github.io/frequenz-client-microgrid-python/v0.5/objects.inv
122+
- https://frequenz-floss.github.io/frequenz-quantities-python/v1/objects.inv
122123
- https://lovasoa.github.io/marshmallow_dataclass/html/objects.inv
123124
- https://marshmallow.readthedocs.io/en/stable/objects.inv
124125
- https://networkx.org/documentation/stable/objects.inv

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ dependencies = [
3030
# changing the version
3131
# (plugins.mkdocstrings.handlers.python.import)
3232
"frequenz-client-microgrid >= 0.6.0, < 0.7.0",
33-
"frequenz-channels >= 1.2.0, < 2.0.0",
34-
"frequenz-quantities >= 1.0.0rc3, < 2.0.0",
33+
"frequenz-channels >= 1.4.0, < 2.0.0",
34+
"frequenz-quantities[marshmallow] >= 1.0.0, < 2.0.0",
3535
"networkx >= 2.8, < 4",
3636
"numpy >= 1.26.4, < 2",
3737
"typing_extensions >= 4.6.1, < 5",

0 commit comments

Comments
 (0)