rpcx: github.com/smallnest/rpcx/serverplugin Index | Files

package serverplugin

import "github.com/smallnest/rpcx/serverplugin"

Index

Package Files

alias.go blacklist.go consul.go etcd.go etcdv3.go influxdb.go mdns.go metrics.go nacos.go opencensus.go opentracing.go rate_limiting.go redis.go req_rate_limiting.go tee.go trace.go whitelist.go zookeeper.go

Variables

var ErrReqReachLimit = errors.New("request reached rate limit")

func InfluxDB Uses

func InfluxDB(r metrics.Registry, d time.Duration, url, database, username, password string)

InfluxDB starts a InfluxDB reporter which will post the metrics from the given registry at each d interval.

func InfluxDBWithTags Uses

func InfluxDBWithTags(r metrics.Registry, d time.Duration, url, database, username, password string, tags map[string]string)

InfluxDBWithTags starts a InfluxDB reporter which will post the metrics from the given registry at each d interval with the specified tags

type AliasPlugin Uses

type AliasPlugin struct {
    Aliases          map[string]*aliasPair
    ReseverseAliases map[string]*aliasPair
}

AliasPlugin can be used to set aliases for services

func NewAliasPlugin Uses

func NewAliasPlugin() *AliasPlugin

NewAliasPlugin creates a new NewAliasPlugin

func (*AliasPlugin) Alias Uses

func (p *AliasPlugin) Alias(aliasServicePath, aliasServiceMethod string, servicePath, serviceMethod string)

Alias sets a alias for the serviceMethod. For example Alias("anewpath&method", "Arith.mul")

func (*AliasPlugin) PostReadRequest Uses

func (p *AliasPlugin) PostReadRequest(ctx context.Context, r *protocol.Message, e error) error

PostReadRequest converts the alias of this service.

func (*AliasPlugin) PreWriteResponse Uses

func (p *AliasPlugin) PreWriteResponse(ctx context.Context, r *protocol.Message, res *protocol.Message) error

PreWriteResponse restore servicePath and serviceMethod.

type BlacklistPlugin Uses

type BlacklistPlugin struct {
    Blacklist     map[string]bool
    BlacklistMask []*net.IPNet // net.ParseCIDR("172.17.0.0/16") to get *net.IPNet
}

BlacklistPlugin is a plugin that control only ip addresses in blacklist can **NOT** access services.

func (*BlacklistPlugin) HandleConnAccept Uses

func (plugin *BlacklistPlugin) HandleConnAccept(conn net.Conn) (net.Conn, bool)

HandleConnAccept check ip.

type ConsulRegisterPlugin Uses

type ConsulRegisterPlugin struct {
    // service address, for example, tcp@127.0.0.1:8972, quic@127.0.0.1:1234
    ServiceAddress string
    // consul addresses
    ConsulServers []string
    // base path for rpcx server, for example com/example/rpcx
    BasePath string
    Metrics  metrics.Registry
    // Registered services
    Services []string

    UpdateInterval time.Duration

    Options *store.Config
    // contains filtered or unexported fields
}

ConsulRegisterPlugin implements consul registry.

func (*ConsulRegisterPlugin) HandleConnAccept Uses

func (p *ConsulRegisterPlugin) HandleConnAccept(conn net.Conn) (net.Conn, bool)

HandleConnAccept handles connections from clients

func (*ConsulRegisterPlugin) PreCall Uses

func (p *ConsulRegisterPlugin) PreCall(_ context.Context, _, _ string, args interface{}) (interface{}, error)

PreCall handles rpc call from clients

func (*ConsulRegisterPlugin) Register Uses

func (p *ConsulRegisterPlugin) Register(name string, rcvr interface{}, metadata string) (err error)

Register handles registering event. this service is registered at BASE/serviceName/thisIpAddress node

func (*ConsulRegisterPlugin) RegisterFunction Uses

func (p *ConsulRegisterPlugin) RegisterFunction(serviceName, fname string, fn interface{}, metadata string) error

func (*ConsulRegisterPlugin) Start Uses

func (p *ConsulRegisterPlugin) Start() error

Start starts to connect consul cluster

func (*ConsulRegisterPlugin) Stop Uses

func (p *ConsulRegisterPlugin) Stop() error

Stop unregister all services.

func (*ConsulRegisterPlugin) Unregister Uses

func (p *ConsulRegisterPlugin) Unregister(name string) (err error)

type EtcdRegisterPlugin Uses

