mirror of
https://github.com/smallnest/rpcx.git
synced 2025-10-05 08:06:58 +08:00
revise annotation
This commit is contained in:
@@ -29,7 +29,7 @@ type DNSDiscovery struct {
|
|||||||
stopCh chan 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) {
|
func NewDNSDiscovery(domain string, network string, port int, d time.Duration) (*DNSDiscovery, error) {
|
||||||
discovery := &DNSDiscovery{domain: domain, network: network, port: port, d: d}
|
discovery := &DNSDiscovery{domain: domain, network: network, port: port, d: d}
|
||||||
discovery.lookup()
|
discovery.lookup()
|
||||||
|
@@ -86,7 +86,7 @@ func (p *pluginContainer) DoConnCreated(conn net.Conn) (net.Conn, error) {
|
|||||||
return conn, nil
|
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) {
|
func (p *pluginContainer) DoConnCreateFailed(network, address string) {
|
||||||
for i := range p.plugins {
|
for i := range p.plugins {
|
||||||
if plugin, ok := p.plugins[i].(ConnCreateFailedPlugin); ok {
|
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
|
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 {
|
func (p *pluginContainer) DoClientConnectionClose(conn net.Conn) error {
|
||||||
var err error
|
var err error
|
||||||
for i := range p.plugins {
|
for i := range p.plugins {
|
||||||
@@ -137,7 +137,7 @@ func (p *pluginContainer) DoClientBeforeEncode(req *protocol.Message) error {
|
|||||||
return nil
|
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 {
|
func (p *pluginContainer) DoClientAfterDecode(req *protocol.Message) error {
|
||||||
var err error
|
var err error
|
||||||
for i := range p.plugins {
|
for i := range p.plugins {
|
||||||
|
@@ -57,7 +57,7 @@ func NewStreamService(addr string, streamHandler StreamHandler, acceptor StreamA
|
|||||||
return fi
|
return fi
|
||||||
}
|
}
|
||||||
|
|
||||||
// EnableFileTransfer supports filetransfer service in this server.
|
// EnableStreamService supports stream service in this server.
|
||||||
func (s *Server) EnableStreamService(serviceName string, streamService *StreamService) {
|
func (s *Server) EnableStreamService(serviceName string, streamService *StreamService) {
|
||||||
if serviceName == "" {
|
if serviceName == "" {
|
||||||
serviceName = share.StreamServiceName
|
serviceName = share.StreamServiceName
|
||||||
|
@@ -21,7 +21,7 @@ type MetricsPlugin struct {
|
|||||||
Prefix string
|
Prefix string
|
||||||
}
|
}
|
||||||
|
|
||||||
//NewMetricsPlugin creates a new MetricsPlugirn
|
// NewMetricsPlugin creates a new MetricsPlugin
|
||||||
func NewMetricsPlugin(registry metrics.Registry) *MetricsPlugin {
|
func NewMetricsPlugin(registry metrics.Registry) *MetricsPlugin {
|
||||||
return &MetricsPlugin{Registry: registry}
|
return &MetricsPlugin{Registry: registry}
|
||||||
}
|
}
|
||||||
@@ -78,8 +78,8 @@ func (p *MetricsPlugin) PostWriteResponse(ctx context.Context, req *protocol.Mes
|
|||||||
|
|
||||||
if t > 0 {
|
if t > 0 {
|
||||||
t = time.Now().UnixNano() - t
|
t = time.Now().UnixNano() - t
|
||||||
if t < 30*time.Minute.Nanoseconds() { //it is impossible that calltime exceeds 30 minute
|
if t < 30*time.Minute.Nanoseconds() { // it is impossible that calltime exceeds 30 minute
|
||||||
//Historgram
|
// Historgram
|
||||||
h := metrics.GetOrRegisterHistogram(p.withPrefix("service."+sp+"."+sm+".CallTime"), p.Registry,
|
h := metrics.GetOrRegisterHistogram(p.withPrefix("service."+sp+"."+sm+".CallTime"), p.Registry,
|
||||||
metrics.NewExpDecaySample(1028, 0.015))
|
metrics.NewExpDecaySample(1028, 0.015))
|
||||||
h.Update(t)
|
h.Update(t)
|
||||||
@@ -91,16 +91,14 @@ func (p *MetricsPlugin) PostWriteResponse(ctx context.Context, req *protocol.Mes
|
|||||||
// Log reports metrics into logs.
|
// Log reports metrics into logs.
|
||||||
//
|
//
|
||||||
// p.Log( 5 * time.Second, log.New(os.Stderr, "metrics: ", log.Lmicroseconds))
|
// p.Log( 5 * time.Second, log.New(os.Stderr, "metrics: ", log.Lmicroseconds))
|
||||||
//
|
|
||||||
func (p *MetricsPlugin) Log(freq time.Duration, l metrics.Logger) {
|
func (p *MetricsPlugin) Log(freq time.Duration, l metrics.Logger) {
|
||||||
go metrics.Log(p.Registry, freq, l)
|
go metrics.Log(p.Registry, freq, l)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Graphite reports metrics into graphite.
|
// Graphite reports metrics into graphite.
|
||||||
//
|
//
|
||||||
// addr, _ := net.ResolveTCPAddr("tcp", "127.0.0.1:2003")
|
// addr, _ := net.ResolveTCPAddr("tcp", "127.0.0.1:2003")
|
||||||
// p.Graphite(10e9, "metrics", addr)
|
// p.Graphite(10e9, "metrics", addr)
|
||||||
//
|
|
||||||
func (p *MetricsPlugin) Graphite(freq time.Duration, prefix string, addr *net.TCPAddr) {
|
func (p *MetricsPlugin) Graphite(freq time.Duration, prefix string, addr *net.TCPAddr) {
|
||||||
go metrics.Graphite(p.Registry, freq, prefix, addr)
|
go metrics.Graphite(p.Registry, freq, prefix, addr)
|
||||||
}
|
}
|
||||||
|
@@ -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 {
|
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)
|
res, err := plugin.limiter.Allow(ctx, r.ServicePath+"/"+r.ServiceMethod, plugin.limit)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Reference in New Issue
Block a user