Repository: qdrant/qdrant
File: src/common/metrics.rs (Rust)

Code before:
                indexed_only_excluded.push(gauge(
                    vector_size as f64,
                    &[("id", &collection.id), ("vector", name)],
                ))
            }

            total_dead_replicas += collection
                .shards
                .iter()
                .flatten()
                .filter(|i| i.replicate_states.values().any(|state| !state.is_active()))
                .count();

            // Shard Transfers

            let mut incoming_transfers = 0;
            let mut outgoing_transfers = 0;

            if let Some(this_peer_id) = peer_id {
                for transfer in collection.transfers.iter().flatten() {
                    if transfer.to == this_peer_id {
                        incoming_transfers += 1;
                    } else if transfer.from == this_peer_id {
                        outgoing_transfers += 1;
                    }
                }
            }

            shard_transfers_in.push(gauge(
                f64::from(incoming_transfers),
                &[("id", &collection.id)],
            ));
            shard_transfers_out.push(gauge(
                f64::from(outgoing_transfers),
                &[("id", &collection.id)],
            ));
        }

        for snapshot_telemetry in self.snapshots.iter().flatten() {
            let id = &snapshot_telemetry.id;

            snapshots_recovery_running.push(gauge(
                snapshot_telemetry
                    .running_snapshot_recovery
                    .unwrap_or_default() as f64,
                &[("id", id)],
            ));
            snapshots_creation_running.push(gauge(
                snapshot_telemetry.running_snapshots.unwrap_or_default() as f64,
                &[("id", id)],
            ));

Review comment (bug):
There are some edge cases where the source and target is the same.

So in that case, let's count both.


```suggestion
                    if transfer.to == this_peer_id {
                        incoming_transfers += 1;
                    }
                    if transfer.from == this_peer_id {
                        outgoing_transfers += 1;
                    }
```

Code after:
                indexed_only_excluded.push(gauge(
                    vector_size as f64,
                    &[("id", &collection.id), ("vector", name)],
                ))
            }

            total_dead_replicas += collection
                .shards
                .iter()
                .flatten()
                .filter(|i| i.replicate_states.values().any(|state| !state.is_active()))
                .count();

            // Shard Transfers

            let mut incoming_transfers = 0;
            let mut outgoing_transfers = 0;

            if let Some(this_peer_id) = peer_id {
                for transfer in collection.transfers.iter().flatten() {
                    if transfer.to == this_peer_id {
                        incoming_transfers += 1;
                    }
                    if transfer.from == this_peer_id {
                        outgoing_transfers += 1;
                    }
                }
            }

            shard_transfers_in.push(gauge(
                f64::from(incoming_transfers),
                &[("id", &collection.id)],
            ));
            shard_transfers_out.push(gauge(
                f64::from(outgoing_transfers),
                &[("id", &collection.id)],
            ));
        }

        for snapshot_telemetry in self.snapshots.iter().flatten() {
            let id = &snapshot_telemetry.id;

            snapshots_recovery_running.push(gauge(
                snapshot_telemetry
                    .running_snapshot_recovery
                    .unwrap_or_default() as f64,
                &[("id", id)],
            ));
            snapshots_creation_running.push(gauge(
                snapshot_telemetry.running_snapshots.unwrap_or_default() as f64,
                &[("id", id)],