Skip to content

feat(test): e2e test for rate limit #243

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jun 7, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions .github/workflows/e2e-metaprotocol.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,61 @@ jobs:
run: bash ${SCRIPTS_DIR}/aeraki.sh
- name: test
run: go test -v github.com/aeraki-mesh/aeraki/test/e2e/metaprotocol/ -run TestPercentageRouting
TestLocalRateLimit:
runs-on: ubuntu-latest
timeout-minutes: 60
strategy:
fail-fast: true
name: TestLocalRateLimit
steps:
- name: Check out code
uses: actions/checkout@v2
- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: 1.16
- name: Install dependencies
run: |
go version
go get golang.org/x/tools/cmd/goimports
- name: build docker
run: make docker-build-e2e
- name: Prepare envrionment
run: bash ${SCRIPTS_DIR}/pre.sh
- name: Install Minikube
run: bash ${SCRIPTS_DIR}/minikube.sh start
- name: Install Istio
run: bash ${SCRIPTS_DIR}/istio.sh -y -f ${COMMON_DIR}/istio-config.yaml
- name: Install aeraki
run: bash ${SCRIPTS_DIR}/aeraki.sh
- name: test
run: go test -v github.com/aeraki-mesh/aeraki/test/e2e/metaprotocol/ -run TestLocalRateLimit
TestGlobalRateLimit:
runs-on: ubuntu-latest
timeout-minutes: 60
strategy:
fail-fast: true
name: TestGlobalRateLimit
steps:
- name: Check out code
uses: actions/checkout@v2
- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: 1.16
- name: Install dependencies
run: |
go version
go get golang.org/x/tools/cmd/goimports
- name: build docker
run: make docker-build-e2e
- name: Prepare envrionment
run: bash ${SCRIPTS_DIR}/pre.sh
- name: Install Minikube
run: bash ${SCRIPTS_DIR}/minikube.sh start
- name: Install Istio
run: bash ${SCRIPTS_DIR}/istio.sh -y -f ${COMMON_DIR}/istio-config.yaml
- name: Install aeraki
run: bash ${SCRIPTS_DIR}/aeraki.sh
- name: test
run: go test -v github.com/aeraki-mesh/aeraki/test/e2e/metaprotocol/ -run TestGlobalRateLimit
64 changes: 61 additions & 3 deletions .github/workflows/e2e-thrift.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ env:
COMMON_DIR: test/e2e/common
AERAKI_IMG_PULL_POLICY: Never
jobs:
test:
TestSidecarOutboundConfig:
runs-on: ubuntu-latest
timeout-minutes: 60
strategy:
fail-fast: true
name: e2e-test
name: TestSidecarOutboundConfig
steps:
- name: Check out code
uses: actions/checkout@v2
Expand All @@ -37,4 +37,62 @@ jobs:
- name: Install aeraki
run: bash ${SCRIPTS_DIR}/aeraki.sh
- name: test
run: make e2e-thrift
run: go test -v github.com/aeraki-mesh/aeraki/test/e2e/thrift/ -run TestSidecarOutboundConfig
TestSidecarInboundConfig:
runs-on: ubuntu-latest
timeout-minutes: 60
strategy:
fail-fast: true
name: TestSidecarInboundConfig
steps:
- name: Check out code
uses: actions/checkout@v2
- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: 1.16
- name: Install dependencies
run: |
go version
go get golang.org/x/tools/cmd/goimports
- name: build docker
run: make docker-build-e2e
- name: Prepare envrionment
run: bash ${SCRIPTS_DIR}/pre.sh
- name: Install Minikube
run: bash ${SCRIPTS_DIR}/minikube.sh start
- name: Install Istio
run: bash ${SCRIPTS_DIR}/istio.sh -y -f ${COMMON_DIR}/istio-config.yaml
- name: Install aeraki
run: bash ${SCRIPTS_DIR}/aeraki.sh
- name: test
run: go test -v github.com/aeraki-mesh/aeraki/test/e2e/thrift/ -run TestSidecarInboundConfig
TestVersionRouting:
runs-on: ubuntu-latest
timeout-minutes: 60
strategy:
fail-fast: true
name: TestVersionRouting
steps:
- name: Check out code
uses: actions/checkout@v2
- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: 1.16
- name: Install dependencies
run: |
go version
go get golang.org/x/tools/cmd/goimports
- name: build docker
run: make docker-build-e2e
- name: Prepare envrionment
run: bash ${SCRIPTS_DIR}/pre.sh
- name: Install Minikube
run: bash ${SCRIPTS_DIR}/minikube.sh start
- name: Install Istio
run: bash ${SCRIPTS_DIR}/istio.sh -y -f ${COMMON_DIR}/istio-config.yaml
- name: Install aeraki
run: bash ${SCRIPTS_DIR}/aeraki.sh
- name: test
run: go test -v github.com/aeraki-mesh/aeraki/test/e2e/thrift/ -run TestVersionRouting
52 changes: 52 additions & 0 deletions test/e2e/metaprotocol/metaprotocol_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func setup() {
util.KubeApply("metaprotocol", "testdata/metaprotocol-sample.yaml", "")
util.KubeApply("metaprotocol", "testdata/serviceentry.yaml", "")
util.KubeApply("metaprotocol", "testdata/destinationrule.yaml", "")
util.KubeApply("metaprotocol", "testdata/rate-limit-server/", "")
}

func shutdown() {
Expand Down Expand Up @@ -145,3 +146,54 @@ func testAttributeMatch(matchPattern string, t *testing.T) {
}
}
}

