Skip to content

Commit

Permalink
remove Status.RPCServers endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
tgross committed Mar 15, 2023
1 parent 094d3ba commit 25d0361
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 87 deletions.
1 change: 0 additions & 1 deletion .semgrep/rpc_endpoint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ rules:
- pattern-not: '"CSIPlugin.List"'
- pattern-not: '"Status.Leader"'
- pattern-not: '"Status.Peers"'
- pattern-not: '"Status.RPCServers"'
- pattern-not: '"Status.Version"'
message: "RPC method $METHOD appears to be unauthenticated"
languages:
Expand Down
27 changes: 0 additions & 27 deletions nomad/status_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,33 +78,6 @@ func (s *Status) Peers(args *structs.GenericRequest, reply *[]string) error {
return nil
}

// RPCServers is used to get all the RPC server addresses in a region
func (s *Status) RPCServers(args *structs.GenericRequest, reply *structs.RPCServersResponse) error {
// note: we're intentionally throwing away any auth error here and only
// authenticate so that we can measure rate metrics
s.srv.Authenticate(s.ctx, args)
s.srv.MeasureRPCRate("status", structs.RateMetricList, args)

if args.Region == "" {
args.Region = s.srv.config.Region
}
if done, err := s.srv.forward("Status.RPCServers", args, args, reply); done {
return err
}

future := s.srv.raft.GetConfiguration()
if err := future.Error(); err != nil {
return err
}

for _, server := range future.Configuration().Servers {
if peer, ok := s.srv.localPeers[server.Address]; ok {
reply.Addresses = append(reply.Addresses, peer.RPCAddr.String())
}
}
return nil
}

// Members return the list of servers in a cluster that a particular server is
// aware of
func (s *Status) Members(args *structs.GenericRequest, reply *structs.ServerMembersResponse) error {
Expand Down
56 changes: 2 additions & 54 deletions nomad/status_endpoint_test.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
package nomad

import (
"fmt"
"net"
"testing"

msgpackrpc "github.com/hashicorp/net-rpc-msgpackrpc"
"github.com/shoenig/test/must"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/hashicorp/nomad/acl"
"github.com/hashicorp/nomad/ci"
"github.com/hashicorp/nomad/helper/uuid"
"github.com/hashicorp/nomad/nomad/mock"
"github.com/hashicorp/nomad/nomad/structs"
"github.com/hashicorp/nomad/testutil"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestStatusPing(t *testing.T) {
Expand Down Expand Up @@ -77,54 +73,6 @@ func TestStatusPeers(t *testing.T) {
}
}

func TestStatus_RPCServers(t *testing.T) {
ci.Parallel(t)

advAddr1 := "127.0.1.1:1234"
adv1, err := net.ResolveTCPAddr("tcp", advAddr1)
must.NoError(t, err)

s1, cleanupS1 := TestServer(t, func(c *Config) {
c.Region = "region1"
c.ClientRPCAdvertise = adv1
})
defer cleanupS1()

s2, cleanupS2 := TestServer(t, func(c *Config) {
c.Region = "region2"
})
defer cleanupS2()

// Join them together
s2Addr := fmt.Sprintf("127.0.0.1:%d", s2.config.SerfConfig.MemberlistConfig.BindPort)
n, err := s1.Join([]string{s2Addr})
must.NoError(t, err, must.Sprintf("Failed joining: %v (%d joined)", err, n))

codec := rpcClient(t, s1)

t.Run("own region", func(t *testing.T) {
arg := &structs.GenericRequest{
QueryOptions: structs.QueryOptions{Region: "region1"},
}
var resp *structs.RPCServersResponse
must.NoError(t, msgpackrpc.CallWithCodec(codec, "Status.RPCServers", arg, &resp))
must.NotNil(t, resp)
must.Len(t, 1, resp.Addresses)
must.Eq(t, advAddr1, resp.Addresses[0])
})

t.Run("other region", func(t *testing.T) {
arg := &structs.GenericRequest{
QueryOptions: structs.QueryOptions{Region: "region2"},
}
var resp *structs.RPCServersResponse
must.NoError(t, msgpackrpc.CallWithCodec(codec, "Status.RPCServers", arg, &resp))
must.NotNil(t, resp)
must.Len(t, 1, resp.Addresses)
must.Eq(t, s2.clientRpcAdvertise.String(), resp.Addresses[0])
})
}

func TestStatusMembers(t *testing.T) {
ci.Parallel(t)

Expand Down
5 changes: 0 additions & 5 deletions nomad/structs/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1171,11 +1171,6 @@ type PeriodicForceRequest struct {
WriteRequest
}

// RPCServersResponse contains the list of RPC addresses for servers in this region
type RPCServersResponse struct {
Addresses []string
}

// ServerMembersResponse has the list of servers in a cluster
type ServerMembersResponse struct {
ServerName string
Expand Down

0 comments on commit 25d0361

Please sign in to comment.