Files
seaweedfs/weed/server/master_grpc_server_cluster.go
T
Chris Lu 14bc6e5e4f servers: advertise the configured metricsPort to the master
Filer, S3 and broker report it on the KeepConnected registration, volume
servers in their heartbeat, and masters return their own in
GetMasterConfiguration. MasterClient gains SetMetricsPort so the eight
callers that have no metrics listener are untouched, and the volume
server takes it as a constructor argument because its heartbeat goroutine
starts there.

In combined "weed server" one metrics listener serves the whole shared
registry, so every component advertises the same port.
2026-09-14 23:32:32 -07:00

58 lines
1.7 KiB
Go

package weed_server
import (
"context"
"math/rand/v2"
"github.com/seaweedfs/seaweedfs/weed/cluster"
"github.com/seaweedfs/seaweedfs/weed/pb"
"github.com/seaweedfs/seaweedfs/weed/pb/master_pb"
)
func (ms *MasterServer) ListClusterNodes(ctx context.Context, req *master_pb.ListClusterNodesRequest) (*master_pb.ListClusterNodesResponse, error) {
resp := &master_pb.ListClusterNodesResponse{}
filerGroup := cluster.FilerGroupName(req.FilerGroup)
clusterNodes := ms.Cluster.ListClusterNode(filerGroup, req.ClientType)
clusterNodes = limitTo(clusterNodes, req.Limit)
for _, node := range clusterNodes {
resp.ClusterNodes = append(resp.ClusterNodes, &master_pb.ListClusterNodesResponse_ClusterNode{
Address: string(node.Address),
Version: node.Version,
CreatedAtNs: node.CreatedTs.UnixNano(),
DataCenter: string(node.DataCenter),
Rack: string(node.Rack),
MetricsPort: node.MetricsPort,
})
}
return resp, nil
}
func (ms *MasterServer) GetOneFiler(filerGroup cluster.FilerGroupName) pb.ServerAddress {
filers := ms.Cluster.ListClusterNode(filerGroup, cluster.FilerType)
if len(filers) > 0 {
return filers[rand.IntN(len(filers))].Address
}
return "localhost:8888"
}
func limitTo(nodes []*cluster.ClusterNode, limit int32) (selected []*cluster.ClusterNode) {
if limit <= 0 || len(nodes) < int(limit) {
return nodes
}
selectedSet := make(map[pb.ServerAddress]*cluster.ClusterNode)
for i := 0; i < int(limit)*3; i++ {
x := rand.IntN(len(nodes))
if _, found := selectedSet[nodes[x].Address]; found {
continue
}
selectedSet[nodes[x].Address] = nodes[x]
}
for _, node := range selectedSet {
selected = append(selected, node)
}
return
}