const (
DIRECT_PREFIX = "direct://"
PROXY_PREFIX = "proxy://"
)
const (
// if we have a long rpc call (e.g. 3 seconds)
// then we can run into timeouts, during the
// interceptor auth phase
// imho - the auth should be handled by "normal"
// loadbalancer function
// (it seems) cnw 19/5/2018
CONST_CALL_TIMEOUT = 4
)
const (
REFRESH = time.Duration(5) * time.Second
)
const (
RESOLVER_ATTRIBUTE_SERVICE_ADDRESS = "service_address"
)
func ClientMetricsUnaryInterceptor(ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error
called for each outbound rpc
func Connect(serviceNameOrPath string) *grpc.ClientConn
func ConnectAt(registryadr string, serviceNameOrPath string) *grpc.ClientConn
convenience method to get a loadbalanced connection to a service use path or servicename (path prefered, it contains the version) unless it successfullly connects it will NOT return (it will either terminate the process or loop)
func ConnectAtNoAuth(registryadr string, serviceNameOrPath string) *grpc.ClientConn
connect to a service which we KNOW requires no authentication and no signature. it is public because of implementation details, but should not be used by clients of goeasyops
func ConnectWithIP(ip string) (*grpc.ClientConn, error)
opens a tcp connection to an ip:port (ip syntax matches argument to net.Dial())
func ConnectWithIPNoBlock(ip string) (*grpc.ClientConn, error)
opens a tcp connection to an ip (no loadbalancing obviously)
func CustomDialer(ctx context.Context, name string) (net.Conn, error)
this is called by grpc to get a connection
func DIS_OutboundContext(inbound context.Context) context.Context
given an inbound Context (e.g. in an RPC call) this creates a new outbound context suitable to call other servers we keep user & org intact. we add/override 'service' token (with our token)
func DialTCPWrapper(serviceName string) (net.Conn, error)
opens a tcp connection to a servicename
func Evict(ctx context.Context, key string) ([]byte, error)
evict (remove) an object from the objectstore by key
func EvictNoResult(ctx context.Context, key string) error
evict (remove) an object from the objectstore by key
func Get(ctx context.Context, key string) ([]byte, error)
get an object from the objectstore by key
func GetClientCreds() credentials.TransportCredentials
get the Client Credentials we use to connect to other RPCs
func GetConnectedInstanceCount(servicelookupid string) int
get instances for a service currently being connected to (that is, it will return 0 for services which have not been dialled (yet)
func GetDependencies() []string
func GetObjectStoreClient() os.ObjectStoreClient
func GetRegistryClient() pb.RegistryClient
func GetSignatureFromAuth()
func GotSig() bool
cannot use init function, because flags might not be initialised (for example registry flag)
func init() {
GetSignatureFromAuth()
}
func PutWithID(ctx context.Context, key string, buf []byte) error
func PutWithIDAndExpiry(ctx context.Context, key string, buf []byte, expiry time.Time) error
func RegisterDependency(name string)
type FancyAddr struct {
Target *registry.Target
// contains filtered or unexported fields
}
func (fa *FancyAddr) Address() string
address, including port, e.g. 10.1.1.1:6000
func (fa *FancyAddr) Connection() (*grpc.ClientConn, error)
func (fa *FancyAddr) IsReady() bool
return true if this is _actually_ available. e.g. a TCP reset will cause this connection to be "not ready", but still be listed in the registry and caches
func (fa *FancyAddr) Key() string
a key that can be used in maps to find this particular fancyaddress.
func (fa *FancyAddr) String() string
this is essentially a list of addresses. the balancer removes/adds/updates addresses and the picker reads/chooses/sorts them. this struct synchronises access between them.
The list is semi-uptodate, that means, it is cached, but updated if go-easyops determines that the registry has better information than its cache. The Addresses in this list are still subject to the filtering done in the registry. The Registry "prefers" certain targets, for example, higher buildids
type FancyAddressList struct {
Name string
// contains filtered or unexported fields
}
func ConnectNoBalance(serviceNameOrPath string) (*FancyAddressList, error)
func ConnectNoBalanceAt(registryadr string, serviceNameOrPath string) (*FancyAddressList, error)
this initiates a balancer for a service and returns an address list. this is not actually balanced, but the fancyaddresslist does maintain the list of active targets.
func GetAllFancyAddressLists() []*FancyAddressList
func NewFancyAddressListWithResolver(servicename string, resolver func(registryadr, servicename string) ([]*registry.Target, error)) (*FancyAddressList, error)
this creates a fancy address list, which does not automatically maintain its list of targets. it also does not (and cannot) be used for loadbalancing, because it has no connection to a grpc LoadBalancer or Picker. sometimes maybe might need a custom resolver for a fancy address list.
func (fal *FancyAddressList) Add(f *FancyAddr)
perhaps should check/panic on duplicates here?
func (fal *FancyAddressList) AllAddresses() []*FancyAddr
return all addresses the fancyaddresslist knows about.
func (fal *FancyAddressList) AllReadyAddresses() []*FancyAddr
return all "ready" addresses (those with a TCP connection in ready state)
func (fal *FancyAddressList) ByAddr(adr string) *FancyAddr
func (fal *FancyAddressList) ByKey(key string) *FancyAddr
returns the fancyaddress that matches the key. see fancyaddress.Key(). this might return nil if no such fancyaddress is known (any more)
func (fal *FancyAddressList) ByMatchingTags(tags map[string]string) []*FancyAddr
func (fal *FancyAddressList) ByNoUserRoutingInfo() []*FancyAddr
get all those without routinginfo or no routinginfo.user
func (fal *FancyAddressList) BySubCon(sc balancer.SubConn) *FancyAddr
func (fal *FancyAddressList) ByUser(userid string) []*FancyAddr
get all those with a routinginfo RunningAs user
func (fal *FancyAddressList) ByWithoutTags() []*FancyAddr
return addresses with 0 tags
func (fal *FancyAddressList) Count() int
func (fal *FancyAddressList) IsEmpty() bool
func (fal *FancyAddressList) RequiredList(addresses []resolver.Address) []*FancyAddr
removes all addresses which are NOT in the array and returns the removed ones
func (fal *FancyAddressList) SelectValid(ctx context.Context) []*FancyAddr
this is called for _every_ rpc call. it should be performance optimised this returns a list of addresses for the picker to pick from. this function is what the picker calls. if loadbalancing is implemented by the user, this function should be used
the rules are: First: Never return any addresses which are not in connectivty state READY. Then from the remaining addresses (in ready state), follow these rules: 1. If we have 0 addresses with routinginfo for a user, return all. 2. if context has no user, return those without routinginfo.user 3. if 1 or more addresses have a routinginfo.user that matches user in context, return only those
func (fal *FancyAddressList) ServiceName() string
servicename, e.g. "registry.Registry"
func (fal *FancyAddressList) Updated()
called by the balancer when a FancyAddr has been updated. (or anyone updating FancyAddr) we may need to clear some caches (now or in future...)
type FancyBalancer struct {
// contains filtered or unexported fields
}
func (f *FancyBalancer) Check()
periodically called by go routine, checks if it's blocking for too long
func (f *FancyBalancer) Close()
Close closes the balancer. The balancer is not required to call ClientConn.RemoveSubConn for its existing SubConns.
func (f *FancyBalancer) ExitIdle()
func (f *FancyBalancer) HandleResolvedAddrs(addresses []resolver.Address, err error)
DEPRECATED - old version of grpc HandleResolvedAddrs is called by gRPC to send updated resolved addresses to balancers. Balancer can create new SubConn or remove SubConn with the addresses. An empty address slice and a non-nil error will be passed if the resolver returns non-nil error to gRPC. Note that each address MUST have an attribute with a registry.ServiceAddress because we cannot transport all the information in just ip/port
func (f *FancyBalancer) HandleSubConnStateChange(sc balancer.SubConn, state connectivity.State)
DEPRECATED - old version of grpc HandleSubConnStateChange is called by gRPC when the connectivity state of sc has changed. Balancer is expected to aggregate all the state of SubConn and report that back to gRPC. Balancer should also generate and update Pickers when its internal state has been changed by the new state.
func (f *FancyBalancer) Picker() *FancyPicker
create a new picker
func (f *FancyBalancer) ResolverError(err error)
EXPERIMENTAL: this is the new-style grpc callback
func (f *FancyBalancer) ServiceName() string
func (f *FancyBalancer) UpdateClientConnState(bc balancer.ClientConnState) error
EXPERIMENTAL: this is the new-style grpc callback, called by the resolver when a state changes it feeds us new addresses
func (f *FancyBalancer) UpdateSubConnState(sc balancer.SubConn, bc balancer.SubConnState)
EXPERIMENTAL: this is the new-style grpc callback
********** the builder for our balancer ****************
type FancyBuilder struct {
}
func (f *FancyBuilder) Build(cc balancer.ClientConn, opts balancer.BuildOptions) balancer.Balancer
Build creates a new balancer for the (new) ClientConn.
func (f *FancyBuilder) Name() string
Name returns the name of balancers built by this builder. It will be used to pick balancers (for example in service config).
func (f *FancyBuilder) ServiceName() string
type FancyPicker struct {
// contains filtered or unexported fields
}
func (f *FancyPicker) Pick(info balancer.PickInfo) (balancer.PickResult, error)
Pick returns the connection to use for this RPC and related information.
Pick should not block. If the balancer needs to do I/O or any blocking or time-consuming work to service this call, it should return ErrNoSubConnAvailable, and the Pick call will be repeated by gRPC when the Picker is updated (using ClientConn.UpdateState).
If an error is returned:
If the error is ErrNoSubConnAvailable, gRPC will block until a new Picker is provided by the balancer (using ClientConn.UpdateState).
If the error implements IsTransientFailure() bool, returning true, wait for ready RPCs will wait, but non-wait for ready RPCs will be terminated with this error's Error() string and status code Unavailable.
Any other errors terminate all RPCs with the code and message provided. If the error is not a status error, it will be converted by gRPC to a status error with code Unknown.
func (f *FancyPicker) ServiceName() string
type FancyResolver struct {
// contains filtered or unexported fields
}
func (f *FancyResolver) ActionResolve()
called sync by the resolver_thread
func (f *FancyResolver) Close()
func (f *FancyResolver) ResolveNow(opts resolver.ResolveNowOptions)
func (f *FancyResolver) ServiceName() string
type FancyResolverBuilder struct {
}
func (f *FancyResolverBuilder) Build(target resolver.Target, cc resolver.ClientConn, opts resolver.BuildOptions) (resolver.Resolver, error)
func (f *FancyResolverBuilder) Scheme() string
this scheme matches the url
func (f *FancyResolverBuilder) ServiceName() string
type ProxyTarget struct {
Target *pb.Target
// contains filtered or unexported fields
}
func GetProxyTarget(ctx context.Context, serviceid string) (*ProxyTarget, error)
func (p *ProxyTarget) Start(c net.Conn) error
send the initialisation sequence
type TargetList struct {
// contains filtered or unexported fields
}
func NewTargetList(servicename string) *TargetList
func (t *TargetList) ByAddress(address string) []*TargetWithConnection
func (t *TargetList) Connections() []*grpc.ClientConn
returns a connection to exactly one target
func (t *TargetList) Targets() []*TargetWithConnection
type TargetWithConnection struct {
// contains filtered or unexported fields
}
func (t *TargetWithConnection) Connection() *grpc.ClientConn
func (t *TargetWithConnection) String() string
| Name | Synopsis |
|---|---|
| .. | |
| stop-service | contains an example of how to use the /internal/ api of gRPC servers to shutdown a server gracefully. |