Skip to content

Commit 14df0a5

Browse files
committed
Revert "Refactor mirror percentage onto pathrules"
This reverts commit 0b6afd8.
1 parent b68d549 commit 14df0a5

File tree

6 files changed

+34
-98
lines changed

6 files changed

+34
-98
lines changed

internal/controller/nginx/config/servers.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ func createLocations(
266266
var rootPathExists bool
267267
var grpcServer bool
268268

269-
//mirrorPathToPercentage := extractMirrorTargetsWithPercentages(server.PathRules)
269+
mirrorPathToPercentage := extractMirrorTargetsWithPercentages(server.PathRules)
270270

271271
for pathRuleIdx, rule := range server.PathRules {
272272
matches := make([]routeMatch, 0, len(rule.MatchRules))
@@ -279,7 +279,7 @@ func createLocations(
279279
grpcServer = true
280280
}
281281

282-
//mirrorPercentage := mirrorPathToPercentage[rule.Path]
282+
mirrorPercentage := mirrorPathToPercentage[rule.Path]
283283

284284
extLocations := initializeExternalLocations(rule, pathsAndTypes)
285285
for i := range extLocations {
@@ -298,7 +298,7 @@ func createLocations(
298298
rule.Path,
299299
rule.GRPC,
300300
keepAliveCheck,
301-
rule.MirrorPercent,
301+
mirrorPercentage,
302302
)
303303
}
304304

@@ -322,7 +322,7 @@ func createLocations(
322322
rule.Path,
323323
rule.GRPC,
324324
keepAliveCheck,
325-
rule.MirrorPercent,
325+
mirrorPercentage,
326326
)
327327

328328
internalLocations = append(internalLocations, intLocation)

internal/controller/nginx/config/servers_test.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ func TestExecuteServers(t *testing.T) {
105105
},
106106
},
107107
},
108-
MirrorPercent: helpers.GetPointer(float64(50)),
109108
},
110109
},
111110
},
@@ -953,7 +952,6 @@ func TestCreateServers(t *testing.T) {
953952
BackendGroup: fooGroup,
954953
},
955954
},
956-
MirrorPercent: helpers.GetPointer(float64(50)),
957955
},
958956
{
959957
Path: "/mirror-filter-100-percent",
@@ -984,7 +982,6 @@ func TestCreateServers(t *testing.T) {
984982
BackendGroup: fooGroup,
985983
},
986984
},
987-
MirrorPercent: helpers.GetPointer(float64(100)),
988985
},
989986
{
990987
Path: "/mirror-filter-0-percent",
@@ -1015,7 +1012,6 @@ func TestCreateServers(t *testing.T) {
10151012
BackendGroup: fooGroup,
10161013
},
10171014
},
1018-
MirrorPercent: helpers.GetPointer(float64(0)),
10191015
},
10201016
{
10211017
Path: "/mirror-filter-duplicate-targets",
@@ -1058,7 +1054,6 @@ func TestCreateServers(t *testing.T) {
10581054
BackendGroup: fooGroup,
10591055
},
10601056
},
1061-
MirrorPercent: helpers.GetPointer(float64(50)),
10621057
},
10631058
{
10641059
Path: "/grpc/mirror",
@@ -2651,8 +2646,8 @@ func TestCreateReturnValForRedirectFilter(t *testing.T) {
26512646

26522647
modifiedHTTPRequestRedirectFilter := func(
26532648
mod func(
2654-
filter *dataplane.HTTPRequestRedirectFilter,
2655-
) *dataplane.HTTPRequestRedirectFilter,
2649+
filter *dataplane.HTTPRequestRedirectFilter,
2650+
) *dataplane.HTTPRequestRedirectFilter,
26562651
) *dataplane.HTTPRequestRedirectFilter {
26572652
return mod(createBasicHTTPRequestRedirectFilter())
26582653
}

internal/controller/nginx/config/split_clients.go

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,17 @@ func createRequestMirrorSplitClients(servers []dataplane.VirtualServer) []http.S
3939
var splitClients []http.SplitClient
4040

4141
for _, server := range servers {
42-
for _, pathRule := range server.PathRules {
43-
if pathRule.MirrorPercent != nil && *pathRule.MirrorPercent != 100 {
42+
mirrorPathToPercentage := extractMirrorTargetsWithPercentages(server.PathRules)
43+
44+
for path, percentage := range mirrorPathToPercentage {
45+
if percentage != nil && *percentage != 100 {
4446
splitClient := http.SplitClient{
4547
// this has to be something unique and able to be accessed from the server block
46-
VariableName: convertSplitClientVariableName(fmt.Sprintf("%s_%.2f", pathRule.Path, *pathRule.MirrorPercent)),
48+
VariableName: convertSplitClientVariableName(fmt.Sprintf("%s_%.2f", path, *percentage)),
4749
Distributions: []http.SplitClientDistribution{
4850
{
49-
Percent: fmt.Sprintf("%.2f", *pathRule.MirrorPercent),
50-
Value: pathRule.Path,
51+
Percent: fmt.Sprintf("%.2f", *percentage),
52+
Value: path,
5153
},
5254
{
5355
Percent: "*",
@@ -59,28 +61,6 @@ func createRequestMirrorSplitClients(servers []dataplane.VirtualServer) []http.S
5961
splitClients = append(splitClients, splitClient)
6062
}
6163
}
62-
//mirrorPathToPercentage := extractMirrorTargetsWithPercentages(server.PathRules)
63-
//
64-
//for path, percentage := range mirrorPathToPercentage {
65-
// if percentage != nil && *percentage != 100 {
66-
// splitClient := http.SplitClient{
67-
// // this has to be something unique and able to be accessed from the server block
68-
// VariableName: convertSplitClientVariableName(fmt.Sprintf("%s_%.2f", path, *percentage)),
69-
// Distributions: []http.SplitClientDistribution{
70-
// {
71-
// Percent: fmt.Sprintf("%.2f", *percentage),
72-
// Value: path,
73-
// },
74-
// {
75-
// Percent: "*",
76-
// Value: "\"\"",
77-
// },
78-
// },
79-
// }
80-
//
81-
// splitClients = append(splitClients, splitClient)
82-
// }
83-
//}
8464
}
8565

8666
return splitClients

internal/controller/nginx/config/split_clients_test.go

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -133,16 +133,13 @@ func TestExecuteSplitClients(t *testing.T) {
133133
},
134134
},
135135
{
136-
Path: http.InternalMirrorRoutePathPrefix + "-my-coffee-backend-test/route1-0",
137-
MirrorPercent: helpers.GetPointer(float64(25)),
136+
Path: http.InternalMirrorRoutePathPrefix + "-my-coffee-backend-test/route1-0",
138137
},
139138
{
140-
Path: http.InternalMirrorRoutePathPrefix + "-my-tea-backend-test/route1-0",
141-
MirrorPercent: helpers.GetPointer(float64(50)),
139+
Path: http.InternalMirrorRoutePathPrefix + "-my-tea-backend-test/route1-0",
142140
},
143141
{
144-
Path: http.InternalMirrorRoutePathPrefix + "-my-coffee-backend-test/route1-1",
145-
MirrorPercent: helpers.GetPointer(float64(25)),
142+
Path: http.InternalMirrorRoutePathPrefix + "-my-coffee-backend-test/route1-1",
146143
},
147144
{
148145
Path: "/mirror-edge-case-percentages",
@@ -178,16 +175,13 @@ func TestExecuteSplitClients(t *testing.T) {
178175
},
179176
},
180177
{
181-
Path: http.InternalMirrorRoutePathPrefix + "-my-coffee-backend-test/route2-0",
182-
MirrorPercent: helpers.GetPointer(float64(0)),
178+
Path: http.InternalMirrorRoutePathPrefix + "-my-coffee-backend-test/route2-0",
183179
},
184180
{
185-
Path: http.InternalMirrorRoutePathPrefix + "-my-tea-backend-test/route2-0",
186-
MirrorPercent: helpers.GetPointer(float64(99.999)),
181+
Path: http.InternalMirrorRoutePathPrefix + "-my-tea-backend-test/route2-0",
187182
},
188183
{
189-
Path: http.InternalMirrorRoutePathPrefix + "-my-coffee-backend-test/route2-1",
190-
MirrorPercent: helpers.GetPointer(float64(0.001)),
184+
Path: http.InternalMirrorRoutePathPrefix + "-my-coffee-backend-test/route2-1",
191185
},
192186
},
193187
},
@@ -247,8 +241,7 @@ func TestExecuteSplitClients(t *testing.T) {
247241
},
248242
},
249243
{
250-
Path: http.InternalMirrorRoutePathPrefix + "-my-same-backend-test/route1-0",
251-
MirrorPercent: helpers.GetPointer(float64(50)),
244+
Path: http.InternalMirrorRoutePathPrefix + "-my-same-backend-test/route1-0",
252245
},
253246
},
254247
},
@@ -304,8 +297,7 @@ func TestExecuteSplitClients(t *testing.T) {
304297
},
305298
},
306299
{
307-
Path: http.InternalMirrorRoutePathPrefix + "-my-backend-test/route1-0",
308-
MirrorPercent: helpers.GetPointer(float64(25)),
300+
Path: http.InternalMirrorRoutePathPrefix + "-my-backend-test/route1-0",
309301
},
310302
},
311303
},
@@ -329,8 +321,7 @@ func TestExecuteSplitClients(t *testing.T) {
329321
},
330322
},
331323
{
332-
Path: http.InternalMirrorRoutePathPrefix + "-my-ssl-backend-test/route1-0",
333-
MirrorPercent: helpers.GetPointer(float64(50)),
324+
Path: http.InternalMirrorRoutePathPrefix + "-my-ssl-backend-test/route1-0",
334325
},
335326
},
336327
},
@@ -419,16 +410,13 @@ func TestCreateRequestMirrorSplitClients(t *testing.T) {
419410
},
420411
},
421412
{
422-
Path: http.InternalMirrorRoutePathPrefix + "-my-coffee-backend-test/route1-0",
423-
MirrorPercent: helpers.GetPointer(float64(25)),
413+
Path: http.InternalMirrorRoutePathPrefix + "-my-coffee-backend-test/route1-0",
424414
},
425415
{
426-
Path: http.InternalMirrorRoutePathPrefix + "-my-tea-backend-test/route1-0",
427-
MirrorPercent: helpers.GetPointer(float64(50)),
416+
Path: http.InternalMirrorRoutePathPrefix + "-my-tea-backend-test/route1-0",
428417
},
429418
{
430-
Path: http.InternalMirrorRoutePathPrefix + "-my-coffee-backend-test/route1-1",
431-
MirrorPercent: helpers.GetPointer(float64(25)),
419+
Path: http.InternalMirrorRoutePathPrefix + "-my-coffee-backend-test/route1-1",
432420
},
433421
},
434422
},
@@ -450,8 +438,7 @@ func TestCreateRequestMirrorSplitClients(t *testing.T) {
450438
},
451439
},
452440
{
453-
Path: http.InternalMirrorRoutePathPrefix + "-my-coffee-backend-test/route1-0",
454-
MirrorPercent: helpers.GetPointer(float64(30)),
441+
Path: http.InternalMirrorRoutePathPrefix + "-my-coffee-backend-test/route1-0",
455442
},
456443
},
457444
},