type EtcdRegisterPlugin struct {
    // service address, for example, tcp@127.0.0.1:8972, quic@127.0.0.1:1234
    ServiceAddress string
    // etcd addresses
    EtcdServers []string
    // base path for rpcx server, for example com/example/rpcx
    BasePath string
    Metrics  metrics.Registry
    // Registered services
    Services []string

    UpdateInterval time.Duration

    Options *store.Config
    // contains filtered or unexported fields
}

EtcdRegisterPlugin implements etcd registry.

func (*EtcdRegisterPlugin) HandleConnAccept Uses

func (p *EtcdRegisterPlugin) HandleConnAccept(conn net.Conn) (net.Conn, bool)

HandleConnAccept handles connections from clients

func (*EtcdRegisterPlugin) PreCall Uses

func (p *EtcdRegisterPlugin) PreCall(_ context.Context, _, _ string, args interface{}) (interface{}, error)

PreCall handles rpc call from clients

func (*EtcdRegisterPlugin) Register Uses

func (p *EtcdRegisterPlugin) Register(name string, rcvr interface{}, metadata string) (err error)

Register handles registering event. this service is registered at BASE/serviceName/thisIpAddress node

func (*EtcdRegisterPlugin) RegisterFunction Uses

func (p *EtcdRegisterPlugin) RegisterFunction(serviceName, fname string, fn interface{}, metadata string) error

func (*EtcdRegisterPlugin) Start Uses

func (p *EtcdRegisterPlugin) Start() error

Start starts to connect etcd cluster

func (*EtcdRegisterPlugin) Stop Uses

func (p *EtcdRegisterPlugin) Stop() error

Stop unregister all services.

func (*EtcdRegisterPlugin) Unregister Uses

func (p *EtcdRegisterPlugin) Unregister(name string) (err error)

type EtcdV3RegisterPlugin Uses

type EtcdV3RegisterPlugin struct {
    // service address, for example, tcp@127.0.0.1:8972, quic@127.0.0.1:1234
    ServiceAddress string
    // etcd addresses
    EtcdServers []string
    // base path for rpcx server, for example com/example/rpcx
    BasePath string
    Metrics  metrics.Registry
    // Registered services
    Services []string

    UpdateInterval time.Duration

    Options *store.Config
    // contains filtered or unexported fields
}

EtcdV3RegisterPlugin implements etcd registry.

func (*EtcdV3RegisterPlugin) HandleConnAccept Uses

func (p *EtcdV3RegisterPlugin) HandleConnAccept(conn net.Conn) (net.Conn, bool)

HandleConnAccept handles connections from clients

func (*EtcdV3RegisterPlugin) PreCall Uses

func (p *EtcdV3RegisterPlugin) PreCall(_ context.Context, _, _ string, args interface{}) (interface{}, error)

PreCall handles rpc call from clients

func (*EtcdV3RegisterPlugin) Register Uses

func (p *EtcdV3RegisterPlugin) Register(name string, rcvr interface{}, metadata string) (err error)

Register handles registering event. this service is registered at BASE/serviceName/thisIpAddress node

func (*EtcdV3RegisterPlugin) RegisterFunction Uses

func (p *EtcdV3RegisterPlugin) RegisterFunction(serviceName, fname string, fn interface{}, metadata string) error

func (*EtcdV3RegisterPlugin) Start Uses

func (p *EtcdV3RegisterPlugin) Start() error

Start starts to connect etcd cluster

func (*EtcdV3RegisterPlugin) Stop Uses

func (p *EtcdV3RegisterPlugin) Stop() error

Stop unregister all services.

func (*EtcdV3RegisterPlugin) Unregister Uses

func (p *EtcdV3RegisterPlugin) Unregister(name string) (err error)

type MDNSRegisterPlugin Uses

type MDNSRegisterPlugin struct {
    // service address, for example, tcp@127.0.0.1:8972, quic@127.0.0.1:1234
    ServiceAddress string

    Metrics metrics.Registry
    // Registered services
    Services       []*serviceMeta
    UpdateInterval time.Duration
    // contains filtered or unexported fields
}

MDNSRegisterPlugin implements mdns/dns-sd registry.

func NewMDNSRegisterPlugin Uses

func NewMDNSRegisterPlugin(serviceAddress string, port int, m metrics.Registry, updateInterval time.Duration, domain string) *MDNSRegisterPlugin

NewMDNSRegisterPlugin return a new MDNSRegisterPlugin. If domain is empty, use "local." in default.

func (*MDNSRegisterPlugin) HandleConnAccept Uses

func (p *MDNSRegisterPlugin) HandleConnAccept(conn net.Conn) (net.Conn, bool)

