chaostoolkit / chaostoolkit-addons

Chaos Toolkit addons (tolerances, controls) that can benefit everyone

Home Page:https://chaostoolkit.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

control for loading configurations from settings.yaml before each chaos run

venkivijay opened this issue · comments

I am not sure if there is any standard way for defining configurations that would be used by multiple chaos experiments. For example, the aws chaos extension requires to define aws_region in each experiment. I wanted this value to be dynamic so I defined it in the configuration block of each experiment. Now that the number of experiments is growing, it is getting real difficult to manage this parameter on the experiment level. I came up with a solution by writing a control which would load the configurations defined on the settings.yaml file before each chaos run.

  • Few things to note
    • Variable that is defined on the settings.yaml file will be used by default
    • Variable defined in experiment top level will override the settings.yaml variable
    • Variable passed from the command line argument chaos run --var key=value will override the experiment defined variable
def configure_control(configuration: Configuration = None,
                      secrets: Secrets = None, settings: Settings = None,
                      experiment: Experiment = None):
    """
    Load configuration values from settings file
    Settings value can be overwritten by defining it in the experiment
    Usage: On settings file
        controls:
        global_values:
            provider:
            type: python
            module: custommodule.utils.control
    """
    settings_config = settings['configuration']
    for (setting_key, setting_value) in settings_config.items():
        if (configuration.get(setting_key)):
            logger.info("Using %s:%s from local experiment",setting_key,setting_value)
        else:
            logger.info("Using %s:%s from settings file",setting_key,setting_value)
            configuration[setting_key] = setting_value