internal/controller/state/dataplane/configuration.go

Lines changed: 8 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -462,20 +462,18 @@ type pathAndType struct {
462462
}
463463

464464
type hostPathRules struct {
465-
rulesPerHost map[string]map[pathAndType]PathRule
466-
listenersForHost map[string]*graph.Listener
467-
httpsListeners []*graph.Listener
468-
port int32
469-
listenersExist bool
470-
mirrorTargetToPercentage map[string]*float64
465+
rulesPerHost map[string]map[pathAndType]PathRule
466+
listenersForHost map[string]*graph.Listener
467+
httpsListeners []*graph.Listener
468+
port int32
469+
listenersExist bool
471470
}
472471

473472
func newHostPathRules() *hostPathRules {
474473
return &hostPathRules{
475-
rulesPerHost: make(map[string]map[pathAndType]PathRule),
476-
listenersForHost: make(map[string]*graph.Listener),
477-
httpsListeners: make([]*graph.Listener, 0),
478-
mirrorTargetToPercentage: make(map[string]*float64),
474+
rulesPerHost: make(map[string]map[pathAndType]PathRule),
475+
listenersForHost: make(map[string]*graph.Listener),
476+
httpsListeners: make([]*graph.Listener, 0),
479477
}
480478
}
481479

@@ -555,25 +553,6 @@ func (hpr *hostPathRules) upsertRoute(
555553
pols := buildPolicies(gateway, route.Policies)
556554

557555
for _, h := range hostnames {
558-
559-
if filters.RequestMirrors != nil {
560-
for _, m := range filters.RequestMirrors {
561-
if m.Target != nil {
562-
if m.Percent == nil {
563-
hpr.mirrorTargetToPercentage[*m.Target] = helpers.GetPointer(100.0)
564-
continue
565-
}
566-
567-
percentage := m.Percent
568-
569-
if _, exists := hpr.mirrorTargetToPercentage[*m.Target]; !exists ||
570-
*percentage > *hpr.mirrorTargetToPercentage[*m.Target] {
571-
hpr.mirrorTargetToPercentage[*m.Target] = percentage // set a higher percentage if it exists
572-
}
573-
}
574-
}
575-
}
576-
577556
for _, m := range rule.Matches {
578557
path := getPath(m.Path)
579558

@@ -628,8 +607,6 @@ func (hpr *hostPathRules) buildServers() []VirtualServer {
628607
for _, r := range rules {
629608
sortMatchRules(r.MatchRules)
630609

631-
r.MirrorPercent = hpr.mirrorTargetToPercentage[r.Path]
632-
633610
s.PathRules = append(s.PathRules, r)
634611
}
635612

internal/controller/state/dataplane/types.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,6 @@ type PathRule struct {
135135
Policies []policies.Policy
136136
// GRPC indicates if this is a gRPC rule
137137
GRPC bool
138-
// MirrorPercent is the percentage of requests to mirror for this PathRule. If this PathRule is not an internal
139-
// mirrored rule, this field is nil.
140-
MirrorPercent *float64
141138
}
142139

143140
// InvalidHTTPFilter is a special filter for handling the case when configured filters are invalid.

0 commit comments

Comments
 (0)