From 881387e5227e465df6406d18bac02ebcd308ad5e Mon Sep 17 00:00:00 2001 From: stefanprodan Date: Mon, 11 Mar 2019 14:54:17 +0200 Subject: [PATCH 1/2] Fix HTTP URI match conditions --- docs/gitbook/how-it-works.md | 2 +- docs/gitbook/usage/ab-testing.md | 2 +- pkg/router/istio.go | 17 +++++++++++++++-- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/docs/gitbook/how-it-works.md b/docs/gitbook/how-it-works.md index 14e87b1a..a09b9249 100644 --- a/docs/gitbook/how-it-works.md +++ b/docs/gitbook/how-it-works.md @@ -347,7 +347,7 @@ You can enable A/B testing by specifying the HTTP match conditions and the numbe match: - headers: user-agent: - regex: "^(?!.*Chrome)(?=.*\bSafari\b).*$" + regex: "^(?!.*Chrome).*Safari.*" - headers: cookie: regex: "^(.*?;)?(user=test)(;.*)?$" diff --git a/docs/gitbook/usage/ab-testing.md b/docs/gitbook/usage/ab-testing.md index 65078043..50659bb4 100644 --- a/docs/gitbook/usage/ab-testing.md +++ b/docs/gitbook/usage/ab-testing.md @@ -72,7 +72,7 @@ spec: match: - headers: user-agent: - regex: "^(?!.*Chrome)(?=.*\bSafari\b).*$" + regex: "^(?!.*Chrome).*Safari.*" - headers: cookie: regex: "^(.*?;)?(type=insider)(;.*)?$" diff --git a/pkg/router/istio.go b/pkg/router/istio.go index 7f3ad674..79ba9feb 100644 --- a/pkg/router/istio.go +++ b/pkg/router/istio.go @@ -93,7 +93,7 @@ func (ir *IstioRouter) Sync(canary *flaggerv1.Canary) error { } if len(canary.Spec.CanaryAnalysis.Match) > 0 { - canaryMatch := append(canary.Spec.Service.Match, canary.Spec.CanaryAnalysis.Match...) + canaryMatch := mergeMatchConditions(canary.Spec.CanaryAnalysis.Match, canary.Spec.Service.Match) newSpec.Http = []istiov1alpha3.HTTPRoute{ { Match: canaryMatch, @@ -274,7 +274,7 @@ func (ir *IstioRouter) SetRoutes( // fix routing (A/B testing) if len(canary.Spec.CanaryAnalysis.Match) > 0 { // merge the common routes with the canary ones - canaryMatch := append(canary.Spec.Service.Match, canary.Spec.CanaryAnalysis.Match...) + canaryMatch := mergeMatchConditions(canary.Spec.CanaryAnalysis.Match, canary.Spec.Service.Match) vsCopy.Spec.Http = []istiov1alpha3.HTTPRoute{ { Match: canaryMatch, @@ -345,3 +345,16 @@ func addHeaders(canary *flaggerv1.Canary) (headers map[string]string) { return } + +// mergeMatchConditions appends the URI match rules to canary conditions +func mergeMatchConditions(canary, defaults []istiov1alpha3.HTTPMatchRequest) []istiov1alpha3.HTTPMatchRequest { + for i := range canary { + for _, d := range defaults { + if d.Uri != nil { + canary[i].Uri = d.Uri + } + } + } + + return canary +} From c720fee3ab2a32e837768a25f9ac5dc6eb567bb8 Mon Sep 17 00:00:00 2001 From: stefanprodan Date: Mon, 11 Mar 2019 15:04:01 +0200 Subject: [PATCH 2/2] Target the canary header in the load test --- artifacts/ab-testing/canary.yaml | 4 ++-- docs/gitbook/usage/ab-testing.md | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/artifacts/ab-testing/canary.yaml b/artifacts/ab-testing/canary.yaml index 679ed18b..f513fb04 100644 --- a/artifacts/ab-testing/canary.yaml +++ b/artifacts/ab-testing/canary.yaml @@ -40,7 +40,7 @@ spec: regex: "^(?!.*Chrome)(?=.*\bSafari\b).*$" - headers: cookie: - regex: "^(.*?;)?(user=test)(;.*)?$" + regex: "^(.*?;)?(type=insider)(;.*)?$" metrics: - name: istio_requests_total # minimum req success rate (non 5xx responses) @@ -58,4 +58,4 @@ spec: url: http://flagger-loadtester.test/ timeout: 5s metadata: - cmd: "hey -z 1m -q 10 -c 2 http://podinfo.test:9898/" + cmd: "hey -z 1m -q 10 -c 2 -H 'Cookie: type=insider' http://podinfo.test:9898/" diff --git a/docs/gitbook/usage/ab-testing.md b/docs/gitbook/usage/ab-testing.md index 50659bb4..1a67ecc5 100644 --- a/docs/gitbook/usage/ab-testing.md +++ b/docs/gitbook/usage/ab-testing.md @@ -93,7 +93,7 @@ spec: url: http://flagger-loadtester.test/ timeout: 5s metadata: - cmd: "hey -z 1m -q 10 -c 2 http://podinfo.test:9898/" + cmd: "hey -z 1m -q 10 -c 2 -H 'Cookie: type=insider' http://podinfo.test:9898/" ``` The above configuration will run an analysis for ten minutes targeting Safari users and those that have an insider cookie.