Skip to content

Commit 21e113c

Browse files
committed
Add run strategies
Signed-off-by: Sylvain Hellegouarch <sh@defuze.org>
1 parent 6b6d83c commit 21e113c

15 files changed

+1489
-274
lines changed

CHANGELOG.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,28 @@
44

55
[Unreleased]: https://github.com/chaostoolkit/chaostoolkit-lib/compare/1.12.0...HEAD
66

7+
### Added
8+
9+
- Steady-state hypothesos runtime strategies can be now set to determine if the
10+
the hypothesis is executed before/after the method as usual (default behavior)
11+
or continously throughout the method too. Yo ucan also make it applied
12+
before or after only, or even only during the method. [#191][191]
13+
14+
[191]: https://github.com/chaostoolkit/chaostoolkit/pull/191
15+
716
### Changed
817

918
- Always pass all secrets to control hookpoints [#187][187]
19+
- Massive refactor of the `run_experiment` function so that it raises now events
20+
of where it is during the execution so that external plugins to the Chaos
21+
Toolkit can react and impact the run. This goes beyond mere controls and
22+
is advanced usage. Still, this is a public interface. [#178][178]
23+
In theory, this is an internal change only and the `run_experiment` function
24+
has not changed its API. However, this may have deep impact if you already
25+
depended on its internals.
1026

1127
[187]: https://github.com/chaostoolkit/chaostoolkit/issues/187
28+
[178]: https://github.com/chaostoolkit/chaostoolkit-lib/issues/178
1229

1330
## [1.12.0][] - 2020-08-17
1431

@@ -19,6 +36,12 @@
1936
- Added ways to override configuration and secrets from var files or passed to
2037
the chaostoolkit cli [chaostoolkit#175][].
2138

39+
### Changed
40+
41+
- Always ensure the [status][statuses] in the journal is one of
42+
the specified value, with a default to `"completed"`.
43+
44+
[statuses]: https://docs.chaostoolkit.org/reference/api/journal/#required-properties
2245

2346
[chaostoolkit#175]: https://github.com/chaostoolkit/chaostoolkit/issues/175
2447

@@ -80,6 +103,22 @@
80103
[168]: https://github.com/chaostoolkit/chaostoolkit-lib/issues/168
81104
[163]: https://github.com/chaostoolkit/chaostoolkit-lib/issues/163
82105

106+
### Added
107+
108+
- Refactored run of the experiment so that we can have multiple run strategies
109+
such as not running the steady-state hypothesis before or after the method
110+
but also one strategy so that the steady-state is continously applied
111+
during the method, with the option to bail the experiment as soon as it
112+
deviates. [#149][149]
113+
114+
### Changed
115+
116+
- Potentially breaking. The following functions have moved from
117+
`chaoslib.experiment` to `chaoslib.run`: `initialize_run_journal`,
118+
`apply_activities`, `apply_rollbacks`.
119+
120+
[149]: https://github.com/chaostoolkit/chaostoolkit/issues/149
121+
83122
### Changed
84123

85124
- Fix error on empty string variables call [#165][165]

chaoslib/caching.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
from logzero import logger
99

10-
from chaoslib.types import Activity, Experiment, Settings
10+
from chaoslib.types import Activity, Experiment, Settings, Schedule, Strategy
1111

1212

1313
__all__ = ["cache_activities", "clear_cache", "lookup_activity", "with_cache"]
@@ -50,7 +50,10 @@ def with_cache(f):
5050
"""
5151
@wraps(f)
5252
def wrapped(experiment: Experiment, settings: Settings = None,
53-
experiment_vars: Dict[str, Any] = None):
53+
experiment_vars: Dict[str, Any] = None,
54+
strategy: Strategy = Strategy.DEFAULT,
55+
schedule: Schedule = None,
56+
event_handlers: List['RunEventHandler'] = None):
5457
try:
5558
if experiment:
5659
cache_activities(experiment)
@@ -62,10 +65,14 @@ def wrapped(experiment: Experiment, settings: Settings = None,
6265

6366
if "settings" in sig.parameters:
6467
arguments["settings"] = settings
65-
6668
if "experiment_vars" in sig.parameters:
6769
arguments["experiment_vars"] = experiment_vars
68-
70+
if "strategy" in sig.parameters:
71+
arguments["strategy"] = strategy
72+
if "schedule" in sig.parameters:
73+
arguments["schedule"] = schedule
74+
if "event_handlers" in sig.parameters:
75+
arguments["event_handlers"] = event_handlers
6976
return f(**arguments)
7077
finally:
7178
clear_cache()

chaoslib/deprecation.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from chaoslib.activity import get_all_activities_in_experiment
77
from chaoslib.types import Experiment
88

9-
__all__ = ["warn_about_deprecated_features"]
9+
__all__ = ["warn_about_deprecated_features", "warn_about_moved_function"]
1010
DeprecatedDictArgsMessage = \
1111
"Process arguments should now be a list to keep the ordering "\
1212
"of the arguments. Dictionary arguments are deprecated for "\
@@ -58,3 +58,7 @@ def warn_about_deprecated_features(experiment: Experiment):
5858
warnings.warn(
5959
DeprecatedVaultMissingPathMessage, DeprecationWarning)
6060
logger.warning(DeprecatedVaultMissingPathMessage)
61+
62+
63+
def warn_about_moved_function(message: str):
64+
warnings.warn(message, DeprecationWarning, stacklevel=2)

0 commit comments

Comments
 (0)