HandleConnAccept handles connections from clients

func (*MDNSRegisterPlugin) PreCall Uses

func (p *MDNSRegisterPlugin) PreCall(_ context.Context, _, _ string, args interface{}) (interface{}, error)

PreCall handles rpc call from clients

func (*MDNSRegisterPlugin) Register Uses

func (p *MDNSRegisterPlugin) Register(name string, rcvr interface{}, metadata string) (err error)

Register handles registering event. this service is registered at BASE/serviceName/thisIpAddress node

func (*MDNSRegisterPlugin) RegisterFunction Uses

func (p *MDNSRegisterPlugin) RegisterFunction(serviceName, fname string, fn interface{}, metadata string) error

func (*MDNSRegisterPlugin) Start Uses

func (p *MDNSRegisterPlugin) Start() error

Start starts to connect etcd cluster

func (*MDNSRegisterPlugin) Stop Uses

func (p *MDNSRegisterPlugin) Stop() error

Stop unregister all services.

func (*MDNSRegisterPlugin) Unregister Uses

func (p *MDNSRegisterPlugin) Unregister(name string) (err error)

type MetricsPlugin Uses

type MetricsPlugin struct {
    Registry metrics.Registry
    Prefix   string
}

MetricsPlugin collects metrics of a rpc server. You can report metrics to log, syslog, Graphite, InfluxDB or others to display them in Dashboard such as grafana, Graphite.

func NewMetricsPlugin Uses

func NewMetricsPlugin(registry metrics.Registry) *MetricsPlugin

NewMetricsPlugin creates a new MetricsPlugirn

func (*MetricsPlugin) Exp Uses

func (p *MetricsPlugin) Exp()

Exp uses the same mechanism as the official expvar but exposed under /debug/metrics, which shows a json representation of all your usual expvars as well as all your go-metrics.

func (*MetricsPlugin) Graphite Uses

func (p *MetricsPlugin) Graphite(freq time.Duration, prefix string, addr *net.TCPAddr)

Graphite reports metrics into graphite.

	addr, _ := net.ResolveTCPAddr("tcp", "127.0.0.1:2003")
 p.Graphite(10e9, "metrics", addr)

func (*MetricsPlugin) HandleConnAccept Uses

func (p *MetricsPlugin) HandleConnAccept(conn net.Conn) (net.Conn, bool)

HandleConnAccept handles connections from clients

func (*MetricsPlugin) InfluxDB Uses

func (p *MetricsPlugin) InfluxDB(freq time.Duration, url, database, username, password string)

InfluxDB reports metrics into influxdb.

p.InfluxDB(10e9, "http://127.0.0.1:8086","metrics", "test","test"})

func (*MetricsPlugin) InfluxDBWithTags Uses

func (p *MetricsPlugin) InfluxDBWithTags(freq time.Duration, url, database, username, password string, tags map[string]string)

InfluxDBWithTags reports metrics into influxdb with tags. you can set node info into tags.

p.InfluxDBWithTags(10e9, "http://127.0.0.1:8086","metrics", "test","test", map[string]string{"host":"127.0.0.1"})

func (*MetricsPlugin) Log Uses

func (p *MetricsPlugin) Log(freq time.Duration, l metrics.Logger)

Log reports metrics into logs.

p.Log( 5 * time.Second, log.New(os.Stderr, "metrics: ", log.Lmicroseconds))

func (*MetricsPlugin) PostReadRequest Uses

func (p *MetricsPlugin) PostReadRequest(ctx context.Context, r *protocol.Message, e error) error

PostReadRequest counts read

func (*MetricsPlugin) PostWriteResponse Uses

func (p *MetricsPlugin) PostWriteResponse(ctx context.Context, req *protocol.Message, res *protocol.Message, e error) error

PostWriteResponse count write

func (*MetricsPlugin) PreReadRequest Uses

func (p *MetricsPlugin) PreReadRequest(ctx context.Context) error

PreReadRequest marks start time of calling service

func (*MetricsPlugin) Register Uses

func (p *MetricsPlugin) Register(name string, rcvr interface{}, metadata string) error

Register handles registering event.

type NacosRegisterPlugin Uses

type NacosRegisterPlugin struct {
    // service address, for example, tcp@127.0.0.1:8972, quic@127.0.0.1:1234
    ServiceAddress string
    // nacos client config
    ClientConfig constant.ClientConfig
    // nacos server config
    ServerConfig []constant.ServerConfig
    Cluster      string
    Weight       float64

    // Registered services
    Services []string
    // contains filtered or unexported fields
}

