Merge pull request #3 from maxingg/main
ospp: add traffic filter sample
diff --git a/dubbogo/simple/traffic/docker/docker-compose.yml b/dubbogo/simple/traffic/docker/docker-compose.yml
new file mode 100644
index 0000000..7ca8ee5
--- /dev/null
+++ b/dubbogo/simple/traffic/docker/docker-compose.yml
@@ -0,0 +1,27 @@
+#
+# Licensed to Apache Software Foundation (ASF) under one or more contributor
+# license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright
+# ownership. Apache Software Foundation (ASF) licenses this file to you 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.
+#
+
+version: '3'
+
+services:
+ zookeeper:
+ image: zookeeper
+ ports:
+ - 2181:2181
+ restart: on-failure
diff --git a/dubbogo/simple/traffic/pixiu/conf.yaml b/dubbogo/simple/traffic/pixiu/conf.yaml
new file mode 100644
index 0000000..122f072
--- /dev/null
+++ b/dubbogo/simple/traffic/pixiu/conf.yaml
@@ -0,0 +1,82 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you 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.
+#
+---
+static_resources:
+ listeners:
+ - name: "net/http"
+ protocol_type: "HTTP"
+ address:
+ socket_address:
+ address: "0.0.0.0"
+ port: 8888
+ filter_chains:
+ filters:
+ - name: dgp.filter.httpconnectionmanager
+ config:
+ route_config:
+ routes:
+ - match:
+ prefix: "/user"
+ route:
+ cluster: "user"
+ cluster_not_found_response_code: 505
+ http_filters:
+ - name: dgp.filter.http.traffic
+ config:
+ traffics:
+ - name: "user-v1"
+ router: "/user"
+ canary-by-header: v1
+ canary-weight: 10
+ - name: "user-v2"
+ router: "/user"
+ canary-by-header: v2
+ canary-weight: 10
+ - name: dgp.filter.http.httpproxy
+ config:
+ config:
+ idle_timeout: 5s
+ 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:
+ - id: 1
+ socket_address:
+ address: 127.0.0.1
+ port: 1315
+ - name: "user-v2"
+ lb_policy: "lb"
+ endpoints:
+ - id: 1
+ socket_address:
+ address: 127.0.0.1
+ port: 1316
+ shutdown_config:
+ timeout: "60s"
+ step_timeout: "10s"
+ reject_policy: "immediacy"
\ No newline at end of file
diff --git a/dubbogo/simple/traffic/readme.md b/dubbogo/simple/traffic/readme.md
new file mode 100644
index 0000000..0e24131
--- /dev/null
+++ b/dubbogo/simple/traffic/readme.md
@@ -0,0 +1,31 @@
+# Traffic Filter quick start
+
+### Start Http Server
+
+```shell
+cd server
+go run server.go
+```
+
+```shell
+cd server/v1
+go run server.go
+```
+
+```shell
+cd server/v2
+go run server.go
+```
+
+### Start Pixiu
+
+```shell
+go run cmd/pixiu/*.go gateway start -c samples/dubbogo/simple/traffic/pixiu/conf.yaml
+```
+
+### Start test
+
+```shell
+curl http://localhost:8888/user
+curl -H "canary-by-header: v1" http://localhost:8888/user
+```
diff --git a/dubbogo/simple/traffic/server/server.go b/dubbogo/simple/traffic/server/server.go
new file mode 100644
index 0000000..0983f27
--- /dev/null
+++ b/dubbogo/simple/traffic/server/server.go
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+
+package main
+
+import (
+ "fmt"
+ "log"
+ "net/http"
+ "strings"
+)
+
+func main() {
+ routers := []string{"/user", "/user/pixiu", "/prefix", "/health"}
+
+ for _, router := range routers {
+ msg := router[strings.LastIndex(router, "/")+1:]
+ http.HandleFunc(router, func(w http.ResponseWriter, r *http.Request) {
+ _, _ = w.Write([]byte(fmt.Sprintf(`{"message":"%s","status":200}`, msg)))
+ })
+ }
+
+ log.Println("Starting sample server ...")
+ log.Fatal(http.ListenAndServe(":1314", nil))
+}
diff --git a/dubbogo/simple/traffic/server/v1/server.go b/dubbogo/simple/traffic/server/v1/server.go
new file mode 100644
index 0000000..6f99759
--- /dev/null
+++ b/dubbogo/simple/traffic/server/v1/server.go
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+
+package main
+
+import (
+ "fmt"
+ "log"
+ "net/http"
+ "strings"
+)
+
+func main() {
+ routers := []string{"/user", "/user/pixiu", "/prefix", "/health"}
+
+ for _, router := range routers {
+ msg := router[strings.LastIndex(router, "/")+1:]
+ http.HandleFunc(router, func(w http.ResponseWriter, r *http.Request) {
+ _, _ = w.Write([]byte(fmt.Sprintf(`{"server": "v1","message":"%s","status":200}`, msg)))
+ })
+ }
+
+ log.Println("Starting sample server ...")
+ log.Fatal(http.ListenAndServe(":1315", nil))
+}
diff --git a/dubbogo/simple/traffic/server/v2/server.go b/dubbogo/simple/traffic/server/v2/server.go
new file mode 100644
index 0000000..e6e6e4f
--- /dev/null
+++ b/dubbogo/simple/traffic/server/v2/server.go
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+
+package main
+
+import (
+ "fmt"
+ "log"
+ "net/http"
+ "strings"
+)
+
+func main() {
+ routers := []string{"/user", "/user/pixiu", "/prefix", "/health"}
+
+ for _, router := range routers {
+ msg := router[strings.LastIndex(router, "/")+1:]
+ http.HandleFunc(router, func(w http.ResponseWriter, r *http.Request) {
+ _, _ = w.Write([]byte(fmt.Sprintf(`{"server": "v2","message":"%s","status":200}`, msg)))
+ })
+ }
+
+ log.Println("Starting sample server ...")
+ log.Fatal(http.ListenAndServe(":1316", nil))
+}