Merge pull request #17 from apache/1.5.5

Add 1.5.5-rc1
diff --git a/filter/sentinel/go-client/cmd/client.go b/filter/sentinel/go-client/cmd/client.go
new file mode 100644
index 0000000..0fab912
--- /dev/null
+++ b/filter/sentinel/go-client/cmd/client.go
@@ -0,0 +1,81 @@
+/*
+ * 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"
+	"time"
+)
+
+import (
+	"github.com/alibaba/sentinel-golang/core/flow"
+	hessian "github.com/apache/dubbo-go-hessian2"
+	"github.com/apache/dubbo-go-samples/helloworld/go-client/pkg"
+	"github.com/dubbogo/gost/log"
+)
+
+import (
+	_ "github.com/apache/dubbo-go/cluster/cluster_impl"
+	_ "github.com/apache/dubbo-go/cluster/loadbalance"
+	_ "github.com/apache/dubbo-go/common/proxy/proxy_factory"
+	"github.com/apache/dubbo-go/config"
+	_ "github.com/apache/dubbo-go/filter/filter_impl"
+	_ "github.com/apache/dubbo-go/protocol/dubbo"
+	_ "github.com/apache/dubbo-go/registry/protocol"
+	_ "github.com/apache/dubbo-go/registry/zookeeper"
+)
+
+var userProvider = new(pkg.UserProvider)
+
+func init() {
+	config.SetConsumerService(userProvider)
+	hessian.RegisterPOJO(&pkg.User{})
+}
+
+// need to setup environment variable "CONF_CONSUMER_FILE_PATH" to "conf/client.yml" before run
+func main() {
+	hessian.RegisterPOJO(&pkg.User{})
+	config.Load()
+	time.Sleep(3 * time.Second)
+
+	_, err := flow.LoadRules([]*flow.Rule{
+		{
+			ID: 666,
+			// protocol:consumer:interfaceName:group:version:method
+			Resource:        "dubbo:consumer:org.apache.dubbo.UserProvider:::GetUser()",
+			MetricType:      flow.QPS,
+			Count:           1,
+			ControlBehavior: flow.Reject,
+		},
+	})
+	if err != nil {
+		panic(err)
+	}
+
+	gxlog.CInfo("\n\n\nstart to test sentinel filter")
+	for i := 0; i <= 5; i++ {
+		user := &pkg.User{}
+		err = userProvider.GetUser(context.TODO(), []interface{}{"A001"}, user)
+		if err != nil {
+			gxlog.CError("error: %v\n", err)
+			continue
+		}
+		gxlog.CInfo("response result: %v\n", user)
+	}
+
+}
diff --git a/filter/sentinel/go-client/conf/client.yml b/filter/sentinel/go-client/conf/client.yml
new file mode 100644
index 0000000..bd79b24
--- /dev/null
+++ b/filter/sentinel/go-client/conf/client.yml
@@ -0,0 +1,62 @@
+# dubbo client yaml configure file
+
+check: true
+# client
+request_timeout : "3s"
+# connect timeout
+connect_timeout : "3s"
+
+# application config
+application:
+  organization : "dubbo.io"
+  name  : "UserInfoClient"
+  module : "dubbo-go user-info client"
+  version : "0.0.1"
+  environment : "dev"
+
+# registry config
+registries :
+  "demoZk":
+    protocol: "zookeeper"
+    timeout	: "3s"
+    address: "127.0.0.1:2181"
+    username: ""
+    password: ""
+
+# reference config
+references:
+  "UserProvider":
+    registry: "demoZk"
+    protocol : "dubbo"
+    interface : "org.apache.dubbo.UserProvider"
+    cluster: "failover"
+    methods :
+    - name: "GetUser"
+      retries: 3
+
+# filter config
+filter: "sentinel-consumer"
+
+# protocol config
+protocol_conf:
+  dubbo:
+    reconnect_interval: 0
+    connection_number: 1
+    heartbeat_period: "5s"
+    session_timeout: "180s"
+    pool_size: 64
+    pool_ttl: 600
+    getty_session_param:
+      compress_encoding: false
+      tcp_no_delay: true
+      tcp_keep_alive: true
+      keep_alive_period: "120s"
+      tcp_r_buf_size: 262144
+      tcp_w_buf_size: 65536
+      pkg_rq_size: 1024
+      pkg_wq_size: 512
+      tcp_read_timeout: "1s"
+      tcp_write_timeout: "5s"
+      wait_timeout: "1s"
+      max_msg_len: 1024000
+      session_name: "client"
diff --git a/filter/sentinel/go-client/conf/log.yml b/filter/sentinel/go-client/conf/log.yml
new file mode 100644
index 0000000..d0400fe
--- /dev/null
+++ b/filter/sentinel/go-client/conf/log.yml
@@ -0,0 +1,28 @@
+
+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: "capital"
+  timeEncoder: "iso8601"
+  durationEncoder: "seconds"
+  callerEncoder: "short"
+  nameEncoder: ""
+
+outputPaths:
+  - "stderr"
+errorOutputPaths:
+  - "stderr"
+initialFields:
diff --git a/filter/sentinel/go-client/pkg/user.go b/filter/sentinel/go-client/pkg/user.go
new file mode 100644
index 0000000..75c964f
--- /dev/null
+++ b/filter/sentinel/go-client/pkg/user.go
@@ -0,0 +1,42 @@
+/*
+ * 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 pkg
+
+import (
+	"context"
+	"time"
+)
+
+type User struct {
+	Id   string
+	Name string
+	Age  int32
+	Time time.Time
+}
+
+type UserProvider struct {
+	GetUser func(ctx context.Context, req []interface{}, rsp *User) error
+}
+
+func (u *UserProvider) Reference() string {
+	return "UserProvider"
+}
+
+func (User) JavaClassName() string {
+	return "org.apache.dubbo.User"
+}
diff --git a/filter/sentinel/go-server/cmd/server.go b/filter/sentinel/go-server/cmd/server.go
new file mode 100644
index 0000000..dabb211
--- /dev/null
+++ b/filter/sentinel/go-server/cmd/server.go
@@ -0,0 +1,92 @@
+/*
+ * 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 (
+	"github.com/alibaba/sentinel-golang/core/flow"
+	hessian "github.com/apache/dubbo-go-hessian2"
+	_ "github.com/apache/dubbo-go/cluster/cluster_impl"
+	_ "github.com/apache/dubbo-go/cluster/loadbalance"
+	"github.com/apache/dubbo-go/common/logger"
+	_ "github.com/apache/dubbo-go/common/proxy/proxy_factory"
+	"github.com/apache/dubbo-go/config"
+	_ "github.com/apache/dubbo-go/filter/filter_impl"
+	_ "github.com/apache/dubbo-go/protocol/dubbo"
+	_ "github.com/apache/dubbo-go/registry/protocol"
+	_ "github.com/apache/dubbo-go/registry/zookeeper"
+)
+
+import (
+	"github.com/apache/dubbo-go-samples/filter/custom_filter/go-server/pkg"
+)
+
+var (
+	survivalTimeout = int(3e9)
+)
+
+// need to setup environment variable "CONF_PROVIDER_FILE_PATH" to "conf/server.yml" before run
+func main() {
+	hessian.RegisterPOJO(&pkg.User{})
+	config.Load()
+	_, err := flow.LoadRules([]*flow.Rule{
+		{
+			ID: 777,
+			// protocol:consumer:interfaceName:group:version:method
+			Resource:        "dubbo:provider:org.apache.dubbo.UserProvider:::GetUser()",
+			MetricType:      flow.QPS,
+			Count:           1,
+			ControlBehavior: flow.Reject,
+		},
+	})
+	if err != nil {
+		panic(err)
+	}
+
+	initSignal()
+}
+
+func initSignal() {
+	signals := make(chan os.Signal, 1)
+	// It is not possible to block SIGKILL or syscall.SIGSTOP
+	signal.Notify(signals, os.Interrupt, os.Kill, 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/filter/sentinel/go-server/conf/client.yml b/filter/sentinel/go-server/conf/client.yml
new file mode 100644
index 0000000..f3e6f00
--- /dev/null
+++ b/filter/sentinel/go-server/conf/client.yml
@@ -0,0 +1,61 @@
+# dubbo client yaml configure file
+
+check: true
+# client
+request_timeout : "3s"
+# connect timeout
+connect_timeout : "3s"
+
+# application config
+application:
+  organization : "dubbo.io"
+  name  : "UserInfoTest"
+  module : "dubbo-go user-info client"
+  version : "0.0.1"
+  environment : "dev"
+
+# registry config
+registries :
+  "demoZk":
+    protocol: "zookeeper"
+    timeout	: "3s"
+    address: "127.0.0.1:2181"
+    username: ""
+    password: ""
+
+filter: "sentinel-provider"
+
+# reference config
+references:
+  "UserProvider":
+    registry: "demoZk"
+    protocol : "dubbo"
+    interface : "org.apache.dubbo.UserProvider"
+    cluster: "failover"
+    methods :
+    - name: "GetUser"
+      retries: 3
+
+# protocol config
+protocol_conf:
+  dubbo:
+    reconnect_interval: 0
+    connection_number: 1
+    heartbeat_period: "5s"
+    session_timeout: "180s"
+    pool_size: 64
+    pool_ttl: 600
+    getty_session_param:
+      compress_encoding: false
+      tcp_no_delay: true
+      tcp_keep_alive: true
+      keep_alive_period: "120s"
+      tcp_r_buf_size: 262144
+      tcp_w_buf_size: 65536
+      pkg_rq_size: 1024
+      pkg_wq_size: 512
+      tcp_read_timeout: "1s"
+      tcp_write_timeout: "5s"
+      wait_timeout: "1s"
+      max_msg_len: 1024000
+      session_name: "client"
diff --git a/filter/sentinel/go-server/conf/log.yml b/filter/sentinel/go-server/conf/log.yml
new file mode 100644
index 0000000..a75bccb
--- /dev/null
+++ b/filter/sentinel/go-server/conf/log.yml
@@ -0,0 +1,28 @@
+
+level: "error"
+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: "capital"
+  timeEncoder: "iso8601"
+  durationEncoder: "seconds"
+  callerEncoder: "short"
+  nameEncoder: ""
+
+outputPaths:
+  - "stderr"
+errorOutputPaths:
+  - "stderr"
+initialFields:
diff --git a/filter/sentinel/go-server/conf/server.yml b/filter/sentinel/go-server/conf/server.yml
new file mode 100644
index 0000000..b614d94
--- /dev/null
+++ b/filter/sentinel/go-server/conf/server.yml
@@ -0,0 +1,58 @@
+# dubbo server yaml configure file
+
+# application config
+application:
+  organization: "dubbo.io"
+  name: "UserInfoServer"
+  module: "dubbo-go user-info server"
+  version: "0.0.1"
+  environment: "dev"
+
+# registry config
+registries:
+  "demoZk":
+    protocol: "zookeeper"
+    timeout: "3s"
+    address: "127.0.0.1:2181"
+
+# service config
+services:
+  "UserProvider":
+    registry: "demoZk"
+    protocol: "dubbo"
+    interface: "org.apache.dubbo.UserProvider"
+    loadbalance: "random"
+    warmup: "100"
+    cluster: "failover"
+    methods:
+      - name: "GetUser"
+        retries: 1
+        loadbalance: "random"
+
+# filter config
+filter: "sentinel-provider"
+
+# protocol config
+protocols:
+  "dubbo":
+    name: "dubbo"
+    port: 20000
+
+protocol_conf:
+  dubbo:
+    session_number: 700
+    session_timeout: "180s"
+    getty_session_param:
+      compress_encoding: false
+      tcp_no_delay: true
+      tcp_keep_alive: true
+      keep_alive_period: "120s"
+      tcp_r_buf_size: 262144
+      tcp_w_buf_size: 65536
+      pkg_rq_size: 1024
+      pkg_wq_size: 512
+      tcp_read_timeout: "1s"
+      tcp_write_timeout: "5s"
+      wait_timeout: "1s"
+      max_msg_len: 1024000
+      session_name: "server"
diff --git a/filter/sentinel/go-server/docker/docker-compose.yml b/filter/sentinel/go-server/docker/docker-compose.yml
new file mode 100644
index 0000000..8724179
--- /dev/null
+++ b/filter/sentinel/go-server/docker/docker-compose.yml
@@ -0,0 +1,9 @@
+version: '3'
+
+services:
+  zookeeper:
+    image: zookeeper
+    ports:
+      - 2181:2181
+    restart: on-failure
+
diff --git a/filter/sentinel/go-server/pkg/user.go b/filter/sentinel/go-server/pkg/user.go
new file mode 100644
index 0000000..37fcb25
--- /dev/null
+++ b/filter/sentinel/go-server/pkg/user.go
@@ -0,0 +1,63 @@
+/*
+ * 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 pkg
+
+import (
+	"context"
+	"time"
+)
+
+import (
+	"github.com/dubbogo/gost/log"
+)
+
+import (
+	hessian "github.com/apache/dubbo-go-hessian2"
+	"github.com/apache/dubbo-go/config"
+)
+
+func init() {
+	config.SetProviderService(new(UserProvider))
+	// ------for hessian2------
+	hessian.RegisterPOJO(&User{})
+}
+
+type User struct {
+	Id   string
+	Name string
+	Age  int32
+	Time time.Time
+}
+
+type UserProvider struct {
+}
+
+func (u *UserProvider) GetUser(ctx context.Context, req []interface{}) (*User, error) {
+	gxlog.CInfo("req:%#v", req)
+	rsp := User{"A001", "Alex Stocks", 18, time.Now()}
+	gxlog.CInfo("rsp:%#v", rsp)
+	return &rsp, nil
+}
+
+func (u *UserProvider) Reference() string {
+	return "UserProvider"
+}
+
+func (u User) JavaClassName() string {
+	return "org.apache.dubbo.User"
+}
diff --git a/filter/sentinel/go-server/tests/integration/main_test.go b/filter/sentinel/go-server/tests/integration/main_test.go
new file mode 100644
index 0000000..98bd630
--- /dev/null
+++ b/filter/sentinel/go-server/tests/integration/main_test.go
@@ -0,0 +1,71 @@
+// +build integration
+
+/*
+ * 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 integration
+
+import (
+	hessian "github.com/apache/dubbo-go-hessian2"
+	"github.com/apache/dubbo-go/config"
+
+	_ "github.com/apache/dubbo-go/cluster/cluster_impl"
+	_ "github.com/apache/dubbo-go/cluster/loadbalance"
+	_ "github.com/apache/dubbo-go/common/proxy/proxy_factory"
+	_ "github.com/apache/dubbo-go/filter/filter_impl"
+	_ "github.com/apache/dubbo-go/metadata/service/inmemory"
+	_ "github.com/apache/dubbo-go/protocol/dubbo"
+	_ "github.com/apache/dubbo-go/registry/protocol"
+	_ "github.com/apache/dubbo-go/registry/zookeeper"
+)
+
+import (
+	"context"
+	"os"
+	"testing"
+	"time"
+)
+
+var userProvider = new(UserProvider)
+
+func TestMain(m *testing.M) {
+	config.SetConsumerService(userProvider)
+	hessian.RegisterPOJO(&User{})
+	config.Load()
+	time.Sleep(3 * time.Second)
+
+	os.Exit(m.Run())
+}
+
+type User struct {
+	Id   string
+	Name string
+	Age  int32
+	Time time.Time
+}
+
+type UserProvider struct {
+	GetUser func(ctx context.Context, req []interface{}, rsp *User) error
+}
+
+func (u *UserProvider) Reference() string {
+	return "UserProvider"
+}
+
+func (User) JavaClassName() string {
+	return "org.apache.dubbo.User"
+}
diff --git a/filter/sentinel/go-server/tests/integration/userprovider_test.go b/filter/sentinel/go-server/tests/integration/userprovider_test.go
new file mode 100644
index 0000000..6b2c871
--- /dev/null
+++ b/filter/sentinel/go-server/tests/integration/userprovider_test.go
@@ -0,0 +1,42 @@
+// +build integration
+
+/*
+ * 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 integration
+
+import (
+	"context"
+	"testing"
+)
+import (
+	"github.com/stretchr/testify/assert"
+)
+
+func TestGetUser(t *testing.T) {
+	user := &User{}
+	err := userProvider.GetUser(context.TODO(), []interface{}{"A001"}, user)
+	assert.Nil(t, err)
+	assert.Equal(t, "A001", user.Id)
+	assert.Equal(t, "Alex Stocks", user.Name)
+	assert.Equal(t, int32(18), user.Age)
+	assert.NotNil(t, user.Time)
+
+	// Because the sentinel filter, the second request will be an error
+	err = userProvider.GetUser(context.TODO(), []interface{}{"A001"}, user)
+	assert.NotNil(t, err)
+}
diff --git a/start_integrate_test.sh b/start_integrate_test.sh
index 9da9681..703d7cb 100755
--- a/start_integrate_test.sh
+++ b/start_integrate_test.sh
@@ -28,6 +28,7 @@
 # filter
 array+=("filter/custom_filter/go-server")
 array+=("filter/tpslimit/go-server")
+array+=("filter/sentinel/go-server")
 
 # general
 array+=("general/dubbo/go-server")