@@ -38,6 +38,20 @@ type UpstreamTrafficSettingSpec struct {
38
38
// directed to the upstream host.
39
39
// +optional
40
40
ConnectionSettings * ConnectionSettingsSpec `json:"connectionSettings,omitempty"`
41
+
42
+ // RateLimit specifies the rate limit settings for the traffic
43
+ // directed to the upstream host.
44
+ // If HTTP rate limiting is specified, the rate limiting is applied
45
+ // at the VirtualHost level applicable to all routes within the
46
+ // VirtualHost.
47
+ // +optional
48
+ RateLimit * RateLimitSpec `json:"rateLimit,omitempty"`
49
+
50
+ // HTTPRoutes defines the list of HTTP routes settings
51
+ // for the upstream host. Settings are applied at a per
52
+ // route level.
53
+ // +optional
54
+ HTTPRoutes []HTTPRouteSpec `json:"httpRoutes,omitempty"`
41
55
}
42
56
43
57
// ConnectionSettingsSpec defines the connection settings for an
@@ -99,6 +113,111 @@ type HTTPConnectionSettings struct {
99
113
MaxRetries * uint32 `json:"maxRetries,omitempty"`
100
114
}
101
115
116
+ // RateLimitSpec defines the rate limiting specification for
117
+ // the upstream host.
118
+ type RateLimitSpec struct {
119
+ // Local specified the local rate limiting specification
120
+ // for the upstream host.
121
+ // Local rate limiting is enforced directly by the upstream
122
+ // host without any involvement of a global rate limiting service.
123
+ // This is applied as a token bucket rate limiter.
124
+ // +optional
125
+ Local * LocalRateLimitSpec `json:"local,omitempty"`
126
+ }
127
+
128
+ // LocalRateLimitSpec defines the local rate limiting specification
129
+ // for the upstream host.
130
+ type LocalRateLimitSpec struct {
131
+ // TCP defines the local rate limiting specification at the network
132
+ // level. This is a token bucket rate limiter where each connection
133
+ // consumes a single token. If the token is available, the connection
134
+ // will be allowed. If no tokens are available, the connection will be
135
+ // immediately closed.
136
+ // +optional
137
+ TCP * TCPLocalRateLimitSpec `json:"tcp,omitempty"`
138
+
139
+ // HTTP defines the local rate limiting specification for HTTP traffic.
140
+ // This is a token bucket rate limiter where each request consumes
141
+ // a single token. If the token is available, the request will be
142
+ // allowed. If no tokens are available, the request will receive the
143
+ // configured rate limit status.
144
+ HTTP * HTTPLocalRateLimitSpec `json:"http,omitempty"`
145
+ }
146
+
147
+ // TCPLocalRateLimitSpec defines the local rate limiting specification
148
+ // for the upstream host at the TCP level.
149
+ type TCPLocalRateLimitSpec struct {
150
+ // Connections defines the number of connections allowed
151
+ // per unit of time before rate limiting occurs.
152
+ Connections uint32 `json:"connections"`
153
+
154
+ // Unit defines the period of time within which connections
155
+ // over the limit will be rate limited.
156
+ // Valid values are "second", "minute" and "hour".
157
+ Unit string `json:"unit"`
158
+
159
+ // Burst defines the number of connections above the baseline
160
+ // rate that are allowed in a short period of time.
161
+ // +optional
162
+ Burst uint32 `json:"burst,omitempty"`
163
+ }
164
+
165
+ // HTTPLocalRateLimitSpec defines the local rate limiting specification
166
+ // for the upstream host at the HTTP level.
167
+ type HTTPLocalRateLimitSpec struct {
168
+ // Requests defines the number of requests allowed
169
+ // per unit of time before rate limiting occurs.
170
+ Requests uint32 `json:"requests"`
171
+
172
+ // Unit defines the period of time within which requests
173
+ // over the limit will be rate limited.
174
+ // Valid values are "second", "minute" and "hour".
175
+ Unit string `json:"unit"`
176
+
177
+ // Burst defines the number of requests above the baseline
178
+ // rate that are allowed in a short period of time.
179
+ // +optional
180
+ Burst uint32 `json:"burst,omitempty"`
181
+
182
+ // ResponseStatusCode defines the HTTP status code to use for responses
183
+ // to rate limited requests. Code must be in the 400-599 (inclusive)
184
+ // error range. If not specified, a default of 429 (Too Many Requests) is used.
185
+ // +optional
186
+ ResponseStatusCode uint32 `json:"responseStatusCode,omitempty"`
187
+
188
+ // ResponseHeadersToAdd defines the list of HTTP headers that should be
189
+ // added to each response for requests that have been rate limited.
190
+ // +optional
191
+ ResponseHeadersToAdd []HTTPHeaderValue `json:"responseHeadersToAdd,omitempty"`
192
+ }
193
+
194
+ // HTTPHeaderValue defines an HTTP header name/value pair
195
+ type HTTPHeaderValue struct {
196
+ // Name defines the name of the HTTP header.
197
+ Name string `json:"name"`
198
+
199
+ // Value defines the value of the header corresponding to the name key.
200
+ Value string `json:"value"`
201
+ }
202
+
203
+ // HTTPRouteSpec defines the settings correspondng to an HTTP route
204
+ type HTTPRouteSpec struct {
205
+ // Path defines the HTTP path.
206
+ Path string `json:"path"`
207
+
208
+ // RateLimit defines the HTTP rate limiting specification for
209
+ // the specified HTTP route.
210
+ RateLimit * HTTPPerRouteRateLimitSpec `json:"rateLimit,omitempty"`
211
+ }
212
+
213
+ // HTTPPerRouteRateLimitSpec defines the rate limiting specification
214
+ // per HTTP route.
215
+ type HTTPPerRouteRateLimitSpec struct {
216
+ // Local defines the local rate limiting specification
217
+ // applied per HTTP route.
218
+ Local * HTTPLocalRateLimitSpec `json:"local,omitempty"`
219
+ }
220
+
102
221
// UpstreamTrafficSettingStatus defines the status of an UpstreamTrafficSetting resource.
103
222
type UpstreamTrafficSettingStatus struct {
104
223
// CurrentStatus defines the current status of an UpstreamTrafficSetting resource.
0 commit comments