From e5a57b560d950f472810122de4348cb32a0df369 Mon Sep 17 00:00:00 2001 From: maxing <1501901576@qq.com> Date: Mon, 1 Aug 2022 17:13:03 +0800 Subject: [PATCH 01/13] feature: wasm and traffic examples add. --- .../simple/jaeger/grpc/api_v2/proto/gen.sh | 2 + .../simple/traffic/docker/docker-compose.yml | 27 ++ dubbogo/simple/traffic/pixiu/conf.yaml | 84 ++++++ dubbogo/simple/traffic/readme.md | 30 ++ dubbogo/simple/traffic/server/server.go | 39 +++ dubbogo/simple/traffic/server/v1/server.go | 39 +++ dubbogo/simple/traffic/server/v2/server.go | 39 +++ dubbogo/simple/wasm/docker/docker-compose.yml | 27 ++ dubbogo/simple/wasm/pixiu/conf.yaml | 70 +++++ dubbogo/simple/wasm/server/app/server.go | 69 +++++ dubbogo/simple/wasm/server/app/user.go | 280 ++++++++++++++++++ .../simple/wasm/server/profiles/dev/log.yml | 45 +++ .../wasm/server/profiles/dev/server.yml | 39 +++ 13 files changed, 790 insertions(+) create mode 100644 dubbogo/simple/jaeger/grpc/api_v2/proto/gen.sh create mode 100644 dubbogo/simple/traffic/docker/docker-compose.yml create mode 100644 dubbogo/simple/traffic/pixiu/conf.yaml create mode 100644 dubbogo/simple/traffic/readme.md create mode 100644 dubbogo/simple/traffic/server/server.go create mode 100644 dubbogo/simple/traffic/server/v1/server.go create mode 100644 dubbogo/simple/traffic/server/v2/server.go create mode 100644 dubbogo/simple/wasm/docker/docker-compose.yml create mode 100644 dubbogo/simple/wasm/pixiu/conf.yaml create mode 100644 dubbogo/simple/wasm/server/app/server.go create mode 100644 dubbogo/simple/wasm/server/app/user.go create mode 100644 dubbogo/simple/wasm/server/profiles/dev/log.yml create mode 100644 dubbogo/simple/wasm/server/profiles/dev/server.yml diff --git a/dubbogo/simple/jaeger/grpc/api_v2/proto/gen.sh b/dubbogo/simple/jaeger/grpc/api_v2/proto/gen.sh new file mode 100644 index 0000000..de0b0c7 --- /dev/null +++ b/dubbogo/simple/jaeger/grpc/api_v2/proto/gen.sh @@ -0,0 +1,2 @@ +#!/bin/zsh +protoc --go_out=.. --go_opt=paths=source_relative --go-grpc_out=.. --go-grpc_opt=paths=source_relative *.proto 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..ae65f4f --- /dev/null +++ b/dubbogo/simple/traffic/pixiu/conf.yaml @@ -0,0 +1,84 @@ +# +# 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/1" + model: canary-by-header + canary: canary-by-header + value: 10 + - name: "user-v2" + router: "/user/1" + model: canary-weight + canary: canary-weight + value: 90 + - 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..8320ff5 --- /dev/null +++ b/dubbogo/simple/traffic/readme.md @@ -0,0 +1,30 @@ +#Traffic Filter quick start +### Start Zookeeper: +```shell +cd samples/dubbogo/simple/traffic +run docker-compose.yml/services +``` +### 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: 10" http://localhost:8888/user +curl -H "canary-weight: 90" 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)) +} diff --git a/dubbogo/simple/wasm/docker/docker-compose.yml b/dubbogo/simple/wasm/docker/docker-compose.yml new file mode 100644 index 0000000..7ca8ee5 --- /dev/null +++ b/dubbogo/simple/wasm/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/wasm/pixiu/conf.yaml b/dubbogo/simple/wasm/pixiu/conf.yaml new file mode 100644 index 0000000..bc5fab6 --- /dev/null +++ b/dubbogo/simple/wasm/pixiu/conf.yaml @@ -0,0 +1,70 @@ +# +# 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: 8883 + filter_chains: + filters: + - name: dgp.filter.httpconnectionmanager + config: + route_config: + routes: + - match: + prefix: "*" + http_filters: + - name: dgp.filter.http.webassembly + config: + wasm_services: + - name: header + - name: dgp.filter.http.dubboproxy + config: + dubboProxyConfig: + auto_resolve: true + registries: + "zookeeper": + protocol: "zookeeper" + timeout: "3s" + address: "127.0.0.1:2181" + username: "" + password: "" + timeout_config: + connect_timeout: 5s + request_timeout: 5s + + server_name: "test_http_dubbo" + generate_request_id: false + config: + idle_timeout: 5s + read_timeout: 5s + write_timeout: 5s + shutdown_config: + timeout: "60s" + step_timeout: "10s" + reject_policy: "immediacy" +wasm: + services: + - name: header + config: + path: data/header.wasm \ No newline at end of file diff --git a/dubbogo/simple/wasm/server/app/server.go b/dubbogo/simple/wasm/server/app/server.go new file mode 100644 index 0000000..776280f --- /dev/null +++ b/dubbogo/simple/wasm/server/app/server.go @@ -0,0 +1,69 @@ +/* + * 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" + "os" + "os/signal" + "syscall" + "time" +) + +import ( + "dubbo.apache.org/dubbo-go/v3/common/logger" + "dubbo.apache.org/dubbo-go/v3/config" + _ "dubbo.apache.org/dubbo-go/v3/imports" +) + +// Version dubbo version +const Version = "2.7.5" + +var survivalTimeout = int(3e9) + +// they are necessary: +// export DUBBO_GO_CONFIG_PATH="../profiles/dev/server.yml" +// export APP_LOG_CONF_FILE="../profiles/dev/log.yml" +func main() { + config.Load() + logger.Infof("dubbo version is: %s", Version) + initSignal() +} + +func initSignal() { + signals := make(chan os.Signal, 1) + // It is not possible to block SIGKILL or syscall.SIGSTOP + signal.Notify(signals, os.Interrupt, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT) + for { + sig := <-signals + logger.Infof("get signal %s", sig.String()) + switch sig { + case syscall.SIGHUP: + // reload() + default: + time.AfterFunc(time.Duration(survivalTimeout), func() { + logger.Warnf("app exit now by force...") + os.Exit(1) + }) + + // The program exits normally or timeout forcibly exits. + fmt.Println("provider app exit now...") + return + } + } +} diff --git a/dubbogo/simple/wasm/server/app/user.go b/dubbogo/simple/wasm/server/app/user.go new file mode 100644 index 0000000..35cc39b --- /dev/null +++ b/dubbogo/simple/wasm/server/app/user.go @@ -0,0 +1,280 @@ +/* + * 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 ( + "context" + "errors" + "fmt" + "sync" + "time" +) + +import ( + "dubbo.apache.org/dubbo-go/v3/config" + + hessian "github.com/apache/dubbo-go-hessian2" +) + +func init() { + config.SetProviderService(new(UserProvider)) + // ------for hessian2------ + hessian.RegisterPOJO(&User{}) + + cache = newUserDB() + + t1, _ := time.Parse( + time.RFC3339, + "2021-08-01T10:08:41+00:00") + + cache.Add(&User{ID: "0001", Code: 1, Name: "tc", Age: 18, Time: t1}) + cache.Add(&User{ID: "0002", Code: 2, Name: "ic", Age: 88, Time: t1}) +} + +var cache *userDB + +// userDB cache user. +type userDB struct { + // key is name, value is user obj + nameIndex map[string]*User + // key is code, value is user obj + codeIndex map[int64]*User + lock sync.Mutex +} + +// userDB create func +func newUserDB() *userDB { + return &userDB{ + nameIndex: make(map[string]*User, 16), + codeIndex: make(map[int64]*User, 16), + lock: sync.Mutex{}, + } +} + +// nolint +func (db *userDB) Add(u *User) bool { + db.lock.Lock() + defer db.lock.Unlock() + + if u.Name == "" || u.Code <= 0 { + return false + } + + if !db.existName(u.Name) && !db.existCode(u.Code) { + return db.AddForName(u) && db.AddForCode(u) + } + + return false +} + +// nolint +func (db *userDB) AddForName(u *User) bool { + if len(u.Name) == 0 { + return false + } + + if _, ok := db.nameIndex[u.Name]; ok { + return false + } + + db.nameIndex[u.Name] = u + return true +} + +// nolint +func (db *userDB) AddForCode(u *User) bool { + if u.Code <= 0 { + return false + } + + if _, ok := db.codeIndex[u.Code]; ok { + return false + } + + db.codeIndex[u.Code] = u + return true +} + +// nolint +func (db *userDB) GetByName(n string) (*User, bool) { + db.lock.Lock() + defer db.lock.Unlock() + + r, ok := db.nameIndex[n] + return r, ok +} + +// nolint +func (db *userDB) GetByCode(n int64) (*User, bool) { + db.lock.Lock() + defer db.lock.Unlock() + + r, ok := db.codeIndex[n] + return r, ok +} + +func (db *userDB) existName(name string) bool { + if len(name) <= 0 { + return false + } + + _, ok := db.nameIndex[name] + if ok { + return true + } + + return false +} + +func (db *userDB) existCode(code int64) bool { + if code <= 0 { + return false + } + + _, ok := db.codeIndex[code] + if ok { + return true + } + + return false +} + +// User user obj. +type User struct { + ID string `json:"id,omitempty"` + Code int64 `json:"code,omitempty"` + Name string `json:"name,omitempty"` + Age int32 `json:"age,omitempty"` + Time time.Time `json:"time,omitempty"` +} + +// UserProvider the dubbo provider. +// like: version: 1.0.0 group: test +type UserProvider struct{} + +// CreateUser new user, PX config POST. +func (u *UserProvider) CreateUser(ctx context.Context, user *User) (*User, error) { + outLn("Req CreateUser data:%#v", user) + if user == nil { + return nil, errors.New("not found") + } + _, ok := cache.GetByName(user.Name) + if ok { + return nil, errors.New("data is exist") + } + + b := cache.Add(user) + if b { + return user, nil + } + + return nil, errors.New("add error") +} + +// GetUserByName query by name, single param, PX config GET. +func (u *UserProvider) GetUserByName(ctx context.Context, name string) (*User, error) { + outLn("Req GetUserByName name:%#v", name) + r, ok := cache.GetByName(name) + if ok { + outLn("Req GetUserByName result:%#v", r) + return r, nil + } + return nil, nil +} + +// GetUserByCode query by code, single param, PX config GET. +func (u *UserProvider) GetUserByCode(ctx context.Context, code int64) (*User, error) { + outLn("Req GetUserByCode name:%#v", code) + r, ok := cache.GetByCode(code) + if ok { + outLn("Req GetUserByCode result:%#v", r) + return r, nil + } + return nil, nil +} + +// GetUserTimeout query by name, will timeout for pixiu. +func (u *UserProvider) GetUserTimeout(ctx context.Context, name string) (*User, error) { + outLn("Req GetUserByName name:%#v", name) + // sleep 10s, pixiu config less than 10s. + time.Sleep(10 * time.Second) + r, ok := cache.GetByName(name) + if ok { + outLn("Req GetUserByName result:%#v", r) + return r, nil + } + return nil, nil +} + +// GetUserByNameAndAge query by name and age, two params, PX config GET. +func (u *UserProvider) GetUserByNameAndAge(ctx context.Context, name string, age int32) (*User, error) { + outLn("Req GetUserByNameAndAge name:%s, age:%d", name, age) + r, ok := cache.GetByName(name) + if ok && r.Age == age { + outLn("Req GetUserByNameAndAge result:%#v", r) + return r, nil + } + return r, nil +} + +// UpdateUser update by user struct, my be another struct, PX config POST or PUT. +func (u *UserProvider) UpdateUser(ctx context.Context, user *User) (bool, error) { + outLn("Req UpdateUser data:%#v", user) + r, ok := cache.GetByName(user.Name) + if ok { + if user.ID != "" { + r.ID = user.ID + } + if user.Age >= 0 { + r.Age = user.Age + } + return true, nil + } + return false, errors.New("not found") +} + +// UpdateUserByName update by user struct, my be another struct, PX config POST or PUT. +func (u *UserProvider) UpdateUserByName(ctx context.Context, name string, user *User) (bool, error) { + outLn("Req UpdateUserByName data:%#v", user) + r, ok := cache.GetByName(name) + if ok { + if user.ID != "" { + r.ID = user.ID + } + if user.Age >= 0 { + r.Age = user.Age + } + return true, nil + } + return false, errors.New("not found") +} + +// nolint +func (u *UserProvider) Reference() string { + return "UserProvider" +} + +// nolint +func (u User) JavaClassName() string { + return "com.dubbogo.pixiu.User" +} + +// nolint +func outLn(format string, args ...interface{}) { + fmt.Printf("\033[32;40m"+format+"\033[0m\n", args...) +} diff --git a/dubbogo/simple/wasm/server/profiles/dev/log.yml b/dubbogo/simple/wasm/server/profiles/dev/log.yml new file mode 100644 index 0000000..9330cda --- /dev/null +++ b/dubbogo/simple/wasm/server/profiles/dev/log.yml @@ -0,0 +1,45 @@ +# +# 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. +# +level: "debug" +development: true +disableCaller: false +disableStacktrace: false +sampling: +encoding: "console" + +# encoder +encoderConfig: + messageKey: "message" + levelKey: "level" + timeKey: "time" + nameKey: "logger" + callerKey: "caller" + stacktraceKey: "stacktrace" + lineEnding: "" + levelEncoder: "capitalColor" + timeEncoder: "iso8601" + durationEncoder: "seconds" + callerEncoder: "short" + nameEncoder: "" + +outputPaths: + - "stderr" +errorOutputPaths: + - "stderr" +initialFields: diff --git a/dubbogo/simple/wasm/server/profiles/dev/server.yml b/dubbogo/simple/wasm/server/profiles/dev/server.yml new file mode 100644 index 0000000..c93feb2 --- /dev/null +++ b/dubbogo/simple/wasm/server/profiles/dev/server.yml @@ -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. +# +# dubbo server yaml configure file +# application config +dubbo: + registries: + zk: + protocol: zookeeper + timeout: 3s + address: 127.0.0.1:2181 + protocols: + dubbo: + name: dubbo + port: 20000 + provider: + registry-ids: zk + services: + UserProvider: + group: test + version: 1.0.0 + cluster: test_dubbo + serialization: hessian2 + interface: com.dubbogo.pixiu.UserService \ No newline at end of file From e3d6c349df1e2adc6e71e8d2cbd934861806adfe Mon Sep 17 00:00:00 2001 From: maxing <1501901576@qq.com> Date: Tue, 2 Aug 2022 11:16:41 +0800 Subject: [PATCH 02/13] fix: wasm filter name modify --- dubbogo/simple/wasm/pixiu/conf.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dubbogo/simple/wasm/pixiu/conf.yaml b/dubbogo/simple/wasm/pixiu/conf.yaml index bc5fab6..3248add 100644 --- a/dubbogo/simple/wasm/pixiu/conf.yaml +++ b/dubbogo/simple/wasm/pixiu/conf.yaml @@ -67,4 +67,4 @@ wasm: services: - name: header config: - path: data/header.wasm \ No newline at end of file + path: data/filter.wasm \ No newline at end of file From 920505521b6aac02ab1a03b1921eca3e841e504c Mon Sep 17 00:00:00 2001 From: maxing <1501901576@qq.com> Date: Sun, 7 Aug 2022 13:10:14 +0800 Subject: [PATCH 03/13] fix: cgo enable; wasm filepath modify. --- dubbogo/simple/wasm/pixiu/conf.yaml | 2 +- igt/Makefile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dubbogo/simple/wasm/pixiu/conf.yaml b/dubbogo/simple/wasm/pixiu/conf.yaml index 3248add..f498836 100644 --- a/dubbogo/simple/wasm/pixiu/conf.yaml +++ b/dubbogo/simple/wasm/pixiu/conf.yaml @@ -67,4 +67,4 @@ wasm: services: - name: header config: - path: data/filter.wasm \ No newline at end of file + path: wasm/data/filter.wasm \ No newline at end of file diff --git a/igt/Makefile b/igt/Makefile index e014efc..554a70e 100644 --- a/igt/Makefile +++ b/igt/Makefile @@ -49,7 +49,7 @@ else export EXT_NAME ?= endif -CGO ?= 0 +CGO ?= 1 ifeq ($(DEBUG), true) BUILD_TYPE := debug GCFLAGS := -gcflags="all=-N -l" From 586465c7e437305a0810cc8483917c48997ab8f0 Mon Sep 17 00:00:00 2001 From: maxing <1501901576@qq.com> Date: Mon, 8 Aug 2022 10:04:46 +0800 Subject: [PATCH 04/13] fix: add data folder. --- dubbogo/simple/wasm/data/filter.go | 73 ++++++++++++++++++++++++++++++ dubbogo/simple/wasm/data/makefile | 29 ++++++++++++ 2 files changed, 102 insertions(+) create mode 100644 dubbogo/simple/wasm/data/filter.go create mode 100644 dubbogo/simple/wasm/data/makefile diff --git a/dubbogo/simple/wasm/data/filter.go b/dubbogo/simple/wasm/data/filter.go new file mode 100644 index 0000000..618d731 --- /dev/null +++ b/dubbogo/simple/wasm/data/filter.go @@ -0,0 +1,73 @@ +/* + * 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 ( + "github.com/tetratelabs/proxy-wasm-go-sdk/proxywasm" + "github.com/tetratelabs/proxy-wasm-go-sdk/proxywasm/types" +) + +func main() { + proxywasm.SetNewHttpContext(newHttpContext) +} + +type myHttpContext struct { + // you must embed the default context so that you need not to re-implement all the methods by yourself + proxywasm.DefaultHttpContext + contextID uint32 +} + +func newHttpContext(rootContextID, contextID uint32) proxywasm.HttpContext { + return &myHttpContext{contextID: contextID} +} + +// override +func (ctx *myHttpContext) OnHttpRequestHeaders(numHeaders int, endOfStream bool) types.Action { + + // add single header + proxywasm.LogInfo("proxywasm add singe header...") + err := proxywasm.AddHttpRequestHeader("go-wasm-header", "hello wasm") + if err != nil { + proxywasm.LogCriticalf("failed to add request headers: %v", err) + } + + // get all header + proxywasm.LogInfo("proxywasm get request headers...") + hs, err := proxywasm.GetHttpRequestHeaders() + if err != nil { + proxywasm.LogCriticalf("failed to get request headers: %v", err) + } + for _, h := range hs { + proxywasm.LogInfof("request header from go wasm --> %s: %s", h[0], h[1]) + } + + return types.ActionContinue +} + +// override +func (ctx *myHttpContext) OnHttpRequestBody(bodySize int, endOfStream bool) types.Action { + // get request body + proxywasm.LogInfo("proxywasm get request body...") + bytes, err := proxywasm.GetHttpRequestBody(0, 100) + if err != nil { + proxywasm.LogCriticalf("failed to get request body: %v", err) + } + proxywasm.LogInfof("proxywasm.GetHttpRequestBody [%s]", string(bytes)) + + return types.ActionContinue +} diff --git a/dubbogo/simple/wasm/data/makefile b/dubbogo/simple/wasm/data/makefile new file mode 100644 index 0000000..2611e16 --- /dev/null +++ b/dubbogo/simple/wasm/data/makefile @@ -0,0 +1,29 @@ +# +# 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. +# + +.PHONY: wasm + +wasm: + docker run -it -v $(shell pwd):/tmp/proxy-wasm-go -e GOPROXY=https://goproxy.cn tinygo/tinygo-dev:a304fb738f2376548e008fbc5c02abf3bdff7156 \ + /bin/bash -c \ + "git clone --depth 1 --branch v0.0.13 https://github.com/tetratelabs/proxy-wasm-go-sdk.git /tmp/proxy-wasm-go/sdk &> /dev/null; \ + cp /tmp/proxy-wasm-go/${name}.go /tmp/proxy-wasm-go/sdk; \ + cd /tmp/proxy-wasm-go/sdk; \ + tinygo build -o /tmp/proxy-wasm-go/${name}.wasm -scheduler=none -target=wasi -wasm-abi=generic -tags 'abi_010' ./${name}.go; \ + rm -rf /tmp/proxy-wasm-go/sdk" \ No newline at end of file From 0529a6a1b2860542adab4f038847b1b8c64f288d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A5=AD=E9=85=92?= <32018399+maxingg@users.noreply.github.com> Date: Mon, 8 Aug 2022 16:40:04 +0800 Subject: [PATCH 05/13] Delete gen.sh --- dubbogo/simple/jaeger/grpc/api_v2/proto/gen.sh | 2 -- 1 file changed, 2 deletions(-) delete mode 100644 dubbogo/simple/jaeger/grpc/api_v2/proto/gen.sh diff --git a/dubbogo/simple/jaeger/grpc/api_v2/proto/gen.sh b/dubbogo/simple/jaeger/grpc/api_v2/proto/gen.sh deleted file mode 100644 index de0b0c7..0000000 --- a/dubbogo/simple/jaeger/grpc/api_v2/proto/gen.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/zsh -protoc --go_out=.. --go_opt=paths=source_relative --go-grpc_out=.. --go-grpc_opt=paths=source_relative *.proto From a23bc33aeae3841661fdc3ec265bdc519a988b05 Mon Sep 17 00:00:00 2001 From: maxing <1501901576@qq.com> Date: Mon, 8 Aug 2022 16:49:07 +0800 Subject: [PATCH 06/13] fix: add go.mod --- go.mod | 4 ++-- go.sum | 8 ++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/go.mod b/go.mod index bfdf212..80af694 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.15 require ( dubbo.apache.org/dubbo-go/v3 v3.0.2-0.20220519062747-f6405fa79d5c - github.com/apache/dubbo-go-hessian2 v1.11.0 + github.com/apache/dubbo-go-hessian2 v1.11.1 github.com/apache/dubbo-go-pixiu v0.5.0-rc01.0.20220624103422-ef05b090d78f github.com/dubbogo/gost v1.11.25 github.com/dubbogo/grpc-go v1.42.9 @@ -15,8 +15,8 @@ require ( github.com/spf13/cobra v1.1.3 github.com/stretchr/objx v0.2.0 // indirect github.com/stretchr/testify v1.7.1 + github.com/tetratelabs/proxy-wasm-go-sdk v0.19.0 google.golang.org/genproto v0.0.0-20211118181313-81c1377c94b1 google.golang.org/grpc v1.45.0 google.golang.org/protobuf v1.28.0 - ) diff --git a/go.sum b/go.sum index 8ec8845..5ecfc07 100644 --- a/go.sum +++ b/go.sum @@ -78,8 +78,9 @@ github.com/apache/dubbo-getty v1.4.8 h1:Q9WKXmVu4Dm16cMJHamegRbxpDiYaGIU+MnPGhJh github.com/apache/dubbo-getty v1.4.8/go.mod h1:cPJlbcHUTNTpiboMQjMHhE9XBni11LiBiG8FdrDuVzk= github.com/apache/dubbo-go-hessian2 v1.9.1/go.mod h1:xQUjE7F8PX49nm80kChFvepA/AvqAZ0oh/UaB6+6pBE= github.com/apache/dubbo-go-hessian2 v1.9.3/go.mod h1:xQUjE7F8PX49nm80kChFvepA/AvqAZ0oh/UaB6+6pBE= -github.com/apache/dubbo-go-hessian2 v1.11.0 h1:VTdT6NStuEqNmyT3AdSN2DLDBqhXvAAyAAAoh9hLavk= github.com/apache/dubbo-go-hessian2 v1.11.0/go.mod h1:7rEw9guWABQa6Aqb8HeZcsYPHsOS7XT1qtJvkmI6c5w= +github.com/apache/dubbo-go-hessian2 v1.11.1 h1:03xs4QCAZHY/gHCOWgOmIUW6Yc842FCLz4R0hxCzPr8= +github.com/apache/dubbo-go-hessian2 v1.11.1/go.mod h1:7rEw9guWABQa6Aqb8HeZcsYPHsOS7XT1qtJvkmI6c5w= github.com/apache/dubbo-go-pixiu v0.5.0-rc01.0.20220624103422-ef05b090d78f h1:mIv5JDr6PU0bIaTOWatRUp1KKR4QJOt6E6QEB5Z5rYk= github.com/apache/dubbo-go-pixiu v0.5.0-rc01.0.20220624103422-ef05b090d78f/go.mod h1:smf5KGyQxedTTItq4Bw7wRJyjp0pcyAi0+b1Pb5yJ1k= github.com/apache/thrift v0.12.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ= @@ -796,6 +797,8 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s= github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= github.com/tebeka/strftime v0.1.3/go.mod h1:7wJm3dZlpr4l/oVK0t1HYIc4rMzQ2XJlOMIUJUJH6XQ= +github.com/tetratelabs/proxy-wasm-go-sdk v0.19.0 h1:x1tYFXF7cCWU7mcZ6TksIjMAk0juu8pBUpK940mo7wo= +github.com/tetratelabs/proxy-wasm-go-sdk v0.19.0/go.mod h1:wigepC0JkAsczvWZzWvhPidwBFLpPykNz6e9jc9D/8s= github.com/tevid/gohamcrest v1.1.1 h1:ou+xSqlIw1xfGTg1uq1nif/htZ2S3EzRqLm2BP+tYU0= github.com/tevid/gohamcrest v1.1.1/go.mod h1:3UvtWlqm8j5JbwYZh80D/PVBt0mJ1eJiYgZMibh0H/k= github.com/tklauser/go-sysconf v0.3.6 h1:oc1sJWvKkmvIxhDHeKWvZS4f6AW+YcoguSfRF2/Hmo4= @@ -1344,8 +1347,9 @@ gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo= gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw= honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= From 7b2d8adf296b19336451c2b5a6db1453ab43b204 Mon Sep 17 00:00:00 2001 From: maxing <1501901576@qq.com> Date: Mon, 8 Aug 2022 19:29:07 +0800 Subject: [PATCH 07/13] refactor: remove traffic sample. --- .../simple/traffic/docker/docker-compose.yml | 27 ------ dubbogo/simple/traffic/pixiu/conf.yaml | 84 ------------------- dubbogo/simple/traffic/readme.md | 30 ------- dubbogo/simple/traffic/server/server.go | 39 --------- dubbogo/simple/traffic/server/v1/server.go | 39 --------- dubbogo/simple/traffic/server/v2/server.go | 39 --------- 6 files changed, 258 deletions(-) delete mode 100644 dubbogo/simple/traffic/docker/docker-compose.yml delete mode 100644 dubbogo/simple/traffic/pixiu/conf.yaml delete mode 100644 dubbogo/simple/traffic/readme.md delete mode 100644 dubbogo/simple/traffic/server/server.go delete mode 100644 dubbogo/simple/traffic/server/v1/server.go delete mode 100644 dubbogo/simple/traffic/server/v2/server.go diff --git a/dubbogo/simple/traffic/docker/docker-compose.yml b/dubbogo/simple/traffic/docker/docker-compose.yml deleted file mode 100644 index 7ca8ee5..0000000 --- a/dubbogo/simple/traffic/docker/docker-compose.yml +++ /dev/null @@ -1,27 +0,0 @@ -# -# 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 deleted file mode 100644 index ae65f4f..0000000 --- a/dubbogo/simple/traffic/pixiu/conf.yaml +++ /dev/null @@ -1,84 +0,0 @@ -# -# 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/1" - model: canary-by-header - canary: canary-by-header - value: 10 - - name: "user-v2" - router: "/user/1" - model: canary-weight - canary: canary-weight - value: 90 - - 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 deleted file mode 100644 index 8320ff5..0000000 --- a/dubbogo/simple/traffic/readme.md +++ /dev/null @@ -1,30 +0,0 @@ -#Traffic Filter quick start -### Start Zookeeper: -```shell -cd samples/dubbogo/simple/traffic -run docker-compose.yml/services -``` -### 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: 10" http://localhost:8888/user -curl -H "canary-weight: 90" http://localhost:8888/user -``` diff --git a/dubbogo/simple/traffic/server/server.go b/dubbogo/simple/traffic/server/server.go deleted file mode 100644 index 0983f27..0000000 --- a/dubbogo/simple/traffic/server/server.go +++ /dev/null @@ -1,39 +0,0 @@ -/* - * 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 deleted file mode 100644 index 6f99759..0000000 --- a/dubbogo/simple/traffic/server/v1/server.go +++ /dev/null @@ -1,39 +0,0 @@ -/* - * 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 deleted file mode 100644 index e6e6e4f..0000000 --- a/dubbogo/simple/traffic/server/v2/server.go +++ /dev/null @@ -1,39 +0,0 @@ -/* - * 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)) -} From a8087dee086367cffd23c558509583705a7c4f1c Mon Sep 17 00:00:00 2001 From: maxing <1501901576@qq.com> Date: Sun, 21 Aug 2022 15:17:54 +0800 Subject: [PATCH 08/13] test: add traffic sample --- .../simple/traffic/docker/docker-compose.yml | 27 ++++++ dubbogo/simple/traffic/pixiu/conf.yaml | 84 +++++++++++++++++++ dubbogo/simple/traffic/readme.md | 30 +++++++ dubbogo/simple/traffic/server/server.go | 39 +++++++++ dubbogo/simple/traffic/server/v1/server.go | 39 +++++++++ dubbogo/simple/traffic/server/v2/server.go | 39 +++++++++ 6 files changed, 258 insertions(+) create mode 100644 dubbogo/simple/traffic/docker/docker-compose.yml create mode 100644 dubbogo/simple/traffic/pixiu/conf.yaml create mode 100644 dubbogo/simple/traffic/readme.md create mode 100644 dubbogo/simple/traffic/server/server.go create mode 100644 dubbogo/simple/traffic/server/v1/server.go create mode 100644 dubbogo/simple/traffic/server/v2/server.go 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..ae65f4f --- /dev/null +++ b/dubbogo/simple/traffic/pixiu/conf.yaml @@ -0,0 +1,84 @@ +# +# 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/1" + model: canary-by-header + canary: canary-by-header + value: 10 + - name: "user-v2" + router: "/user/1" + model: canary-weight + canary: canary-weight + value: 90 + - 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..8320ff5 --- /dev/null +++ b/dubbogo/simple/traffic/readme.md @@ -0,0 +1,30 @@ +#Traffic Filter quick start +### Start Zookeeper: +```shell +cd samples/dubbogo/simple/traffic +run docker-compose.yml/services +``` +### 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: 10" http://localhost:8888/user +curl -H "canary-weight: 90" 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)) +} From 59c7356204d1b7911d13235701b24c1b1a97728f Mon Sep 17 00:00:00 2001 From: maxing <1501901576@qq.com> Date: Sun, 21 Aug 2022 21:35:37 +0800 Subject: [PATCH 09/13] add traffic test --- dubbogo/simple/traffic/test/pixiu_test.go | 44 +++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 dubbogo/simple/traffic/test/pixiu_test.go diff --git a/dubbogo/simple/traffic/test/pixiu_test.go b/dubbogo/simple/traffic/test/pixiu_test.go new file mode 100644 index 0000000..002f263 --- /dev/null +++ b/dubbogo/simple/traffic/test/pixiu_test.go @@ -0,0 +1,44 @@ +/* + * 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 test + +import ( + "io/ioutil" + "net/http" + "strings" + "testing" + "time" +) + +import ( + "github.com/stretchr/testify/assert" +) + +func TestGET(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("canary-by-header", "10") + 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"`)) +} From d1911497e765a02c3b0689582780d20f306fd1bd Mon Sep 17 00:00:00 2001 From: maxing <1501901576@qq.com> Date: Mon, 22 Aug 2022 20:22:45 +0800 Subject: [PATCH 10/13] test: add wasmFilter test --- dubbogo/simple/wasm/pixiu/conf.yaml | 2 +- dubbogo/simple/wasm/test/pixiu_test.go | 50 ++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 dubbogo/simple/wasm/test/pixiu_test.go diff --git a/dubbogo/simple/wasm/pixiu/conf.yaml b/dubbogo/simple/wasm/pixiu/conf.yaml index f498836..d3b5d1f 100644 --- a/dubbogo/simple/wasm/pixiu/conf.yaml +++ b/dubbogo/simple/wasm/pixiu/conf.yaml @@ -65,6 +65,6 @@ static_resources: reject_policy: "immediacy" wasm: services: - - name: header + - name: wasm.header config: path: wasm/data/filter.wasm \ No newline at end of file diff --git a/dubbogo/simple/wasm/test/pixiu_test.go b/dubbogo/simple/wasm/test/pixiu_test.go new file mode 100644 index 0000000..7884310 --- /dev/null +++ b/dubbogo/simple/wasm/test/pixiu_test.go @@ -0,0 +1,50 @@ +/* + * 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 test + +import ( + "io/ioutil" + "net/http" + "strings" + "testing" + "time" +) + +import ( + "github.com/stretchr/testify/assert" +) + +func TestPost(t *testing.T) { + url := "http://localhost:8883/UserService/com.dubbogo.pixiu.UserService/GetUserByName" + data := "{\"types\":\"string\",\"values\":\"tc\"}" + client := &http.Client{Timeout: 5 * time.Second} + req, err := http.NewRequest("POST", url, strings.NewReader(data)) + req.Header.Set("x-dubbo-http1.1-dubbo-version", "1.0.0") + req.Header.Set("x-dubbo-service-protocol", "dubbo") + req.Header.Set("x-dubbo-service-version", "1.0.0") + req.Header.Set("x-dubbo-service-group", "test") + + assert.NoError(t, err) + req.Header.Add("Content-Type", "application/json") + 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.Contains(t, string(s), "hello wasm") +} From c8ea6b39c196746596338582f46b4a65e42feea8 Mon Sep 17 00:00:00 2001 From: maxing <1501901576@qq.com> Date: Tue, 23 Aug 2022 15:30:55 +0800 Subject: [PATCH 11/13] fix: correct wasmservice name in conf.yaml --- dubbogo/simple/wasm/pixiu/conf.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dubbogo/simple/wasm/pixiu/conf.yaml b/dubbogo/simple/wasm/pixiu/conf.yaml index d3b5d1f..9e6b572 100644 --- a/dubbogo/simple/wasm/pixiu/conf.yaml +++ b/dubbogo/simple/wasm/pixiu/conf.yaml @@ -37,7 +37,7 @@ static_resources: - name: dgp.filter.http.webassembly config: wasm_services: - - name: header + - name: wasm.header - name: dgp.filter.http.dubboproxy config: dubboProxyConfig: From 5588dbed8807b907791f33a4200a877e90811266 Mon Sep 17 00:00:00 2001 From: maxing <1501901576@qq.com> Date: Mon, 29 Aug 2022 12:55:19 +0800 Subject: [PATCH 12/13] =?UTF-8?q?docs=EF=BC=9Aupdate=20readme=20doc=20form?= =?UTF-8?q?at.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dubbogo/simple/traffic/readme.md | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/dubbogo/simple/traffic/readme.md b/dubbogo/simple/traffic/readme.md index 8320ff5..2da4736 100644 --- a/dubbogo/simple/traffic/readme.md +++ b/dubbogo/simple/traffic/readme.md @@ -1,28 +1,37 @@ -#Traffic Filter quick start +# Traffic Filter quick start + ### Start Zookeeper: + ```shell cd samples/dubbogo/simple/traffic run docker-compose.yml/services ``` + ### 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: 10" http://localhost:8888/user From 4572da156fa2a48f9e03593fcc524503d39074a3 Mon Sep 17 00:00:00 2001 From: maxing <1501901576@qq.com> Date: Fri, 16 Sep 2022 20:54:16 +0800 Subject: [PATCH 13/13] fix: traffic filter sample update --- dubbogo/simple/traffic/pixiu/conf.yaml | 14 ++++++-------- dubbogo/simple/traffic/readme.md | 3 +-- dubbogo/simple/traffic/test/pixiu_test.go | 4 ++-- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/dubbogo/simple/traffic/pixiu/conf.yaml b/dubbogo/simple/traffic/pixiu/conf.yaml index ae65f4f..122f072 100644 --- a/dubbogo/simple/traffic/pixiu/conf.yaml +++ b/dubbogo/simple/traffic/pixiu/conf.yaml @@ -41,15 +41,13 @@ static_resources: config: traffics: - name: "user-v1" - router: "/user/1" - model: canary-by-header - canary: canary-by-header - value: 10 + router: "/user" + canary-by-header: v1 + canary-weight: 10 - name: "user-v2" - router: "/user/1" - model: canary-weight - canary: canary-weight - value: 90 + router: "/user" + canary-by-header: v2 + canary-weight: 10 - name: dgp.filter.http.httpproxy config: config: diff --git a/dubbogo/simple/traffic/readme.md b/dubbogo/simple/traffic/readme.md index 2da4736..2ec86b0 100644 --- a/dubbogo/simple/traffic/readme.md +++ b/dubbogo/simple/traffic/readme.md @@ -34,6 +34,5 @@ go run cmd/pixiu/*.go gateway start -c samples/dubbogo/simple/traffic/pixiu/conf ```shell curl http://localhost:8888/user -curl -H "canary-by-header: 10" http://localhost:8888/user -curl -H "canary-weight: 90" http://localhost:8888/user +curl -H "canary-by-header: v1" http://localhost:8888/user ``` diff --git a/dubbogo/simple/traffic/test/pixiu_test.go b/dubbogo/simple/traffic/test/pixiu_test.go index 002f263..185de38 100644 --- a/dubbogo/simple/traffic/test/pixiu_test.go +++ b/dubbogo/simple/traffic/test/pixiu_test.go @@ -34,11 +34,11 @@ func TestGET(t *testing.T) { client := &http.Client{Timeout: 5 * time.Second} req, err := http.NewRequest("GET", url, nil) assert.NoError(t, err) - req.Header.Add("canary-by-header", "10") + req.Header.Add("canary-by-header", "v2") 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"`)) + assert.True(t, strings.Contains(string(s), `"server": "v2"`)) }