This is an automated email from the ASF dual-hosted git repository.

alexstocks pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/dubbo-go-pixiu-samples.git


The following commit(s) were added to refs/heads/main by this push:
     new 34f51fa  add samples for header route
     new 2904b0e  Merge pull request #30 from shawnh2/header-route
34f51fa is described below

commit 34f51fadf9739f593f11dc27cd36eaa207dedc78
Author: Shawnh2 <[email protected]>
AuthorDate: Fri Jun 16 21:36:13 2023 +0800

    add samples for header route
---
 .../traffic/pixiu/{conf.yaml => canary-conf.yaml}  |  0
 .../traffic/pixiu/{conf.yaml => header-conf.yaml}  | 49 ++++++++++++----------
 dubbogo/simple/traffic/readme.md                   | 38 ++++++++++++++++-
 dubbogo/simple/traffic/test/pixiu_test.go          | 48 +++++++++++++++++++--
 4 files changed, 108 insertions(+), 27 deletions(-)

diff --git a/dubbogo/simple/traffic/pixiu/conf.yaml 
b/dubbogo/simple/traffic/pixiu/canary-conf.yaml
similarity index 100%
copy from dubbogo/simple/traffic/pixiu/conf.yaml
copy to dubbogo/simple/traffic/pixiu/canary-conf.yaml
diff --git a/dubbogo/simple/traffic/pixiu/conf.yaml 
b/dubbogo/simple/traffic/pixiu/header-conf.yaml
similarity index 64%
rename from dubbogo/simple/traffic/pixiu/conf.yaml
rename to dubbogo/simple/traffic/pixiu/header-conf.yaml
index 25ba09e..99ccfbb 100644
--- a/dubbogo/simple/traffic/pixiu/conf.yaml
+++ b/dubbogo/simple/traffic/pixiu/header-conf.yaml
@@ -32,25 +32,35 @@ static_resources:
                 route_config:
                   routes:
                     - match:
+                        # both prefix and header
                         prefix: "/user"
+                        headers:
+                          - name: X-A
+                            values: ["t1","t2","t3"]
+                          - name: X-B
+                            values: ["t4","t5","t6"]
+                          - name: X-A
+                            values: ["t1"]
                       route:
-                        cluster: "user"
-                        cluster_not_found_response_code: 505
+                        cluster: "user-v1"
+                    - match:
+                        # only header
+                        headers:
+                          - name: X-B
+                            values: ["t4","t5","t6"]
+                          - name: X-C
+                            values: ["t1"]
+                      route:
+                        cluster: "user-v2"
+                    - match:
+                        # header with regex value
+                        headers:
+                          - name: REG
+                            values: ["t{2}"]
+                            regex: true
+                        route:
+                          cluster: "user-v3"
                 http_filters:
-                  - name: dgp.filter.http.traffic
-                    config:
-                      traffics:
-                        - name: "user-v1"
-                          router: "/user"
-                          canary-by-header: v1
-                          canary-weight: 0
-                        - name: "user-v2"
-                          router: "/user"
-                          canary-by-header: v2
-                          canary-weight: 100
-                        - name: "user-v3"
-                          router: "/user"
-                          canary-by-header: v3
                   - name: dgp.filter.http.httpproxy
                     config:
       config:
@@ -58,13 +68,6 @@ static_resources:
         read_timeout: 5s
         write_timeout: 5s
   clusters:
-    - name: "user"
-      lb_policy: "lb"
-      endpoints:
-        - id: 1
-          socket_address:
-            address: 127.0.0.1
-            port: 1314
     - name: "user-v1"
       lb_policy: "lb"
       endpoints:
diff --git a/dubbogo/simple/traffic/readme.md b/dubbogo/simple/traffic/readme.md
index 0e24131..901dbaa 100644
--- a/dubbogo/simple/traffic/readme.md
+++ b/dubbogo/simple/traffic/readme.md
@@ -1,5 +1,7 @@
 # Traffic Filter quick start
 
+## Canary Distribution
+
 ### Start Http Server
 
 ```shell
@@ -20,7 +22,7 @@ go run server.go
 ### Start Pixiu
 
 ```shell
