This is an automated email from the ASF dual-hosted git repository.

ocket8888 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git


The following commit(s) were added to refs/heads/master by this push:
     new 22c418f78e Consider DS Regional field for MaxOriginConnections of Edge 
Caches (#7160)
22c418f78e is described below

commit 22c418f78e04001c2d9cbf893cc97dbd6d8d0c02
Author: Zach Hoffman <[email protected]>
AuthorDate: Thu Oct 27 20:19:29 2022 +0000

    Consider DS Regional field for MaxOriginConnections of Edge Caches (#7160)
    
    * Consider DS Regional field for MaxOriginConnections of Edge Caches
    
    * Move Regional Delivery Service-handling case for Mid Caches
    
    * Revert false positive from variable rename
    
    * Remove no-op variable assignments
---
 lib/go-atscfg/headerrewritedotconfig.go      |  44 +++---
 lib/go-atscfg/headerrewritedotconfig_test.go | 203 ++++++++++++++-------------
 2 files changed, 131 insertions(+), 116 deletions(-)

diff --git a/lib/go-atscfg/headerrewritedotconfig.go 
b/lib/go-atscfg/headerrewritedotconfig.go
index 83cf556578..e47a87568a 100644
--- a/lib/go-atscfg/headerrewritedotconfig.go
+++ b/lib/go-atscfg/headerrewritedotconfig.go
@@ -302,7 +302,7 @@ func getAssignedTierPeers(
        if serverIsMid(server) {
                return getAssignedMids(server, ds, servers, 
deliveryServiceServers, cacheGroups)
        }
-       return getAssignedEdges(ds, servers, deliveryServiceServers)
+       return getAssignedEdges(ds, server, servers, deliveryServiceServers)
 }
 
 // getAssignedEdges returns all EDGE caches assigned to ds via 
DeliveryService-Service. Does not consider Topologies.
@@ -310,6 +310,7 @@ func getAssignedTierPeers(
 // Returns the list of assigned servers, and any warnings.
 func getAssignedEdges(
        ds *DeliveryService,
+       server *Server,
        servers []Server,
        deliveryServiceServers []DeliveryServiceServer,
 ) ([]Server, []string) {
@@ -326,22 +327,25 @@ func getAssignedEdges(
        }
 
        assignedEdges := []Server{}
-       for _, server := range servers {
-               if server.CDNName == nil {
+       for _, sv := range servers {
+               if sv.CDNName == nil {
                        warnings = append(warnings, "servers had server with 
missing cdnName, skipping!")
                        continue
                }
-               if server.ID == nil {
+               if sv.ID == nil {
                        warnings = append(warnings, "servers had server with 
missing id, skipping!")
                        continue
                }
-               if *server.CDNName != *ds.CDNName {
+               if *sv.CDNName != *ds.CDNName {
                        continue
                }
-               if _, ok := dsServerIDs[*server.ID]; !ok && ds.Topology == nil {
+               if _, ok := dsServerIDs[*sv.ID]; !ok && ds.Topology == nil {
                        continue
                }
-               assignedEdges = append(assignedEdges, server)
+               if ds != nil && ds.Regional && *sv.Cachegroup != 
*server.Cachegroup {
+                       continue
+               }
+               assignedEdges = append(assignedEdges, sv)
        }
        return assignedEdges, warnings
 }
@@ -368,16 +372,16 @@ func getAssignedMids(
        serverCGs := map[tc.CacheGroupName]struct{}{}
        for _, sv := range servers {
                if sv.CDNName == nil {
-                       warnings = append(warnings, "TO returned Servers server 
with missing CDNName, skipping!")
+                       warnings = append(warnings, "TO returned Servers sv 
with missing CDNName, skipping!")
                        continue
                } else if sv.ID == nil {
-                       warnings = append(warnings, "TO returned Servers server 
with missing ID, skipping!")
+                       warnings = append(warnings, "TO returned Servers sv 
with missing ID, skipping!")
                        continue
                } else if sv.Status == nil {
-                       warnings = append(warnings, "TO returned Servers server 
with missing Status, skipping!")
+                       warnings = append(warnings, "TO returned Servers sv 
with missing Status, skipping!")
                        continue
                } else if sv.Cachegroup == nil {
-                       warnings = append(warnings, "TO returned Servers server 
with missing Cachegroup, skipping!")
+                       warnings = append(warnings, "TO returned Servers sv 
with missing Cachegroup, skipping!")
                        continue
                }
 
@@ -390,9 +394,6 @@ func getAssignedMids(
                if tc.CacheStatus(*sv.Status) != tc.CacheStatusReported && 
tc.CacheStatus(*sv.Status) != tc.CacheStatusOnline {
                        continue
                }
-               if ds != nil && ds.Regional && *sv.Cachegroup != 
*server.Cachegroup {
-                       continue
-               }
                serverCGs[tc.CacheGroupName(*sv.Cachegroup)] = struct{}{}
        }
 
@@ -412,22 +413,25 @@ func getAssignedMids(
        }
 
        assignedMids := []Server{}
-       for _, server := range servers {
-               if server.CDNName == nil {
+       for _, sv := range servers {
+               if sv.CDNName == nil {
                        warnings = append(warnings, "TO returned Servers server 
with missing CDNName, skipping!")
                        continue
                }
-               if server.Cachegroup == nil {
+               if sv.Cachegroup == nil {
                        warnings = append(warnings, "TO returned Servers server 
with missing Cachegroup, skipping!")
                        continue
                }
-               if *server.CDNName != *ds.CDNName {
+               if *sv.CDNName != *ds.CDNName {
+                       continue
+               }
+               if _, ok := parentCGs[*sv.Cachegroup]; !ok {
                        continue
                }
-               if _, ok := parentCGs[*server.Cachegroup]; !ok {
+               if ds != nil && ds.Regional && *sv.Cachegroup != 
*server.Cachegroup {
                        continue
                }
-               assignedMids = append(assignedMids, server)
+               assignedMids = append(assignedMids, sv)
        }
 
        return assignedMids, warnings
diff --git a/lib/go-atscfg/headerrewritedotconfig_test.go 
b/lib/go-atscfg/headerrewritedotconfig_test.go
index 4cc362d9ab..28f2725df8 100644
--- a/lib/go-atscfg/headerrewritedotconfig_test.go
+++ b/lib/go-atscfg/headerrewritedotconfig_test.go
@@ -364,96 +364,7 @@ func TestGetCachegroupsInSameTopologyTier(t *testing.T) {
        }
 }
 
-func TestGetTopologyTierServers(t *testing.T) {
-       allCachegroups := []tc.CacheGroupNullable{
-               {
-                       Name: util.StrPtr("edge1"),
-                       Type: util.StrPtr(tc.CacheGroupEdgeTypeName),
-               },
-               {
-                       Name: util.StrPtr("edge2"),
-                       Type: util.StrPtr(tc.CacheGroupEdgeTypeName),
-               },
-               {
-                       Name: util.StrPtr("org1"),
-                       Type: util.StrPtr(tc.CacheGroupOriginTypeName),
-               },
-       }
-
-       allServers := []Server{
-               {
-                       Cachegroup: util.Ptr("edge1"),
-                       HostName:   util.Ptr("edgeCache1"),
-                       ID:         util.Ptr(0),
-               },
-               {
-                       Cachegroup: util.Ptr("edge2"),
-                       HostName:   util.Ptr("edgeCache2"),
-                       ID:         util.Ptr(0),
-               },
-       }
-
-       topology := tc.Topology{
-               Nodes: []tc.TopologyNode{
-                       {
-                               Cachegroup: "edge1",
-                               Parents:    []int{2},
-                       },
-                       {
-                               Cachegroup: "edge2",
-                               Parents:    []int{2},
-                       },
-                       {
-                               Cachegroup: "org1",
-                       },
-               },
-       }
-
-       type testCase struct {
-               ds                     *DeliveryService
-               dsRequiredCapabilities map[ServerCapability]struct{}
-               cg                     tc.CacheGroupName
-               topology               tc.Topology
-               cacheGroups            []tc.CacheGroupNullable
-               servers                []Server
-               serverCapabilities     map[int]map[ServerCapability]struct{}
-
-               expectedHostnames []string
-       }
-       testCases := []testCase{
-               {
-                       ds:          &DeliveryService{},
-                       cg:          tc.CacheGroupName("edge1"),
-                       topology:    topology,
-                       cacheGroups: allCachegroups,
-                       servers:     allServers,
-
-                       expectedHostnames: []string{"edgeCache1", "edgeCache2"},
-               },
-               {
-                       ds:          &DeliveryService{Regional: true},
-                       cg:          tc.CacheGroupName("edge1"),
-                       topology:    topology,
-                       cacheGroups: allCachegroups,
-                       servers:     allServers,
-
-                       expectedHostnames: []string{"edgeCache1"},
-               },
-       }
-
-       for _, tc := range testCases {
-               actualServers, _ := getTopologyTierServers(tc.ds, 
tc.dsRequiredCapabilities, tc.cg, tc.topology, tc.cacheGroups, tc.servers, 
tc.serverCapabilities)
-               actualHostnames := []string{}
-               for _, as := range actualServers {
-                       actualHostnames = append(actualHostnames, *as.HostName)
-               }
-               if !reflect.DeepEqual(tc.expectedHostnames, actualHostnames) {
-                       t.Errorf("getting servers in same topology tier -- 
expected: %v, actual: %v", tc.expectedHostnames, actualHostnames)
-               }
-       }
-}
-
-func TestGetAssignedMids(t *testing.T) {
+func TestGetAssignedTierPeers(t *testing.T) {
        allCachegroups := []tc.CacheGroupNullable{
                {
                        Name:       util.StrPtr("edge1"),
@@ -481,7 +392,7 @@ func TestGetAssignedMids(t *testing.T) {
                },
        }
 
-       allServers := []Server{
+       edges := []Server{
                {
                        Cachegroup: util.Ptr("edge1"),
                        CDNName:    util.Ptr("mycdn"),
@@ -496,13 +407,15 @@ func TestGetAssignedMids(t *testing.T) {
                        ID:         util.Ptr(2),
                        Status:     util.Ptr(string(tc.CacheStatusReported)),
                },
-
+       }
+       mids := []Server{
                {
                        Cachegroup: util.Ptr("mid1"),
                        CDNName:    util.Ptr("mycdn"),
                        HostName:   util.Ptr("midCache1"),
                        ID:         util.Ptr(3),
                        Status:     util.Ptr(string(tc.CacheStatusReported)),
+                       Type:       tc.MidTypePrefix,
                },
                {
                        Cachegroup: util.Ptr("mid2"),
@@ -510,28 +423,73 @@ func TestGetAssignedMids(t *testing.T) {
                        HostName:   util.Ptr("midCache2"),
                        ID:         util.Ptr(4),
                        Status:     util.Ptr(string(tc.CacheStatusReported)),
+                       Type:       tc.MidTypePrefix,
                },
        }
+       allServers := append(edges, mids...)
 
-       allDeliveryServices := []DeliveryService{{}, {}}
+       topology := tc.Topology{
+               Name: "mytopology",
+               Nodes: []tc.TopologyNode{
+                       {
+                               Cachegroup: "edge1",
+                               Parents:    []int{2},
+                       },
+                       {
+                               Cachegroup: "edge2",
+                               Parents:    []int{2},
+                       },
+                       {
+                               Cachegroup: "org1",
+                       },
+               },
+       }
+
+       allDeliveryServices := []DeliveryService{{}, {}, {}, {}}
        allDeliveryServices[0].ID = util.Ptr(1)
        allDeliveryServices[0].CDNName = util.Ptr("mycdn")
        allDeliveryServices[1].ID = util.Ptr(2)
        allDeliveryServices[1].Regional = true
        allDeliveryServices[1].CDNName = util.Ptr("mycdn")
+       allDeliveryServices[2].Topology = util.Ptr(topology.Name)
+       allDeliveryServices[3].Topology = util.Ptr(topology.Name)
+       allDeliveryServices[3].Regional = true
 
        type testCase struct {
                server                 *Server
                ds                     *DeliveryService
+               topology               tc.Topology
                deliveryServiceServers []DeliveryServiceServer
+               dsRequiredCapabilities map[ServerCapability]struct{}
                servers                []Server
                cacheGroups            []tc.CacheGroupNullable
+               serverCapabilities     map[int]map[ServerCapability]struct{}
 
                expectedHostnames []string
        }
        testCases := []testCase{
+               // topology
+               {
+                       ds:          &allDeliveryServices[2],
+                       server:      &allServers[0],
+                       topology:    topology,
+                       cacheGroups: allCachegroups,
+                       servers:     allServers,
+
+                       expectedHostnames: []string{"edgeCache1", "edgeCache2"},
+               },
+               {
+                       ds:          &allDeliveryServices[3],
+                       server:      &allServers[0],
+                       topology:    topology,
+                       cacheGroups: allCachegroups,
+                       servers:     allServers,
+
+                       expectedHostnames: []string{"edgeCache1"},
+               },
+               // mid
                {
-                       server:  &allServers[0],
+                       server:  &allServers[2],
                        ds:      &allDeliveryServices[0],
                        servers: allServers,
                        deliveryServiceServers: []DeliveryServiceServer{
@@ -557,7 +515,7 @@ func TestGetAssignedMids(t *testing.T) {
                        expectedHostnames: []string{"midCache1", "midCache2"},
                },
                {
-                       server:  &allServers[0],
+                       server:  &allServers[2],
                        ds:      &allDeliveryServices[1],
                        servers: allServers,
                        deliveryServiceServers: []DeliveryServiceServer{
@@ -582,10 +540,63 @@ func TestGetAssignedMids(t *testing.T) {
 
                        expectedHostnames: []string{"midCache1"},
                },
+               // edge
+               {
+                       server:  &edges[0],
+                       ds:      &allDeliveryServices[0],
+                       servers: edges,
+                       deliveryServiceServers: []DeliveryServiceServer{
+                               {
+                                       Server:          1,
+                                       DeliveryService: 1,
+                               },
+                               {
+                                       Server:          2,
+                                       DeliveryService: 1,
+                               },
+                               {
+                                       Server:          3,
+                                       DeliveryService: 1,
+                               },
+                               {
+                                       Server:          4,
+                                       DeliveryService: 1,
+                               },
+                       },
+                       cacheGroups: allCachegroups,
+
+                       expectedHostnames: []string{"edgeCache1", "edgeCache2"},
+               },
+               {
+                       server:  &edges[0],
+                       ds:      &allDeliveryServices[1],
+                       servers: edges,
+                       deliveryServiceServers: []DeliveryServiceServer{
+                               {
+                                       Server:          1,
+                                       DeliveryService: 2,
+                               },
+                               {
+                                       Server:          2,
+                                       DeliveryService: 2,
+                               },
+                               {
+                                       Server:          3,
+                                       DeliveryService: 2,
+                               },
+                               {
+                                       Server:          4,
+                                       DeliveryService: 2,
+                               },
+                       },
+                       cacheGroups: allCachegroups,
+
+                       expectedHostnames: []string{"edgeCache1"},
+               },
        }
 
        for _, tc := range testCases {
-               actualServers, _ := getAssignedMids(tc.server, tc.ds, 
tc.servers, tc.deliveryServiceServers, tc.cacheGroups)
+               actualServers, _ := getAssignedTierPeers(tc.server, tc.ds, 
tc.topology, tc.servers, tc.deliveryServiceServers, tc.cacheGroups, 
tc.serverCapabilities, tc.dsRequiredCapabilities)
                actualHostnames := []string{}
                for _, as := range actualServers {
                        actualHostnames = append(actualHostnames, *as.HostName)

Reply via email to