Esempio n. 1
0
def process_metrics_parameters(request_params):
    """Processes the request's querystring arguments to pass to a view function
    """
    start = process_time_parameter(request_params, 'start')
    end = process_time_parameter(request_params, 'end')

    if not start and not end:
        raise e.InvalidParameters(errors=['start and end are required'])

    interval = request_params.get('interval')
    if interval:
        try:
            interval = parse_interval(interval)
        except:
            raise e.InvalidParameters(
                errors=['"%s" is an invalid interval' % interval])

    order = request_params.get('order', 'desc')

    filters = {}
    for key in request_params.keys():
        val = request_params[key]
        if key not in RESERVED_PARAMETERS:
            if val == 'true' or val == 'false':
                val = val == 'true'
            filters[key] = val

    return start, end, interval, order, filters
Esempio n. 2
0
def test_parse_interval():
    assert parse_interval('1s') == timedelta(seconds=1)
    assert parse_interval('1m') == timedelta(minutes=1)
    assert parse_interval('1h') == timedelta(hours=1)
    assert parse_interval('24h') == timedelta(hours=24)
    assert parse_interval('1d') == timedelta(days=1)