Skip to content

Commit 14c29cc

Browse files
authored
fix: reduce the complexity of calculating route priority (#2459)
Signed-off-by: ashing <[email protected]>
1 parent 8a2b2b1 commit 14c29cc

File tree

4 files changed

+23
-22
lines changed

4 files changed

+23
-22
lines changed

.github/actions/add-pr-comment

Submodule add-pr-comment added at dd126dd

.github/workflows/apisix-conformance-test.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ concurrency:
3131
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
3232
cancel-in-progress: true
3333

34+
permissions:
35+
pull-requests: write
36+
3437
jobs:
3538
prepare:
3639
name: Prepare
@@ -124,3 +127,11 @@ jobs:
124127
echo '```yaml' >> report.md
125128
cat apisix-ingress-controller-conformance-report.yaml >> report.md
126129
echo '```' >> report.md
130+
131+
- name: Report Conformance Test Result to PR Comment
132+
if: ${{ github.event_name == 'pull_request' }}
133+
uses: ./.github/actions/add-pr-comment
134+
with:
135+
message-id: 'apisix-conformance-test-report-${{ matrix.provider_type }}'
136+
message-path: |
137+
report.md

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,6 @@
2121
[submodule ".github/actions/markdown-link-check"]
2222
path = .github/actions/markdown-link-check
2323
url = https://github.com/gaurav-nelson/github-action-markdown-link-check.git
24+
[submodule ".github/actions/add-pr-comment"]
25+
path = .github/actions/add-pr-comment
26+
url = https://github.com/mshick/add-pr-comment.git

internal/provider/adc/translator/httproute.go

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -382,14 +382,14 @@ func (t *Translator) translateBackendRef(tctx *provider.TranslateContext, ref ga
382382
// ref: https://github.com/Kong/kubernetes-ingress-controller/blob/57472721319e2c63e56cb8540425257e8e02520f/internal/dataplane/translator/subtranslator/httproute_atc.go#L279-L296
383383
func calculateHTTPRoutePriority(match *gatewayv1.HTTPRouteMatch, ruleIndex int, hosts []string) uint64 {
384384
const (
385-
// PreciseHostnameShiftBits assigns bit 43-50 for the length of hostname(max length=253).
386-
PreciseHostnameShiftBits = 43
387-
// HostnameLengthShiftBits assigns bits 35-42 for the length of hostname(max length=253).
388-
HostnameLengthShiftBits = 35
389-
// ExactPathShiftBits assigns bit 34 to mark if the match is exact path match.
390-
ExactPathShiftBits = 34
391-
// PathLengthShiftBits assigns bits 23-32 to path length. (max length = 1024, but must start with /)
392-
PathLengthShiftBits = 23
385+
// PreciseHostnameShiftBits assigns bit 31-38 for the length of hostname(max length=253).
386+
// which has 8 bits, so the max length of hostname is 2^8-1 = 255.
387+
PreciseHostnameShiftBits = 31
388+
389+
// HostnameLengthShiftBits assigns bits 23-30 for the length of hostname(max length=253).
390+
// which has 8 bits, so the max length of hostname is 2^8-1 = 255.
391+
HostnameLengthShiftBits = 23
392+
393393
// MethodMatchShiftBits assigns bit 22 to mark if method is specified.
394394
MethodMatchShiftBits = 22
395395
// HeaderNumberShiftBits assign bits 17-21 to number of headers. (max number of headers = 16)
@@ -430,20 +430,6 @@ func calculateHTTPRoutePriority(match *gatewayv1.HTTPRouteMatch, ruleIndex int,
430430
priority |= (uint64(maxHostnameLength) << HostnameLengthShiftBits)
431431
}
432432

433-
// ExactPathShiftBits
434-
if match.Path != nil && match.Path.Type != nil && *match.Path.Type == gatewayv1.PathMatchExact {
435-
priority |= (1 << ExactPathShiftBits)
436-
}
437-
438-
// PathLengthShiftBits
439-
// max length of path is 1024, but path must start with /, so we use PathLength-1 to fill the bits.
440-
if match.Path != nil && match.Path.Value != nil {
441-
pathLength := len(*match.Path.Value)
442-
if pathLength > 0 {
443-
priority |= (uint64(pathLength-1) << PathLengthShiftBits)
444-
}
445-
}
446-
447433
// MethodMatchShiftBits
448434
if match.Method != nil {
449435
priority |= (1 << MethodMatchShiftBits)

0 commit comments

Comments
 (0)