admin: show the right master ports when -port.grpc is not port+10000 (#12570)

* admin: take master HTTP ports from raft member names

The masters page and dashboard turned each raft member's gRPC address
into an HTTP address by subtracting 10000 from the port, so masters with
a custom -port.grpc showed wrong or negative ports. Raft members are
named after their master address, which carries the HTTP port; use it
and keep the old derivation only for names that are not addresses.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* admin: test raft member address mapping

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Chris LuandClaude Opus 5.5 authored and GitHub committed 2026-11-11 15:22:29 -08:00
1 parent a0f95e16bc
commit 3f557b73c8
3 files changed
+42 -3

No files matched your search

+13 -1
View File
@@ -12,6 +12,7 @@ import (
"github.com/seaweedfs/seaweedfs/weed/iam"
"github.com/seaweedfs/seaweedfs/weed/pb"
"github.com/seaweedfs/seaweedfs/weed/pb/master_pb"
"github.com/seaweedfs/seaweedfs/weed/util"
)
// Access key status constants
@@ -290,6 +291,17 @@ func (s *AdminServer) ShowOverview(w http.ResponseWriter, r *http.Request) {
writeJSON(w, http.StatusOK, topology)
}
// raftMasterHttpAddress returns a raft member's HTTP address. Members are
// named after their master address, while the raft address only carries the
// gRPC port, which is not always the HTTP port + 10000.
func raftMasterHttpAddress(server *master_pb.RaftListClusterServersResponse_ClusterServers) string {
httpAddress := pb.ServerAddress(server.Id).ToHttpAddress()
if _, port, err := util.ParseHostPort(httpAddress); err == nil && port > 0 && port < 65536 {
return httpAddress
}
return pb.GrpcAddressToServerAddress(server.Address)
}
// getMasterNodesStatus returns the full set of master nodes in the cluster.
// It prefers the authoritative raft membership (RaftListClusterServers) and
// falls back to the currently-connected master if the raft call fails, so the
@@ -313,7 +325,7 @@ func (s *AdminServer) getMasterNodesStatus() []MasterNode {
glog.Warningf("skip master with invalid raft address %q: %v", server.Address, splitErr)
continue
}
httpAddress := pb.GrpcAddressToServerAddress(server.Address)
httpAddress := raftMasterHttpAddress(server)
if httpAddress == "" {
glog.Warningf("skip master with invalid raft address %q", server.Address)
continue
+28
View File
@@ -0,0 +1,28 @@
package dash
import (
"testing"
"github.com/seaweedfs/seaweedfs/weed/pb/master_pb"
)
func TestRaftMasterHttpAddress(t *testing.T) {
tests := []struct {
name, id, address, want string
}{
{"goraft names members by full address", "127.101.0.1:11111.11112", "127.101.0.1:11112", "127.101.0.1:11111"},
{"hashicorp names members by http address", "127.102.0.1:2222", "127.102.0.1:3333", "127.102.0.1:2222"},
{"default ports", "10.0.0.1:9333", "10.0.0.1:19333", "10.0.0.1:9333"},
{"ipv6", "[::1]:2222.3333", "[::1]:3333", "[::1]:2222"},
{"id that is not an address", "master-a", "10.0.0.2:19333", "10.0.0.2:9333"},
{"id without a valid port", "10.0.0.3:0", "10.0.0.3:19334", "10.0.0.3:9334"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := raftMasterHttpAddress(&master_pb.RaftListClusterServersResponse_ClusterServers{Id: tt.id, Address: tt.address})
if got != tt.want {
t.Errorf("raftMasterHttpAddress(%q, %q) = %q, want %q", tt.id, tt.address, got, tt.want)
}
})
}
}
+1 -2
View File
@@ -1371,8 +1371,7 @@ func (s *AdminServer) GetClusterMasters() (*ClusterMastersData, error) {
// Process each raft server
for _, server := range resp.ClusterServers {
// Raft stores gRPC addresses, convert to HTTP address
httpAddress := pb.GrpcAddressToServerAddress(server.Address)
httpAddress := raftMasterHttpAddress(server)
if httpAddress == "" {
continue
}