Skip to content

Commit 5106149

Browse files
ronethingdspo
authored andcommitted
fix: reduce the complexity of calculating route priority (#2459)
Signed-off-by: ashing <[email protected]> (cherry picked from commit 14c29cc)
1 parent 9656885 commit 5106149

File tree

4 files changed

+41
-25
lines changed

4 files changed

+41
-25
lines changed

.github/actions/add-pr-comment

Submodule add-pr-comment added at dd126dd

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

Lines changed: 6 additions & 3 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
@@ -116,7 +119,7 @@ jobs:
116119
if: ${{ github.event_name == 'push' }}
117120
uses: actions/upload-artifact@v4
118121
with:
119-
name: apisix-ingress-controller-conformance-report.yaml
122+
name: apisix-ingress-controller-conformance-report-${{ matrix.provider_type }}.yaml
120123
path: apisix-ingress-controller-conformance-report.yaml
121124

122125
- name: Format Conformance Test Report
@@ -129,8 +132,8 @@ jobs:
129132
130133
- name: Report Conformance Test Result to PR Comment
131134
if: ${{ github.event_name == 'pull_request' }}
132-
uses: mshick/add-pr-comment@v2
135+
uses: ./.github/actions/add-pr-comment
133136
with:
134-
message-id: 'apisix-conformance-test-report'
137+
message-id: 'apisix-conformance-test-report-${{ matrix.provider_type }}'
135138
message-path: |
136139
report.md

.gitmodules

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
[submodule ".github/actions/paths-filter"]
19+
path = .github/actions/paths-filter
20+
url = https://github.com/dorny/paths-filter.git
21+
[submodule ".github/actions/markdown-link-check"]
22+
path = .github/actions/markdown-link-check
23+
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)