func TestLocalRateLimit(t *testing.T) {
util.WaitForDeploymentsReady("metaprotocol", 10*time.Minute, "")
util.KubeApply("metaprotocol", "testdata/metarouter-local-ratelimit.yaml", "")
defer util.KubeDelete("metaprotocol", "testdata/metarouter-local-ratelimit.yaml", "")

log.Info("Waiting for rules to propagate ...")
time.Sleep(1 * time.Minute)
consumerPod, _ := util.GetPodName("metaprotocol", "app=dubbo-sample-consumer", "")
success := 0
for i := 0; i < 10; i++ {
dubboResponse, _ := util.PodExec("metaprotocol", consumerPod, "dubbo-sample-consumer",
"curl -s 127.0.0.1:9009/hello", false, "")
response := "response from dubbo-sample-provider"
log.Info(dubboResponse)
if strings.Contains(dubboResponse, response) {
success++
}
}
if success != 2 {
t.Errorf("local rate limit failed, want: %v got:%v ", 2, success)
} else {
t.Logf("%v requests have been sent to server", success)
}
}

func TestGlobalRateLimit(t *testing.T) {
util.WaitForDeploymentsReady("metaprotocol", 10*time.Minute, "")
util.KubeApply("metaprotocol", "testdata/metarouter-global-ratelimit.yaml", "")
defer util.KubeDelete("metaprotocol", "testdata/metarouter-global-ratelimit.yaml", "")

log.Info("Waiting for rules to propagate ...")
time.Sleep(1 * time.Minute)
consumerPod, _ := util.GetPodName("metaprotocol", "app=dubbo-sample-consumer", "")
success := 0
for i := 0; i < 20; i++ {
dubboResponse, _ := util.PodExec("metaprotocol", consumerPod, "dubbo-sample-consumer",
"curl -s 127.0.0.1:9009/hello", false, "")
response := "response from dubbo-sample-provider"
log.Info(dubboResponse)
if strings.Contains(dubboResponse, response) {
success++
}
}

if success != 10 {
t.Errorf("global rate limit failed, want: %v got:%v ", 10, success)
} else {
t.Logf("%v requests have been sent to server", success)
}
}
34 changes: 34 additions & 0 deletions test/e2e/metaprotocol/testdata/metarouter-global-ratelimit.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Copyright Aeraki Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

---
apiVersion: metaprotocol.aeraki.io/v1alpha1
kind: MetaRouter
metadata:
name: test-metaprotocol-route
spec:
hosts:
- org.apache.dubbo.samples.basic.api.demoservice
globalRateLimit:
domain: production
match:
attributes:
method:
exact: sayHello
rateLimitService: outbound|8081||rate-limit-server.metaprotocol.svc.cluster.local
requestTimeout: 100ms
denyOnFail: true
descriptors:
- property: method
descriptorKey: method
46 changes: 46 additions & 0 deletions test/e2e/metaprotocol/testdata/metarouter-local-ratelimit.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Copyright Aeraki Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

---
apiVersion: metaprotocol.aeraki.io/v1alpha1
kind: MetaRouter
metadata:
name: test-metaprotocol-route
spec:
hosts:
- org.apache.dubbo.samples.basic.api.demoservice
routes:
- name: default
match:
attributes:
method:
exact: sayHello
route:
- destination:
host: org.apache.dubbo.samples.basic.api.demoservice
subset: v1
localRateLimit:
tokenBucket:
fillInterval: 60s
maxTokens: 5
tokensPerFill: 5
conditions:
- tokenBucket:
fillInterval: 20s
maxTokens: 2
tokensPerFill: 2
match:
attributes:
method:
exact: sayHello
28 changes: 28 additions & 0 deletions test/e2e/metaprotocol/testdata/rate-limit-server/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Copyright Aeraki Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

---
apiVersion: v1
kind: ConfigMap
metadata:
name: rate-limit-config
data:
config.yaml: |
domain: production
descriptors:
- key: method
value: "sayHello"
rate_limit:
unit: minute
requests_per_unit: 10
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# Copyright Aeraki Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

---
apiVersion: apps/v1
kind: Deployment
metadata:
name: rate-limit-server
labels:
app: rate-limit-server
spec:
selector:
matchLabels:
app: rate-limit-server
replicas: 1
template:
metadata:
labels:
app: rate-limit-server
annotations:
sidecar.istio.io/inject: "false"
spec:
containers:
- name: rate-limit-server
image: envoyproxy/ratelimit:master
volumeMounts:
- name: ratelimit-config
mountPath: /data/ratelimit/config
readOnly: true
command: ["/bin/sh", "-c"]
args: ["mkdir -p /ratelimit/config && cp /data/ratelimit/config/config.yaml /ratelimit/config/config.yaml && cat /ratelimit/config/config.yaml && /bin/ratelimit"]
env:
- name: USE_STATSD
value: "false"
- name: LOG_LEVEL
value: debug
- name: REDIS_SOCKET_TYPE
value: tcp
- name: REDIS_URL
value: 127.0.0.1:6379
- name: RUNTIME_ROOT
value: "/"
- name: RUNTIME_SUBDIRECTORY
value: "ratelimit"
- name: RUNTIME_WATCH_ROOT
value: "false"
- name: redis
image: redis:alpine
volumes:
- name: ratelimit-config
configMap:
name: rate-limit-config

---
apiVersion: v1
kind: Service
metadata:
name: rate-limit-server
spec:
selector:
app: rate-limit-server
ports:
- name: tcp-rate-limit-server
protocol: TCP
port: 8081
targetPort: 8081