Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
Signed-off-by: hejianpeng <[email protected]>
  • Loading branch information
zirain committed Apr 28, 2023
1 parent 2dcf4b8 commit 8120c2b
Show file tree
Hide file tree
Showing 6 changed files with 242 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
http:
- name: "first-listener"
address: "0.0.0.0"
port: 10080
hostnames:
- "*"
routes:
- name: "first-route"
rateLimit:
global:
rules:
- headerMatches:
- name: "x-user-id"
exact: "one"
limit:
requests: 5
unit: second
pathMatch:
exact: "foo/bar"
destinations:
- host: "1.2.3.4"
port: 50000
- name: "second-route"
rateLimit:
global:
rules:
- headerMatches:
- name: "x-user-id"
distinct: true
limit:
requests: 5
unit: second
pathMatch:
exact: "example"
destinations:
- host: "1.2.3.4"
port: 50000
- name: "third-route"
rateLimit:
global:
rules:
- limit:
requests: 5
unit: second
pathMatch:
exact: "test"
destinations:
- host: "1.2.3.4"
port: 50000
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
- commonLbConfig:
localityWeightedLbConfig: {}
connectTimeout: 10s
dnsLookupFamily: V4_ONLY
edsClusterConfig:
edsConfig:
ads: {}
resourceApiVersion: V3
name: first-route
outlierDetection: {}
perConnectionBufferLimitBytes: 32768
type: EDS
- commonLbConfig:
localityWeightedLbConfig: {}
connectTimeout: 10s
dnsLookupFamily: V4_ONLY
edsClusterConfig:
edsConfig:
ads: {}
resourceApiVersion: V3
name: second-route
outlierDetection: {}
perConnectionBufferLimitBytes: 32768
type: EDS
- commonLbConfig:
localityWeightedLbConfig: {}
connectTimeout: 10s
dnsLookupFamily: V4_ONLY
edsClusterConfig:
edsConfig:
ads: {}
resourceApiVersion: V3
name: third-route
outlierDetection: {}
perConnectionBufferLimitBytes: 32768
type: EDS
- commonLbConfig:
localityWeightedLbConfig: {}
connectTimeout: 10s
dnsLookupFamily: V4_ONLY
dnsRefreshRate: 30s
loadAssignment:
clusterName: ratelimit_cluster
endpoints:
- lbEndpoints:
- endpoint:
address:
socketAddress:
address: envoy-ratelimit.envoy-gateway-system.svc.example-cluster.local
portValue: 8081
loadBalancingWeight: 1
locality: {}
name: ratelimit_cluster
outlierDetection: {}
perConnectionBufferLimitBytes: 32768
respectDnsTtl: true
type: STRICT_DNS
typedExtensionProtocolOptions:
envoy.extensions.upstreams.http.v3.HttpProtocolOptions:
'@type': type.googleapis.com/envoy.extensions.upstreams.http.v3.HttpProtocolOptions
explicitHttpConfig:
http2ProtocolOptions: {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
- clusterName: first-route
endpoints:
- lbEndpoints:
- endpoint:
address:
socketAddress:
address: 1.2.3.4
portValue: 50000
loadBalancingWeight: 1
locality: {}
- clusterName: second-route
endpoints:
- lbEndpoints:
- endpoint:
address:
socketAddress:
address: 1.2.3.4
portValue: 50000
loadBalancingWeight: 1
locality: {}
- clusterName: third-route
endpoints:
- lbEndpoints:
- endpoint:
address:
socketAddress:
address: 1.2.3.4
portValue: 50000
loadBalancingWeight: 1
locality: {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
- accessLog:
- filter:
responseFlagFilter:
flags:
- NR
name: envoy.access_loggers.file
typedConfig:
'@type': type.googleapis.com/envoy.extensions.access_loggers.file.v3.FileAccessLog
path: /dev/stdout
address:
socketAddress:
address: 0.0.0.0
portValue: 10080
defaultFilterChain:
filters:
- name: envoy.filters.network.http_connection_manager
typedConfig:
'@type': type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
accessLog:
- name: envoy.access_loggers.file
typedConfig:
'@type': type.googleapis.com/envoy.extensions.access_loggers.file.v3.FileAccessLog
path: /dev/stdout
httpFilters:
- name: envoy.filters.http.ratelimit
typedConfig:
'@type': type.googleapis.com/envoy.extensions.filters.http.ratelimit.v3.RateLimit
domain: first-listener
rateLimitService:
grpcService:
envoyGrpc:
clusterName: ratelimit_cluster
transportApiVersion: V3
- name: envoy.filters.http.router
typedConfig:
'@type': type.googleapis.com/envoy.extensions.filters.http.router.v3.Router
mergeSlashes: true
normalizePath: true
pathWithEscapedSlashesAction: UNESCAPE_AND_REDIRECT
rds:
configSource:
ads: {}
resourceApiVersion: V3
routeConfigName: first-listener
statPrefix: http
upgradeConfigs:
- upgradeType: websocket
useRemoteAddress: true
name: first-listener
perConnectionBufferLimitBytes: 32768
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
- name: first-listener
virtualHosts:
- domains:
- '*'
name: first-listener
routes:
- match:
path: foo/bar
name: first-route
route:
cluster: first-route
rateLimits:
- actions:
- headerValueMatch:
descriptorKey: first-route-key-rule-0-match-0
descriptorValue: first-route-value-rule-0-match-0
expectMatch: true
headers:
- name: x-user-id
stringMatch:
exact: one
- match:
path: example
name: second-route
route:
cluster: second-route
rateLimits:
- actions:
- requestHeaders:
descriptorKey: second-route-key-rule-0-match-0
headerName: x-user-id
- match:
path: test
name: third-route
route:
cluster: third-route
rateLimits:
- actions:
- genericKey:
descriptorKey: third-route-key-rule-0-match--1
descriptorValue: third-route-value-rule-0-match--1
11 changes: 10 additions & 1 deletion internal/xds/translator/translator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ var (
func TestTranslateXds(t *testing.T) {
testCases := []struct {
name string
dnsDomain string
requireSecrets bool
}{
{
Expand Down Expand Up @@ -115,6 +116,10 @@ func TestTranslateXds(t *testing.T) {
{
name: "ratelimit",
},
{
name: "ratelimit-custom-domain",
dnsDomain: "example-cluster.local",
},
{
name: "ratelimit-sourceip",
},
Expand All @@ -135,10 +140,14 @@ func TestTranslateXds(t *testing.T) {
for _, tc := range testCases {
tc := tc
t.Run(tc.name, func(t *testing.T) {
dnsDomain := tc.dnsDomain
if dnsDomain == "" {
dnsDomain = "cluster.local"
}
ir := requireXdsIRFromInputTestData(t, "xds-ir", tc.name+".yaml")
tr := &Translator{
GlobalRateLimit: &GlobalRateLimitSettings{
ServiceURL: ratelimit.GetServiceURL("envoy-gateway-system", "cluster.local"),
ServiceURL: ratelimit.GetServiceURL("envoy-gateway-system", dnsDomain),
},
}

Expand Down

0 comments on commit 8120c2b

Please sign in to comment.