Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 7709eaa

Browse files
committedJul 13, 2023
use traits.encode for expected priorities in tests
1 parent 3024155 commit 7709eaa

File tree

2 files changed

+59
-11
lines changed

2 files changed

+59
-11
lines changed
 

‎internal/dataplane/parser/translators/httproute_atc.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -478,9 +478,10 @@ func AssignRoutePriorityToSplitHTTPRoutes(
478478
Priority: priority + relativeOrderBits,
479479
})
480480
}
481-
// log the
481+
// Just in case, log a very unlikely scenario where we have more than 2^18 routes with the same base
482+
// priority and we have no bit space for them to be deterministically ordered.
482483
if len(routes) > (1 << 18) {
483-
logger.Info("Too many HTTPRoutes are distinguished by relative orders", "httproute_number", len(routes))
484+
logger.V(util.WarnLevel).Info("Too many HTTPRoutes to be deterministically ordered", "httproute_number", len(routes))
484485
}
485486
}
486487

‎internal/dataplane/parser/translators/httproute_atc_test.go

+56-9
Original file line numberDiff line numberDiff line change
@@ -831,6 +831,8 @@ func TestAssignRoutePriorityToSplitHTTPRoutes(t *testing.T) {
831831
matchIndex int
832832
}
833833
now := time.Now()
834+
const maxRelativeOrderPriorityBits = (1 << 18) - 1
835+
834836
testCases := []struct {
835837
name string
836838
splitHTTPRoutes []*gatewayv1beta1.HTTPRoute
@@ -890,14 +892,24 @@ func TestAssignRoutePriorityToSplitHTTPRoutes(t *testing.T) {
890892
hostname: "foo.com",
891893
ruleIndex: 0,
892894
matchIndex: 0,
893-
}: (2 << 50) | (1 << 49) | (7 << 41) | (1 << 40) | (3 << 29) | ((1 << 18) - 1),
895+
}: HTTPRoutePriorityTraits{
896+
PreciseHostname: true,
897+
HostnameLength: len("foo.com"),
898+
PathType: gatewayv1beta1.PathMatchExact,
899+
PathLength: len("/foo"),
900+
}.EncodeToPriority() + maxRelativeOrderPriorityBits,
894901
{
895902
namespace: "default",
896903
name: "httproute-2",
897904
hostname: "*.bar.com",
898905
ruleIndex: 0,
899906
matchIndex: 0,
900-
}: (2 << 50) | (9 << 41) | (1 << 40) | (3 << 29) | ((1 << 18) - 1),
907+
}: HTTPRoutePriorityTraits{
908+
PreciseHostname: false,
909+
HostnameLength: len("*.bar.com"),
910+
PathType: gatewayv1beta1.PathMatchExact,
911+
PathLength: len("/bar"),
912+
}.EncodeToPriority() + maxRelativeOrderPriorityBits,
901913
},
902914
},
903915
{
@@ -953,14 +965,24 @@ func TestAssignRoutePriorityToSplitHTTPRoutes(t *testing.T) {
953965
hostname: "foo.com",
954966
ruleIndex: 0,
955967
matchIndex: 0,
956-
}: (2 << 50) | (1 << 49) | (7 << 41) | (1 << 40) | (3 << 29) | ((1 << 18) - 1),
968+
}: HTTPRoutePriorityTraits{
969+
PreciseHostname: true,
970+
HostnameLength: len("foo.com"),
971+
PathType: gatewayv1beta1.PathMatchExact,
972+
PathLength: len("/foo"),
973+
}.EncodeToPriority() + maxRelativeOrderPriorityBits,
957974
{
958975
namespace: "default",
959976
name: "httproute-2",
960977
hostname: "bar.com",
961978
ruleIndex: 0,
962979
matchIndex: 0,
963-
}: (2 << 50) | (1 << 49) | (7 << 41) | (1 << 40) | (3 << 29) | ((1 << 18) - 1) - 1,
980+
}: HTTPRoutePriorityTraits{
981+
PreciseHostname: true,
982+
HostnameLength: len("bar.com"),
983+
PathType: gatewayv1beta1.PathMatchExact,
984+
PathLength: len("/foo"),
985+
}.EncodeToPriority() + maxRelativeOrderPriorityBits - 1,
964986
},
965987
},
966988
{
@@ -1016,14 +1038,24 @@ func TestAssignRoutePriorityToSplitHTTPRoutes(t *testing.T) {
10161038
hostname: "foo.com",
10171039
ruleIndex: 0,
10181040
matchIndex: 0,
1019-
}: (2 << 50) | (1 << 49) | (7 << 41) | (1 << 40) | (3 << 29) | ((1 << 18) - 1),
1041+
}: HTTPRoutePriorityTraits{
1042+
PreciseHostname: true,
1043+
HostnameLength: len("foo.com"),
1044+
PathType: gatewayv1beta1.PathMatchExact,
1045+
PathLength: len("/foo"),
1046+
}.EncodeToPriority() + maxRelativeOrderPriorityBits,
10201047
{
10211048
namespace: "default",
10221049
name: "httproute-2",
10231050
hostname: "bar.com",
10241051
ruleIndex: 0,
10251052
matchIndex: 0,
1026-
}: (2 << 50) | (1 << 49) | (7 << 41) | (1 << 40) | (3 << 29) | ((1 << 18) - 1) - 1,
1053+
}: HTTPRoutePriorityTraits{
1054+
PreciseHostname: true,
1055+
HostnameLength: len("bar.com"),
1056+
PathType: gatewayv1beta1.PathMatchExact,
1057+
PathLength: len("/foo"),
1058+
}.EncodeToPriority() + maxRelativeOrderPriorityBits - 1,
10271059
},
10281060
},
10291061
{
@@ -1079,14 +1111,24 @@ func TestAssignRoutePriorityToSplitHTTPRoutes(t *testing.T) {
10791111
hostname: "foo.com",
10801112
ruleIndex: 0,
10811113
matchIndex: 0,
1082-
}: (2 << 50) | (1 << 49) | (7 << 41) | (1 << 40) | (3 << 29) | ((1 << 18) - 1),
1114+
}: HTTPRoutePriorityTraits{
1115+
PreciseHostname: true,
1116+
HostnameLength: len("foo.com"),
1117+
PathType: gatewayv1beta1.PathMatchExact,
1118+
PathLength: len("/foo"),
1119+
}.EncodeToPriority() + maxRelativeOrderPriorityBits,
10831120
{
10841121
namespace: "default",
10851122
name: "httproute-1",
10861123
hostname: "foo.com",
10871124
ruleIndex: 0,
10881125
matchIndex: 1,
1089-
}: (2 << 50) | (1 << 49) | (7 << 41) | (1 << 40) | (3 << 29) | ((1 << 18) - 1) - 1,
1126+
}: HTTPRoutePriorityTraits{
1127+
PreciseHostname: true,
1128+
HostnameLength: len("bar.com"),
1129+
PathType: gatewayv1beta1.PathMatchExact,
1130+
PathLength: len("/foo"),
1131+
}.EncodeToPriority() + maxRelativeOrderPriorityBits - 1,
10901132
},
10911133
},
10921134
{
@@ -1158,7 +1200,12 @@ func TestAssignRoutePriorityToSplitHTTPRoutes(t *testing.T) {
11581200
hostname: "foo.com",
11591201
ruleIndex: 0,
11601202
matchIndex: 0,
1161-
}: (2 << 50) | (1 << 49) | (7 << 41) | (1 << 40) | (3 << 29) | ((1 << 18) - 1),
1203+
}: HTTPRoutePriorityTraits{
1204+
PreciseHostname: true,
1205+
HostnameLength: len("foo.com"),
1206+
PathType: gatewayv1beta1.PathMatchExact,
1207+
PathLength: len("/foo"),
1208+
}.EncodeToPriority() + maxRelativeOrderPriorityBits,
11621209
},
11631210
},
11641211
}

0 commit comments

Comments
 (0)
Please sign in to comment.