@@ -225,21 +225,22 @@ type rewriteConfig struct {
225225}
226226
227227// 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 )
230230
231231 for _ , rule := range pathRules {
232232 for _ , matchRule := range rule .MatchRules {
233233 for _ , mirrorFilter := range matchRule .Filters .RequestMirrors {
234234 if mirrorFilter .Target != nil {
235235 if mirrorFilter .Percent == nil {
236- mirrorTargets [* mirrorFilter .Target ] = 100.0
236+ mirrorTargets [* mirrorFilter .Target ] = helpers . GetPointer ( 100.0 )
237237 continue
238238 }
239239
240- percentage := * mirrorFilter .Percent
240+ percentage := mirrorFilter .Percent
241241
242- if _ , exists := mirrorTargets [* mirrorFilter .Target ]; ! exists || percentage > mirrorTargets [* mirrorFilter .Target ] {
242+ if _ , exists := mirrorTargets [* mirrorFilter .Target ]; ! exists ||
243+ * percentage > * mirrorTargets [* mirrorFilter .Target ] {
243244 mirrorTargets [* mirrorFilter .Target ] = percentage // set a higher percentage if it exists
244245 }
245246 }
@@ -278,12 +279,7 @@ func createLocations(
278279 grpcServer = true
279280 }
280281
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 ]
287283
288284 extLocations := initializeExternalLocations (rule , pathsAndTypes )
289285 for i := range extLocations {
@@ -464,7 +460,7 @@ func updateLocation(
464460 path string ,
465461 grpc bool ,
466462 keepAliveCheck keepAliveChecker ,
467- mirrorPercentage float64 ,
463+ mirrorPercentage * float64 ,
468464) http.Location {
469465 if filters .InvalidFilter != nil {
470466 location .Return = & http.Return {Code : http .StatusInternalServerError }
@@ -533,7 +529,7 @@ func updateLocationMirrorFilters(
533529 location http.Location ,
534530 mirrorFilters []* dataplane.HTTPRequestMirrorFilter ,
535531 path string ,
536- mirrorPercentage float64 ,
532+ mirrorPercentage * float64 ,
537533) http.Location {
538534 for _ , filter := range mirrorFilters {
539535 if filter .Target != nil {
@@ -547,9 +543,9 @@ func updateLocationMirrorFilters(
547543
548544 // if the mirrorPercentage is 100.0 or negative (we set it to negative when there is no mirror filter because 0.0
549545 // 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 {
551547 location .MirrorSplitClientsVariableName = convertSplitClientVariableName (
552- fmt .Sprintf ("%s_%.2f" , path , mirrorPercentage ),
548+ fmt .Sprintf ("%s_%.2f" , path , * mirrorPercentage ),
553549 )
554550 }
555551
@@ -599,7 +595,7 @@ func updateLocations(
599595 path string ,
600596 grpc bool ,
601597 keepAliveCheck keepAliveChecker ,
602- mirrorPercentage float64 ,
598+ mirrorPercentage * float64 ,
603599) []http.Location {
604600 updatedLocations := make ([]http.Location , len (buildLocations ))
605601
@@ -1070,12 +1066,12 @@ func getConnectionHeader(keepAliveCheck keepAliveChecker, backends []dataplane.B
10701066
10711067// deduplicateStrings removes duplicate strings from a slice while preserving order.
10721068func deduplicateStrings (content []string ) []string {
1073- seen := make (map [string ]bool )
1069+ seen := make (map [string ]struct {} )
10741070 result := make ([]string , 0 , len (content ))
10751071
10761072 for _ , str := range content {
1077- if ! seen [str ] {
1078- seen [str ] = true
1073+ if _ , exists := seen [str ]; ! exists {
1074+ seen [str ] = struct {}{}
10791075 result = append (result , str )
10801076 }
10811077 }
0 commit comments