@@ -225,21 +225,22 @@ type rewriteConfig struct {
225
225
}
226
226
227
227
// extractMirrorTargetsWithPercentages extracts mirror targets and their percentages from path rules.
228
- func extractMirrorTargetsWithPercentages (pathRules []dataplane.PathRule ) map [string ]float64 {
229
- mirrorTargets := make (map [string ]float64 )
228
+ func extractMirrorTargetsWithPercentages (pathRules []dataplane.PathRule ) map [string ]* float64 {
229
+ mirrorTargets := make (map [string ]* float64 )
230
230
231
231
for _ , rule := range pathRules {
232
232
for _ , matchRule := range rule .MatchRules {
233
233
for _ , mirrorFilter := range matchRule .Filters .RequestMirrors {
234
234
if mirrorFilter .Target != nil {
235
235
if mirrorFilter .Percent == nil {
236
- mirrorTargets [* mirrorFilter .Target ] = 100.0
236
+ mirrorTargets [* mirrorFilter .Target ] = helpers . GetPointer ( 100.0 )
237
237
continue
238
238
}
239
239
240
- percentage := * mirrorFilter .Percent
240
+ percentage := mirrorFilter .Percent
241
241
242
- if _ , exists := mirrorTargets [* mirrorFilter .Target ]; ! exists || percentage > mirrorTargets [* mirrorFilter .Target ] {
242
+ if _ , exists := mirrorTargets [* mirrorFilter .Target ]; ! exists ||
243
+ * percentage > * mirrorTargets [* mirrorFilter .Target ] {
243
244
mirrorTargets [* mirrorFilter .Target ] = percentage // set a higher percentage if it exists
244
245
}
245
246
}
@@ -278,12 +279,7 @@ func createLocations(
278
279
grpcServer = true
279
280
}
280
281
281
- mirrorPercentage , exists := mirrorPathToPercentage [rule .Path ]
282
- if ! exists {
283
- // need a way to differentiate between no mirror filter and a mirror filter with 0 percent set, and
284
- // I don't want to pass an extra boolean around.
285
- mirrorPercentage = - 1
286
- }
282
+ mirrorPercentage := mirrorPathToPercentage [rule .Path ]
287
283
288
284
extLocations := initializeExternalLocations (rule , pathsAndTypes )
289
285
for i := range extLocations {
@@ -464,7 +460,7 @@ func updateLocation(
464
460
path string ,
465
461
grpc bool ,
466
462
keepAliveCheck keepAliveChecker ,
467
- mirrorPercentage float64 ,
463
+ mirrorPercentage * float64 ,
468
464
) http.Location {
469
465
if filters .InvalidFilter != nil {
470
466
location .Return = & http.Return {Code : http .StatusInternalServerError }
@@ -533,7 +529,7 @@ func updateLocationMirrorFilters(
533
529
location http.Location ,
534
530
mirrorFilters []* dataplane.HTTPRequestMirrorFilter ,
535
531
path string ,
536
- mirrorPercentage float64 ,
532
+ mirrorPercentage * float64 ,
537
533
) http.Location {
538
534
for _ , filter := range mirrorFilters {
539
535
if filter .Target != nil {
@@ -547,9 +543,9 @@ func updateLocationMirrorFilters(
547
543
548
544
// if the mirrorPercentage is 100.0 or negative (we set it to negative when there is no mirror filter because 0.0
549
545
// is valid), the split clients variable is not generated, and we want to let all the traffic get mirrored.
550
- if mirrorPercentage != 100.0 && mirrorPercentage >= 0 .0 {
546
+ if mirrorPercentage != nil && * mirrorPercentage != 100 .0 {
551
547
location .MirrorSplitClientsVariableName = convertSplitClientVariableName (
552
- fmt .Sprintf ("%s_%.2f" , path , mirrorPercentage ),
548
+ fmt .Sprintf ("%s_%.2f" , path , * mirrorPercentage ),
553
549
)
554
550
}
555
551
@@ -599,7 +595,7 @@ func updateLocations(
599
595
path string ,
600
596
grpc bool ,
601
597
keepAliveCheck keepAliveChecker ,
602
- mirrorPercentage float64 ,
598
+ mirrorPercentage * float64 ,
603
599
) []http.Location {
604
600
updatedLocations := make ([]http.Location , len (buildLocations ))
605
601
@@ -1070,12 +1066,12 @@ func getConnectionHeader(keepAliveCheck keepAliveChecker, backends []dataplane.B
1070
1066
1071
1067
// deduplicateStrings removes duplicate strings from a slice while preserving order.
1072
1068
func deduplicateStrings (content []string ) []string {
1073
- seen := make (map [string ]bool )
1069
+ seen := make (map [string ]struct {} )
1074
1070
result := make ([]string , 0 , len (content ))
1075
1071
1076
1072
for _ , str := range content {
1077
- if ! seen [str ] {
1078
- seen [str ] = true
1073
+ if _ , exists := seen [str ]; ! exists {
1074
+ seen [str ] = struct {}{}
1079
1075
result = append (result , str )
1080
1076
}
1081
1077
}
0 commit comments