roles/collect-logs/library/ara_influxdb.py
def translate(measure, json_data, only_ok):
    '''Create data to send to InfluxDB server in format SCHEME

    Fields keys are taken from ARA data according to task names.

    :param measure: name of InfluxDB measurement
    :param json_data: JSON data with tasks and times
    :param: only_ok: boolean, where to count only successful tasks
    :return: full InfluxDB scheme
    '''

    DATA['measure'] = measure
    if os.environ.get('START_JOB_TIME'):
        DATA['job_duration'] = int(
            datetime.datetime.utcnow().strftime("%s")) - int(
            os.environ.get('START_JOB_TIME'))
    if os.environ.get('ZUUL_PIPELINE'):
        if 'check' in os.environ['ZUUL_PIPELINE']:
            DATA['pipeline'] = 'check'
        elif 'gate' in os.environ['ZUUL_PIPELINE']:
            DATA['pipeline'] = 'gate'
        elif 'periodic' in os.environ['ZUUL_PIPELINE']:
            DATA['pipeline'] = 'periodic'
    if (os.environ.get('DEVSTACK_GATE_TIMEOUT') and
            os.environ.get('REMAINING_TIME')):
        DATA['zuul_host_prepare'] = (int(
            os.environ['DEVSTACK_GATE_TIMEOUT']) - int(
            os.environ['REMAINING_TIME'])) * 60

    data = ast.literal_eval(json_data)
    # create a dictionary with durations for each task
    # every task could run multiple times
    times_dict = {}
    for task in data:
        if not only_ok or task['Status'] in ['changed', 'ok']:
            name = task['Name']
            if name in times_dict:
                times_dict[name].append(task['Duration'])
            else:
                times_dict[name] = [task['Duration']]
    # because of some tasks are executed multiple times we need to count
    # all of them and make summary of all durations
    for i in times_dict:
        times_dict[i] = sum([task_length(t) for t in times_dict[i]])
    # replace tasks lists in DATA with tasks durations
    for i in DATA:
        if isinstance(DATA[i], list):
            DATA[i] = sum([int(times_dict.get(k, 0)) for k in DATA[i]])
    return SCHEME.format(**DATA)
Create data to send to InfluxDB server in format SCHEME

    Fields keys are taken from ARA data according to task names.

    :param measure: name of InfluxDB measurement
    :param json_data: JSON data with tasks and times
    :param: only_ok: boolean, where to count only successful tasks
    :return: full InfluxDB scheme
    
Create data to send to InfluxDB server in format SCHEME
Fields keys are taken from ARA data according to task names.


Create data to send to InfluxDB server in format SCHEME Fields keys are taken from ARA data according to task names .
def translate(measure, json_data, only_ok):
    DATA['measure'] = measure
    if os.environ.get('START_JOB_TIME'):
        DATA['job_duration'] = int(
            datetime.datetime.utcnow().strftime("%s")) - int(
            os.environ.get('START_JOB_TIME'))
    if os.environ.get('ZUUL_PIPELINE'):
        if 'check' in os.environ['ZUUL_PIPELINE']:
            DATA['pipeline'] = 'check'
        elif 'gate' in os.environ['ZUUL_PIPELINE']:
            DATA['pipeline'] = 'gate'
        elif 'periodic' in os.environ['ZUUL_PIPELINE']:
            DATA['pipeline'] = 'periodic'
    if (os.environ.get('DEVSTACK_GATE_TIMEOUT') and
            os.environ.get('REMAINING_TIME')):
        DATA['zuul_host_prepare'] = (int(
            os.environ['DEVSTACK_GATE_TIMEOUT']) - int(
            os.environ['REMAINING_TIME'])) * 60
    data = ast.literal_eval(json_data)
    times_dict = {}
    for task in data:
        if not only_ok or task['Status'] in ['changed', 'ok']:
            name = task['Name']
            if name in times_dict:
                times_dict[name].append(task['Duration'])
            else:
                times_dict[name] = [task['Duration']]
    for i in times_dict:
        times_dict[i] = sum([task_length(t) for t in times_dict[i]])
    for i in DATA:
        if isinstance(DATA[i], list):
            DATA[i] = sum([int(times_dict.get(k, 0)) for k in DATA[i]])
    return SCHEME.format(**DATA)
def translate ( measure , json_data , only_ok ) : DATA [ 'measure' ] = measure if os . environ . get ( 'START_JOB_TIME' ) : DATA [ 'job_duration' ] = int ( datetime . datetime . utcnow ( ) . strftime ( "%s" ) ) - int ( os . environ . get ( 'START_JOB_TIME' ) ) if os . environ . get ( 'ZUUL_PIPELINE' ) : if 'check' in os . environ [ 'ZUUL_PIPELINE' ] : DATA [ 'pipeline' ] = 'check' elif 'gate' in os . environ [ 'ZUUL_PIPELINE' ] : DATA [ 'pipeline' ] = 'gate' elif 'periodic' in os . environ [ 'ZUUL_PIPELINE' ] : DATA [ 'pipeline' ] = 'periodic' if ( os . environ . get ( 'DEVSTACK_GATE_TIMEOUT' ) and os . environ . get ( 'REMAINING_TIME' ) ) : DATA [ 'zuul_host_prepare' ] = ( int ( os . environ [ 'DEVSTACK_GATE_TIMEOUT' ] ) - int ( os . environ [ 'REMAINING_TIME' ] ) ) * 60 data = ast . literal_eval ( json_data ) times_dict = { } for task in data : if not only_ok or task [ 'Status' ] in [ 'changed' , 'ok' ] : name = task [ 'Name' ] if name in times_dict : times_dict [ name ] . append ( task [ 'Duration' ] ) else : times_dict [ name ] = [ task [ 'Duration' ] ] for i in times_dict : times_dict [ i ] = sum ( [ task_length ( t ) for t in times_dict [ i ] ] ) for i in DATA : if isinstance ( DATA [ i ] , list ) : DATA [ i ] = sum ( [ int ( times_dict . get ( k , 0 ) ) for k in DATA [ i ] ] ) return SCHEME . format ( ** DATA )
Create data to send to InfluxDB server in format SCHEME
Fields keys are taken from ARA data according to task names.
Create data to send to InfluxDB server in format SCHEME Fields keys are taken from ARA data according to task names .
'''Create data to send to InfluxDB server in format SCHEME

    Fields keys are taken from ARA data according to task names.

    :param measure: name of InfluxDB measurement
    :param json_data: JSON data with tasks and times
    :param: only_ok: boolean, where to count only successful tasks
    :return: full InfluxDB scheme
    ''' # create a dictionary with durations for each task # every task could run multiple times # because of some tasks are executed multiple times we need to count # all of them and make summary of all durations # replace tasks lists in DATA with tasks durations
measure
json_data
only_ok