Skip to content

Commit

Permalink
Rename PeerName to Peer on prepared queries and exported services (
Browse files Browse the repository at this point in the history
  • Loading branch information
erichaberkorn authored Oct 4, 2022
1 parent f2d42f9 commit 1b56544
Show file tree
Hide file tree
Showing 32 changed files with 141 additions and 138 deletions.
3 changes: 3 additions & 0 deletions .changelog/14854.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:breaking-change
peering: Rename `PeerName` to `Peer` on prepared queries and exported services.
```
14 changes: 7 additions & 7 deletions agent/consul/internal_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3334,19 +3334,19 @@ func TestInternal_ExportedPeeredServices_ACLEnforcement(t *testing.T) {
{
Name: "web",
Consumers: []structs.ServiceConsumer{
{PeerName: "peer-1"},
{Peer: "peer-1"},
},
},
{
Name: "db",
Consumers: []structs.ServiceConsumer{
{PeerName: "peer-2"},
{Peer: "peer-2"},
},
},
{
Name: "api",
Consumers: []structs.ServiceConsumer{
{PeerName: "peer-1"},
{Peer: "peer-1"},
},
},
},
Expand Down Expand Up @@ -3405,7 +3405,7 @@ func TestInternal_ExportedPeeredServices_ACLEnforcement(t *testing.T) {
`
service "web" { policy = "read" }
service "api" { policy = "read" }
service "db" { policy = "deny" }
service "db" { policy = "deny" }
`),
expect: map[string]structs.ServiceList{
"peer-1": {
Expand Down Expand Up @@ -3514,19 +3514,19 @@ func TestInternal_ExportedServicesForPeer_ACLEnforcement(t *testing.T) {
{
Name: "web",
Consumers: []structs.ServiceConsumer{
{PeerName: "peer-1"},
{Peer: "peer-1"},
},
},
{
Name: "db",
Consumers: []structs.ServiceConsumer{
{PeerName: "peer-2"},
{Peer: "peer-2"},
},
},
{
Name: "api",
Consumers: []structs.ServiceConsumer{
{PeerName: "peer-1"},
{Peer: "peer-1"},
},
},
},
Expand Down
14 changes: 7 additions & 7 deletions agent/consul/leader_peering_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ func TestLeader_PeeringSync_Lifecycle_UnexportWhileDown(t *testing.T) {
Services: []structs.ExportedService{
{
Name: "foo",
Consumers: []structs.ServiceConsumer{{PeerName: "my-peer-dialer"}},
Consumers: []structs.ServiceConsumer{{Peer: "my-peer-dialer"}},
},
},
},
Expand Down Expand Up @@ -1014,7 +1014,7 @@ func TestLeader_Peering_ImportedExportedServicesCount(t *testing.T) {
Name: structs.WildcardSpecifier,
Consumers: []structs.ServiceConsumer{
{
PeerName: "my-peer-s2",
Peer: "my-peer-s2",
},
},
},
Expand Down Expand Up @@ -1042,15 +1042,15 @@ func TestLeader_Peering_ImportedExportedServicesCount(t *testing.T) {
Name: "a-service",
Consumers: []structs.ServiceConsumer{
{
PeerName: "my-peer-s2",
Peer: "my-peer-s2",
},
},
},
{
Name: "b-service",
Consumers: []structs.ServiceConsumer{
{
PeerName: "my-peer-s2",
Peer: "my-peer-s2",
},
},
},
Expand All @@ -1069,7 +1069,7 @@ func TestLeader_Peering_ImportedExportedServicesCount(t *testing.T) {
Name: "a-service",
Consumers: []structs.ServiceConsumer{
{
PeerName: "my-peer-s2",
Peer: "my-peer-s2",
},
},
},
Expand All @@ -1088,15 +1088,15 @@ func TestLeader_Peering_ImportedExportedServicesCount(t *testing.T) {
Name: "a-service",
Consumers: []structs.ServiceConsumer{
{
PeerName: "my-peer-s2",
Peer: "my-peer-s2",
},
},
},
{
Name: "c-service",
Consumers: []structs.ServiceConsumer{
{
PeerName: "my-peer-s2",
Peer: "my-peer-s2",
},
},
},
Expand Down
2 changes: 1 addition & 1 deletion agent/consul/prepared_query/walk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func TestWalk_ServiceQuery(t *testing.T) {
".Tags[0]:tag1",
".Tags[1]:tag2",
".Tags[2]:tag3",
".PeerName:",
".Peer:",
}
expected = append(expected, entMetaWalkFields...)
sort.Strings(expected)
Expand Down
12 changes: 6 additions & 6 deletions agent/consul/prepared_query_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ func (p *PreparedQuery) execute(query *structs.PreparedQuery,
f = state.CheckConnectServiceNodes
}

_, nodes, err := f(nil, query.Service.Service, &query.Service.EnterpriseMeta, query.Service.PeerName)
_, nodes, err := f(nil, query.Service.Service, &query.Service.EnterpriseMeta, query.Service.Peer)
if err != nil {
return err
}
Expand Down Expand Up @@ -571,7 +571,7 @@ func (p *PreparedQuery) execute(query *structs.PreparedQuery,
reply.DNS = query.DNS

// Stamp the result with its this datacenter or peer.
if peerName := query.Service.PeerName; peerName != "" {
if peerName := query.Service.Peer; peerName != "" {
reply.PeerName = peerName
reply.Datacenter = ""
} else {
Expand Down Expand Up @@ -756,7 +756,7 @@ func queryFailover(q queryServer, query *structs.PreparedQuery,
}
}

if target.PeerName != "" {
if target.Peer != "" {
targets = append(targets, target)
}
}
Expand All @@ -777,9 +777,9 @@ func queryFailover(q queryServer, query *structs.PreparedQuery,

// Reset PeerName because it may have been set by a previous failover
// target.
query.Service.PeerName = target.PeerName
query.Service.Peer = target.Peer
dc := target.Datacenter
if target.PeerName != "" {
if target.Peer != "" {
dc = q.GetLocalDC()
}

Expand All @@ -798,7 +798,7 @@ func queryFailover(q queryServer, query *structs.PreparedQuery,
if err = q.ExecuteRemote(remote, reply); err != nil {
q.GetLogger().Warn("Failed querying for service in datacenter",
"service", query.Service.Service,
"peerName", query.Service.PeerName,
"peerName", query.Service.Peer,
"datacenter", dc,
"error", err,
)
Expand Down
16 changes: 8 additions & 8 deletions agent/consul/prepared_query_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func TestPreparedQuery_Apply(t *testing.T) {

// Fix that and ensure Targets and NearestN cannot be set at the same time.
query.Query.Service.Failover.NearestN = 1
query.Query.Service.Failover.Targets = []structs.QueryFailoverTarget{{PeerName: "peer"}}
query.Query.Service.Failover.Targets = []structs.QueryFailoverTarget{{Peer: "peer"}}
err = msgpackrpc.CallWithCodec(codec, "PreparedQuery.Apply", &query, &reply)
if err == nil || !strings.Contains(err.Error(), "Targets cannot be populated with") {
t.Fatalf("bad: %v", err)
Expand All @@ -97,7 +97,7 @@ func TestPreparedQuery_Apply(t *testing.T) {
// Fix that and ensure Targets and Datacenters cannot be set at the same time.
query.Query.Service.Failover.NearestN = 0
query.Query.Service.Failover.Datacenters = []string{"dc2"}
query.Query.Service.Failover.Targets = []structs.QueryFailoverTarget{{PeerName: "peer"}}
query.Query.Service.Failover.Targets = []structs.QueryFailoverTarget{{Peer: "peer"}}
err = msgpackrpc.CallWithCodec(codec, "PreparedQuery.Apply", &query, &reply)
if err == nil || !strings.Contains(err.Error(), "Targets cannot be populated with") {
t.Fatalf("bad: %v", err)
Expand Down Expand Up @@ -1552,7 +1552,7 @@ func TestPreparedQuery_Execute(t *testing.T) {
Services: []structs.ExportedService{
{
Name: "foo",
Consumers: []structs.ServiceConsumer{{PeerName: dialingPeerName}},
Consumers: []structs.ServiceConsumer{{Peer: dialingPeerName}},
},
},
},
Expand Down Expand Up @@ -2429,7 +2429,7 @@ func TestPreparedQuery_Execute(t *testing.T) {
query.Query.Service.Failover = structs.QueryFailoverOptions{
Targets: []structs.QueryFailoverTarget{
{Datacenter: "dc2"},
{PeerName: acceptingPeerName},
{Peer: acceptingPeerName},
},
}
require.NoError(t, msgpackrpc.CallWithCodec(codec1, "PreparedQuery.Apply", &query, &query.Query.ID))
Expand Down Expand Up @@ -2950,7 +2950,7 @@ func (m *mockQueryServer) GetOtherDatacentersByDistance() ([]string, error) {
}

func (m *mockQueryServer) ExecuteRemote(args *structs.PreparedQueryExecuteRemoteRequest, reply *structs.PreparedQueryExecuteResponse) error {
peerName := args.Query.Service.PeerName
peerName := args.Query.Service.Peer
dc := args.Datacenter
if peerName != "" {
m.QueryLog = append(m.QueryLog, fmt.Sprintf("peer:%s", peerName))
Expand Down Expand Up @@ -3302,15 +3302,15 @@ func TestPreparedQuery_queryFailover(t *testing.T) {
// Failover returns data from the first cluster peer with data.
query.Service.Failover.Datacenters = nil
query.Service.Failover.Targets = []structs.QueryFailoverTarget{
{PeerName: "cluster-01"},
{Peer: "cluster-01"},
{Datacenter: "dc44"},
{PeerName: "cluster-02"},
{Peer: "cluster-02"},
}
{
mock := &mockQueryServer{
Datacenters: []string{"dc44"},
QueryFn: func(args *structs.PreparedQueryExecuteRemoteRequest, reply *structs.PreparedQueryExecuteResponse) error {
if args.Query.Service.PeerName == "cluster-02" {
if args.Query.Service.Peer == "cluster-02" {
reply.Nodes = nodes()
}
return nil
Expand Down
12 changes: 6 additions & 6 deletions agent/consul/state/config_entry_oss_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func TestStore_peersForService(t *testing.T) {
Name: "not-" + queryName,
Consumers: []structs.ServiceConsumer{
{
PeerName: "zip",
Peer: "zip",
},
},
},
Expand All @@ -80,18 +80,18 @@ func TestStore_peersForService(t *testing.T) {
Name: "not-" + queryName,
Consumers: []structs.ServiceConsumer{
{
PeerName: "zip",
Peer: "zip",
},
},
},
{
Name: structs.WildcardSpecifier,
Consumers: []structs.ServiceConsumer{
{
PeerName: "bar",
Peer: "bar",
},
{
PeerName: "baz",
Peer: "baz",
},
},
},
Expand All @@ -108,15 +108,15 @@ func TestStore_peersForService(t *testing.T) {
Name: queryName,
Consumers: []structs.ServiceConsumer{
{
PeerName: "baz",
Peer: "baz",
},
},
},
{
Name: structs.WildcardSpecifier,
Consumers: []structs.ServiceConsumer{
{
PeerName: "zip",
Peer: "zip",
},
},
},
Expand Down
10 changes: 5 additions & 5 deletions agent/consul/state/config_entry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1569,7 +1569,7 @@ func TestStore_ConfigEntry_GraphValidation(t *testing.T) {
Name: "default",
Services: []structs.ExportedService{{
Name: "main",
Consumers: []structs.ServiceConsumer{{PeerName: "my-peer"}},
Consumers: []structs.ServiceConsumer{{Peer: "my-peer"}},
}},
},
expectErr: `contains cross-datacenter resolver redirect`,
Expand All @@ -1588,7 +1588,7 @@ func TestStore_ConfigEntry_GraphValidation(t *testing.T) {
Name: "default",
Services: []structs.ExportedService{{
Name: "*",
Consumers: []structs.ServiceConsumer{{PeerName: "my-peer"}},
Consumers: []structs.ServiceConsumer{{Peer: "my-peer"}},
}},
},
expectErr: `contains cross-datacenter resolver redirect`,
Expand All @@ -1609,7 +1609,7 @@ func TestStore_ConfigEntry_GraphValidation(t *testing.T) {
Name: "default",
Services: []structs.ExportedService{{
Name: "main",
Consumers: []structs.ServiceConsumer{{PeerName: "my-peer"}},
Consumers: []structs.ServiceConsumer{{Peer: "my-peer"}},
}},
},
expectErr: `contains cross-datacenter failover`,
Expand All @@ -1630,7 +1630,7 @@ func TestStore_ConfigEntry_GraphValidation(t *testing.T) {
Name: "default",
Services: []structs.ExportedService{{
Name: "*",
Consumers: []structs.ServiceConsumer{{PeerName: "my-peer"}},
Consumers: []structs.ServiceConsumer{{Peer: "my-peer"}},
}},
},
expectErr: `contains cross-datacenter failover`,
Expand All @@ -1641,7 +1641,7 @@ func TestStore_ConfigEntry_GraphValidation(t *testing.T) {
Name: "default",
Services: []structs.ExportedService{{
Name: "main",
Consumers: []structs.ServiceConsumer{{PeerName: "my-peer"}},
Consumers: []structs.ServiceConsumer{{Peer: "my-peer"}},
}},
},
},
Expand Down
8 changes: 4 additions & 4 deletions agent/consul/state/peering.go
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,7 @@ func exportedServicesForPeerTxn(
// Service was covered by a wildcard that was already accounted for
continue
}
if consumer.PeerName != peering.Name {
if consumer.Peer != peering.Name {
continue
}
sawPeer = true
Expand Down Expand Up @@ -940,7 +940,7 @@ func listServicesExportedToAnyPeerByConfigEntry(

sawPeer := false
for _, consumer := range svc.Consumers {
if consumer.PeerName == "" {
if consumer.Peer == "" {
continue
}
sawPeer = true
Expand Down Expand Up @@ -1312,8 +1312,8 @@ func peersForServiceTxn(
}

for _, c := range entry.Services[targetIdx].Consumers {
if c.PeerName != "" {
results = append(results, c.PeerName)
if c.Peer != "" {
results = append(results, c.Peer)
}
}
return idx, results, nil
Expand Down
Loading

0 comments on commit 1b56544

Please sign in to comment.