19b1124999
Issue #572 exposes metrics but they carry the peer ID in binary. This was ok with our internal codecs but it doesn't seem to work very well with json, and makes the output format unusable. This makes the Metric.Peer field a string. Additinoally, fixes calling the command without arguments and displaying the date in the right format. License: MIT Signed-off-by: Hector Sanjuan <code@hector.link>
29 lines
563 B
Go
29 lines
563 B
Go
package metrics
|
|
|
|
import (
|
|
"github.com/ipfs/ipfs-cluster/api"
|
|
|
|
peer "github.com/libp2p/go-libp2p-peer"
|
|
)
|
|
|
|
// 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
|
|
}
|