Skip to content

Commit 9e40480

Browse files
committed
revert: local ratelimit descriptor key
Signed-off-by: kkk777-7 <kota.kimura0725@gmail.com>
1 parent 5cb3b15 commit 9e40480

File tree

6 files changed

+55
-56
lines changed

6 files changed

+55
-56
lines changed

api/v1alpha1/ratelimit_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ type RateLimitSpec struct {
1313
// Deprecated: Use Global and/or Local fields directly instead. Both can be specified simultaneously for combined rate limiting.
1414
//
1515
// +optional
16-
Type *RateLimitType `json:"type"`
16+
Type *RateLimitType `json:"type,omitempty"`
1717
// Global defines global rate limit configuration.
1818
//
1919
// +optional

internal/gatewayapi/testdata/backendtrafficpolicy-with-ratelimit-both-type.out.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ backendTrafficPolicies:
2626
limit:
2727
requests: 10
2828
unit: Hour
29-
type: null
3029
targetRef:
3130
group: gateway.networking.k8s.io
3231
kind: GRPCRoute

internal/xds/translator/local_ratelimit.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ func buildRouteLocalRateLimits(local *ir.LocalRateLimit) (
213213

214214
if match.Distinct {
215215
// For distinct matches, we only check if the header exists using the RequestHeaders action.
216-
descriptorKey := fmt.Sprintf("local_%s", getRouteRuleDescriptor(rIdx, mIdx))
216+
descriptorKey := getRouteRuleDescriptor(rIdx, mIdx)
217217
action = &routev3.RateLimit_Action{
218218
ActionSpecifier: &routev3.RateLimit_Action_RequestHeaders_{
219219
RequestHeaders: &routev3.RateLimit_Action_RequestHeaders{
@@ -230,8 +230,8 @@ func buildRouteLocalRateLimits(local *ir.LocalRateLimit) (
230230
} else {
231231
// For exact matches, we check if there is an existing header with the matching value using the
232232
// HeaderValueMatch action.
233-
descriptorKey := fmt.Sprintf("local_%s", getRouteRuleDescriptor(rIdx, mIdx))
234-
descriptorVal := fmt.Sprintf("local_%s", getRouteRuleDescriptor(rIdx, mIdx))
233+
descriptorKey := getRouteRuleDescriptor(rIdx, mIdx)
234+
descriptorVal := getRouteRuleDescriptor(rIdx, mIdx)
235235
headerMatcher := &routev3.HeaderMatcher{
236236
Name: match.Name,
237237
HeaderMatchSpecifier: &routev3.HeaderMatcher_StringMatch{
@@ -281,7 +281,7 @@ func buildRouteLocalRateLimits(local *ir.LocalRateLimit) (
281281
},
282282
}
283283
entry := &rlv3.RateLimitDescriptor_Entry{
284-
Key: fmt.Sprintf("local_%s", descriptorMaskedRemoteAddress),
284+
Key: descriptorMaskedRemoteAddress,
285285
Value: rule.CIDRMatch.CIDR,
286286
}
287287
descriptorEntries = append(descriptorEntries, entry)
@@ -298,7 +298,7 @@ func buildRouteLocalRateLimits(local *ir.LocalRateLimit) (
298298
// If the CIDRMatch is distinct, we use the built-in remote address descriptor key without a value.
299299
// This means that each distinct client IP will be counted separately.
300300
entry = &rlv3.RateLimitDescriptor_Entry{
301-
Key: fmt.Sprintf("local_%s", descriptorRemoteAddress),
301+
Key: descriptorRemoteAddress,
302302
}
303303
descriptorEntries = append(descriptorEntries, entry)
304304
rlActions = append(rlActions, action)

internal/xds/translator/testdata/out/xds-ir/local-ratelimit-distinct.routes.yaml

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
rateLimits:
1414
- actions:
1515
- requestHeaders:
16-
descriptorKey: local_rule-0-match-0
16+
descriptorKey: rule-0-match-0
1717
headerName: x-user-id
1818
upgradeConfigs:
1919
- upgradeType: websocket
@@ -23,7 +23,7 @@
2323
alwaysConsumeDefaultTokenBucket: false
2424
descriptors:
2525
- entries:
26-
- key: local_rule-0-match-0
26+
- key: rule-0-match-0
2727
tokenBucket:
2828
fillInterval: 0s
2929
maxTokens: 5
@@ -48,33 +48,33 @@
4848
rateLimits:
4949
- actions:
5050
- headerValueMatch:
51-
descriptorKey: local_rule-0-match-0
52-
descriptorValue: local_rule-0-match-0
51+
descriptorKey: rule-0-match-0
52+
descriptorValue: rule-0-match-0
5353
expectMatch: true
5454
headers:
5555
- name: x-user-id
5656
stringMatch:
5757
exact: one
5858
- headerValueMatch:
59-
descriptorKey: local_rule-0-match-1
60-
descriptorValue: local_rule-0-match-1
59+
descriptorKey: rule-0-match-1
60+
descriptorValue: rule-0-match-1
6161
expectMatch: true
6262
headers:
6363
- name: x-org-id
6464
stringMatch:
6565
exact: foo
6666
- actions:
6767
- headerValueMatch:
68-
descriptorKey: local_rule-1-match-0
69-
descriptorValue: local_rule-1-match-0
68+
descriptorKey: rule-1-match-0
69+
descriptorValue: rule-1-match-0
7070
expectMatch: true
7171
headers:
7272
- name: x-user-id
7373
stringMatch:
7474
exact: two
7575
- headerValueMatch:
76-
descriptorKey: local_rule-1-match-1
77-
descriptorValue: local_rule-1-match-1
76+
descriptorKey: rule-1-match-1
77+
descriptorValue: rule-1-match-1
7878
expectMatch: true
7979
headers:
8080
- name: x-org-id
@@ -91,22 +91,22 @@
9191
alwaysConsumeDefaultTokenBucket: false
9292
descriptors:
9393
- entries:
94-
- key: local_rule-0-match-0
95-
value: local_rule-0-match-0
96-
- key: local_rule-0-match-1
97-
value: local_rule-0-match-1
94+
- key: rule-0-match-0
95+
value: rule-0-match-0
96+
- key: rule-0-match-1
97+
value: rule-0-match-1
9898
tokenBucket:
9999
fillInterval: 3600s
100100
maxTokens: 10
101101
tokensPerFill: 10
102102
- entries:
103-
- key: local_rule-1-match-0
104-
value: local_rule-1-match-0
105-
- key: local_rule-1-match-1
106-
value: local_rule-1-match-1
107-
- key: local_masked_remote_address
103+
- key: rule-1-match-0
104+
value: rule-1-match-0
105+
- key: rule-1-match-1
106+
value: rule-1-match-1
107+
- key: masked_remote_address
108108
value: 192.168.0.0/16
109-
- key: local_remote_address
109+
- key: remote_address
110110
tokenBucket:
111111
fillInterval: 60s
112112
maxTokens: 10

internal/xds/translator/testdata/out/xds-ir/local-ratelimit.routes.yaml

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@
1313
rateLimits:
1414
- actions:
1515
- headerValueMatch:
16-
descriptorKey: local_rule-0-match-0
17-
descriptorValue: local_rule-0-match-0
16+
descriptorKey: rule-0-match-0
17+
descriptorValue: rule-0-match-0
1818
expectMatch: true
1919
headers:
2020
- name: x-user-id
2121
stringMatch:
2222
exact: one
2323
- headerValueMatch:
24-
descriptorKey: local_rule-0-match-1
25-
descriptorValue: local_rule-0-match-1
24+
descriptorKey: rule-0-match-1
25+
descriptorValue: rule-0-match-1
2626
expectMatch: true
2727
headers:
2828
- name: x-org-id
@@ -36,10 +36,10 @@
3636
alwaysConsumeDefaultTokenBucket: false
3737
descriptors:
3838
- entries:
39-
- key: local_rule-0-match-0
40-
value: local_rule-0-match-0
41-
- key: local_rule-0-match-1
42-
value: local_rule-0-match-1
39+
- key: rule-0-match-0
40+
value: rule-0-match-0
41+
- key: rule-0-match-1
42+
value: rule-0-match-1
4343
tokenBucket:
4444
fillInterval: 3600s
4545
maxTokens: 10
@@ -64,33 +64,33 @@
6464
rateLimits:
6565
- actions:
6666
- headerValueMatch:
67-
descriptorKey: local_rule-0-match-0
68-
descriptorValue: local_rule-0-match-0
67+
descriptorKey: rule-0-match-0
68+
descriptorValue: rule-0-match-0
6969
expectMatch: true
7070
headers:
7171
- name: x-user-id
7272
stringMatch:
7373
exact: one
7474
- headerValueMatch:
75-
descriptorKey: local_rule-0-match-1
76-
descriptorValue: local_rule-0-match-1
75+
descriptorKey: rule-0-match-1
76+
descriptorValue: rule-0-match-1
7777
expectMatch: true
7878
headers:
7979
- name: x-org-id
8080
stringMatch:
8181
exact: foo
8282
- actions:
8383
- headerValueMatch:
84-
descriptorKey: local_rule-1-match-0
85-
descriptorValue: local_rule-1-match-0
84+
descriptorKey: rule-1-match-0
85+
descriptorValue: rule-1-match-0
8686
expectMatch: true
8787
headers:
8888
- name: x-user-id
8989
stringMatch:
9090
exact: two
9191
- headerValueMatch:
92-
descriptorKey: local_rule-1-match-1
93-
descriptorValue: local_rule-1-match-1
92+
descriptorKey: rule-1-match-1
93+
descriptorValue: rule-1-match-1
9494
expectMatch: true
9595
headers:
9696
- name: x-org-id
@@ -106,20 +106,20 @@
106106
alwaysConsumeDefaultTokenBucket: false
107107
descriptors:
108108
- entries:
109-
- key: local_rule-0-match-0
110-
value: local_rule-0-match-0
111-
- key: local_rule-0-match-1
112-
value: local_rule-0-match-1
109+
- key: rule-0-match-0
110+
value: rule-0-match-0
111+
- key: rule-0-match-1
112+
value: rule-0-match-1
113113
tokenBucket:
114114
fillInterval: 3600s
115115
maxTokens: 10
116116
tokensPerFill: 10
117117
- entries:
118-
- key: local_rule-1-match-0
119-
value: local_rule-1-match-0
120-
- key: local_rule-1-match-1
121-
value: local_rule-1-match-1
122-
- key: local_masked_remote_address
118+
- key: rule-1-match-0
119+
value: rule-1-match-0
120+
- key: rule-1-match-1
121+
value: rule-1-match-1
122+
- key: masked_remote_address
123123
value: 192.168.0.0/16
124124
tokenBucket:
125125
fillInterval: 60s

internal/xds/translator/testdata/out/xds-ir/ratelimit-both-type.routes.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
rateLimits:
3434
- actions:
3535
- headerValueMatch:
36-
descriptorKey: local_rule-0-match-0
37-
descriptorValue: local_rule-0-match-0
36+
descriptorKey: rule-0-match-0
37+
descriptorValue: rule-0-match-0
3838
expectMatch: true
3939
headers:
4040
- name: x-user-id
@@ -55,8 +55,8 @@
5555
alwaysConsumeDefaultTokenBucket: false
5656
descriptors:
5757
- entries:
58-
- key: local_rule-0-match-0
59-
value: local_rule-0-match-0
58+
- key: rule-0-match-0
59+
value: rule-0-match-0
6060
tokenBucket:
6161
fillInterval: 3600s
6262
maxTokens: 10

0 commit comments

Comments
 (0)