2022-10-19 23:23:11 +03:00
|
|
|
package metrics
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/ipfs-cluster/ipfs-cluster/api"
|
|
|
|
|
2022-12-18 21:15:13 +02:00
|
|
|
peer "github.com/libp2p/go-libp2p/core/peer"
|
2022-10-19 23:23:11 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
// PeersetFilter removes all metrics not belonging to the given
|
|
|
|
// peerset
|
|
|
|
func PeersetFilter(metrics []api.Metric, peerset []peer.ID) []api.Metric {
|
|
|
|
peerMap := make(map[peer.ID]struct{})
|
|
|
|
for _, pid := range peerset {
|
|
|
|
peerMap[pid] = struct{}{}
|
|
|
|
}
|
|
|
|
|
|
|
|
filtered := make([]api.Metric, 0, len(metrics))
|
|
|
|
|
|
|
|
for _, metric := range metrics {
|
|
|
|
_, ok := peerMap[metric.Peer]
|
|
|
|
if !ok {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
filtered = append(filtered, metric)
|
|
|
|
}
|
|
|
|
|
|
|
|
return filtered
|
|
|
|
}
|