Skip to content

Commit 2aaf7f0

Browse files
Xunzhuomergify[bot]
andcommitted
feat(test): e2e test for rate limit (aeraki-mesh#243)
* e2e test for rate limit Signed-off-by: Xunzhuo <[email protected]> * fix lint and add test to workflow Signed-off-by: Xunzhuo <[email protected]> * fix lint Signed-off-by: Xunzhuo <[email protected]> * fix global rate limit e2e test Signed-off-by: Xunzhuo <[email protected]> * Update metarouter-local-ratelimit.yaml Signed-off-by: Xunzhuo <[email protected]> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
1 parent 16938d9 commit 2aaf7f0

File tree

7 files changed

+356
-3
lines changed

7 files changed

+356
-3
lines changed

.github/workflows/e2e-metaprotocol.yaml

+58
Original file line numberDiff line numberDiff line change
@@ -154,3 +154,61 @@ jobs:
154154
run: bash ${SCRIPTS_DIR}/aeraki.sh
155155
- name: test
156156
run: go test -v github.com/aeraki-mesh/aeraki/test/e2e/metaprotocol/ -run TestPercentageRouting
157+
TestLocalRateLimit:
158+
runs-on: ubuntu-latest
159+
timeout-minutes: 60
160+
strategy:
161+
fail-fast: true
162+
name: TestLocalRateLimit
163+
steps:
164+
- name: Check out code
165+
uses: actions/checkout@v2
166+
- name: Setup Go
167+
uses: actions/setup-go@v2
168+
with:
169+
go-version: 1.16
170+
- name: Install dependencies
171+
run: |
172+
go version
173+
go get golang.org/x/tools/cmd/goimports
174+
- name: build docker
175+
run: make docker-build-e2e
176+
- name: Prepare envrionment
177+
run: bash ${SCRIPTS_DIR}/pre.sh
178+
- name: Install Minikube
179+
run: bash ${SCRIPTS_DIR}/minikube.sh start
180+
- name: Install Istio
181+
run: bash ${SCRIPTS_DIR}/istio.sh -y -f ${COMMON_DIR}/istio-config.yaml
182+
- name: Install aeraki
183+
run: bash ${SCRIPTS_DIR}/aeraki.sh
184+
- name: test
185+
run: go test -v github.com/aeraki-mesh/aeraki/test/e2e/metaprotocol/ -run TestLocalRateLimit
186+
TestGlobalRateLimit:
187+
runs-on: ubuntu-latest
188+
timeout-minutes: 60
189+
strategy:
190+
fail-fast: true
191+
name: TestGlobalRateLimit
192+
steps:
193+
- name: Check out code
194+
uses: actions/checkout@v2
195+
- name: Setup Go
196+
uses: actions/setup-go@v2
197+
with:
198+
go-version: 1.16
199+
- name: Install dependencies
200+
run: |
201+
go version
202+
go get golang.org/x/tools/cmd/goimports
203+
- name: build docker
204+
run: make docker-build-e2e
205+
- name: Prepare envrionment
206+
run: bash ${SCRIPTS_DIR}/pre.sh
207+
- name: Install Minikube
208+
run: bash ${SCRIPTS_DIR}/minikube.sh start
209+
- name: Install Istio
210+
run: bash ${SCRIPTS_DIR}/istio.sh -y -f ${COMMON_DIR}/istio-config.yaml
211+
- name: Install aeraki
212+
run: bash ${SCRIPTS_DIR}/aeraki.sh
213+
- name: test
214+
run: go test -v github.com/aeraki-mesh/aeraki/test/e2e/metaprotocol/ -run TestGlobalRateLimit

.github/workflows/e2e-thrift.yaml

+61-3
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ env:
99
COMMON_DIR: test/e2e/common
1010
AERAKI_IMG_PULL_POLICY: Never
1111
jobs:
12-
test:
12+
TestSidecarOutboundConfig:
1313
runs-on: ubuntu-latest
1414
timeout-minutes: 60
1515
strategy:
1616
fail-fast: true
17-
name: e2e-test
17+
name: TestSidecarOutboundConfig
1818
steps:
1919
- name: Check out code
2020
uses: actions/checkout@v2
@@ -37,4 +37,62 @@ jobs:
3737
- name: Install aeraki
3838
run: bash ${SCRIPTS_DIR}/aeraki.sh
3939
- name: test
40-
run: make e2e-thrift
40+
run: go test -v github.com/aeraki-mesh/aeraki/test/e2e/thrift/ -run TestSidecarOutboundConfig
41+
TestSidecarInboundConfig:
42+
runs-on: ubuntu-latest
43+
timeout-minutes: 60
44+
strategy:
45+
fail-fast: true
46+
name: TestSidecarInboundConfig
47+
steps:
48+
- name: Check out code
49+
uses: actions/checkout@v2
50+
- name: Setup Go
51+
uses: actions/setup-go@v2
52+
with:
53+
go-version: 1.16
54+
- name: Install dependencies
55+
run: |
56+
go version
57+
go get golang.org/x/tools/cmd/goimports
58+
- name: build docker
59+
run: make docker-build-e2e
60+
- name: Prepare envrionment
61+
run: bash ${SCRIPTS_DIR}/pre.sh
62+
- name: Install Minikube
63+
run: bash ${SCRIPTS_DIR}/minikube.sh start
64+
- name: Install Istio
65+
run: bash ${SCRIPTS_DIR}/istio.sh -y -f ${COMMON_DIR}/istio-config.yaml
66+
- name: Install aeraki
67+
run: bash ${SCRIPTS_DIR}/aeraki.sh
68+
- name: test
69+
run: go test -v github.com/aeraki-mesh/aeraki/test/e2e/thrift/ -run TestSidecarInboundConfig
70+
TestVersionRouting:
71+
runs-on: ubuntu-latest
72+
timeout-minutes: 60
73+
strategy:
74+
fail-fast: true
75+
name: TestVersionRouting
76+
steps:
77+
- name: Check out code
78+
uses: actions/checkout@v2
79+
- name: Setup Go
80+
uses: actions/setup-go@v2
81+
with:
82+
go-version: 1.16
83+
- name: Install dependencies
84+
run: |
85+
go version
86+
go get golang.org/x/tools/cmd/goimports
87+
- name: build docker
88+
run: make docker-build-e2e
89+
- name: Prepare envrionment
90+
run: bash ${SCRIPTS_DIR}/pre.sh
91+
- name: Install Minikube
92+
run: bash ${SCRIPTS_DIR}/minikube.sh start
93+
- name: Install Istio
94+
run: bash ${SCRIPTS_DIR}/istio.sh -y -f ${COMMON_DIR}/istio-config.yaml
95+
- name: Install aeraki
96+
run: bash ${SCRIPTS_DIR}/aeraki.sh
97+
- name: test
98+
run: go test -v github.com/aeraki-mesh/aeraki/test/e2e/thrift/ -run TestVersionRouting

test/e2e/metaprotocol/metaprotocol_test.go

+52
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ func setup() {
3838
util.KubeApply("metaprotocol", "testdata/metaprotocol-sample.yaml", "")
3939
util.KubeApply("metaprotocol", "testdata/serviceentry.yaml", "")
4040
util.KubeApply("metaprotocol", "testdata/destinationrule.yaml", "")
41+
util.KubeApply("metaprotocol", "testdata/rate-limit-server/", "")
4142
}
4243

4344
func shutdown() {
@@ -145,3 +146,54 @@ func testAttributeMatch(matchPattern string, t *testing.T) {
145146
}
146147
}
147148
}
149+
150+
func TestLocalRateLimit(t *testing.T) {
151+
util.WaitForDeploymentsReady("metaprotocol", 10*time.Minute, "")
152+
util.KubeApply("metaprotocol", "testdata/metarouter-local-ratelimit.yaml", "")
153+
defer util.KubeDelete("metaprotocol", "testdata/metarouter-local-ratelimit.yaml", "")
154+
155+
log.Info("Waiting for rules to propagate ...")
156+
time.Sleep(1 * time.Minute)
157+
consumerPod, _ := util.GetPodName("metaprotocol", "app=dubbo-sample-consumer", "")
158+
success := 0
159+
for i := 0; i < 10; i++ {
160+
dubboResponse, _ := util.PodExec("metaprotocol", consumerPod, "dubbo-sample-consumer",
161+
"curl -s 127.0.0.1:9009/hello", false, "")
162+
response := "response from dubbo-sample-provider"
163+
log.Info(dubboResponse)
164+
if strings.Contains(dubboResponse, response) {
165+
success++
166+
}
167+
}
168+
if success != 2 {
169+
t.Errorf("local rate limit failed, want: %v got:%v ", 2, success)
170+
} else {
171+
t.Logf("%v requests have been sent to server", success)
172+
}
173+
}
174+
175+
func TestGlobalRateLimit(t *testing.T) {
176+
util.WaitForDeploymentsReady("metaprotocol", 10*time.Minute, "")
177+
util.KubeApply("metaprotocol", "testdata/metarouter-global-ratelimit.yaml", "")
178+
defer util.KubeDelete("metaprotocol", "testdata/metarouter-global-ratelimit.yaml", "")
179+
180+
log.Info("Waiting for rules to propagate ...")
181+
time.Sleep(1 * time.Minute)
182+
consumerPod, _ := util.GetPodName("metaprotocol", "app=dubbo-sample-consumer", "")
183+
success := 0
184+
for i := 0; i < 20; i++ {
185+
dubboResponse, _ := util.PodExec("metaprotocol", consumerPod, "dubbo-sample-consumer",
186+
"curl -s 127.0.0.1:9009/hello", false, "")
187+
response := "response from dubbo-sample-provider"
188+
log.Info(dubboResponse)
189+
if strings.Contains(dubboResponse, response) {
190+
success++
191+
}
192+
}
193+
194+
if success != 10 {
195+
t.Errorf("global rate limit failed, want: %v got:%v ", 10, success)
196+
} else {
197+
t.Logf("%v requests have been sent to server", success)
198+
}
199+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Copyright Aeraki Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
---
16+
apiVersion: metaprotocol.aeraki.io/v1alpha1
17+
kind: MetaRouter
18+
metadata:
19+
name: test-metaprotocol-route
20+
spec:
21+
hosts:
22+
- org.apache.dubbo.samples.basic.api.demoservice
23+
globalRateLimit:
24+
domain: production
25+
match:
26+
attributes:
27+
method:
28+
exact: sayHello
29+
rateLimitService: outbound|8081||rate-limit-server.metaprotocol.svc.cluster.local
30+
requestTimeout: 100ms
31+
denyOnFail: true
32+
descriptors:
33+
- property: method
34+
descriptorKey: method
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Copyright Aeraki Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
---
16+
apiVersion: metaprotocol.aeraki.io/v1alpha1
17+
kind: MetaRouter
18+
metadata:
19+
name: test-metaprotocol-route
20+
spec:
21+
hosts:
22+
- org.apache.dubbo.samples.basic.api.demoservice
23+
routes:
24+
- name: default
25+
match:
26+
attributes:
27+
method:
28+
exact: sayHello
29+
route:
30+
- destination:
31+
host: org.apache.dubbo.samples.basic.api.demoservice
32+
subset: v1
33+
localRateLimit:
34+
tokenBucket:
35+
fillInterval: 60s
36+
maxTokens: 5
37+
tokensPerFill: 5
38+
conditions:
39+
- tokenBucket:
40+
fillInterval: 60s
41+
maxTokens: 2
42+
tokensPerFill: 2
43+
match:
44+
attributes:
45+
method:
46+
exact: sayHello
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Copyright Aeraki Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
---
16+
apiVersion: v1
17+
kind: ConfigMap
18+
metadata:
19+
name: rate-limit-config
20+
data:
21+
config.yaml: |
22+
domain: production
23+
descriptors:
24+
- key: method
25+
value: "sayHello"
26+
rate_limit:
27+
unit: minute
28+
requests_per_unit: 10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# Copyright Aeraki Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
---
16+
apiVersion: apps/v1
17+
kind: Deployment
18+
metadata:
19+
name: rate-limit-server
20+
labels:
21+
app: rate-limit-server
22+
spec:
23+
selector:
24+
matchLabels:
25+
app: rate-limit-server
26+
replicas: 1
27+
template:
28+
metadata:
29+
labels:
30+
app: rate-limit-server
31+
annotations:
32+
sidecar.istio.io/inject: "false"
33+
spec:
34+
containers:
35+
- name: rate-limit-server
36+
image: envoyproxy/ratelimit:master
37+
volumeMounts:
38+
- name: ratelimit-config
39+
mountPath: /data/ratelimit/config
40+
readOnly: true
41+
command: ["/bin/sh", "-c"]
42+
args: ["mkdir -p /ratelimit/config && cp /data/ratelimit/config/config.yaml /ratelimit/config/config.yaml && cat /ratelimit/config/config.yaml && /bin/ratelimit"]
43+
env:
44+
- name: USE_STATSD
45+
value: "false"
46+
- name: LOG_LEVEL
47+
value: debug
48+
- name: REDIS_SOCKET_TYPE
49+
value: tcp
50+
- name: REDIS_URL
51+
value: 127.0.0.1:6379
52+
- name: RUNTIME_ROOT
53+
value: "/"
54+
- name: RUNTIME_SUBDIRECTORY
55+
value: "ratelimit"
56+
- name: RUNTIME_WATCH_ROOT
57+
value: "false"
58+
- name: redis
59+
image: redis:alpine
60+
volumes:
61+
- name: ratelimit-config
62+
configMap:
63+
name: rate-limit-config
64+
65+
---
66+
apiVersion: v1
67+
kind: Service
68+
metadata:
69+
name: rate-limit-server
70+
spec:
71+
selector:
72+
app: rate-limit-server
73+
ports:
74+
- name: tcp-rate-limit-server
75+
protocol: TCP
76+
port: 8081
77+
targetPort: 8081

0 commit comments

Comments
 (0)