Skip to content

Commit

Permalink
Add e2e tests for ingress A/B Testing
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanprodan committed Apr 2, 2020
1 parent b8e9f57 commit 14e9c7f
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 104 deletions.
9 changes: 2 additions & 7 deletions pkg/router/ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,8 @@ func (i *IngressRouter) SetRoutes(
cookie = v.Exact
} else {
header = k
if v.Regex != "" {
headerRegex = v.Regex
} else {
headerValue = v.Exact
}
headerRegex = v.Regex
headerValue = v.Exact
}
}
}
Expand Down Expand Up @@ -206,7 +203,6 @@ func (i *IngressRouter) makeAnnotations(annotations map[string]string) map[strin
}

res[i.GetAnnotationWithPrefix("canary")] = "false"
res[i.GetAnnotationWithPrefix("canary-weight")] = "0"

return res
}
Expand All @@ -221,7 +217,6 @@ func (i *IngressRouter) makeHeaderAnnotations(annotations map[string]string,
}

res[i.GetAnnotationWithPrefix("canary")] = "true"
res[i.GetAnnotationWithPrefix("canary-weight")] = "0"

if cookie != "" {
res[i.GetAnnotationWithPrefix("canary-by-cookie")] = cookie
Expand Down
3 changes: 0 additions & 3 deletions pkg/router/ingress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,13 @@ func TestIngressRouter_Reconcile(t *testing.T) {
require.NoError(t, err)

canaryAn := "custom.ingress.kubernetes.io/canary"
canaryWeightAn := "custom.ingress.kubernetes.io/canary-weight"

canaryName := fmt.Sprintf("%s-canary", mocks.ingressCanary.Spec.IngressRef.Name)
inCanary, err := router.kubeClient.NetworkingV1beta1().Ingresses("default").Get(canaryName, metav1.GetOptions{})
require.NoError(t, err)

// test initialisation
assert.Equal(t, "false", inCanary.Annotations[canaryAn])
assert.Equal(t, "0", inCanary.Annotations[canaryWeightAn])
}

func TestIngressRouter_GetSetRoutes(t *testing.T) {
Expand Down Expand Up @@ -80,7 +78,6 @@ func TestIngressRouter_GetSetRoutes(t *testing.T) {

// test promotion
assert.Equal(t, "false", inCanary.Annotations[canaryAn])
assert.Equal(t, "0", inCanary.Annotations[canaryWeightAn])
}

func TestIngressRouter_ABTest(t *testing.T) {
Expand Down
200 changes: 107 additions & 93 deletions test/e2e-nginx-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,65 @@ echo '>>> Initialising canary'
kubectl apply -f ${REPO_ROOT}/test/e2e-workload.yaml
kubectl apply -f ${REPO_ROOT}/test/e2e-ingress.yaml

echo '>>> Create metric templates'
cat <<EOF | kubectl apply -f -
apiVersion: flagger.app/v1beta1
kind: MetricTemplate
metadata:
name: error-rate
namespace: ingress-nginx
spec:
provider:
type: prometheus
address: http://flagger-prometheus.ingress-nginx:9090
query: |
100 - sum(
rate(
http_request_duration_seconds_count{
kubernetes_namespace="{{ namespace }}",
kubernetes_pod_name=~"{{ target }}-[0-9a-zA-Z]+(-[0-9a-zA-Z]+)",
path="root",
status!~"5.*"
}[{{ interval }}]
)
)
/
sum(
rate(
http_request_duration_seconds_count{
kubernetes_namespace="{{ namespace }}",
kubernetes_pod_name=~"{{ target }}-[0-9a-zA-Z]+(-[0-9a-zA-Z]+)",
path="root"
}[{{ interval }}]
)
)
* 100
EOF

cat <<EOF | kubectl apply -f -
apiVersion: flagger.app/v1beta1
kind: MetricTemplate
metadata:
name: latency
namespace: ingress-nginx
spec:
provider:
type: prometheus
address: http://flagger-prometheus.ingress-nginx:9090
query: |
histogram_quantile(0.99,
sum(
rate(
http_request_duration_seconds_bucket{
kubernetes_namespace="{{ namespace }}",
kubernetes_pod_name=~"{{ target }}-[0-9a-zA-Z]+(-[0-9a-zA-Z]+)",
path="root"
}[{{ interval }}]
)
) by (le)
)
EOF

cat <<EOF | kubectl apply -f -
apiVersion: flagger.app/v1beta1
kind: Canary
Expand All @@ -39,58 +98,30 @@ spec:
targetPort: http
analysis:
interval: 15s
threshold: 15
maxWeight: 30
stepWeight: 10
threshold: 5
maxWeight: 40
stepWeight: 20
metrics:
- name: "http-request-success-rate"
threshold: 99
interval: 1m
query: |
100 - sum(
rate(
http_request_duration_seconds_count{
kubernetes_namespace="test",
kubernetes_pod_name=~"podinfo-[0-9a-zA-Z]+(-[0-9a-zA-Z]+)",
path="root",
status!~"5.*"
}[1m]
)
)
/
sum(
rate(
http_request_duration_seconds_count{
kubernetes_namespace="test",
kubernetes_pod_name=~"podinfo-[0-9a-zA-Z]+(-[0-9a-zA-Z]+)",
path="root"
}[1m]
)
)
* 100
- name: "latency"
threshold: 0.5
interval: 1m
query: |
histogram_quantile(0.99,
sum(
rate(
http_request_duration_seconds_bucket{
kubernetes_namespace="test",
kubernetes_pod_name=~"podinfo-[0-9a-zA-Z]+(-[0-9a-zA-Z]+)",
path="root"
}[1m]
)
) by (le)
)
- name: error-rate
templateRef:
name: error-rate
namespace: ingress-nginx
thresholdRange:
max: 1
interval: 30s
- name: latency
templateRef:
name: latency
namespace: ingress-nginx
thresholdRange:
max: 0.5
interval: 30s
webhooks:
- name: load-test
url: http://flagger-loadtester.test/
timeout: 5s
metadata:
type: cmd
cmd: "hey -z 10m -q 10 -c 2 -host app.example.com http://nginx-ingress-controller.ingress-nginx"
logCmdOutput: "true"
cmd: "hey -z 2m -q 10 -c 2 -host app.example.com http://nginx-ingress-controller.ingress-nginx"
EOF

echo '>>> Waiting for primary to be ready'
Expand Down Expand Up @@ -173,73 +204,56 @@ spec:
progressDeadlineSeconds: 60
service:
port: 80
targetPort: 9898
targetPort: http
analysis:
interval: 10s
interval: 15s
threshold: 5
iterations: 5
iterations: 3
match:
- headers:
x-canary:
exact: "insider"
- headers:
cookie:
exact: "canary"
- headers:
x-user:
exact: "insider"
metrics:
- name: "http-request-success-rate"
threshold: 99
interval: 1m
query: |
100 - sum(
rate(
http_request_duration_seconds_count{
kubernetes_namespace="test",
kubernetes_pod_name=~"podinfo-[0-9a-zA-Z]+(-[0-9a-zA-Z]+)",
path="root",
status!~"5.*"
}[1m]
)
)
/
sum(
rate(
http_request_duration_seconds_count{
kubernetes_namespace="test",
kubernetes_pod_name=~"podinfo-[0-9a-zA-Z]+(-[0-9a-zA-Z]+)",
path="root"
}[1m]
)
)
* 100
- name: error-rate
templateRef:
name: error-rate
namespace: ingress-nginx
thresholdRange:
max: 1
interval: 30s
- name: latency
templateRef:
name: latency
namespace: ingress-nginx
thresholdRange:
max: 0.5
interval: 30s
webhooks:
- name: pre
type: pre-rollout
- name: test-header-routing
type: rollout
url: http://flagger-loadtester.test/
timeout: 5s
metadata:
type: cmd
cmd: "hey -z 10m -q 10 -c 2 -H 'X-Canary: insider' -host app.example.com http://nginx-ingress-controller.ingress-nginx"
logCmdOutput: "true"
- name: post
type: post-rollout
type: bash
cmd: "curl -sH 'x-user: insider' -H 'Host: app.example.com' http://nginx-ingress-controller.ingress-nginx | grep '3.1.2'"
- name: load-test
type: rollout
url: http://flagger-loadtester.test/
timeout: 15s
metadata:
type: cmd
cmd: "curl -sH 'Host: app.example.com' http://nginx-ingress-controller.ingress-nginx"
logCmdOutput: "true"
cmd: "hey -z 2m -q 10 -c 2 -H 'x-user: insider' -host app.example.com http://nginx-ingress-controller.ingress-nginx"
EOF

echo '>>> Triggering A/B testing'
kubectl -n test set image deployment/podinfo podinfod=stefanprodan/podinfo:3.1.2

echo '>>> Waiting for A/B testing promotion'
retries=50
retries=6
count=0
ok=false
until ${ok}; do
kubectl -n test describe deployment/podinfo-primary | grep '3.1.2' && ok=true || ok=false
sleep 10
sleep 30
kubectl -n ingress-nginx logs deployment/flagger --tail 1
count=$(($count + 1))
if [[ ${count} -eq ${retries} ]]; then
Expand All @@ -255,4 +269,4 @@ echo '✔ A/B testing promotion test passed'

kubectl -n ingress-nginx logs deployment/flagger

echo '✔ All tests passed'
echo '✔ All tests passed'
2 changes: 1 addition & 1 deletion test/e2e-nginx.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
set -o errexit

REPO_ROOT=$(git rev-parse --show-toplevel)
NGINX_HELM_VERSION=1.34.2 # ingress v0.30.0
NGINX_HELM_VERSION=1.34.3 # ingress v0.30.0

echo '>>> Installing NGINX Ingress'
kubectl create ns ingress-nginx
Expand Down

0 comments on commit 14e9c7f

Please sign in to comment.