예제 #1
0
def validate_sli(obj: dict, sli: dict, act: Action):
    if 'name' not in sli or not sli['name']:
        act.error('Field "name" is missing in SLI definition.')

    if 'unit' not in sli or not sli['unit']:
        act.error('Field "unit" is missing in SLI definition.')

    if 'source' not in sli:
        act.error('Field "source" is missing in SLI definition.')

    source = sli.get('source', {})

    required = {'aggregation', 'check_id', 'keys'}
    missing = set(required) - set(source.keys())

    # checking SLI source structure
    if missing:
        act.error(
            'Fields {} are missing in SLI source definition.'.format(missing))

    if 'keys' not in missing and not source.get('keys'):
        act.error('Field "keys" value is missing in SLI source definition.')

    # Checking aggregation sanity
    aggregation = source.get('aggregation', {})
    agg_type = aggregation.get('type')
    if 'aggregation' not in missing:
        if not agg_type or agg_type not in AGG_TYPES:
            act.error(
                'Field "type" is missing in SLI source aggregation. Valid values are: {}'
                .format(AGG_TYPES))

        if agg_type == 'weighted' and not aggregation.get('weight_keys'):
            act.error(
                'Field "weight_keys" is missing in SLI source aggregation for type "weighted".'
            )

    if 'check_id' not in missing and 'keys' not in missing and source['keys']:
        try:
            validate_sli_source(obj, source)
        except SLRClientError as e:
            act.fatal_error(e)
예제 #2
0
def validate_slo(slo: dict, act: Action):
    if not slo.get('title'):
        act.error('Field "title" is missing in SLO definition.')

    for target in slo.get('targets', []):
        validate_target(target, act)