depot/packages/networking/ipfs-cluster/monitor/metrics/util.go

29 lines
576 B
Go
Raw Permalink Normal View History

2022-10-19 23:23:11 +03:00
package metrics
import (
"github.com/ipfs-cluster/ipfs-cluster/api"
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
}