(conn)
return rows
Return metrics about issues detected by RethinkDB.
Return metrics about issues detected by RethinkDB.
Return metrics about issues detected by RethinkDB .
def get_current_issues_metrics(conn):
    # type: (rethinkdb.net.Connection) -> List[tuple]
    """
    Return metrics about issues detected by RethinkDB.
    """
    current_issues = CURRENT_ISSUES.pluck('type', 'critical')
    # NOTE: Need to `.run()` these separately because ReQL does not support putting grouped data in raw
    # expressions yet. See: https://github.com/rethinkdb/rethinkdb/issues/2067
    issues_by_type = current_issues.group('type').count().run(conn)  # type: Dict[str, int]
    critical_issues_by_type = (
        current_issues.filter(r.row['critical']).group('type').count().run(conn)
    )  # type: Dict[str, int]

    # Join manually by job type. Note that groups may not have all job types (eg if there are 0 issues for that type).
    merged = collections.defaultdict(lambda: {'issues': 0, 'critical_issues': 0})  # type: Dict[str, Dict[str, int]]
    for job_type, issues in issues_by_type.items():
        merged[job_type]['issues'] = issues
    for job_type, critical_issues in critical_issues_by_type.items():
        merged[job_type]['critical_issues'] = critical_issues

    rows = []  # type: List[tuple]
    for job_type, document in merged.items():
        row = (
            job_type,
            document['issues'],
            document['critical_issues'],
        )
        rows.append(row)

    return rows
def get_current_issues_metrics ( conn ) : # type: (rethinkdb.net.Connection) -> List[tuple] current_issues = CURRENT_ISSUES . pluck ( 'type' , 'critical' ) # NOTE: Need to `.run()` these separately because ReQL does not support putting grouped data in raw # expressions yet. See: https://github.com/rethinkdb/rethinkdb/issues/2067 issues_by_type = current_issues . group ( 'type' ) . count ( ) . run ( conn ) # type: Dict[str, int] critical_issues_by_type = ( current_issues . filter ( r . row [ 'critical' ] ) . group ( 'type' ) . count ( ) . run ( conn ) ) # type: Dict[str, int] # Join manually by job type. Note that groups may not have all job types (eg if there are 0 issues for that type). merged = collections . defaultdict ( lambda : { 'issues' : 0 , 'critical_issues' : 0 } ) # type: Dict[str, Dict[str, int]] for job_type , issues in issues_by_type . items ( ) : merged [ job_type ] [ 'issues' ] = issues for job_type , critical_issues in critical_issues_by_type . items ( ) : merged [ job_type ] [ 'critical_issues' ] = critical_issues rows = [ ] # type: List[tuple] for job_type , document in merged . items ( ) : row = ( job_type , document [ 'issues' ] , document [ 'critical_issues' ] , ) rows . append ( row ) return rows