Ejemplo n.º 1
0
def load_slo_samples(folder_path, **ctx):
    """List and load all SLO samples from folder path.

    Args:
        folder_path (str): Folder path to load SLO configs from.
        ctx (dict): Context for env variables.

    Returns:
        list: List of loaded SLO configs.
    """
    return [
        load_sample(filename, **ctx)
        for filename in list_slo_configs(f'{SAMPLE_DIR}/{folder_path}')
    ]
Ejemplo n.º 2
0
def cli(args):
    """Main CLI function.

    Args:
        args (Namespace): Argparsed CLI parameters.

    Returns:
        dict: Dict of all reports indexed by config file path.
    """
    utils.setup_logging()
    export = args.export
    delete = args.delete
    timestamp = args.timestamp
    start = time.time()

    # Load error budget policy
    LOGGER.debug(
        f"Loading Error Budget config from {args.error_budget_policy}")
    eb_path = utils.normalize(args.error_budget_policy)
    eb_policy = utils.parse_config(eb_path)

    # Parse SLO folder for configs
    slo_configs = utils.list_slo_configs(args.slo_config)
    if not slo_configs:
        LOGGER.error(f'No SLO configs found in SLO folder {args.slo_config}.')

    # Load SLO configs and compute SLO reports
    all_reports = {}
    for path in slo_configs:
        slo_config_name = path.split("/")[-1]
        LOGGER.debug(f'Loading SLO config "{slo_config_name}"')
        slo_config = utils.parse_config(path)
        reports = compute(slo_config,
                          eb_policy,
                          timestamp=timestamp,
                          do_export=export,
                          delete=delete)
        all_reports[path] = reports
    end = time.time()
    duration = round(end - start, 1)
    LOGGER.info(f'Run summary | SLO Configs: {len(slo_configs)} | '
                f'Error Budget Policy Steps: {len(eb_policy)} | '
                f'Total: {len(slo_configs) * len(eb_policy)} | '
                f'Duration: {duration}s')
    return all_reports