diff --git a/contrib/registry/etcd/etcd.go b/contrib/registry/etcd/etcd.go index 623e1e7ca75..690149c014e 100644 --- a/contrib/registry/etcd/etcd.go +++ b/contrib/registry/etcd/etcd.go @@ -8,6 +8,7 @@ package etcd import ( + "reflect" "time" etcd3 "go.etcd.io/etcd/client/v3" @@ -79,26 +80,34 @@ func NewWithClient(client *etcd3.Client, option ...Option) *Registry { } // extractResponseToServices extracts etcd watch response context to service list. -func extractResponseToServices(res *etcd3.GetResponse) ([]*gsvc.Service, error) { +func extractResponseToServices(res *etcd3.GetResponse) ([]gsvc.Service, error) { if res == nil || res.Kvs == nil { return nil, nil } var ( - services []*gsvc.Service + services []gsvc.Service serviceKey string - serviceMap = make(map[string]*gsvc.Service) + serviceMap = make(map[string]*gsvc.LocalService) ) for _, kv := range res.Kvs { - service, err := gsvc.NewServiceWithKV(kv.Key, kv.Value) + service, err := gsvc.NewServiceWithKV(string(kv.Key), string(kv.Value)) if err != nil { return services, err } - if service != nil { - serviceKey = service.KeyWithoutEndpoints() - if s, ok := serviceMap[serviceKey]; ok { - s.Endpoints = append(s.Endpoints, service.Endpoints...) + localService, ok := service.(*gsvc.LocalService) + if !ok { + return nil, gerror.Newf( + `service from "gsvc.NewServiceWithKV" is not "*gsvc.LocalService", but "%s"`, + reflect.TypeOf(service), + ) + } + if localService != nil { + serviceKey = localService.GetPrefix() + var localServiceInMap *gsvc.LocalService + if localServiceInMap, ok = serviceMap[serviceKey]; ok { + localServiceInMap.Endpoints = append(localServiceInMap.Endpoints, localService.Endpoints...) } else { - serviceMap[serviceKey] = service + serviceMap[serviceKey] = localService services = append(services, service) } } diff --git a/contrib/registry/etcd/etcd_discovery.go b/contrib/registry/etcd/etcd_discovery.go index 1ad2f7f8514..7821271f425 100644 --- a/contrib/registry/etcd/etcd_discovery.go +++ b/contrib/registry/etcd/etcd_discovery.go @@ -15,8 +15,12 @@ import ( ) // Search is the etcd discovery search function. -func (r *Registry) Search(ctx context.Context, in gsvc.SearchInput) ([]*gsvc.Service, error) { - res, err := r.kv.Get(ctx, in.Key(), etcd3.WithPrefix()) +func (r *Registry) Search(ctx context.Context, in gsvc.SearchInput) ([]gsvc.Service, error) { + if in.Prefix == "" && in.Name != "" { + in.Prefix = gsvc.NewServiceWithName(in.Name).GetPrefix() + } + + res, err := r.kv.Get(ctx, in.Prefix, etcd3.WithPrefix()) if err != nil { return nil, err } @@ -25,18 +29,12 @@ func (r *Registry) Search(ctx context.Context, in gsvc.SearchInput) ([]*gsvc.Ser return nil, err } // Service filter. - filteredServices := make([]*gsvc.Service, 0) + filteredServices := make([]gsvc.Service, 0) for _, v := range services { - if in.Deployment != "" && in.Deployment != v.Deployment { - continue - } - if in.Namespace != "" && in.Namespace != v.Namespace { - continue - } - if in.Name != "" && in.Name != v.Name { + if in.Name != "" && in.Name != v.GetName() { continue } - if in.Version != "" && in.Version != v.Version { + if in.Version != "" && in.Version != v.GetVersion() { continue } service := v diff --git a/contrib/registry/etcd/etcd_registrar.go b/contrib/registry/etcd/etcd_registrar.go index 99f52b5c5b2..cd6051b1f41 100644 --- a/contrib/registry/etcd/etcd_registrar.go +++ b/contrib/registry/etcd/etcd_registrar.go @@ -16,19 +16,19 @@ import ( ) // Register implements the gsvc.Register interface. -func (r *Registry) Register(ctx context.Context, service *gsvc.Service) error { +func (r *Registry) Register(ctx context.Context, service gsvc.Service) (gsvc.Service, error) { r.lease = etcd3.NewLease(r.client) grant, err := r.lease.Grant(ctx, int64(r.keepaliveTTL.Seconds())) if err != nil { - return gerror.Wrapf(err, `etcd grant failed with keepalive ttl "%s"`, r.keepaliveTTL) + return nil, gerror.Wrapf(err, `etcd grant failed with keepalive ttl "%s"`, r.keepaliveTTL) } var ( - key = service.Key() - value = service.Value() + key = service.GetKey() + value = service.GetValue() ) _, err = r.client.Put(ctx, key, value, etcd3.WithLease(grant.ID)) if err != nil { - return gerror.Wrapf( + return nil, gerror.Wrapf( err, `etcd put failed with key "%s", value "%s", lease "%d"`, key, value, grant.ID, @@ -41,16 +41,15 @@ func (r *Registry) Register(ctx context.Context, service *gsvc.Service) error { ) keepAliceCh, err := r.client.KeepAlive(context.Background(), grant.ID) if err != nil { - return err + return nil, err } go r.doKeepAlive(grant.ID, keepAliceCh) - service.Separator = gsvc.DefaultSeparator - return nil + return service, nil } // Deregister implements the gsvc.Deregister interface. -func (r *Registry) Deregister(ctx context.Context, service *gsvc.Service) error { - _, err := r.client.Delete(ctx, service.Key()) +func (r *Registry) Deregister(ctx context.Context, service gsvc.Service) error { + _, err := r.client.Delete(ctx, service.GetKey()) if r.lease != nil { _ = r.lease.Close() } diff --git a/contrib/registry/etcd/etcd_watcher.go b/contrib/registry/etcd/etcd_watcher.go index afeee375608..55deca99c20 100644 --- a/contrib/registry/etcd/etcd_watcher.go +++ b/contrib/registry/etcd/etcd_watcher.go @@ -43,7 +43,7 @@ func newWatcher(key string, client *etcd3.Client) (*watcher, error) { } // Proceed is used to watch the key. -func (w *watcher) Proceed() ([]*gsvc.Service, error) { +func (w *watcher) Proceed() ([]gsvc.Service, error) { select { case <-w.ctx.Done(): return nil, w.ctx.Err() @@ -58,7 +58,7 @@ func (w *watcher) Close() error { return w.watcher.Close() } -func (w *watcher) getServicesByPrefix() ([]*gsvc.Service, error) { +func (w *watcher) getServicesByPrefix() ([]gsvc.Service, error) { res, err := w.kv.Get(w.ctx, w.key, etcd3.WithPrefix()) if err != nil { return nil, err diff --git a/contrib/registry/etcd/go.mod b/contrib/registry/etcd/go.mod index 8580c8fc1a9..6e091bf565b 100644 --- a/contrib/registry/etcd/go.mod +++ b/contrib/registry/etcd/go.mod @@ -4,7 +4,7 @@ go 1.15 require ( github.com/gogf/gf/v2 v2.0.0 - go.etcd.io/etcd/client/v3 v3.5.1 + go.etcd.io/etcd/client/v3 v3.5.4 ) replace github.com/gogf/gf/v2 => ../../../ diff --git a/contrib/registry/etcd/go.sum b/contrib/registry/etcd/go.sum index 1b99f6a6753..bda77ea73f5 100644 --- a/contrib/registry/etcd/go.sum +++ b/contrib/registry/etcd/go.sum @@ -160,7 +160,7 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo= github.com/prometheus/client_golang v1.7.1/go.mod h1:PY5Wy2awLA44sXw4AOSfFBetzPP4j5+D6mVACh+pe2M= -github.com/prometheus/client_golang v1.11.0/go.mod h1:Z6t4BnS23TR94PD6BsDNk8yVqroYurpAkEiz0P2BEV0= +github.com/prometheus/client_golang v1.11.1/go.mod h1:Z6t4BnS23TR94PD6BsDNk8yVqroYurpAkEiz0P2BEV0= github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= @@ -189,12 +189,12 @@ github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9de github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= github.com/yuin/goldmark v1.4.0/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= -go.etcd.io/etcd/api/v3 v3.5.1 h1:v28cktvBq+7vGyJXF8G+rWJmj+1XUmMtqcLnH8hDocM= -go.etcd.io/etcd/api/v3 v3.5.1/go.mod h1:cbVKeC6lCfl7j/8jBhAK6aIYO9XOjdptoxU/nLQcPvs= -go.etcd.io/etcd/client/pkg/v3 v3.5.1 h1:XIQcHCFSG53bJETYeRJtIxdLv2EWRGxcfzR8lSnTH4E= -go.etcd.io/etcd/client/pkg/v3 v3.5.1/go.mod h1:IJHfcCEKxYu1Os13ZdwCwIUTUVGYTSAM3YSwc9/Ac1g= -go.etcd.io/etcd/client/v3 v3.5.1 h1:oImGuV5LGKjCqXdjkMHCyWa5OO1gYKCnC/1sgdfj1Uk= -go.etcd.io/etcd/client/v3 v3.5.1/go.mod h1:OnjH4M8OnAotwaB2l9bVgZzRFKru7/ZMoS46OtKyd3Q= +go.etcd.io/etcd/api/v3 v3.5.4 h1:OHVyt3TopwtUQ2GKdd5wu3PmmipR4FTwCqoEjSyRdIc= +go.etcd.io/etcd/api/v3 v3.5.4/go.mod h1:5GB2vv4A4AOn3yk7MftYGHkUfGtDHnEraIjym4dYz5A= +go.etcd.io/etcd/client/pkg/v3 v3.5.4 h1:lrneYvz923dvC14R54XcA7FXoZ3mlGZAgmwhfm7HqOg= +go.etcd.io/etcd/client/pkg/v3 v3.5.4/go.mod h1:IJHfcCEKxYu1Os13ZdwCwIUTUVGYTSAM3YSwc9/Ac1g= +go.etcd.io/etcd/client/v3 v3.5.4 h1:p83BUL3tAYS0OT/r0qglgc3M1JjhM0diV8DSWAhVXv4= +go.etcd.io/etcd/client/v3 v3.5.4/go.mod h1:ZaRkVgBZC+L+dLCjTcF1hRXpgZXQPOvnA/Ak/gq3kiY= go.opentelemetry.io/otel v1.7.0 h1:Z2lA3Tdch0iDcrhJXDIlC94XE+bxok1F9B+4Lz/lGsM= go.opentelemetry.io/otel v1.7.0/go.mod h1:5BdUoMIz5WEs0vt0CUEMtSSaTSHBBVwrhnz7+nrD5xk= go.opentelemetry.io/otel/sdk v1.7.0 h1:4OmStpcKVOfvDOgCt7UriAPtKolwIhxpnSNI/yK+1B0= diff --git a/contrib/registry/polaris/go.mod b/contrib/registry/polaris/go.mod index 6d16b18b538..f3c6027b284 100644 --- a/contrib/registry/polaris/go.mod +++ b/contrib/registry/polaris/go.mod @@ -4,7 +4,7 @@ go 1.15 require ( github.com/gogf/gf/v2 v2.0.0 - github.com/polarismesh/polaris-go v1.1.0 + github.com/polarismesh/polaris-go v1.2.0-beta.0.0.20220517041223-596a6a63b00f ) replace github.com/gogf/gf/v2 => ../../../ diff --git a/contrib/registry/polaris/go.sum b/contrib/registry/polaris/go.sum index 86246f13f46..8a496ace52c 100644 --- a/contrib/registry/polaris/go.sum +++ b/contrib/registry/polaris/go.sum @@ -62,8 +62,8 @@ github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDk github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= github.com/cncf/udpa/go v0.0.0-20210930031921-04548b0d99d4/go.mod h1:6pvJx4me5XPnfI9Z40ddWsdw2W/uZgQLFXToKeRcDiI= -github.com/cncf/xds/go v0.0.0-20210805033703-aa0b78936158/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= github.com/cncf/xds/go v0.0.0-20210922020428-25de7278fc84/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= +github.com/cncf/xds/go v0.0.0-20211001041855-01bcc9b48dfe/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= github.com/cncf/xds/go v0.0.0-20211011173535-cb28da3451f1/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= @@ -74,7 +74,7 @@ github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymF github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk= -github.com/envoyproxy/go-control-plane v0.9.10-0.20210907150352-cf90f659a021/go.mod h1:AFq3mo9L8Lqqiid3OhADV3RfLJnjiw63cSpi+fDTRC0= +github.com/envoyproxy/go-control-plane v0.10.2-0.20220325020618-49ff273808a1/go.mod h1:KJwIaB5Mv44NWtYuAOFCVOjcI94vtpEz2JU/D2v6IjE= github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w= github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk= @@ -149,6 +149,7 @@ github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.7 h1:81/ik6ipDQS2aGcBfIN5dHDB36BwrStyeAQquSYCV4o= github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= @@ -250,8 +251,8 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/polarismesh/polaris-go v1.1.0 h1:nFvn3q3XaVFhzF7pBnIySrN0ZZBwvbbYXC5r2DpsQN0= -github.com/polarismesh/polaris-go v1.1.0/go.mod h1:tquawfjEKp1W3ffNJQSzhfditjjoZ7tvhOCElN7Efzs= +github.com/polarismesh/polaris-go v1.2.0-beta.0.0.20220517041223-596a6a63b00f h1:IL2vXn/LjasI79p2X0/j8DZ+XnV5wgnjNpO1PQjn9Bc= +github.com/polarismesh/polaris-go v1.2.0-beta.0.0.20220517041223-596a6a63b00f/go.mod h1:xXTl4b5ybYkwvXZA+nc1HNyLK/bsHUg08R4ewTa9axc= github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo= github.com/prometheus/client_golang v1.7.1/go.mod h1:PY5Wy2awLA44sXw4AOSfFBetzPP4j5+D6mVACh+pe2M= @@ -314,12 +315,12 @@ go.opentelemetry.io/otel/trace v1.7.0/go.mod h1:fzLSB9nqR2eXzxPXb2JW9IKE+ScyXA48 go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI= go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw= go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= -go.uber.org/goleak v1.1.11-0.20210813005559-691160354723 h1:sHOAIxRGBp443oHZIPB+HsUGaksVCXVQENPxwTfQdH4= -go.uber.org/goleak v1.1.11-0.20210813005559-691160354723/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ= +go.uber.org/goleak v1.1.11 h1:wy28qYRKZgnJTxGxvye5/wgWr1EKjmUDGYox5mGlRlI= +go.uber.org/goleak v1.1.11/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ= go.uber.org/multierr v1.6.0 h1:y6IPFStTAIT5Ytl7/XYmHvzXQ7S3g/IeZW9hyZ5thw4= go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU= -go.uber.org/zap v1.19.1 h1:ue41HOKd1vGURxrmeKIgELGb3jPW9DMUDGtsinblHwI= -go.uber.org/zap v1.19.1/go.mod h1:j3DNczoxDZroyBnOT1L/Q79cfUMGZxlv/9dzN7SM1rI= +go.uber.org/zap v1.21.0 h1:WefMeulhovoZ2sYXz7st6K0sLj7bBhpiFaud4r4zST8= +go.uber.org/zap v1.21.0/go.mod h1:wjWOCqI0f2ZZrJF/UufIOkiC8ii6tm1iqIsLo76RfJw= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= @@ -394,9 +395,9 @@ golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96b golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk= golang.org/x/net v0.0.0-20210525063256-abc453219eb5/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/net v0.0.0-20210917221730-978cfadd31cf/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2 h1:CIJ76btIcR3eFI5EgSo6k1qKw9KJexJuRLI9G7Hp5wE= golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4 h1:HVyaeDAYux4pnY+D/SiwmLOR36ewZ4iGQIIrtnuCjFA= +golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -453,25 +454,31 @@ golang.org/x/sys v0.0.0-20200803210538-64077c9b5642/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210112080510-489259a85091/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423185535-09eb48e85fd7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220114195835-da31bd327af9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220412211240-33da011f77ad h1:ntjMns5wyP/fN65tdBD4g8J5w8n015+iIIs9rtjXkY0= golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6 h1:nonptSpoQ4vQjyraW20DXPAglgQfVnM9ZC6MmNLMR60= +golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.3.8-0.20211105212822-18b340fc7af2 h1:GLw7MR8AfAG2GmGcmVgObFOHXYypgGjnGno25RDwn3Y= golang.org/x/text v0.3.8-0.20211105212822-18b340fc7af2/go.mod h1:EFNZuWvGYxIRUEX+K8UmCFwYmZjqcrnq15ZuVldZkZ0= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= @@ -578,8 +585,9 @@ google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEY google.golang.org/genproto v0.0.0-20200618031413-b414f8b61790/go.mod h1:jDfRM7FcilCzHH/e9qn6dsT145K34l5v+OpcnNgKAAA= google.golang.org/genproto v0.0.0-20200729003335-053ba62fc06f/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= google.golang.org/genproto v0.0.0-20200804131852-c06518451d9c/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= -google.golang.org/genproto v0.0.0-20200825200019-8632dd797987 h1:PDIOdWxZ8eRizhKa1AAvY53xsvLB1cWorMjslvY3VA8= google.golang.org/genproto v0.0.0-20200825200019-8632dd797987/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20220504150022-98cd25cafc72 h1:iif0mpUetMBqcQPUoq+JnCcmzvfpp8wRx515va8wP1c= +google.golang.org/genproto v0.0.0-20220504150022-98cd25cafc72/go.mod h1:RAyBrSAP7Fh3Nc84ghnVLDPuV51xc9agzmm4Ph6i0Q4= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= @@ -594,8 +602,9 @@ google.golang.org/grpc v1.30.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM google.golang.org/grpc v1.31.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= google.golang.org/grpc v1.33.1/go.mod h1:fr5YgcSWrqhRRxogOsw7RzIpsmvOZ6IcH4kBYTpR3n0= google.golang.org/grpc v1.36.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU= -google.golang.org/grpc v1.42.0 h1:XT2/MFpuPFsEX2fWh3YQtHkZ+WYZFQRfaUgLZYj/p6A= -google.golang.org/grpc v1.42.0/go.mod h1:k+4IHHFw41K8+bbowsex27ge2rCb65oeWqe4jJ590SU= +google.golang.org/grpc v1.46.0/go.mod h1:vN9eftEi1UMyUsIF80+uQXhHjbXYbm0uXoFCACuMGWk= +google.golang.org/grpc v1.46.2 h1:u+MLGgVf7vRdjEYZ8wDFhAVNmhkbJ5hmrA1LMWK1CAQ= +google.golang.org/grpc v1.46.2/go.mod h1:vN9eftEi1UMyUsIF80+uQXhHjbXYbm0uXoFCACuMGWk= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= @@ -607,8 +616,10 @@ google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpAD google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4= google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= -google.golang.org/protobuf v1.26.0 h1:bxAC2xTBsZGibn2RTntX0oH50xLsqy1OxA9tTL3p/lk= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +google.golang.org/protobuf v1.28.0 h1:w43yiav+6bVFTBQFZX0r7ipe9JQ1QsbMgHwbBziscLw= +google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/contrib/registry/polaris/polaris.go b/contrib/registry/polaris/polaris.go index 59a251311f6..b01f9945a30 100644 --- a/contrib/registry/polaris/polaris.go +++ b/contrib/registry/polaris/polaris.go @@ -8,20 +8,12 @@ package polaris import ( - "context" - "fmt" - "strconv" - "strings" "time" "github.com/polarismesh/polaris-go" "github.com/polarismesh/polaris-go/pkg/config" - "github.com/polarismesh/polaris-go/pkg/model" - "github.com/gogf/gf/v2/errors/gerror" "github.com/gogf/gf/v2/net/gsvc" - "github.com/gogf/gf/v2/text/gstr" - "github.com/gogf/gf/v2/util/gconv" ) var ( @@ -29,9 +21,9 @@ var ( ) const ( - // instanceIDSeparator Instance id Separator. instanceIDSeparator = "-" - endpointDelimiter = ":" + metadataKeyKind = "kind" + metadataKeyVersion = "version" ) type options struct { @@ -169,55 +161,3 @@ func NewWithConfig(conf config.Configuration, opts ...Option) (r *Registry) { } return New(provider, consumer, opts...) } - -func instancesToServiceInstances(instances []model.Instance) []*gsvc.Service { - serviceInstances := make([]*gsvc.Service, 0, len(instances)) - for _, instance := range instances { - if instance.IsHealthy() { - serviceInstances = append(serviceInstances, instanceToServiceInstance(instance)) - } - } - return serviceInstances -} - -func instanceToServiceInstance(instance model.Instance) *gsvc.Service { - metadata := instance.GetMetadata() - names := strings.Split(instance.GetService(), instanceIDSeparator) - if names != nil && len(names) > 4 { - return &gsvc.Service{ - Prefix: names[0], - Deployment: names[1], - Namespace: names[2], - Name: names[3], - Version: metadata["version"], - Metadata: gconv.Map(metadata), - Endpoints: []string{fmt.Sprintf("%s:%d", instance.GetHost(), instance.GetPort())}, - Separator: instanceIDSeparator, - } - } - - return &gsvc.Service{ - Name: instance.GetService(), - Namespace: instance.GetNamespace(), - Version: metadata["version"], - Metadata: gconv.Map(metadata), - Endpoints: []string{fmt.Sprintf("%s:%d", instance.GetHost(), instance.GetPort())}, - Separator: instanceIDSeparator, - } -} - -// getHostAndPortFromEndpoint get host and port from endpoint. -func getHostAndPortFromEndpoint(ctx context.Context, endpoint string) (host string, port int, err error) { - endpoints := gstr.SplitAndTrim(endpoint, endpointDelimiter) - if len(endpoints) < 2 { - err = gerror.Newf(`invalid endpoint "%s"`, endpoint) - return - } - host = endpoints[0] - // port to int - if port, err = strconv.Atoi(endpoints[1]); err != nil { - err = gerror.Wrapf(err, `convert port string "%s" to int failed`, endpoints[1]) - return - } - return -} diff --git a/contrib/registry/polaris/polaris_discovery.go b/contrib/registry/polaris/polaris_discovery.go index 51c74ab9e15..e6bd21c0766 100644 --- a/contrib/registry/polaris/polaris_discovery.go +++ b/contrib/registry/polaris/polaris_discovery.go @@ -8,20 +8,28 @@ package polaris import ( "context" + "fmt" + "strings" "github.com/polarismesh/polaris-go" "github.com/polarismesh/polaris-go/pkg/model" "github.com/gogf/gf/v2/net/gsvc" + "github.com/gogf/gf/v2/util/gconv" ) // Search returns the service instances in memory according to the service name. -func (r *Registry) Search(ctx context.Context, in gsvc.SearchInput) ([]*gsvc.Service, error) { - in.Separator = instanceIDSeparator +func (r *Registry) Search(ctx context.Context, in gsvc.SearchInput) ([]gsvc.Service, error) { + if in.Prefix == "" && in.Name != "" { + service := &Service{ + Service: gsvc.NewServiceWithName(in.Name), + } + in.Prefix = service.GetPrefix() + } // get all instances instancesResponse, err := r.consumer.GetAllInstances(&polaris.GetAllInstancesRequest{ GetAllInstancesRequest: model.GetAllInstancesRequest{ - Service: in.Key(), + Service: in.Prefix, Namespace: r.opt.Namespace, Timeout: &r.opt.Timeout, RetryCount: &r.opt.RetryCount, @@ -38,3 +46,44 @@ func (r *Registry) Search(ctx context.Context, in gsvc.SearchInput) ([]*gsvc.Ser func (r *Registry) Watch(ctx context.Context, serviceName string) (gsvc.Watcher, error) { return newWatcher(ctx, r.opt.Namespace, serviceName, r.consumer) } + +func instancesToServiceInstances(instances []model.Instance) []gsvc.Service { + serviceInstances := make([]gsvc.Service, 0, len(instances)) + for _, instance := range instances { + if instance.IsHealthy() { + serviceInstances = append(serviceInstances, instanceToServiceInstance(instance)) + } + } + return serviceInstances +} + +func instanceToServiceInstance(instance model.Instance) gsvc.Service { + var ( + s *gsvc.LocalService + metadata = instance.GetMetadata() + names = strings.Split(instance.GetService(), instanceIDSeparator) + endpoints = gsvc.NewEndpoints(fmt.Sprintf("%s:%d", instance.GetHost(), instance.GetPort())) + ) + if names != nil && len(names) > 4 { + s = &gsvc.LocalService{ + Head: names[0], + Deployment: names[1], + Namespace: names[2], + Name: names[3], + Version: metadata[metadataKeyVersion], + Metadata: gconv.Map(metadata), + Endpoints: endpoints, + } + } else { + s = &gsvc.LocalService{ + Name: instance.GetService(), + Namespace: instance.GetNamespace(), + Version: metadata[metadataKeyVersion], + Metadata: gconv.Map(metadata), + Endpoints: endpoints, + } + } + return &Service{ + Service: s, + } +} diff --git a/contrib/registry/polaris/polaris_registrar.go b/contrib/registry/polaris/polaris_registrar.go index 8f0424f2c84..90ce34bf19d 100644 --- a/contrib/registry/polaris/polaris_registrar.go +++ b/contrib/registry/polaris/polaris_registrar.go @@ -20,47 +20,48 @@ import ( ) // Register the registration. -func (r *Registry) Register(ctx context.Context, serviceInstance *gsvc.Service) error { - ids := make([]string, 0, len(serviceInstance.Endpoints)) - // set separator - serviceInstance.Separator = instanceIDSeparator - for _, endpoint := range serviceInstance.Endpoints { - host, portNum, err := getHostAndPortFromEndpoint(ctx, endpoint) - if err != nil { - return err - } - +func (r *Registry) Register(ctx context.Context, service gsvc.Service) (gsvc.Service, error) { + // Replace input service to custom service type. + service = &Service{ + Service: service, + } + // Register logic. + var ( + ids = make([]string, 0, len(service.GetEndpoints())) + serviceVersion = service.GetVersion() + ) + for _, endpoint := range service.GetEndpoints() { // medata var rmd map[string]interface{} - if serviceInstance.Metadata == nil { + if service.GetMetadata().IsEmpty() { rmd = map[string]interface{}{ - "kind": gsvc.DefaultProtocol, - "version": serviceInstance.Version, + metadataKeyKind: gsvc.DefaultProtocol, + metadataKeyVersion: service.GetVersion(), } } else { - rmd = make(map[string]interface{}, len(serviceInstance.Metadata)+2) - rmd["kind"] = gsvc.DefaultProtocol - if protocol, ok := serviceInstance.Metadata[gsvc.MDProtocol]; ok { - rmd["kind"] = gconv.String(protocol) + rmd = make(map[string]interface{}, len(service.GetMetadata())+2) + rmd[metadataKeyKind] = gsvc.DefaultProtocol + if protocol, ok := service.GetMetadata()[gsvc.MDProtocol]; ok { + rmd[metadataKeyKind] = gconv.String(protocol) } - rmd["version"] = serviceInstance.Version - for k, v := range serviceInstance.Metadata { + rmd[metadataKeyVersion] = serviceVersion + for k, v := range service.GetMetadata() { rmd[k] = v } } // Register - service, err := r.provider.Register( + registeredService, err := r.provider.Register( &polaris.InstanceRegisterRequest{ InstanceRegisterRequest: model.InstanceRegisterRequest{ - Service: serviceInstance.KeyWithoutEndpoints(), + Service: service.GetPrefix(), ServiceToken: r.opt.ServiceToken, Namespace: r.opt.Namespace, - Host: host, - Port: portNum, + Host: endpoint.Host(), + Port: endpoint.Port(), Protocol: r.opt.Protocol, Weight: &r.opt.Weight, Priority: &r.opt.Priority, - Version: &serviceInstance.Version, + Version: &serviceVersion, Metadata: gconv.MapStrStr(rmd), Healthy: &r.opt.Healthy, Isolate: &r.opt.Isolate, @@ -70,69 +71,36 @@ func (r *Registry) Register(ctx context.Context, serviceInstance *gsvc.Service) }, }) if err != nil { - return err + return nil, err } - instanceID := service.InstanceID - if r.opt.Heartbeat { - // start heartbeat report - go func() { - ticker := time.NewTicker(time.Second * time.Duration(r.opt.TTL)) - defer ticker.Stop() - - for { - select { - case <-ticker.C: - err = r.provider.Heartbeat(&polaris.InstanceHeartbeatRequest{ - InstanceHeartbeatRequest: model.InstanceHeartbeatRequest{ - Service: serviceInstance.KeyWithoutEndpoints(), - Namespace: r.opt.Namespace, - Host: host, - Port: portNum, - ServiceToken: r.opt.ServiceToken, - InstanceID: instanceID, - Timeout: &r.opt.Timeout, - RetryCount: &r.opt.RetryCount, - }, - }) - if err != nil { - g.Log().Error(ctx, err.Error()) - continue - } - case <-r.c: - g.Log().Debug(ctx, "stop heartbeat") - return - } - } - }() + r.doHeartBeat(ctx, registeredService.InstanceID, service, endpoint) } - ids = append(ids, instanceID) + ids = append(ids, registeredService.InstanceID) } // need to set InstanceID for Deregister - serviceInstance.ID = gstr.Join(ids, instanceIDSeparator) - return nil + service.(*Service).ID = gstr.Join(ids, instanceIDSeparator) + return service, nil } // Deregister the registration. -func (r *Registry) Deregister(ctx context.Context, serviceInstance *gsvc.Service) error { +func (r *Registry) Deregister(ctx context.Context, service gsvc.Service) error { r.c <- struct{}{} - split := gstr.Split(serviceInstance.ID, instanceIDSeparator) - serviceInstance.Separator = instanceIDSeparator - for i, endpoint := range serviceInstance.Endpoints { - host, portNum, err := getHostAndPortFromEndpoint(ctx, endpoint) - if err != nil { - return err - } + var ( + err error + split = gstr.Split(service.(*Service).ID, instanceIDSeparator) + ) + for i, endpoint := range service.GetEndpoints() { // Deregister err = r.provider.Deregister( &polaris.InstanceDeRegisterRequest{ InstanceDeRegisterRequest: model.InstanceDeRegisterRequest{ - Service: serviceInstance.KeyWithoutEndpoints(), + Service: service.GetPrefix(), ServiceToken: r.opt.ServiceToken, Namespace: r.opt.Namespace, InstanceID: split[i], - Host: host, - Port: portNum, + Host: endpoint.Host(), + Port: endpoint.Port(), Timeout: &r.opt.Timeout, RetryCount: &r.opt.RetryCount, }, @@ -144,3 +112,36 @@ func (r *Registry) Deregister(ctx context.Context, serviceInstance *gsvc.Service } return nil } + +func (r *Registry) doHeartBeat(ctx context.Context, instanceID string, service gsvc.Service, endpoint gsvc.Endpoint) { + go func() { + ticker := time.NewTicker(time.Second * time.Duration(r.opt.TTL)) + defer ticker.Stop() + + for { + select { + case <-ticker.C: + err := r.provider.Heartbeat(&polaris.InstanceHeartbeatRequest{ + InstanceHeartbeatRequest: model.InstanceHeartbeatRequest{ + Service: service.GetPrefix(), + Namespace: r.opt.Namespace, + Host: endpoint.Host(), + Port: endpoint.Port(), + ServiceToken: r.opt.ServiceToken, + InstanceID: instanceID, + Timeout: &r.opt.Timeout, + RetryCount: &r.opt.RetryCount, + }, + }) + if err != nil { + g.Log().Error(ctx, err.Error()) + continue + } + g.Log().Debug(ctx, "heartbeat success") + case <-r.c: + g.Log().Debug(ctx, "stop heartbeat") + return + } + } + }() +} diff --git a/contrib/registry/polaris/polaris_service.go b/contrib/registry/polaris/polaris_service.go new file mode 100644 index 00000000000..63307fd8076 --- /dev/null +++ b/contrib/registry/polaris/polaris_service.go @@ -0,0 +1,28 @@ +package polaris + +import ( + "github.com/gogf/gf/v2/net/gsvc" + "github.com/gogf/gf/v2/text/gstr" +) + +// Service for wrapping gsvc.Server and extends extra attributes for polaris purpose. +type Service struct { + gsvc.Service // Common service object. + ID string // ID is the unique instance ID as registered, for some registrar server. +} + +// GetKey overwrites the GetKey function of gsvc.Service for replacing separator string. +func (s *Service) GetKey() string { + key := s.Service.GetKey() + key = gstr.Replace(key, gsvc.DefaultSeparator, instanceIDSeparator) + key = gstr.TrimLeft(key, instanceIDSeparator) + return key +} + +// GetPrefix overwrites the GetPrefix function of gsvc.Service for replacing separator string. +func (s *Service) GetPrefix() string { + prefix := s.Service.GetPrefix() + prefix = gstr.Replace(prefix, gsvc.DefaultSeparator, instanceIDSeparator) + prefix = gstr.TrimLeft(prefix, instanceIDSeparator) + return prefix +} diff --git a/contrib/registry/polaris/polaris_watcher.go b/contrib/registry/polaris/polaris_watcher.go index 00d040c8dc6..bf2ae55741f 100644 --- a/contrib/registry/polaris/polaris_watcher.go +++ b/contrib/registry/polaris/polaris_watcher.go @@ -22,7 +22,7 @@ type Watcher struct { Ctx context.Context Cancel context.CancelFunc Channel <-chan model.SubScribeEvent - ServiceInstances []*gsvc.Service + ServiceInstances []gsvc.Service } func newWatcher(ctx context.Context, namespace string, serviceName string, consumer polaris.ConsumerAPI) (*Watcher, error) { @@ -52,7 +52,7 @@ func newWatcher(ctx context.Context, namespace string, serviceName string, consu // 1.the first time to watch and the service instance list is not empty. // 2.any service instance changes found. // if the above two conditions are not met, it will block until the context deadline is exceeded or canceled -func (w *Watcher) Proceed() ([]*gsvc.Service, error) { +func (w *Watcher) Proceed() ([]gsvc.Service, error) { select { case <-w.Ctx.Done(): return nil, w.Ctx.Err() @@ -67,7 +67,7 @@ func (w *Watcher) Proceed() ([]*gsvc.Service, error) { if instanceEvent.DeleteEvent != nil { for _, instance := range instanceEvent.DeleteEvent.Instances { for i, serviceInstance := range w.ServiceInstances { - if serviceInstance.ID == instance.GetId() { + if serviceInstance.(*Service).ID == instance.GetId() { // remove equal if len(w.ServiceInstances) <= 1 { w.ServiceInstances = w.ServiceInstances[0:0] @@ -82,7 +82,7 @@ func (w *Watcher) Proceed() ([]*gsvc.Service, error) { if instanceEvent.UpdateEvent != nil { for i, serviceInstance := range w.ServiceInstances { for _, update := range instanceEvent.UpdateEvent.UpdateList { - if serviceInstance.ID == update.Before.GetId() { + if serviceInstance.(*Service).ID == update.Before.GetId() { w.ServiceInstances[i] = instanceToServiceInstance(update.After) } } @@ -90,7 +90,10 @@ func (w *Watcher) Proceed() ([]*gsvc.Service, error) { } // handle AddEvent if instanceEvent.AddEvent != nil { - w.ServiceInstances = append(w.ServiceInstances, instancesToServiceInstances(instanceEvent.AddEvent.Instances)...) + w.ServiceInstances = append( + w.ServiceInstances, + instancesToServiceInstances(instanceEvent.AddEvent.Instances)..., + ) } } } diff --git a/contrib/registry/polaris/polaris_test.go b/contrib/registry/polaris/polaris_z_test.go similarity index 71% rename from contrib/registry/polaris/polaris_test.go rename to contrib/registry/polaris/polaris_z_test.go index 10e119a1e25..12e857055ce 100644 --- a/contrib/registry/polaris/polaris_test.go +++ b/contrib/registry/polaris/polaris_z_test.go @@ -30,20 +30,19 @@ func TestRegistry(t *testing.T) { ctx := context.Background() - svc := &gsvc.Service{ + svc := &gsvc.LocalService{ Name: "goframe-provider-0-tcp", Version: "test", Metadata: map[string]interface{}{"app": "goframe", gsvc.MDProtocol: "tcp"}, - Endpoints: []string{"127.0.0.1:9000"}, - Separator: instanceIDSeparator, + Endpoints: gsvc.NewEndpoints("127.0.0.1:9000"), } - err := r.Register(ctx, svc) + s, err := r.Register(ctx, svc) if err != nil { t.Fatal(err) } - err = r.Deregister(ctx, svc) + err = r.Deregister(ctx, s) if err != nil { t.Fatal(err) } @@ -59,54 +58,51 @@ func TestRegistryMany(t *testing.T) { WithTTL(100), ) - svc := &gsvc.Service{ + svc := &gsvc.LocalService{ Name: "goframe-provider-1-tcp", Version: "test", Metadata: map[string]interface{}{"app": "goframe", gsvc.MDProtocol: "tcp"}, - Endpoints: []string{"127.0.0.1:9000"}, - Separator: instanceIDSeparator, + Endpoints: gsvc.NewEndpoints("127.0.0.1:9000"), } - svc1 := &gsvc.Service{ + svc1 := &gsvc.LocalService{ Name: "goframe-provider-2-tcp", Version: "test", Metadata: map[string]interface{}{"app": "goframe", gsvc.MDProtocol: "tcp"}, - Endpoints: []string{"127.0.0.1:9001"}, - Separator: instanceIDSeparator, + Endpoints: gsvc.NewEndpoints("127.0.0.1:9001"), } - svc2 := &gsvc.Service{ + svc2 := &gsvc.LocalService{ Name: "goframe-provider-3-tcp", Version: "test", Metadata: map[string]interface{}{"app": "goframe", gsvc.MDProtocol: "tcp"}, - Endpoints: []string{"127.0.0.1:9002"}, - Separator: instanceIDSeparator, + Endpoints: gsvc.NewEndpoints("127.0.0.1:9002"), } - err := r.Register(context.Background(), svc) + s0, err := r.Register(context.Background(), svc) if err != nil { t.Fatal(err) } - err = r.Register(context.Background(), svc1) + s1, err := r.Register(context.Background(), svc1) if err != nil { t.Fatal(err) } - err = r.Register(context.Background(), svc2) + s2, err := r.Register(context.Background(), svc2) if err != nil { t.Fatal(err) } - err = r.Deregister(context.Background(), svc) + err = r.Deregister(context.Background(), s0) if err != nil { t.Fatal(err) } - err = r.Deregister(context.Background(), svc1) + err = r.Deregister(context.Background(), s1) if err != nil { t.Fatal(err) } - err = r.Deregister(context.Background(), svc2) + err = r.Deregister(context.Background(), s2) if err != nil { t.Fatal(err) } @@ -124,26 +120,23 @@ func TestGetService(t *testing.T) { ctx := context.Background() - svc := &gsvc.Service{ + svc := &gsvc.LocalService{ Name: "goframe-provider-4-tcp", Version: "test", Metadata: map[string]interface{}{"app": "goframe", gsvc.MDProtocol: "tcp"}, - Endpoints: []string{"127.0.0.1:9000"}, - Separator: instanceIDSeparator, + Endpoints: gsvc.NewEndpoints("127.0.0.1:9000"), } - err := r.Register(ctx, svc) + s, err := r.Register(ctx, svc) if err != nil { t.Fatal(err) } time.Sleep(time.Second * 1) serviceInstances, err := r.Search(ctx, gsvc.SearchInput{ - Prefix: svc.Prefix, - Deployment: svc.Deployment, - Namespace: svc.Namespace, - Name: svc.Name, - Version: svc.Version, - Metadata: svc.Metadata, + Prefix: s.GetPrefix(), + Name: svc.Name, + Version: svc.Version, + Metadata: svc.Metadata, }) if err != nil { t.Fatal(err) @@ -152,7 +145,7 @@ func TestGetService(t *testing.T) { g.Log().Info(ctx, instance) } - err = r.Deregister(ctx, svc) + err = r.Deregister(ctx, s) if err != nil { t.Fatal(err) } @@ -170,20 +163,23 @@ func TestWatch(t *testing.T) { ctx := gctx.New() - svc := &gsvc.Service{ + svc := &gsvc.LocalService{ Name: "goframe-provider-4-tcp", Version: "test", Metadata: map[string]interface{}{"app": "goframe", gsvc.MDProtocol: "tcp"}, - Endpoints: []string{"127.0.0.1:9000"}, - Separator: instanceIDSeparator, + Endpoints: gsvc.NewEndpoints("127.0.0.1:9000"), } - watch, err := r.Watch(context.Background(), svc.KeyWithoutEndpoints()) + s := &Service{ + Service: svc, + } + + watch, err := r.Watch(context.Background(), s.GetPrefix()) if err != nil { t.Fatal(err) } - err = r.Register(context.Background(), svc) + s1, err := r.Register(context.Background(), svc) if err != nil { t.Fatal(err) } @@ -197,10 +193,10 @@ func TestWatch(t *testing.T) { } for _, instance := range next { // it will output one instance - g.Log().Info(ctx, instance) + g.Log().Info(ctx, "Register Proceed service: ", instance) } - err = r.Deregister(context.Background(), svc) + err = r.Deregister(context.Background(), s1) if err != nil { t.Fatal(err) } @@ -212,7 +208,7 @@ func TestWatch(t *testing.T) { } for _, instance := range next { // it will output nothing - g.Log().Info(ctx, instance) + g.Log().Info(ctx, "Deregister Proceed service: ", instance) } err = watch.Close() diff --git a/contrib/trace/jaeger/go.mod b/contrib/trace/jaeger/go.mod index 75ab1581ccf..921eb884d53 100644 --- a/contrib/trace/jaeger/go.mod +++ b/contrib/trace/jaeger/go.mod @@ -5,7 +5,7 @@ go 1.15 require ( github.com/gogf/gf/v2 v2.0.0 go.opentelemetry.io/otel v1.7.0 - go.opentelemetry.io/otel/exporters/jaeger v1.3.0 + go.opentelemetry.io/otel/exporters/jaeger v1.7.0 go.opentelemetry.io/otel/sdk v1.7.0 ) diff --git a/contrib/trace/jaeger/go.sum b/contrib/trace/jaeger/go.sum index 719f4d31a82..ed14d898384 100644 --- a/contrib/trace/jaeger/go.sum +++ b/contrib/trace/jaeger/go.sum @@ -18,12 +18,9 @@ github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMo github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= github.com/fsnotify/fsnotify v1.5.4 h1:jRbGcIw6P2Meqdwuo0H1p6JVLbL5DHKAKlYndzMwVZI= github.com/fsnotify/fsnotify v1.5.4/go.mod h1:OVB6XrOHzAwXMpEM7uPOzcehqUV2UqJxmVXmkdnm1bU= -github.com/go-logr/logr v1.2.0/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= -github.com/go-logr/logr v1.2.1/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= github.com/go-logr/logr v1.2.3 h1:2DntVwHkVopvECVRSlL5PSo9eG+cAkDCuckLubN+rq0= github.com/go-logr/logr v1.2.3/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= -github.com/go-logr/stdr v1.2.0/go.mod h1:YkVgnZu1ZjjL7xTxrfm/LLZBfkhTqSR1ydtm6jTKKwI= github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= github.com/go-redis/redis/v8 v8.11.5 h1:AcZZR7igkdvfVmQTPnu9WE37LRrO/YrBH5zWyjDC0oI= @@ -43,7 +40,6 @@ github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.7 h1:81/ik6ipDQS2aGcBfIN5dHDB36BwrStyeAQquSYCV4o= github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE= github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= @@ -84,20 +80,16 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= -github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.4.0/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= -go.opentelemetry.io/otel v1.3.0/go.mod h1:PWIKzi6JCp7sM0k9yZ43VX+T345uNbAkDKwHVjb2PTs= go.opentelemetry.io/otel v1.7.0 h1:Z2lA3Tdch0iDcrhJXDIlC94XE+bxok1F9B+4Lz/lGsM= go.opentelemetry.io/otel v1.7.0/go.mod h1:5BdUoMIz5WEs0vt0CUEMtSSaTSHBBVwrhnz7+nrD5xk= -go.opentelemetry.io/otel/exporters/jaeger v1.3.0 h1:HfydzioALdtcB26H5WHc4K47iTETJCdloL7VN579/L0= -go.opentelemetry.io/otel/exporters/jaeger v1.3.0/go.mod h1:KoYHi1BtkUPncGSRtCe/eh1ijsnePhSkxwzz07vU0Fc= -go.opentelemetry.io/otel/sdk v1.3.0/go.mod h1:rIo4suHNhQwBIPg9axF8V9CA72Wz2mKF1teNrup8yzs= +go.opentelemetry.io/otel/exporters/jaeger v1.7.0 h1:wXgjiRldljksZkZrldGVe6XrG9u3kYDyQmkZwmm5dI0= +go.opentelemetry.io/otel/exporters/jaeger v1.7.0/go.mod h1:PwQAOqBgqbLQRKlj466DuD2qyMjbtcPpfPfj+AqbSBs= go.opentelemetry.io/otel/sdk v1.7.0 h1:4OmStpcKVOfvDOgCt7UriAPtKolwIhxpnSNI/yK+1B0= go.opentelemetry.io/otel/sdk v1.7.0/go.mod h1:uTEOTwaqIVuTGiJN7ii13Ibp75wJmYUDe374q6cZwUU= -go.opentelemetry.io/otel/trace v1.3.0/go.mod h1:c/VDhno8888bvQYmbYLqe41/Ldmr/KKunbvWM4/fEjk= go.opentelemetry.io/otel/trace v1.7.0 h1:O37Iogk1lEkMRXewVtZ1BBTVn5JEp8GrJvP92bJqC6o= go.opentelemetry.io/otel/trace v1.7.0/go.mod h1:fzLSB9nqR2eXzxPXb2JW9IKE+ScyXA48yyE4TNvoHqU= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= diff --git a/example/go.mod b/example/go.mod index 2e0a92f625f..86bae38a78e 100644 --- a/example/go.mod +++ b/example/go.mod @@ -3,18 +3,20 @@ module github.com/gogf/gf/example go 1.15 require ( - github.com/gogf/gf/contrib/registry/etcd/v2 v2.0.0-rc2 + github.com/gogf/gf/contrib/drivers/mysql/v2 v2.1.0-rc3 + github.com/gogf/gf/contrib/registry/etcd/v2 v2.1.0-rc3.0.20220523034830-510fa3faf03f github.com/gogf/gf/contrib/registry/polaris/v2 v2.0.0-rc2 github.com/gogf/gf/contrib/trace/jaeger/v2 v2.0.0-rc2 - github.com/gogf/gf/v2 v2.0.0 - github.com/gogf/katyusha v0.3.1-0.20220128101623-e25b27a99b29 + github.com/gogf/gf/v2 v2.1.0-rc3.0.20220523034830-510fa3faf03f + github.com/gogf/katyusha v0.4.0 github.com/gogo/protobuf v1.3.2 github.com/golang/protobuf v1.5.2 - github.com/polarismesh/polaris-go v1.1.0 - google.golang.org/grpc v1.46.0 + github.com/polarismesh/polaris-go v1.2.0-beta.0.0.20220517041223-596a6a63b00f + google.golang.org/grpc v1.46.2 ) replace ( + github.com/gogf/gf/contrib/drivers/mysql/v2 => ../contrib/drivers/mysql/ github.com/gogf/gf/contrib/registry/etcd/v2 => ../contrib/registry/etcd/ github.com/gogf/gf/contrib/registry/polaris/v2 => ../contrib/registry/polaris/ github.com/gogf/gf/contrib/trace/jaeger/v2 => ../contrib/trace/jaeger/ diff --git a/example/go.sum b/example/go.sum index 6df3bcbb55c..476035be699 100644 --- a/example/go.sum +++ b/example/go.sum @@ -32,11 +32,9 @@ cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RX cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= -github.com/BurntSushi/toml v1.0.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= github.com/BurntSushi/toml v1.1.0 h1:ksErzDEI1khOiGPgpwuI7x2ebx/uXQNw7xJpn9Eq1+I= github.com/BurntSushi/toml v1.1.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= -github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= github.com/agiledragon/gomonkey v2.0.2+incompatible h1:eXKi9/piiC3cjJD1658mEE2o3NjkJ5vDLgYjCQu0Xlw= github.com/agiledragon/gomonkey v2.0.2+incompatible/go.mod h1:2NGfXu1a80LLr2cmWXGBDaHEjb1idR6+FVlX5T3D9hw= github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= @@ -52,8 +50,6 @@ github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+Ce github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= -github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko= -github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/cespare/xxhash/v2 v2.1.2 h1:YRXhKfTDauu4ajMg1TPgFO5jnlC2HCbmLXMcTG5cbYE= github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= @@ -66,8 +62,6 @@ github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDk github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= github.com/cncf/udpa/go v0.0.0-20210930031921-04548b0d99d4/go.mod h1:6pvJx4me5XPnfI9Z40ddWsdw2W/uZgQLFXToKeRcDiI= -github.com/cncf/xds/go v0.0.0-20210312221358-fbca930ec8ed/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= -github.com/cncf/xds/go v0.0.0-20210805033703-aa0b78936158/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= github.com/cncf/xds/go v0.0.0-20210922020428-25de7278fc84/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= github.com/cncf/xds/go v0.0.0-20211001041855-01bcc9b48dfe/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= github.com/cncf/xds/go v0.0.0-20211011173535-cb28da3451f1/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= @@ -86,8 +80,6 @@ github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.m github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk= github.com/envoyproxy/go-control-plane v0.9.9-0.20210217033140-668b12f5399d/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk= -github.com/envoyproxy/go-control-plane v0.9.9-0.20210512163311-63b5d3c536b0/go.mod h1:hliV/p42l8fGbc6Y9bQ70uLwIvmJyVE5k4iMKlh8wCQ= -github.com/envoyproxy/go-control-plane v0.9.10-0.20210907150352-cf90f659a021/go.mod h1:AFq3mo9L8Lqqiid3OhADV3RfLJnjiw63cSpi+fDTRC0= github.com/envoyproxy/go-control-plane v0.10.2-0.20220325020618-49ff273808a1/go.mod h1:KJwIaB5Mv44NWtYuAOFCVOjcI94vtpEz2JU/D2v6IjE= github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w= @@ -107,23 +99,20 @@ github.com/go-kit/log v0.1.0/go.mod h1:zbhenjAZHb184qTLMA9ZjW7ThYL0H2mk7Q6pNt4vb github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A= -github.com/go-logr/logr v1.2.0/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= -github.com/go-logr/logr v1.2.1/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= github.com/go-logr/logr v1.2.3 h1:2DntVwHkVopvECVRSlL5PSo9eG+cAkDCuckLubN+rq0= github.com/go-logr/logr v1.2.3/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= -github.com/go-logr/stdr v1.2.0/go.mod h1:YkVgnZu1ZjjL7xTxrfm/LLZBfkhTqSR1ydtm6jTKKwI= github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= github.com/go-redis/redis/v8 v8.11.5 h1:AcZZR7igkdvfVmQTPnu9WE37LRrO/YrBH5zWyjDC0oI= github.com/go-redis/redis/v8 v8.11.5/go.mod h1:gREzHqY1hg6oD9ngVRbLStwAWKhA0FEgq8Jd4h5lpwo= +github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE= +github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE= github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= -github.com/gogf/katyusha v0.3.0/go.mod h1:AknlfKGS7HjZfLiz74Nd/eL2uq7bg+9aucZgfvXw8vQ= -github.com/gogf/katyusha v0.3.1-0.20220128101623-e25b27a99b29 h1:s28bNu6QekQG3XFFB3G6YV3AGvQz8Uj4lBu/WXIeF28= -github.com/gogf/katyusha v0.3.1-0.20220128101623-e25b27a99b29/go.mod h1:vb72az4+b2cn1gHfJ5n2sESbfQ0jM7iO55DNt2RQ7mc= -github.com/gogf/katyusha/example v0.0.0-20220128090236-a633147589ae/go.mod h1:DSPRXlHUWIRpXa2v8eKpVh0eGwdCiqXBng3wnn8B62g= +github.com/gogf/katyusha v0.4.0 h1:mQVfXHhzC+UQf11Q8HAk9IOhQZ1VMXqGUqezyywZUOs= +github.com/gogf/katyusha v0.4.0/go.mod h1:nqsIWBsImnq9+OLlfB6iNef6ZLRyR2L1Bnk9h2aZvKs= github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= @@ -233,15 +222,13 @@ github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/magiconair/properties v1.8.6 h1:5ibWZ6iY0NctNGWo87LalDlEZ6R41TqbbDamhfG/Qzo= github.com/magiconair/properties v1.8.6/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60= +github.com/mattn/go-colorable v0.1.9 h1:sqDoxXbdeALODt0DAeJCVp38ps9ZogZEAXjus69YV3U= github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= -github.com/mattn/go-colorable v0.1.12 h1:jF+Du6AlPIjs2BiUiQlKOX0rt3SujHxPnksPKZbaA40= -github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4= github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y= github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= +github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0= github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= -github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU= -github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU= github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= @@ -279,12 +266,13 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/polarismesh/polaris-go v1.1.0 h1:nFvn3q3XaVFhzF7pBnIySrN0ZZBwvbbYXC5r2DpsQN0= -github.com/polarismesh/polaris-go v1.1.0/go.mod h1:tquawfjEKp1W3ffNJQSzhfditjjoZ7tvhOCElN7Efzs= +github.com/polarismesh/polaris-go v1.2.0-beta.0.0.20220517041223-596a6a63b00f h1:IL2vXn/LjasI79p2X0/j8DZ+XnV5wgnjNpO1PQjn9Bc= +github.com/polarismesh/polaris-go v1.2.0-beta.0.0.20220517041223-596a6a63b00f/go.mod h1:xXTl4b5ybYkwvXZA+nc1HNyLK/bsHUg08R4ewTa9axc= github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo= github.com/prometheus/client_golang v1.7.1/go.mod h1:PY5Wy2awLA44sXw4AOSfFBetzPP4j5+D6mVACh+pe2M= github.com/prometheus/client_golang v1.11.0/go.mod h1:Z6t4BnS23TR94PD6BsDNk8yVqroYurpAkEiz0P2BEV0= +github.com/prometheus/client_golang v1.11.1/go.mod h1:Z6t4BnS23TR94PD6BsDNk8yVqroYurpAkEiz0P2BEV0= github.com/prometheus/client_golang v1.12.1 h1:ZiaPsmm9uiBeaSMRznKsCDNtPCS0T3JVDGF+06gjBzk= github.com/prometheus/client_golang v1.12.1/go.mod h1:3Z9XVyYiZYEO+YQWt3RD2R3jrbd179Rt297l4aS6nDY= github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= @@ -303,8 +291,6 @@ github.com/prometheus/procfs v0.1.3/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4O github.com/prometheus/procfs v0.6.0/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA= github.com/prometheus/procfs v0.7.3 h1:4jVXhlkAyzOScmCkXBTOLRLTz8EeU+eyjrwB/EPq0VU= github.com/prometheus/procfs v0.7.3/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA= -github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY= -github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= @@ -314,7 +300,6 @@ github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykE github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s= github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= -github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI= github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= @@ -333,42 +318,35 @@ github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9de github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= github.com/yuin/goldmark v1.4.0/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= -go.etcd.io/etcd/api/v3 v3.5.1 h1:v28cktvBq+7vGyJXF8G+rWJmj+1XUmMtqcLnH8hDocM= -go.etcd.io/etcd/api/v3 v3.5.1/go.mod h1:cbVKeC6lCfl7j/8jBhAK6aIYO9XOjdptoxU/nLQcPvs= -go.etcd.io/etcd/client/pkg/v3 v3.5.1 h1:XIQcHCFSG53bJETYeRJtIxdLv2EWRGxcfzR8lSnTH4E= -go.etcd.io/etcd/client/pkg/v3 v3.5.1/go.mod h1:IJHfcCEKxYu1Os13ZdwCwIUTUVGYTSAM3YSwc9/Ac1g= -go.etcd.io/etcd/client/v3 v3.5.1 h1:oImGuV5LGKjCqXdjkMHCyWa5OO1gYKCnC/1sgdfj1Uk= -go.etcd.io/etcd/client/v3 v3.5.1/go.mod h1:OnjH4M8OnAotwaB2l9bVgZzRFKru7/ZMoS46OtKyd3Q= +go.etcd.io/etcd/api/v3 v3.5.4 h1:OHVyt3TopwtUQ2GKdd5wu3PmmipR4FTwCqoEjSyRdIc= +go.etcd.io/etcd/api/v3 v3.5.4/go.mod h1:5GB2vv4A4AOn3yk7MftYGHkUfGtDHnEraIjym4dYz5A= +go.etcd.io/etcd/client/pkg/v3 v3.5.4 h1:lrneYvz923dvC14R54XcA7FXoZ3mlGZAgmwhfm7HqOg= +go.etcd.io/etcd/client/pkg/v3 v3.5.4/go.mod h1:IJHfcCEKxYu1Os13ZdwCwIUTUVGYTSAM3YSwc9/Ac1g= +go.etcd.io/etcd/client/v3 v3.5.4 h1:p83BUL3tAYS0OT/r0qglgc3M1JjhM0diV8DSWAhVXv4= +go.etcd.io/etcd/client/v3 v3.5.4/go.mod h1:ZaRkVgBZC+L+dLCjTcF1hRXpgZXQPOvnA/Ak/gq3kiY= go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.opencensus.io v0.22.3/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= -go.opentelemetry.io/otel v1.3.0/go.mod h1:PWIKzi6JCp7sM0k9yZ43VX+T345uNbAkDKwHVjb2PTs= go.opentelemetry.io/otel v1.7.0 h1:Z2lA3Tdch0iDcrhJXDIlC94XE+bxok1F9B+4Lz/lGsM= go.opentelemetry.io/otel v1.7.0/go.mod h1:5BdUoMIz5WEs0vt0CUEMtSSaTSHBBVwrhnz7+nrD5xk= -go.opentelemetry.io/otel/exporters/jaeger v1.3.0 h1:HfydzioALdtcB26H5WHc4K47iTETJCdloL7VN579/L0= -go.opentelemetry.io/otel/exporters/jaeger v1.3.0/go.mod h1:KoYHi1BtkUPncGSRtCe/eh1ijsnePhSkxwzz07vU0Fc= -go.opentelemetry.io/otel/sdk v1.3.0/go.mod h1:rIo4suHNhQwBIPg9axF8V9CA72Wz2mKF1teNrup8yzs= +go.opentelemetry.io/otel/exporters/jaeger v1.7.0 h1:wXgjiRldljksZkZrldGVe6XrG9u3kYDyQmkZwmm5dI0= +go.opentelemetry.io/otel/exporters/jaeger v1.7.0/go.mod h1:PwQAOqBgqbLQRKlj466DuD2qyMjbtcPpfPfj+AqbSBs= go.opentelemetry.io/otel/sdk v1.7.0 h1:4OmStpcKVOfvDOgCt7UriAPtKolwIhxpnSNI/yK+1B0= go.opentelemetry.io/otel/sdk v1.7.0/go.mod h1:uTEOTwaqIVuTGiJN7ii13Ibp75wJmYUDe374q6cZwUU= -go.opentelemetry.io/otel/trace v1.3.0/go.mod h1:c/VDhno8888bvQYmbYLqe41/Ldmr/KKunbvWM4/fEjk= go.opentelemetry.io/otel/trace v1.7.0 h1:O37Iogk1lEkMRXewVtZ1BBTVn5JEp8GrJvP92bJqC6o= go.opentelemetry.io/otel/trace v1.7.0/go.mod h1:fzLSB9nqR2eXzxPXb2JW9IKE+ScyXA48yyE4TNvoHqU= go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI= +go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw= go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= -go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE= -go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= -go.uber.org/goleak v1.1.11-0.20210813005559-691160354723/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ= go.uber.org/goleak v1.1.11 h1:wy28qYRKZgnJTxGxvye5/wgWr1EKjmUDGYox5mGlRlI= go.uber.org/goleak v1.1.11/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ= +go.uber.org/multierr v1.6.0 h1:y6IPFStTAIT5Ytl7/XYmHvzXQ7S3g/IeZW9hyZ5thw4= go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU= -go.uber.org/multierr v1.7.0 h1:zaiO/rmgFjbmCXdSYJWQcdvOCsthmdaHfr3Gm2Kx4Ec= -go.uber.org/multierr v1.7.0/go.mod h1:7EAYxJLBy9rStEaz58O2t4Uvip6FSURkq8/ppBp95ak= go.uber.org/zap v1.17.0/go.mod h1:MXVU+bhUf/A7Xi2HNOnopQOrmycQ5Ih87HtOu4q5SSo= -go.uber.org/zap v1.19.1/go.mod h1:j3DNczoxDZroyBnOT1L/Q79cfUMGZxlv/9dzN7SM1rI= -go.uber.org/zap v1.20.0 h1:N4oPlghZwYG55MlU6LXk/Zp00FVNE9X9wrYO8CEs4lc= -go.uber.org/zap v1.20.0/go.mod h1:wjWOCqI0f2ZZrJF/UufIOkiC8ii6tm1iqIsLo76RfJw= +go.uber.org/zap v1.21.0 h1:WefMeulhovoZ2sYXz7st6K0sLj7bBhpiFaud4r4zST8= +go.uber.org/zap v1.21.0/go.mod h1:wjWOCqI0f2ZZrJF/UufIOkiC8ii6tm1iqIsLo76RfJw= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= @@ -444,10 +422,10 @@ golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96b golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk= golang.org/x/net v0.0.0-20210525063256-abc453219eb5/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/net v0.0.0-20210917221730-978cfadd31cf/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd h1:O7DYs+zxREGLKzKoMQrtrEacpb0ZVXA5rIwylE2Xchk= -golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= +golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= +golang.org/x/net v0.0.0-20220520000938-2e3eb7b945c2 h1:NWy5+hlRbC7HK+PmcXVUmW1IMyFce7to56IUvhUFm7Y= +golang.org/x/net v0.0.0-20220520000938-2e3eb7b945c2/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -515,11 +493,11 @@ golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220114195835-da31bd327af9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220412211240-33da011f77ad h1:ntjMns5wyP/fN65tdBD4g8J5w8n015+iIIs9rtjXkY0= golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6 h1:nonptSpoQ4vQjyraW20DXPAglgQfVnM9ZC6MmNLMR60= +golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -641,8 +619,8 @@ google.golang.org/genproto v0.0.0-20200729003335-053ba62fc06f/go.mod h1:FWY/as6D google.golang.org/genproto v0.0.0-20200804131852-c06518451d9c/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= google.golang.org/genproto v0.0.0-20200825200019-8632dd797987/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= google.golang.org/genproto v0.0.0-20210602131652-f16073e35f0c/go.mod h1:UODoCrxHCcBojKKwX1terBiRUaqAsFqJiF615XL43r0= -google.golang.org/genproto v0.0.0-20220126215142-9970aeb2e350 h1:YxHp5zqIcAShDEvRr5/0rVESVS+njYF68PSdazrNLJo= -google.golang.org/genproto v0.0.0-20220126215142-9970aeb2e350/go.mod h1:5CzLGKJ67TSI2B9POpiiyGha0AjJvZIUgRMt1dSmuhc= +google.golang.org/genproto v0.0.0-20220504150022-98cd25cafc72 h1:iif0mpUetMBqcQPUoq+JnCcmzvfpp8wRx515va8wP1c= +google.golang.org/genproto v0.0.0-20220504150022-98cd25cafc72/go.mod h1:RAyBrSAP7Fh3Nc84ghnVLDPuV51xc9agzmm4Ph6i0Q4= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= @@ -658,11 +636,9 @@ google.golang.org/grpc v1.31.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM google.golang.org/grpc v1.33.1/go.mod h1:fr5YgcSWrqhRRxogOsw7RzIpsmvOZ6IcH4kBYTpR3n0= google.golang.org/grpc v1.36.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU= google.golang.org/grpc v1.38.0/go.mod h1:NREThFqKR1f3iQ6oBuvc5LadQuXVGo9rkm5ZGrQdJfM= -google.golang.org/grpc v1.40.0/go.mod h1:ogyxbiOoUXAkP+4+xa6PZSE9DZgIHtSpzjDTB9KAK34= -google.golang.org/grpc v1.42.0/go.mod h1:k+4IHHFw41K8+bbowsex27ge2rCb65oeWqe4jJ590SU= -google.golang.org/grpc v1.44.0/go.mod h1:k+4IHHFw41K8+bbowsex27ge2rCb65oeWqe4jJ590SU= -google.golang.org/grpc v1.46.0 h1:oCjezcn6g6A75TGoKYBPgKmVBLexhYLM6MebdrPApP8= google.golang.org/grpc v1.46.0/go.mod h1:vN9eftEi1UMyUsIF80+uQXhHjbXYbm0uXoFCACuMGWk= +google.golang.org/grpc v1.46.2 h1:u+MLGgVf7vRdjEYZ8wDFhAVNmhkbJ5hmrA1LMWK1CAQ= +google.golang.org/grpc v1.46.2/go.mod h1:vN9eftEi1UMyUsIF80+uQXhHjbXYbm0uXoFCACuMGWk= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= @@ -675,8 +651,9 @@ google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGj google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= -google.golang.org/protobuf v1.27.1 h1:SnqbnDw1V7RiZcXPx5MEeqPv2s79L9i7BJUlG/+RurQ= google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +google.golang.org/protobuf v1.28.0 h1:w43yiav+6bVFTBQFZX0r7ipe9JQ1QsbMgHwbBziscLw= +google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/example/registry/http/client/main.go b/example/registry/http/client/main.go index 86fd60478ff..fd539db705b 100644 --- a/example/registry/http/client/main.go +++ b/example/registry/http/client/main.go @@ -6,15 +6,18 @@ import ( "github.com/gogf/gf/contrib/registry/etcd/v2" "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/gsel" "github.com/gogf/gf/v2/net/gsvc" "github.com/gogf/gf/v2/os/gctx" ) func main() { gsvc.SetRegistry(etcd.New(`127.0.0.1:2379`)) + gsel.SetBuilder(gsel.NewBuilderRoundRobin()) + client := g.Client() for i := 0; i < 100; i++ { - res, err := g.Client().Get(gctx.New(), `http://hello.svc/`) + res, err := client.Get(gctx.New(), `http://hello.svc/`) if err != nil { panic(err) } diff --git a/example/registry/polaris/client/main.go b/example/registry/polaris/client/main.go index 466eb937474..61ad73e65b6 100644 --- a/example/registry/polaris/client/main.go +++ b/example/registry/polaris/client/main.go @@ -7,7 +7,6 @@ import ( "github.com/polarismesh/polaris-go/pkg/config" "github.com/gogf/gf/contrib/registry/polaris/v2" - "github.com/gogf/gf/v2/frame/g" "github.com/gogf/gf/v2/net/gsvc" "github.com/gogf/gf/v2/os/gctx" @@ -16,7 +15,7 @@ import ( func main() { conf := config.NewDefaultConfiguration([]string{"192.168.100.222:8091"}) - gsvc.SetRegistry(polaris.NewWithConfig(conf, polaris.WithTTL(100))) + gsvc.SetRegistry(polaris.NewWithConfig(conf, polaris.WithTTL(10))) for i := 0; i < 100; i++ { res, err := g.Client().Get(gctx.New(), `http://hello.svc/`) diff --git a/example/registry/polaris/server/main.go b/example/registry/polaris/server/main.go index 63608d085a9..0038060db18 100644 --- a/example/registry/polaris/server/main.go +++ b/example/registry/polaris/server/main.go @@ -13,7 +13,7 @@ func main() { conf := config.NewDefaultConfiguration([]string{"192.168.100.222:8091"}) // TTL egt 2*time.Second - gsvc.SetRegistry(polaris.NewWithConfig(conf, polaris.WithTTL(100))) + gsvc.SetRegistry(polaris.NewWithConfig(conf, polaris.WithTTL(10))) s := g.Server(`hello.svc`) s.BindHandler("/", func(r *ghttp.Request) { diff --git a/example/trace/grpc_with_db/server/main.go b/example/trace/grpc_with_db/server/main.go index 78a986ae018..fccfc2230d4 100644 --- a/example/trace/grpc_with_db/server/main.go +++ b/example/trace/grpc_with_db/server/main.go @@ -5,7 +5,7 @@ import ( "fmt" "time" - "github.com/gogf/katyusha/krpc" + _ "github.com/gogf/gf/contrib/drivers/mysql/v2" "github.com/gogf/gf/contrib/trace/jaeger/v2" "github.com/gogf/gf/example/trace/grpc_with_db/protobuf/user" @@ -13,6 +13,7 @@ import ( "github.com/gogf/gf/v2/frame/g" "github.com/gogf/gf/v2/os/gcache" "github.com/gogf/gf/v2/os/gctx" + "github.com/gogf/katyusha/krpc" ) type server struct{} diff --git a/example/trace/http_with_db/server/main.go b/example/trace/http_with_db/server/main.go index 2aa9ed286f7..2a1e946dbf2 100644 --- a/example/trace/http_with_db/server/main.go +++ b/example/trace/http_with_db/server/main.go @@ -5,6 +5,8 @@ import ( "fmt" "time" + _ "github.com/gogf/gf/contrib/drivers/mysql/v2" + "github.com/gogf/gf/contrib/trace/jaeger/v2" "github.com/gogf/gf/v2/database/gdb" "github.com/gogf/gf/v2/frame/g" diff --git a/net/gclient/gclient_discovery.go b/net/gclient/gclient_discovery.go index edfeb3ed6f9..b1f52b8545d 100644 --- a/net/gclient/gclient_discovery.go +++ b/net/gclient/gclient_discovery.go @@ -22,12 +22,12 @@ const ( ) type discoveryNode struct { - service *gsvc.Service + service gsvc.Service address string } // Service is the client discovery service. -func (n *discoveryNode) Service() *gsvc.Service { +func (n *discoveryNode) Service() gsvc.Service { return n.service } @@ -49,11 +49,11 @@ func internalMiddlewareDiscovery(c *Client, r *http.Request) (response *Response if gsvc.GetRegistry() == nil { return c.Next(r) } - var service *gsvc.Service - service, err = gsvc.GetWithWatch(ctx, r.URL.Host, func(service *gsvc.Service) { - intlog.Printf(ctx, `http client watching service "%s" changed`, service.KeyWithoutEndpoints()) - if v := clientSelectorMap.Get(service.KeyWithoutEndpoints()); v != nil { - if err = updateSelectorNodesByService(v.(gsel.Selector), service); err != nil { + var service gsvc.Service + service, err = gsvc.GetAndWatch(ctx, r.URL.Host, func(service gsvc.Service) { + intlog.Printf(ctx, `http client watching service "%s" changed`, service.GetPrefix()) + if v := clientSelectorMap.Get(service.GetPrefix()); v != nil { + if err = updateSelectorNodesByService(ctx, v.(gsel.Selector), service); err != nil { intlog.Errorf(context.Background(), `%+v`, err) } } @@ -65,13 +65,13 @@ func internalMiddlewareDiscovery(c *Client, r *http.Request) (response *Response return c.Next(r) } // Balancer. - selectorMapKey := service.KeyWithoutEndpoints() + selectorMapKey := service.GetPrefix() selector := clientSelectorMap.GetOrSetFuncLock(selectorMapKey, func() interface{} { intlog.Printf(ctx, `http client create selector for service "%s"`, selectorMapKey) return gsel.GetBuilder().Build() }).(gsel.Selector) // Update selector nodes. - if err = updateSelectorNodesByService(selector, service); err != nil { + if err = updateSelectorNodesByService(ctx, selector, service); err != nil { return nil, err } // Pick one node from multiple addresses. @@ -87,13 +87,13 @@ func internalMiddlewareDiscovery(c *Client, r *http.Request) (response *Response return c.Next(r) } -func updateSelectorNodesByService(selector gsel.Selector, service *gsvc.Service) error { - nodes := make([]gsel.Node, 0) - for _, address := range service.Endpoints { +func updateSelectorNodesByService(ctx context.Context, selector gsel.Selector, service gsvc.Service) error { + nodes := make(gsel.Nodes, 0) + for _, endpoint := range service.GetEndpoints() { nodes = append(nodes, &discoveryNode{ service: service, - address: address, + address: endpoint.String(), }) } - return selector.Update(nodes) + return selector.Update(ctx, nodes) } diff --git a/net/ghttp/ghttp.go b/net/ghttp/ghttp.go index e29bfed3d20..c6afb6916c2 100644 --- a/net/ghttp/ghttp.go +++ b/net/ghttp/ghttp.go @@ -37,7 +37,7 @@ type ( statusHandlerMap map[string][]HandlerFunc // Custom status handler map. sessionManager *gsession.Manager // Session manager. openapi *goai.OpenApiV3 // The OpenApi specification management object. - service *gsvc.Service // The service for Registry. + service gsvc.Service // The service for Registry. } // Router object. diff --git a/net/ghttp/ghttp_server_registry.go b/net/ghttp/ghttp_server_registry.go index 2659740dc8c..12408db5fc4 100644 --- a/net/ghttp/ghttp_server_registry.go +++ b/net/ghttp/ghttp_server_registry.go @@ -25,6 +25,7 @@ func (s *Server) doServiceRegister() { protocol = gsvc.DefaultProtocol insecure = true address = s.config.Address + err error ) if address == "" { address = s.config.HTTPSAddr @@ -45,13 +46,13 @@ func (s *Server) doServiceRegister() { gsvc.MDProtocol: protocol, gsvc.MDInsecure: insecure, } - s.service = &gsvc.Service{ + s.service = &gsvc.LocalService{ Name: s.GetName(), - Endpoints: []string{fmt.Sprintf(`%s:%s`, ip, port)}, + Endpoints: gsvc.NewEndpoints(fmt.Sprintf(`%s:%s`, ip, port)), Metadata: metadata, } s.Logger().Debugf(ctx, `service register: %+v`, s.service) - if err := gsvc.Register(ctx, s.service); err != nil { + if s.service, err = gsvc.Register(ctx, s.service); err != nil { s.Logger().Fatalf(ctx, `%+v`, err) } } diff --git a/net/gsel/gsel.go b/net/gsel/gsel.go index 3b6d1249a8c..f616aaaa0f9 100644 --- a/net/gsel/gsel.go +++ b/net/gsel/gsel.go @@ -24,15 +24,18 @@ type Selector interface { Pick(ctx context.Context) (node Node, done DoneFunc, err error) // Update updates services into Selector. - Update(nodes []Node) error + Update(ctx context.Context, nodes Nodes) error } // Node is node interface. type Node interface { - Service() *gsvc.Service + Service() gsvc.Service Address() string } +// Nodes contains multiple Node. +type Nodes []Node + // DoneFunc is callback function when RPC invoke done. type DoneFunc func(ctx context.Context, di DoneInfo) @@ -83,3 +86,15 @@ type DoneInfoMD interface { // before removing it from md. Delete(k string) } + +// String formats and returns Nodes as string. +func (ns Nodes) String() string { + var s string + for _, node := range ns { + if s != "" { + s += "," + } + s += node.Address() + } + return s +} diff --git a/net/gsel/gsel_selector_least_connection.go b/net/gsel/gsel_selector_least_connection.go index 2a862572683..96e2c145f9c 100644 --- a/net/gsel/gsel_selector_least_connection.go +++ b/net/gsel/gsel_selector_least_connection.go @@ -11,6 +11,7 @@ import ( "sync" "github.com/gogf/gf/v2/container/gtype" + "github.com/gogf/gf/v2/internal/intlog" ) const SelectorLeastConnection = "BalancerLeastConnection" @@ -31,7 +32,8 @@ func NewSelectorLeastConnection() Selector { } } -func (s *selectorLeastConnection) Update(nodes []Node) error { +func (s *selectorLeastConnection) Update(ctx context.Context, nodes Nodes) error { + intlog.Printf(ctx, `Update nodes: %s`, nodes.String()) var newNodes []*leastConnectionNode for _, v := range nodes { node := v @@ -65,5 +67,7 @@ func (s *selectorLeastConnection) Pick(ctx context.Context) (node Node, done Don done = func(ctx context.Context, di DoneInfo) { pickedNode.inflight.Add(-1) } - return pickedNode.Node, done, nil + node = pickedNode.Node + intlog.Printf(ctx, `Picked node: %s`, node.Address()) + return node, done, nil } diff --git a/net/gsel/gsel_selector_random.go b/net/gsel/gsel_selector_random.go index 466f306749a..973f09da67c 100644 --- a/net/gsel/gsel_selector_random.go +++ b/net/gsel/gsel_selector_random.go @@ -10,6 +10,7 @@ import ( "context" "sync" + "github.com/gogf/gf/v2/internal/intlog" "github.com/gogf/gf/v2/util/grand" ) @@ -17,7 +18,7 @@ const SelectorRandom = "BalancerRandom" type selectorRandom struct { mu sync.RWMutex - nodes []Node + nodes Nodes } func NewSelectorRandom() Selector { @@ -26,7 +27,8 @@ func NewSelectorRandom() Selector { } } -func (s *selectorRandom) Update(nodes []Node) error { +func (s *selectorRandom) Update(ctx context.Context, nodes Nodes) error { + intlog.Printf(ctx, `Update nodes: %s`, nodes.String()) s.mu.Lock() defer s.mu.Unlock() s.nodes = nodes @@ -39,5 +41,7 @@ func (s *selectorRandom) Pick(ctx context.Context) (node Node, done DoneFunc, er if len(s.nodes) == 0 { return nil, nil, nil } - return s.nodes[grand.Intn(len(s.nodes))], nil, nil + node = s.nodes[grand.Intn(len(s.nodes))] + intlog.Printf(ctx, `Picked node: %s`, node.Address()) + return node, nil, nil } diff --git a/net/gsel/gsel_selector_round_robin.go b/net/gsel/gsel_selector_round_robin.go index 8f82bf920c0..d8f98fca38e 100644 --- a/net/gsel/gsel_selector_round_robin.go +++ b/net/gsel/gsel_selector_round_robin.go @@ -9,23 +9,26 @@ package gsel import ( "context" "sync" + + "github.com/gogf/gf/v2/internal/intlog" ) const SelectorRoundRobin = "BalancerRoundRobin" type selectorRoundRobin struct { mu sync.RWMutex - nodes []Node + nodes Nodes next int } func NewSelectorRoundRobin() Selector { return &selectorRoundRobin{ - nodes: make([]Node, 0), + nodes: make(Nodes, 0), } } -func (s *selectorRoundRobin) Update(nodes []Node) error { +func (s *selectorRoundRobin) Update(ctx context.Context, nodes Nodes) error { + intlog.Printf(ctx, `Update nodes: %s`, nodes.String()) s.mu.Lock() s.nodes = nodes s.mu.Unlock() @@ -37,5 +40,6 @@ func (s *selectorRoundRobin) Pick(ctx context.Context) (node Node, done DoneFunc defer s.mu.RUnlock() node = s.nodes[s.next] s.next = (s.next + 1) % len(s.nodes) + intlog.Printf(ctx, `Picked node: %s`, node.Address()) return } diff --git a/net/gsel/gsel_selector_weight.go b/net/gsel/gsel_selector_weight.go index bbbf59d125e..873d343b827 100644 --- a/net/gsel/gsel_selector_weight.go +++ b/net/gsel/gsel_selector_weight.go @@ -10,6 +10,7 @@ import ( "context" "sync" + "github.com/gogf/gf/v2/internal/intlog" "github.com/gogf/gf/v2/net/gsvc" "github.com/gogf/gf/v2/util/grand" ) @@ -18,16 +19,17 @@ const SelectorWeight = "BalancerWeight" type selectorWeight struct { mu sync.RWMutex - nodes []Node + nodes Nodes } func NewSelectorWeight() Selector { return &selectorWeight{ - nodes: make([]Node, 0), + nodes: make(Nodes, 0), } } -func (s *selectorWeight) Update(nodes []Node) error { +func (s *selectorWeight) Update(ctx context.Context, nodes Nodes) error { + intlog.Printf(ctx, `Update nodes: %s`, nodes.String()) var newNodes []Node for _, v := range nodes { node := v @@ -47,9 +49,11 @@ func (s *selectorWeight) Pick(ctx context.Context) (node Node, done DoneFunc, er if len(s.nodes) == 0 { return nil, nil, nil } - return s.nodes[grand.Intn(len(s.nodes))], nil, nil + node = s.nodes[grand.Intn(len(s.nodes))] + intlog.Printf(ctx, `Picked node: %s`, node.Address()) + return node, nil, nil } func (s *selectorWeight) getWeight(node Node) int { - return node.Service().Metadata.Get(gsvc.MDWeight).Int() + return node.Service().GetMetadata().Get(gsvc.MDWeight).Int() } diff --git a/net/gsvc/gsvc.go b/net/gsvc/gsvc.go index 8615fcf899e..ad7b8397115 100644 --- a/net/gsvc/gsvc.go +++ b/net/gsvc/gsvc.go @@ -23,16 +23,17 @@ type Registry interface { // Registrar interface for service registrar. type Registrar interface { // Register registers `service` to Registry. - Register(ctx context.Context, service *Service) error + // Note that it returns a new Service if it changes the input Service with custom one. + Register(ctx context.Context, service Service) (Service, error) // Deregister off-lines and removes `service` from the Registry. - Deregister(ctx context.Context, service *Service) error + Deregister(ctx context.Context, service Service) error } // Discovery interface for service discovery. type Discovery interface { // Search searches and returns services with specified condition. - Search(ctx context.Context, in SearchInput) ([]*Service, error) + Search(ctx context.Context, in SearchInput) ([]Service, error) // Watch watches specified condition changes. Watch(ctx context.Context, key string) (Watcher, error) @@ -41,55 +42,94 @@ type Discovery interface { // Watcher interface for service. type Watcher interface { // Proceed proceeds watch in blocking way. - Proceed() ([]*Service, error) + Proceed() ([]Service, error) // Close closes the watcher. Close() error } -// Service definition. -type Service struct { - ID string // ID is the unique instance ID as registered. - Prefix string // Service prefix. - Deployment string // Service deployment name, eg: dev, qa, staging, prod, etc. - Namespace string // Service Namespace, to indicate different services in the same environment with the same Name. - Name string // Name for the service. - Version string // Service version, eg: v1.0.0, v2.1.1, etc. - Endpoints []string // Service Endpoints, pattern: IP:port, eg: 192.168.1.2:8000. - Metadata Metadata // Custom data for this service, which can be set using JSON by environment or command-line. - Separator string // Separator for service name and version, eg: _, -, etc. +// Service interface for service definition. +type Service interface { + // GetName returns the name of the service. + // The name is necessary for a service, and should be unique among services. + GetName() string + + // GetVersion returns the version of the service. + // It is suggested using GNU version naming like: v1.0.0, v2.0.1, v2.1.0-rc. + // A service can have multiple versions deployed at once. + // If no version set in service, the default version of service is "latest". + GetVersion() string + + // GetKey formats and returns a unique key string for service. + // The result key is commonly used for key-value registrar server. + GetKey() string + + // GetValue formats and returns the value of the service. + // The result value is commonly used for key-value registrar server. + GetValue() string + + // GetPrefix formats and returns the key prefix string. + // The result prefix string is commonly used in key-value registrar server + // for service searching. + // + // Take etcd server for example, the prefix string is used like: + // `etcdctl get /services/prod/hello.svc --prefix` + GetPrefix() string + + // GetMetadata returns the Metadata map of service. + // The Metadata is key-value pair map specifying extra attributes of a service. + GetMetadata() Metadata + + // GetEndpoints returns the Endpoints of service. + // The Endpoints contain multiple host/port information of service. + GetEndpoints() Endpoints } +// Endpoint interface for service. +type Endpoint interface { + // Host returns the IPv4/IPv6 address of a service. + Host() string + + // Port returns the port of a service. + Port() int + + // String formats and returns the Endpoint as a string. + String() string +} + +// Endpoints are composed by multiple Endpoint. +type Endpoints []Endpoint + // Metadata stores custom key-value pairs. type Metadata map[string]interface{} // SearchInput is the input for service searching. type SearchInput struct { - Prefix string // Service prefix. - Deployment string // Service deployment name, eg: dev, qa, staging, prod, etc. - Namespace string // Service Namespace, to indicate different services in the same environment with the same Name. - Name string // Name for the service. - Version string // Service version, eg: v1.0.0, v2.1.1, etc.} - Metadata Metadata // Custom data for this service, which can be set using JSON by environment or command-line. - Separator string // Separator for service name and version, eg: _, -, etc. + Prefix string // Search by key prefix. + Name string // Search by service name. + Version string // Search by service version. + Metadata Metadata // Filter by metadata if there are multiple result. } const ( - Schema = `services` - DefaultPrefix = `services` - DefaultDeployment = `default` - DefaultNamespace = `default` - DefaultVersion = `latest` - EnvPrefix = `GF_GSVC_PREFIX` - EnvDeployment = `GF_GSVC_DEPLOYMENT` - EnvNamespace = `GF_GSVC_NAMESPACE` - EnvName = `GF_GSVC_Name` - EnvVersion = `GF_GSVC_VERSION` - MDProtocol = `protocol` - MDInsecure = `insecure` - MDWeight = `weight` - defaultTimeout = 5 * time.Second - DefaultProtocol = `http` + Schema = `services` + DefaultHead = `services` + DefaultDeployment = `default` + DefaultNamespace = `default` + DefaultVersion = `latest` + EnvPrefix = `GF_GSVC_PREFIX` + EnvDeployment = `GF_GSVC_DEPLOYMENT` + EnvNamespace = `GF_GSVC_NAMESPACE` + EnvName = `GF_GSVC_Name` + EnvVersion = `GF_GSVC_VERSION` + MDProtocol = `protocol` + MDInsecure = `insecure` + MDWeight = `weight` + DefaultProtocol = `http` + DefaultSeparator = "/" + defaultTimeout = 5 * time.Second + endpointHostPortDelimiter = ":" + endpointsDelimiter = "," ) var defaultRegistry Registry diff --git a/net/gsvc/gsvc_discovery.go b/net/gsvc/gsvc_discovery.go index 5be3e64994d..518b87c03c3 100644 --- a/net/gsvc/gsvc_discovery.go +++ b/net/gsvc/gsvc_discovery.go @@ -17,31 +17,26 @@ import ( "github.com/gogf/gf/v2/util/gutil" ) +// watchedServiceMap stores used service var watchedServiceMap = gmap.New(true) // ServiceWatch is used to watch the service status. -type ServiceWatch func(service *Service) +type ServiceWatch func(service Service) -// Get the watched service map. -func Get(ctx context.Context, name string) (service *Service, err error) { - return GetWithWatch(ctx, name, nil) +// Get retrieves and returns the service by service name. +func Get(ctx context.Context, name string) (service Service, err error) { + return GetAndWatch(ctx, name, nil) } -// GetWithWatch is used to getting the service with watch. -func GetWithWatch(ctx context.Context, name string, watch ServiceWatch) (service *Service, err error) { +// GetAndWatch is used to getting the service with custom watch callback function. +func GetAndWatch(ctx context.Context, name string, watch ServiceWatch) (service Service, err error) { v := watchedServiceMap.GetOrSetFuncLock(name, func() interface{} { var ( - s = NewServiceWithName(name) - services []*Service + services []Service watcher Watcher ) services, err = Search(ctx, SearchInput{ - Prefix: s.Prefix, - Deployment: s.Deployment, - Namespace: s.Namespace, - Name: s.Name, - Version: s.Version, - Metadata: s.Metadata, + Name: name, }) if err != nil { return nil @@ -50,26 +45,31 @@ func GetWithWatch(ctx context.Context, name string, watch ServiceWatch) (service err = gerror.NewCodef(gcode.CodeNotFound, `service not found with name "%s"`, name) return nil } + + // Just pick one if multiple. service = services[0] + // Watch the service changes in goroutine. - watcher, err = Watch(ctx, service.KeyWithoutEndpoints()) - if err != nil { - return nil + if watch != nil { + if watcher, err = Watch(ctx, service.GetPrefix()); err != nil { + return nil + } + go watchAndUpdateService(watcher, service, watch) } - go watchAndUpdateService(watcher, service, watch) return service }) if v != nil { - service = v.(*Service) + service = v.(Service) } return } -func watchAndUpdateService(watcher Watcher, service *Service, watchFunc ServiceWatch) { +// watchAndUpdateService watches and updates the service in memory if it is changed. +func watchAndUpdateService(watcher Watcher, service Service, watchFunc ServiceWatch) { var ( ctx = context.Background() err error - services []*Service + services []Service ) for { time.Sleep(time.Second) @@ -79,7 +79,7 @@ func watchAndUpdateService(watcher Watcher, service *Service, watchFunc ServiceW continue } if len(services) > 0 { - watchedServiceMap.Set(service.Name, services[0]) + watchedServiceMap.Set(service.GetName(), services[0]) if watchFunc != nil { gutil.TryCatch(func() { watchFunc(services[0]) @@ -92,7 +92,7 @@ func watchAndUpdateService(watcher Watcher, service *Service, watchFunc ServiceW } // Search searches and returns services with specified condition. -func Search(ctx context.Context, in SearchInput) ([]*Service, error) { +func Search(ctx context.Context, in SearchInput) ([]Service, error) { if defaultRegistry == nil { return nil, gerror.NewCodef(gcode.CodeNotImplemented, `no Registry is registered`) } diff --git a/net/gsvc/gsvc_endpoint.go b/net/gsvc/gsvc_endpoint.go new file mode 100644 index 00000000000..f75e3fe3e33 --- /dev/null +++ b/net/gsvc/gsvc_endpoint.go @@ -0,0 +1,55 @@ +// Copyright GoFrame Author(https://goframe.org). All Rights Reserved. +// +// This Source Code Form is subject to the terms of the MIT License. +// If a copy of the MIT was not distributed with this file, +// You can obtain one at https://github.com/gogf/gf. + +// Package gsvc provides service registry and discovery definition. +package gsvc + +import ( + "fmt" + + "github.com/gogf/gf/v2/errors/gcode" + "github.com/gogf/gf/v2/errors/gerror" + "github.com/gogf/gf/v2/text/gstr" + "github.com/gogf/gf/v2/util/gconv" +) + +// LocalEndpoint implements interface Endpoint. +type LocalEndpoint struct { + host string // host can be either IPv4 or IPv6 address. + port int // port is port as commonly known. +} + +// NewEndpoint creates and returns an Endpoint from address string of pattern "host:port", +// eg: "192.168.1.100:80". +func NewEndpoint(address string) Endpoint { + array := gstr.SplitAndTrim(address, endpointHostPortDelimiter) + if len(array) != 2 { + panic(gerror.NewCodef( + gcode.CodeInvalidParameter, + `invalid address "%s" for creating endpoint, endpoint address is like "ip:port"`, + address, + )) + } + return &LocalEndpoint{ + host: array[0], + port: gconv.Int(array[1]), + } +} + +// Host returns the IPv4/IPv6 address of a service. +func (e *LocalEndpoint) Host() string { + return e.host +} + +// Port returns the port of a service. +func (e *LocalEndpoint) Port() int { + return e.port +} + +// String formats and returns the Endpoint as a string, like: 192.168.1.100:80. +func (e *LocalEndpoint) String() string { + return fmt.Sprintf(`%s:%d`, e.host, e.port) +} diff --git a/net/gsvc/gsvc_endpoints.go b/net/gsvc/gsvc_endpoints.go new file mode 100644 index 00000000000..2fbcb60716d --- /dev/null +++ b/net/gsvc/gsvc_endpoints.go @@ -0,0 +1,35 @@ +// Copyright GoFrame Author(https://goframe.org). All Rights Reserved. +// +// This Source Code Form is subject to the terms of the MIT License. +// If a copy of the MIT was not distributed with this file, +// You can obtain one at https://github.com/gogf/gf. + +// Package gsvc provides service registry and discovery definition. +package gsvc + +import ( + "github.com/gogf/gf/v2/text/gstr" +) + +// NewEndpoints creates and returns Endpoints from multiple addresses like: +// "192.168.1.100:80,192.168.1.101:80". +func NewEndpoints(addresses string) Endpoints { + endpoints := make([]Endpoint, 0) + for _, address := range gstr.SplitAndTrim(addresses, endpointsDelimiter) { + endpoints = append(endpoints, NewEndpoint(address)) + } + return endpoints +} + +// String formats and returns the Endpoints as a string like: +// "192.168.1.100:80,192.168.1.101:80" +func (es Endpoints) String() string { + var s string + for _, endpoint := range es { + if s != "" { + s += endpointsDelimiter + } + s += endpoint.String() + } + return s +} diff --git a/net/gsvc/gsvc_metadata.go b/net/gsvc/gsvc_metadata.go index 015c4432a8d..264021ce31b 100644 --- a/net/gsvc/gsvc_metadata.go +++ b/net/gsvc/gsvc_metadata.go @@ -15,6 +15,13 @@ func (m Metadata) Set(key string, value string) { m[key] = value } +// Sets sets key-value pairs into metadata. +func (m Metadata) Sets(kvs map[string]interface{}) { + for k, v := range kvs { + m[k] = v + } +} + // Get retrieves and returns value of specified key as gvar. func (m Metadata) Get(key string) *gvar.Var { if v, ok := m[key]; ok { @@ -22,3 +29,8 @@ func (m Metadata) Get(key string) *gvar.Var { } return nil } + +// IsEmpty checks and returns whether current Metadata is empty. +func (m Metadata) IsEmpty() bool { + return len(m) == 0 +} diff --git a/net/gsvc/gsvc_registry.go b/net/gsvc/gsvc_registry.go index 24d0355d26e..ca0f6578e33 100644 --- a/net/gsvc/gsvc_registry.go +++ b/net/gsvc/gsvc_registry.go @@ -14,9 +14,9 @@ import ( ) // Register registers `service` to default registry.. -func Register(ctx context.Context, service *Service) error { +func Register(ctx context.Context, service Service) (Service, error) { if defaultRegistry == nil { - return gerror.NewCodef(gcode.CodeNotImplemented, `no Registry is registered`) + return nil, gerror.NewCodef(gcode.CodeNotImplemented, `no Registry is registered`) } ctx, cancel := context.WithTimeout(ctx, defaultTimeout) defer cancel() @@ -25,7 +25,7 @@ func Register(ctx context.Context, service *Service) error { } // Deregister removes `service` from default registry. -func Deregister(ctx context.Context, service *Service) error { +func Deregister(ctx context.Context, service Service) error { if defaultRegistry == nil { return gerror.NewCodef(gcode.CodeNotImplemented, `no Registry is registered`) } diff --git a/net/gsvc/gsvc_search.go b/net/gsvc/gsvc_search.go deleted file mode 100644 index 1e76e9e63ce..00000000000 --- a/net/gsvc/gsvc_search.go +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright GoFrame Author(https://goframe.org). All Rights Reserved. -// -// This Source Code Form is subject to the terms of the MIT License. -// If a copy of the MIT was not distributed with this file, -// You can obtain one at https://github.com/gogf/gf. - -package gsvc - -// Key formats and returns a string for prefix searching purpose. -func (s *SearchInput) Key() string { - separator := DefaultSeparator - if s.Separator != "" { - separator = s.Separator - } - keyPrefix := "" - if s.Prefix != "" { - if separator == DefaultSeparator { - keyPrefix += separator + s.Prefix - } else { - keyPrefix += s.Prefix - } - } - if s.Deployment != "" { - keyPrefix += separator + s.Deployment - if s.Namespace != "" { - keyPrefix += separator + s.Namespace - if s.Name != "" { - keyPrefix += separator + s.Name - if s.Version != "" { - keyPrefix += separator + s.Version - } - } - } - } - - return keyPrefix -} diff --git a/net/gsvc/gsvc_service.go b/net/gsvc/gsvc_service.go index 7dc971dff1a..277144cc01a 100644 --- a/net/gsvc/gsvc_service.go +++ b/net/gsvc/gsvc_service.go @@ -8,7 +8,6 @@ package gsvc import ( "context" - "fmt" "github.com/gogf/gf/v2/encoding/gjson" "github.com/gogf/gf/v2/errors/gcode" @@ -18,43 +17,49 @@ import ( "github.com/gogf/gf/v2/text/gstr" ) -const ( - // DefaultSeparator is the default separator for the service name and method name. - DefaultSeparator = "/" - endpointDelimiter = "," -) +// LocalService provides a default implements for interface Service. +type LocalService struct { + Head string // Service custom head string in service key. + Deployment string // Service deployment name, eg: dev, qa, staging, prod, etc. + Namespace string // Service Namespace, to indicate different services in the same environment with the same Name. + Name string // Name for the service. + Version string // Service version, eg: v1.0.0, v2.1.1, etc. + Endpoints Endpoints // Service Endpoints, pattern: IP:port, eg: 192.168.1.2:8000. + Metadata Metadata // Custom data for this service, which can be set using JSON by environment or command-line. +} -// NewServiceWithName creates and returns service from `name`. -func NewServiceWithName(name string) (s *Service) { - s = &Service{ +// NewServiceWithName creates and returns a default implements for interface Service by service name. +func NewServiceWithName(name string) Service { + s := &LocalService{ Name: name, Metadata: make(Metadata), } s.autoFillDefaultAttributes() - return + return s } -// NewServiceWithKV creates and returns service from `key` and `value`. -func NewServiceWithKV(key, value []byte) (s *Service, err error) { - array := gstr.Split(gstr.Trim(string(key), DefaultSeparator), DefaultSeparator) +// NewServiceWithKV creates and returns a default implements for interface Service by key-value pair string. +func NewServiceWithKV(key, value string) (Service, error) { + var ( + err error + array = gstr.Split(gstr.Trim(key, DefaultSeparator), DefaultSeparator) + ) if len(array) < 6 { err = gerror.NewCodef(gcode.CodeInvalidParameter, `invalid service key "%s"`, key) - - return + return nil, err } - s = &Service{ - Prefix: array[0], + s := &LocalService{ + Head: array[0], Deployment: array[1], Namespace: array[2], Name: array[3], Version: array[4], - Endpoints: gstr.Split(array[5], endpointDelimiter), + Endpoints: NewEndpoints(array[5]), Metadata: make(Metadata), - Separator: DefaultSeparator, } s.autoFillDefaultAttributes() if len(value) > 0 { - if err = gjson.Unmarshal(value, &s.Metadata); err != nil { + if err = gjson.Unmarshal([]byte(value), &s.Metadata); err != nil { err = gerror.WrapCodef(gcode.CodeInvalidParameter, err, `invalid service value "%s"`, value) return nil, err } @@ -62,37 +67,31 @@ func NewServiceWithKV(key, value []byte) (s *Service, err error) { return s, nil } -// Key formats the service information and returns the Service as registering key. -func (s *Service) Key() string { - separator := DefaultSeparator - if s.Separator != "" { - separator = s.Separator - } - serviceNameUnique := s.KeyWithoutEndpoints() - serviceNameUnique += separator + gstr.Join(s.Endpoints, ",") - return serviceNameUnique +// GetName returns the name of the service. +// The name is necessary for a service, and should be unique among services. +func (s *LocalService) GetName() string { + return s.Name } -// KeyWithSchema formats the service information and returns the Service as dialing target key. -func (s *Service) KeyWithSchema() string { - return fmt.Sprintf(`%s://%s`, Schema, s.Key()) +// GetVersion returns the version of the service. +// It is suggested using GNU version naming like: v1.0.0, v2.0.1, v2.1.0-rc. +// A service can have multiple versions deployed at once. +// If no version set in service, the default version of service is "latest". +func (s *LocalService) GetVersion() string { + return s.Version } -// KeyWithoutEndpoints formats the service information and returns a string as a unique name of service. -func (s *Service) KeyWithoutEndpoints() string { - s.autoFillDefaultAttributes() - separator := DefaultSeparator - if s.Separator != "" { - separator = s.Separator - } - if separator != DefaultSeparator { - return gstr.Join([]string{s.Prefix, s.Deployment, s.Namespace, s.Name, s.Version}, separator) - } - return separator + gstr.Join([]string{s.Prefix, s.Deployment, s.Namespace, s.Name, s.Version}, separator) +// GetKey formats and returns a unique key string for service. +// The result key is commonly used for key-value registrar server. +func (s *LocalService) GetKey() string { + serviceNameUnique := s.GetPrefix() + serviceNameUnique += DefaultSeparator + s.Endpoints.String() + return serviceNameUnique } -// Value formats the service information and returns the Service as registering value. -func (s *Service) Value() string { +// GetValue formats and returns the value of the service. +// The result value is commonly used for key-value registrar server. +func (s *LocalService) GetValue() string { b, err := gjson.Marshal(s.Metadata) if err != nil { intlog.Errorf(context.TODO(), `%+v`, err) @@ -100,18 +99,41 @@ func (s *Service) Value() string { return string(b) } -// Address returns the first endpoint of Service. -// Eg: 192.168.1.12:9000. -func (s *Service) Address() string { - if len(s.Endpoints) == 0 { - return "" - } - return s.Endpoints[0] +// GetPrefix formats and returns the key prefix string. +// The result prefix string is commonly used in key-value registrar server +// for service searching. +// +// Take etcd server for example, the prefix string is used like: +// `etcdctl get /services/prod/hello.svc --prefix` +func (s *LocalService) GetPrefix() string { + s.autoFillDefaultAttributes() + return DefaultSeparator + gstr.Join( + []string{ + s.Head, + s.Deployment, + s.Namespace, + s.Name, + s.Version, + }, + DefaultSeparator, + ) +} + +// GetMetadata returns the Metadata map of service. +// The Metadata is key-value pair map specifying extra attributes of a service. +func (s *LocalService) GetMetadata() Metadata { + return s.Metadata +} + +// GetEndpoints returns the Endpoints of service. +// The Endpoints contain multiple host/port information of service. +func (s *LocalService) GetEndpoints() Endpoints { + return s.Endpoints } -func (s *Service) autoFillDefaultAttributes() { - if s.Prefix == "" { - s.Prefix = gcmd.GetOptWithEnv(EnvPrefix, DefaultPrefix).String() +func (s *LocalService) autoFillDefaultAttributes() { + if s.Head == "" { + s.Head = gcmd.GetOptWithEnv(EnvPrefix, DefaultHead).String() } if s.Deployment == "" { s.Deployment = gcmd.GetOptWithEnv(EnvDeployment, DefaultDeployment).String()