NacosRegisterPlugin implements consul registry.

func (*NacosRegisterPlugin) Register Uses

func (p *NacosRegisterPlugin) Register(name string, rcvr interface{}, metadata string) (err error)

Register handles registering event. this service is registered at BASE/serviceName/thisIpAddress node

func (*NacosRegisterPlugin) RegisterFunction Uses

func (p *NacosRegisterPlugin) RegisterFunction(serviceName, fname string, fn interface{}, metadata string) error

func (*NacosRegisterPlugin) Start Uses

func (p *NacosRegisterPlugin) Start() error

Start starts to connect consul cluster

func (*NacosRegisterPlugin) Stop Uses

func (p *NacosRegisterPlugin) Stop() error

Stop unregister all services.

func (*NacosRegisterPlugin) Unregister Uses

func (p *NacosRegisterPlugin) Unregister(name string) (err error)

type OpenCensusPlugin Uses

type OpenCensusPlugin struct{}

func (OpenCensusPlugin) PostConnAccept Uses

func (p OpenCensusPlugin) PostConnAccept(conn net.Conn) (net.Conn, bool)

func (OpenCensusPlugin) PostWriteResponse Uses

func (p OpenCensusPlugin) PostWriteResponse(ctx context.Context, req *protocol.Message, res *protocol.Message, err error) error

func (OpenCensusPlugin) PreHandleRequest Uses

func (p OpenCensusPlugin) PreHandleRequest(ctx context.Context, r *protocol.Message) error

func (OpenCensusPlugin) Register Uses

func (p OpenCensusPlugin) Register(name string, rcvr interface{}, metadata string) error

func (OpenCensusPlugin) RegisterFunction Uses

func (p OpenCensusPlugin) RegisterFunction(serviceName, fname string, fn interface{}, metadata string) error

type OpenTracingPlugin Uses

type OpenTracingPlugin struct{}

func (OpenTracingPlugin) PostConnAccept Uses

func (p OpenTracingPlugin) PostConnAccept(conn net.Conn) (net.Conn, bool)

func (OpenTracingPlugin) PostWriteResponse Uses

func (p OpenTracingPlugin) PostWriteResponse(ctx context.Context, req *protocol.Message, res *protocol.Message, err error) error

func (OpenTracingPlugin) PreHandleRequest Uses

func (p OpenTracingPlugin) PreHandleRequest(ctx context.Context, r *protocol.Message) error

func (OpenTracingPlugin) Register Uses

func (p OpenTracingPlugin) Register(name string, rcvr interface{}, metadata string) error

func (OpenTracingPlugin) RegisterFunction Uses

func (p OpenTracingPlugin) RegisterFunction(serviceName, fname string, fn interface{}, metadata string) error

type RateLimitingPlugin Uses

type RateLimitingPlugin struct {
    FillInterval time.Duration
    Capacity     int64
    // contains filtered or unexported fields
}

RateLimitingPlugin can limit connecting per unit time

func NewRateLimitingPlugin Uses

func NewRateLimitingPlugin(fillInterval time.Duration, capacity int64) *RateLimitingPlugin

NewRateLimitingPlugin creates a new RateLimitingPlugin

func (*RateLimitingPlugin) HandleConnAccept Uses

func (plugin *RateLimitingPlugin) HandleConnAccept(conn net.Conn) (net.Conn, bool)

HandleConnAccept can limit connecting rate

type RedisRegisterPlugin Uses

type RedisRegisterPlugin struct {
    // service address, for example, tcp@127.0.0.1:8972, quic@127.0.0.1:1234
    ServiceAddress string
    // redis addresses
    RedisServers []string
    // base path for rpcx server, for example com/example/rpcx
    BasePath string
    Metrics  metrics.Registry
    // Registered services
    Services []string

    UpdateInterval time.Duration

    Options *store.Config
    // contains filtered or unexported fields
}

RedisRegisterPlugin implements redis registry.

func (*RedisRegisterPlugin) HandleConnAccept Uses

func (p *RedisRegisterPlugin) HandleConnAccept(conn net.Conn) (net.Conn, bool)

HandleConnAccept handles connections from clients

func (*RedisRegisterPlugin) PreCall Uses

func (p *RedisRegisterPlugin) PreCall(_ context.Context, _, _ string, args interface{}) (interface{}, error)

PreCall handles rpc call from clients

func (*RedisRegisterPlugin) Register Uses

func (p *RedisRegisterPlugin) Register(name string, rcvr interface{}, metadata string) (err error)