-go run cmd/pixiu/*.go gateway start -c 
samples/dubbogo/simple/traffic/pixiu/conf.yaml
+go run cmd/pixiu/*.go gateway start -c 
samples/dubbogo/simple/traffic/pixiu/canary-conf.yaml
 ```
 
 ### Start test
@@ -29,3 +31,37 @@ go run cmd/pixiu/*.go gateway start -c 
samples/dubbogo/simple/traffic/pixiu/conf
 curl http://localhost:8888/user
 curl -H "canary-by-header: v1" http://localhost:8888/user
 ```
+
+## Header Route
+
+### Start Http Server
+
+```shell
+cd server/v1
+go run server.go
+```
+
+```shell
+cd server/v2
+go run server.go
+```
+
+```shell
+cd server/v3
+go run server.go
+```
+
+### Start Pixiu
+
+```shell
+go run cmd/pixiu/*.go gateway start -c 
samples/dubbogo/simple/traffic/pixiu/header-conf.yaml
+```
+
+### Start test
+
+```shell
+curl http://localhost:8888/user
+curl -H "X-C: t1" http://localhost:8888
+curl -H "REG: tt" http://localhost:8888
+curl -H "X-A: t1" http://localhost:8888/user
+```
diff --git a/dubbogo/simple/traffic/test/pixiu_test.go 
b/dubbogo/simple/traffic/test/pixiu_test.go
index 8d396ef..334a626 100644
--- a/dubbogo/simple/traffic/test/pixiu_test.go
+++ b/dubbogo/simple/traffic/test/pixiu_test.go
@@ -29,7 +29,7 @@ import (
        "github.com/stretchr/testify/assert"
 )
 
-func TestGET(t *testing.T) {
+func TestCanaryGET(t *testing.T) {
        url := "http://localhost:8888/user";
        client := &http.Client{Timeout: 5 * time.Second}
        req, err := http.NewRequest("GET", url, nil)
@@ -43,7 +43,7 @@ func TestGET(t *testing.T) {
        assert.True(t, strings.Contains(string(s), `"server": "v1"`))
 }
 
-func TestGET1(t *testing.T) {
+func TestCanaryGET1(t *testing.T) {
        url := "http://localhost:8888/user";
        client := &http.Client{Timeout: 5 * time.Second}
        req, err := http.NewRequest("GET", url, nil)
@@ -56,7 +56,7 @@ func TestGET1(t *testing.T) {
        assert.True(t, strings.Contains(string(s), `"server": "v2"`))
 }
 
-func TestGET2(t *testing.T) {
+func TestCanaryGET2(t *testing.T) {
        url := "http://localhost:8888/user";
        client := &http.Client{Timeout: 5 * time.Second}
        req, err := http.NewRequest("GET", url, nil)
@@ -69,3 +69,45 @@ func TestGET2(t *testing.T) {
        s, _ := ioutil.ReadAll(resp.Body)
        assert.True(t, strings.Contains(string(s), `"server": "v3"`))
 }
+
+func TestHeaderGET1(t *testing.T) {
+       url := "http://localhost:8888/user";
+       client := &http.Client{Timeout: 5 * time.Second}
+       req, err := http.NewRequest("GET", url, nil)
+       assert.NoError(t, err)
+       req.Header.Add("X-A", "t1")
+       resp, err := client.Do(req)
+       assert.NoError(t, err)
+       assert.NotNil(t, resp)
+       assert.Equal(t, 200, resp.StatusCode)
+       s, _ := ioutil.ReadAll(resp.Body)
+       assert.True(t, strings.Contains(string(s), `"server": "v1"`))
+}
+
+func TestHeaderGET2(t *testing.T) {
+       url := "http://localhost:8888";
+       client := &http.Client{Timeout: 5 * time.Second}
+       req, err := http.NewRequest("GET", url, nil)
+       assert.NoError(t, err)
+       req.Header.Add("X-C", "t1")
+       resp, err := client.Do(req)
+       assert.NoError(t, err)
+       assert.NotNil(t, resp)
+       assert.Equal(t, 200, resp.StatusCode)
+       s, _ := ioutil.ReadAll(resp.Body)
+       assert.True(t, strings.Contains(string(s), `"server": "v2"`))
+}
+
+func TestHeaderGET3(t *testing.T) {
+       url := "http://localhost:8888";
+       client := &http.Client{Timeout: 5 * time.Second}
+       req, err := http.NewRequest("GET", url, nil)
+       assert.NoError(t, err)
+       req.Header.Add("REG", "tt")
+       resp, err := client.Do(req)
+       assert.NoError(t, err)
+       assert.NotNil(t, resp)
+       assert.Equal(t, 200, resp.StatusCode)
+       s, _ := ioutil.ReadAll(resp.Body)
+       assert.True(t, strings.Contains(string(s), `"server": "v3"`))
+}

Reply via email to