(conn)
return rows
Return metrics for each shard of each `table` in each `db`.
Return metrics for each shard of each `table` in each `db`.
Return metrics for each shard of each table in each db .
def get_shard_metrics(conn):
    # type: (rethinkdb.net.Connection) -> List[tuple]
    """
    Return metrics for each shard of each `table` in each `db`.
    """
    results = (
        # Grab table statuses with shards info.
        TABLE_STATUS.pluck('id', {'shards': ['replicas', 'primary_replicas']})
        # table_status -> [shard1, shard2, ...]
        .concat_map(lambda row: row['shards'].map(lambda shard: row.merge(shard))).without('shards')
        # Attach table info to shards
        .merge({'table': TABLE_CONFIG.get(r.row['id']).pluck('id', 'db', 'name')})
    ).run(conn)

    rows = []  # type: List[tuple]
    for _, shards in itertools.groupby(results, lambda r: r['table']['name']):
        for shard_index, shard in enumerate(shards):
            row = (
                shard_index,
                shard['table']['name'],
                shard['table']['db'],
                len(shard['replicas']),
                len(shard['primary_replicas']),
            )
            rows.append(row)

    return rows
def get_shard_metrics ( conn ) : # type: (rethinkdb.net.Connection) -> List[tuple] results = ( # Grab table statuses with shards info. TABLE_STATUS . pluck ( 'id' , { 'shards' : [ 'replicas' , 'primary_replicas' ] } ) # table_status -> [shard1, shard2, ...] . concat_map ( lambda row : row [ 'shards' ] . map ( lambda shard : row . merge ( shard ) ) ) . without ( 'shards' ) # Attach table info to shards . merge ( { 'table' : TABLE_CONFIG . get ( r . row [ 'id' ] ) . pluck ( 'id' , 'db' , 'name' ) } ) ) . run ( conn ) rows = [ ] # type: List[tuple] for _ , shards in itertools . groupby ( results , lambda r : r [ 'table' ] [ 'name' ] ) : for shard_index , shard in enumerate ( shards ) : row = ( shard_index , shard [ 'table' ] [ 'name' ] , shard [ 'table' ] [ 'db' ] , len ( shard [ 'replicas' ] ) , len ( shard [ 'primary_replicas' ] ) , ) rows . append ( row ) return rows