From 3c2e8dcf8792ec750b72e02d86b4f1a8d12e1f15 Mon Sep 17 00:00:00 2001 From: wenxu12345 <44203734@qq.com> Date: Fri, 29 Apr 2022 16:33:01 +0800 Subject: [PATCH 1/6] config --- pkg/grpc-etcdv3/getcdv3/resolver.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/pkg/grpc-etcdv3/getcdv3/resolver.go b/pkg/grpc-etcdv3/getcdv3/resolver.go index ea6367008..108266150 100644 --- a/pkg/grpc-etcdv3/getcdv3/resolver.go +++ b/pkg/grpc-etcdv3/getcdv3/resolver.go @@ -44,12 +44,16 @@ func NewResolver(schema, etcdAddr, serviceName string) (*Resolver, error) { r.etcdAddr = etcdAddr resolver.Register(&r) - conn, err := grpc.Dial( - GetPrefix(schema, serviceName), + ctx, _ := context.WithTimeout(context.TODO(), time.Second*5) + conn, err := grpc.DialContext(ctx, GetPrefix(schema, serviceName), grpc.WithDefaultServiceConfig(fmt.Sprintf(`{"LoadBalancingPolicy": "%s"}`, roundrobin.Name)), - grpc.WithInsecure(), - grpc.WithTimeout(time.Duration(5)*time.Second), - ) + grpc.WithInsecure()) + //conn, err := grpc.Dial( + // GetPrefix(schema, serviceName), + // grpc.WithDefaultServiceConfig(fmt.Sprintf(`{"LoadBalancingPolicy": "%s"}`, roundrobin.Name)), + // grpc.WithInsecure(), + // grpc.WithTimeout(time.Duration(5)*time.Second), + //) if err == nil { r.grpcClientConn = conn } From d5e5659a2c847882b2ca89ef0ab4c7326c58c66f Mon Sep 17 00:00:00 2001 From: wenxu12345 <44203734@qq.com> Date: Fri, 29 Apr 2022 16:42:42 +0800 Subject: [PATCH 2/6] config --- pkg/grpc-etcdv3/getcdv3/resolver.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pkg/grpc-etcdv3/getcdv3/resolver.go b/pkg/grpc-etcdv3/getcdv3/resolver.go index 108266150..4a8c5d644 100644 --- a/pkg/grpc-etcdv3/getcdv3/resolver.go +++ b/pkg/grpc-etcdv3/getcdv3/resolver.go @@ -1,6 +1,7 @@ package getcdv3 import ( + "Open_IM/pkg/common/log" "context" "fmt" "strings" @@ -48,6 +49,8 @@ func NewResolver(schema, etcdAddr, serviceName string) (*Resolver, error) { conn, err := grpc.DialContext(ctx, GetPrefix(schema, serviceName), grpc.WithDefaultServiceConfig(fmt.Sprintf(`{"LoadBalancingPolicy": "%s"}`, roundrobin.Name)), grpc.WithInsecure()) + log.Debug("", "etcd key ", GetPrefix(schema, serviceName), "value ", *r.grpcClientConn) + //conn, err := grpc.Dial( // GetPrefix(schema, serviceName), // grpc.WithDefaultServiceConfig(fmt.Sprintf(`{"LoadBalancingPolicy": "%s"}`, roundrobin.Name)), @@ -71,6 +74,7 @@ func GetConn(schema, etcdaddr, serviceName string) *grpc.ClientConn { r, ok := nameResolver[schema+serviceName] rwNameResolverMutex.RUnlock() if ok { + log.Debug("", "etcd key ", schema+serviceName, "value ", *r.grpcClientConn, *r) return r.grpcClientConn } @@ -78,15 +82,18 @@ func GetConn(schema, etcdaddr, serviceName string) *grpc.ClientConn { r, ok = nameResolver[schema+serviceName] if ok { rwNameResolverMutex.Unlock() + log.Debug("", "etcd key ", schema+serviceName, "value ", *r.grpcClientConn, *r) return r.grpcClientConn } r, err := NewResolver(schema, etcdaddr, serviceName) if err != nil { + log.Error("", "etcd failed ", schema, etcdaddr, serviceName) rwNameResolverMutex.Unlock() return nil } + log.Debug("", "etcd key ", schema+serviceName, "value ", *r.grpcClientConn, *r) nameResolver[schema+serviceName] = r rwNameResolverMutex.Unlock() return r.grpcClientConn From 16a2d80801b2ddf0787e8c84471dc3ad60782561 Mon Sep 17 00:00:00 2001 From: wenxu12345 <44203734@qq.com> Date: Fri, 29 Apr 2022 17:02:03 +0800 Subject: [PATCH 3/6] config --- pkg/grpc-etcdv3/getcdv3/resolver.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/grpc-etcdv3/getcdv3/resolver.go b/pkg/grpc-etcdv3/getcdv3/resolver.go index 4a8c5d644..76e5643c9 100644 --- a/pkg/grpc-etcdv3/getcdv3/resolver.go +++ b/pkg/grpc-etcdv3/getcdv3/resolver.go @@ -45,7 +45,7 @@ func NewResolver(schema, etcdAddr, serviceName string) (*Resolver, error) { r.etcdAddr = etcdAddr resolver.Register(&r) - ctx, _ := context.WithTimeout(context.TODO(), time.Second*5) + ctx, _ := context.WithTimeout(context.Background(), time.Second*5) conn, err := grpc.DialContext(ctx, GetPrefix(schema, serviceName), grpc.WithDefaultServiceConfig(fmt.Sprintf(`{"LoadBalancingPolicy": "%s"}`, roundrobin.Name)), grpc.WithInsecure()) From e68086e149e5c3ec87a07821d278063c13974e8e Mon Sep 17 00:00:00 2001 From: wenxu12345 <44203734@qq.com> Date: Fri, 29 Apr 2022 17:04:15 +0800 Subject: [PATCH 4/6] config --- pkg/grpc-etcdv3/getcdv3/resolver.go | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/pkg/grpc-etcdv3/getcdv3/resolver.go b/pkg/grpc-etcdv3/getcdv3/resolver.go index 76e5643c9..18b2f8b57 100644 --- a/pkg/grpc-etcdv3/getcdv3/resolver.go +++ b/pkg/grpc-etcdv3/getcdv3/resolver.go @@ -44,19 +44,19 @@ func NewResolver(schema, etcdAddr, serviceName string) (*Resolver, error) { r.schema = schema r.etcdAddr = etcdAddr resolver.Register(&r) - - ctx, _ := context.WithTimeout(context.Background(), time.Second*5) - conn, err := grpc.DialContext(ctx, GetPrefix(schema, serviceName), - grpc.WithDefaultServiceConfig(fmt.Sprintf(`{"LoadBalancingPolicy": "%s"}`, roundrobin.Name)), - grpc.WithInsecure()) + // + //ctx, _ := context.WithTimeout(context.Background(), time.Second*5) + //conn, err := grpc.DialContext(ctx, GetPrefix(schema, serviceName), + // grpc.WithDefaultServiceConfig(fmt.Sprintf(`{"LoadBalancingPolicy": "%s"}`, roundrobin.Name)), + // grpc.WithInsecure()) log.Debug("", "etcd key ", GetPrefix(schema, serviceName), "value ", *r.grpcClientConn) - //conn, err := grpc.Dial( - // GetPrefix(schema, serviceName), - // grpc.WithDefaultServiceConfig(fmt.Sprintf(`{"LoadBalancingPolicy": "%s"}`, roundrobin.Name)), - // grpc.WithInsecure(), - // grpc.WithTimeout(time.Duration(5)*time.Second), - //) + conn, err := grpc.Dial( + GetPrefix(schema, serviceName), + grpc.WithDefaultServiceConfig(fmt.Sprintf(`{"LoadBalancingPolicy": "%s"}`, roundrobin.Name)), + grpc.WithInsecure(), + grpc.WithTimeout(time.Duration(5)*time.Second), + ) if err == nil { r.grpcClientConn = conn } From 8701f8868c9227c147a79b14b881811419b9bc53 Mon Sep 17 00:00:00 2001 From: Gordon <1432970085@qq.com> Date: Fri, 29 Apr 2022 17:58:57 +0800 Subject: [PATCH 5/6] test --- go.mod | 1 + 1 file changed, 1 insertion(+) diff --git a/go.mod b/go.mod index fbe6a063e..0b75f41f6 100644 --- a/go.mod +++ b/go.mod @@ -45,6 +45,7 @@ require ( github.com/spf13/viper v1.9.0 github.com/stretchr/testify v1.7.0 github.com/tencentyun/qcloud-cos-sts-sdk v0.0.0-20210325043845-84a0811633ca + github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5 // indirect go.etcd.io/etcd/api/v3 v3.5.2 go.etcd.io/etcd/client/v3 v3.5.2 go.mongodb.org/mongo-driver v1.8.3 From ecb11cf927d94fdfb1a1de8d67f609ec3646770e Mon Sep 17 00:00:00 2001 From: Gordon <1432970085@qq.com> Date: Fri, 29 Apr 2022 17:59:53 +0800 Subject: [PATCH 6/6] test --- go.sum | 1 + 1 file changed, 1 insertion(+) diff --git a/go.sum b/go.sum index 40edeaa45..eea7ba356 100644 --- a/go.sum +++ b/go.sum @@ -482,6 +482,7 @@ github.com/tidwall/pretty v1.0.0 h1:HsD+QiTn7sK6flMKIvNmpqz1qrpP3Ps6jOKIKMooyg4= github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk= github.com/tjfoc/gmsm v1.3.2 h1:7JVkAn5bvUJ7HtU08iW6UiD+UTmJTIToHCfeFzkcCxM= github.com/tjfoc/gmsm v1.3.2/go.mod h1:HaUcFuY0auTiaHB9MHFGCPx5IaLhTUd2atbCFBQXn9w= +github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/ugorji/go v1.1.7 h1:/68gy2h+1mWMrwZFeD1kQialdSzAb432dtpeJ42ovdo= github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw= github.com/ugorji/go/codec v1.1.7 h1:2SvQaVZ1ouYrrKKwoSk2pzd4A9evlKJb9oTL+OaLUSs=