From 5a28ff1560e729b29029bf9ab99e059872364b8c Mon Sep 17 00:00:00 2001 From: 14March <53811984+hcraM41@users.noreply.github.com> Date: Thu, 17 Aug 2023 11:11:59 +0800 Subject: [PATCH 1/3] normalize annotation --- client/geo_utils.go | 2 +- client/mode.go | 22 +++++++++++----------- client/ping_utils.go | 2 +- client/smooth_weighted_round_robin.go | 4 ++-- server/jsonrpc2_wire.go | 2 +- serverplugin/alias.go | 2 +- serverplugin/mdns.go | 2 +- serverplugin/redis.go | 2 +- 8 files changed, 19 insertions(+), 19 deletions(-) diff --git a/client/geo_utils.go b/client/geo_utils.go index ecb18c4a..7d00ac63 100644 --- a/client/geo_utils.go +++ b/client/geo_utils.go @@ -4,7 +4,7 @@ import ( "math" ) -//https://gist.github.com/cdipaolo/d3f8db3848278b49db68 +// https://gist.github.com/cdipaolo/d3f8db3848278b49db68 func getDistanceFrom(lat1, lon1, lat2, lon2 float64) float64 { var la1, lo1, la2, lo2, r float64 la1 = lat1 * math.Pi / 180 diff --git a/client/mode.go b/client/mode.go index c80acefc..1ae877f1 100644 --- a/client/mode.go +++ b/client/mode.go @@ -1,16 +1,16 @@ package client -//FailMode decides how clients action when clients fail to invoke services +// FailMode decides how clients action when clients fail to invoke services type FailMode int const ( - //Failover selects another server automaticaly + // Failover selects another server automaticaly Failover FailMode = iota - //Failfast returns error immediately + // Failfast returns error immediately Failfast - //Failtry use current client again + // Failtry use current client again Failtry - //Failbackup select another server if the first server doesn't respond in specified time and use the fast response. + // Failbackup select another server if the first server doesn't respond in specified time and use the fast response. Failbackup ) @@ -18,17 +18,17 @@ const ( type SelectMode int const ( - //RandomSelect is selecting randomly + // RandomSelect is selecting randomly RandomSelect SelectMode = iota - //RoundRobin is selecting by round robin + // RoundRobin is selecting by round robin RoundRobin - //WeightedRoundRobin is selecting by weighted round robin + // WeightedRoundRobin is selecting by weighted round robin WeightedRoundRobin - //WeightedICMP is selecting by weighted Ping time + // WeightedICMP is selecting by weighted Ping time WeightedICMP - //ConsistentHash is selecting by hashing + // ConsistentHash is selecting by hashing ConsistentHash - //Closest is selecting the closest server + // Closest is selecting the closest server Closest // SelectByUser is selecting by implementation of users diff --git a/client/ping_utils.go b/client/ping_utils.go index 075014c7..1e93512e 100644 --- a/client/ping_utils.go +++ b/client/ping_utils.go @@ -48,7 +48,7 @@ func createICMPWeighted(servers map[string]string) []*Weighted { // Ping gets network traffic by ICMP func Ping(host string) (rtt int, err error) { - rtt = 1000 //default and timeout is 1000 ms + rtt = 1000 // default and timeout is 1000 ms pinger, err := ping.NewPinger(host) if err != nil { diff --git a/client/smooth_weighted_round_robin.go b/client/smooth_weighted_round_robin.go index edfd98bc..fa36b3a0 100644 --- a/client/smooth_weighted_round_robin.go +++ b/client/smooth_weighted_round_robin.go @@ -15,7 +15,7 @@ type Weighted struct { // } // } -//https://github.com/phusion/nginx/commit/27e94984486058d73157038f7950a0a36ecc6e35 +// https://github.com/phusion/nginx/commit/27e94984486058d73157038f7950a0a36ecc6e35 func nextWeighted(servers []*Weighted) (best *Weighted) { total := 0 @@ -25,7 +25,7 @@ func nextWeighted(servers []*Weighted) (best *Weighted) { if w == nil { continue } - //if w is down, continue + // if w is down, continue w.CurrentWeight += w.EffectiveWeight total += w.EffectiveWeight diff --git a/server/jsonrpc2_wire.go b/server/jsonrpc2_wire.go index 6174637e..026a45d8 100644 --- a/server/jsonrpc2_wire.go +++ b/server/jsonrpc2_wire.go @@ -18,7 +18,7 @@ const ( CodeUnknownJSONRPCError = -32001 // CodeParseJSONRPCError is used when invalid JSON was received by the server. CodeParseJSONRPCError = -32700 - //CodeInvalidjsonrpcRequest is used when the JSON sent is not a valid jsonrpcRequest object. + // CodeInvalidjsonrpcRequest is used when the JSON sent is not a valid jsonrpcRequest object. CodeInvalidjsonrpcRequest = -32600 // CodeMethodNotFound should be returned by the handler when the method does // not exist / is not available. diff --git a/serverplugin/alias.go b/serverplugin/alias.go index 4f59ad90..f632d67c 100644 --- a/serverplugin/alias.go +++ b/serverplugin/alias.go @@ -12,7 +12,7 @@ type aliasPair struct { servicePath, serviceMethod string } -//AliasPlugin can be used to set aliases for services +// AliasPlugin can be used to set aliases for services type AliasPlugin struct { Aliases map[string]*aliasPair ReseverseAliases map[string]*aliasPair diff --git a/serverplugin/mdns.go b/serverplugin/mdns.go index 0cafeee6..44bd132d 100644 --- a/serverplugin/mdns.go +++ b/serverplugin/mdns.go @@ -87,7 +87,7 @@ func (p *MDNSRegisterPlugin) Start() error { extra["connections"] = fmt.Sprintf("%.2f", metrics.GetOrRegisterMeter("connections", p.Metrics).RateMean()) } - //set this same metrics for all services at this server + // set this same metrics for all services at this server for _, sm := range p.Services { v, _ := url.ParseQuery(string(sm.Meta)) for key, value := range extra { diff --git a/serverplugin/redis.go b/serverplugin/redis.go index 435b5056..f53354b1 100644 --- a/serverplugin/redis.go +++ b/serverplugin/redis.go @@ -88,7 +88,7 @@ func (p *RedisRegisterPlugin) Start() error { extra["calls"] = fmt.Sprintf("%.2f", metrics.GetOrRegisterMeter("calls", p.Metrics).RateMean()) extra["connections"] = fmt.Sprintf("%.2f", metrics.GetOrRegisterMeter("connections", p.Metrics).RateMean()) } - //set this same metrics for all services at this server + // set this same metrics for all services at this server for _, name := range p.Services { nodePath := fmt.Sprintf("%s/%s/%s", p.BasePath, name, p.ServiceAddress) kvPair, err := p.kv.Get(nodePath) From a6008a8d99c28945f3d58dc7c6e8da2be04e14aa Mon Sep 17 00:00:00 2001 From: 14March <53811984+hcraM41@users.noreply.github.com> Date: Thu, 17 Aug 2023 11:21:04 +0800 Subject: [PATCH 2/3] revise annotation --- client/dns_discovery.go | 2 +- client/plugin.go | 6 +++--- server/stream.go | 2 +- serverplugin/metrics.go | 12 +++++------- serverplugin/req_rate_limiting_redis.go | 2 +- 5 files changed, 11 insertions(+), 13 deletions(-) diff --git a/client/dns_discovery.go b/client/dns_discovery.go index 22264d6d..820087b1 100644 --- a/client/dns_discovery.go +++ b/client/dns_discovery.go @@ -29,7 +29,7 @@ type DNSDiscovery struct { stopCh chan struct{} } -// NewPeer2PeerDiscovery returns a new Peer2PeerDiscovery. +// NewDNSDiscovery returns a new DNSDiscovery. func NewDNSDiscovery(domain string, network string, port int, d time.Duration) (*DNSDiscovery, error) { discovery := &DNSDiscovery{domain: domain, network: network, port: port, d: d} discovery.lookup() diff --git a/client/plugin.go b/client/plugin.go index 95a0f786..681c8d1f 100644 --- a/client/plugin.go +++ b/client/plugin.go @@ -86,7 +86,7 @@ func (p *pluginContainer) DoConnCreated(conn net.Conn) (net.Conn, error) { return conn, nil } -// DoConnCreated is called in case of client connection created. +// DoConnCreateFailed is called in case of client connection create failed. func (p *pluginContainer) DoConnCreateFailed(network, address string) { for i := range p.plugins { if plugin, ok := p.plugins[i].(ConnCreateFailedPlugin); ok { @@ -109,7 +109,7 @@ func (p *pluginContainer) DoClientConnected(conn net.Conn) (net.Conn, error) { return conn, nil } -// DoClientConnected is called in case of connected. +// DoClientConnectionClose is called in case of connection close. func (p *pluginContainer) DoClientConnectionClose(conn net.Conn) error { var err error for i := range p.plugins { @@ -137,7 +137,7 @@ func (p *pluginContainer) DoClientBeforeEncode(req *protocol.Message) error { return nil } -// DoClientBeforeEncode is called when requests are encoded and sent. +// DoClientAfterDecode is called when requests are decoded and received. func (p *pluginContainer) DoClientAfterDecode(req *protocol.Message) error { var err error for i := range p.plugins { diff --git a/server/stream.go b/server/stream.go index 98f4a7b0..816c8106 100644 --- a/server/stream.go +++ b/server/stream.go @@ -57,7 +57,7 @@ func NewStreamService(addr string, streamHandler StreamHandler, acceptor StreamA return fi } -// EnableFileTransfer supports filetransfer service in this server. +// EnableStreamService supports stream service in this server. func (s *Server) EnableStreamService(serviceName string, streamService *StreamService) { if serviceName == "" { serviceName = share.StreamServiceName diff --git a/serverplugin/metrics.go b/serverplugin/metrics.go index 4f8821f3..4c29a13f 100644 --- a/serverplugin/metrics.go +++ b/serverplugin/metrics.go @@ -21,7 +21,7 @@ type MetricsPlugin struct { Prefix string } -//NewMetricsPlugin creates a new MetricsPlugirn +// NewMetricsPlugin creates a new MetricsPlugin func NewMetricsPlugin(registry metrics.Registry) *MetricsPlugin { return &MetricsPlugin{Registry: registry} } @@ -78,8 +78,8 @@ func (p *MetricsPlugin) PostWriteResponse(ctx context.Context, req *protocol.Mes if t > 0 { t = time.Now().UnixNano() - t - if t < 30*time.Minute.Nanoseconds() { //it is impossible that calltime exceeds 30 minute - //Historgram + if t < 30*time.Minute.Nanoseconds() { // it is impossible that calltime exceeds 30 minute + // Historgram h := metrics.GetOrRegisterHistogram(p.withPrefix("service."+sp+"."+sm+".CallTime"), p.Registry, metrics.NewExpDecaySample(1028, 0.015)) h.Update(t) @@ -91,16 +91,14 @@ func (p *MetricsPlugin) PostWriteResponse(ctx context.Context, req *protocol.Mes // Log reports metrics into logs. // // p.Log( 5 * time.Second, log.New(os.Stderr, "metrics: ", log.Lmicroseconds)) -// func (p *MetricsPlugin) Log(freq time.Duration, l metrics.Logger) { go metrics.Log(p.Registry, freq, l) } // Graphite reports metrics into graphite. // -// addr, _ := net.ResolveTCPAddr("tcp", "127.0.0.1:2003") -// p.Graphite(10e9, "metrics", addr) -// +// addr, _ := net.ResolveTCPAddr("tcp", "127.0.0.1:2003") +// p.Graphite(10e9, "metrics", addr) func (p *MetricsPlugin) Graphite(freq time.Duration, prefix string, addr *net.TCPAddr) { go metrics.Graphite(p.Registry, freq, prefix, addr) } diff --git a/serverplugin/req_rate_limiting_redis.go b/serverplugin/req_rate_limiting_redis.go index c8f67d0a..faf75ff7 100644 --- a/serverplugin/req_rate_limiting_redis.go +++ b/serverplugin/req_rate_limiting_redis.go @@ -39,7 +39,7 @@ func NewRedisRateLimitingPlugin(addrs []string, rate int, burst int, period time } } -// PreReadRequest can limit request processing. +// PostReadRequest can limit request processing. func (plugin *RedisRateLimitingPlugin) PostReadRequest(ctx context.Context, r *protocol.Message, e error) error { res, err := plugin.limiter.Allow(ctx, r.ServicePath+"/"+r.ServiceMethod, plugin.limit) if err != nil { From 675614d309ad8d52930509352e55f2043f29bd56 Mon Sep 17 00:00:00 2001 From: 14March <53811984+hcraM41@users.noreply.github.com> Date: Thu, 17 Aug 2023 11:32:28 +0800 Subject: [PATCH 3/3] recovery annotation --- serverplugin/metrics.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/serverplugin/metrics.go b/serverplugin/metrics.go index 4c29a13f..bf774e93 100644 --- a/serverplugin/metrics.go +++ b/serverplugin/metrics.go @@ -97,8 +97,8 @@ func (p *MetricsPlugin) Log(freq time.Duration, l metrics.Logger) { // Graphite reports metrics into graphite. // -// addr, _ := net.ResolveTCPAddr("tcp", "127.0.0.1:2003") -// p.Graphite(10e9, "metrics", addr) +// addr, _ := net.ResolveTCPAddr("tcp", "127.0.0.1:2003") +// p.Graphite(10e9, "metrics", addr) func (p *MetricsPlugin) Graphite(freq time.Duration, prefix string, addr *net.TCPAddr) { go metrics.Graphite(p.Registry, freq, prefix, addr) }