Register handles registering event. this service is registered at BASE/serviceName/thisIpAddress node

func (*RedisRegisterPlugin) Start Uses

func (p *RedisRegisterPlugin) Start() error

Start starts to connect redis cluster

func (*RedisRegisterPlugin) Stop Uses

func (p *RedisRegisterPlugin) Stop() error

Stop unregister all services.

func (*RedisRegisterPlugin) Unregister Uses

func (p *RedisRegisterPlugin) Unregister(name string) (err error)

type ReqRateLimitingPlugin Uses

type ReqRateLimitingPlugin struct {
    FillInterval time.Duration
    Capacity     int64
    // contains filtered or unexported fields
}

ReqRateLimitingPlugin can limit requests per unit time

func NewReqRateLimitingPlugin Uses

func NewReqRateLimitingPlugin(fillInterval time.Duration, capacity int64, block bool) *ReqRateLimitingPlugin

NewReqRateLimitingPlugin creates a new RateLimitingPlugin

func (*ReqRateLimitingPlugin) PreReadRequest Uses

func (plugin *ReqRateLimitingPlugin) PreReadRequest(ctx context.Context) error

PreReadRequest can limit request processing.

type TeeConnPlugin Uses

type TeeConnPlugin struct {
    // contains filtered or unexported fields
}

TeeConnPlugin is a plugin that copy requests from clients and send to a io.Writer.

func NewTeeConnPlugin Uses

func NewTeeConnPlugin(w io.Writer) *TeeConnPlugin

func (*TeeConnPlugin) HandleConnAccept Uses

func (plugin *TeeConnPlugin) HandleConnAccept(conn net.Conn) (net.Conn, bool)

HandleConnAccept check ip.

func (*TeeConnPlugin) Update Uses

func (plugin *TeeConnPlugin) Update(w io.Writer)

Update can start a stream copy by setting a non-nil w. If you set a nil w, it doesn't copy stream.

type WhitelistPlugin Uses

type WhitelistPlugin struct {
    Whitelist     map[string]bool
    WhitelistMask []*net.IPNet // net.ParseCIDR("172.17.0.0/16") to get *net.IPNet
}

WhitelistPlugin is a plugin that control only ip addresses in whitelist can access services.

func (*WhitelistPlugin) HandleConnAccept Uses

func (plugin *WhitelistPlugin) HandleConnAccept(conn net.Conn) (net.Conn, bool)

HandleConnAccept check ip.

type ZooKeeperRegisterPlugin Uses

type ZooKeeperRegisterPlugin struct {
    // service address, for example, tcp@127.0.0.1:8972, quic@127.0.0.1:1234
    ServiceAddress string
    // zookeeper addresses
    ZooKeeperServers []string
    // base path for rpcx server, for example com/example/rpcx
    BasePath string
    Metrics  metrics.Registry
    // Registered services
    Services []string

    UpdateInterval time.Duration

    Options *store.Config
    // contains filtered or unexported fields
}

ZooKeeperRegisterPlugin implements zookeeper registry.

func (*ZooKeeperRegisterPlugin) HandleConnAccept Uses

func (p *ZooKeeperRegisterPlugin) HandleConnAccept(conn net.Conn) (net.Conn, bool)

HandleConnAccept handles connections from clients

func (*ZooKeeperRegisterPlugin) PreCall Uses

func (p *ZooKeeperRegisterPlugin) PreCall(_ context.Context, _, _ string, args interface{}) (interface{}, error)

PreCall handles rpc call from clients

func (*ZooKeeperRegisterPlugin) Register Uses

func (p *ZooKeeperRegisterPlugin) Register(name string, rcvr interface{}, metadata string) (err error)

Register handles registering event. this service is registered at BASE/serviceName/thisIpAddress node

func (*ZooKeeperRegisterPlugin) RegisterFunction Uses

func (p *ZooKeeperRegisterPlugin) RegisterFunction(serviceName, fname string, fn interface{}, metadata string) error

func (*ZooKeeperRegisterPlugin) Start Uses

func (p *ZooKeeperRegisterPlugin) Start() error

Start starts to connect zookeeper cluster

func (*ZooKeeperRegisterPlugin) Stop Uses

func (p *ZooKeeperRegisterPlugin) Stop() error

Stop unregister all services.

func (*ZooKeeperRegisterPlugin) Unregister Uses

func (p *ZooKeeperRegisterPlugin) Unregister(name string) (err error)

Package serverplugin imports 41 packages (graph) and is imported by 39 packages. Updated 2020-10-27. Refresh now. Tools for package owners.