Documentation ¶
Overview ¶
Package roxyresolver provides advanced implementations of gRPC-compatible address resolution strategies.
Index ¶
- Constants
- func EnableCheck()
- func GetATCClient(ctx context.Context) *atcclient.ATCClient
- func GetEtcdV3Client(ctx context.Context) *v3.Client
- func GetMembership(addr resolver.Address) *membership.Roxy
- func GetShardID(ctx context.Context) (shardID int32, ok bool)
- func GetZKConn(ctx context.Context) *zk.Conn
- func Logger() *zerolog.Logger
- func MapEtcdError(err error) error
- func MapZKError(err error) error
- func NewATCBalancerBuilder() balancer.Builder
- func NewATCBuilder(ctx context.Context, rng *rand.Rand, client *atcclient.ATCClient) resolver.Builder
- func NewDNSBuilder(ctx context.Context, rng *rand.Rand, serviceConfigJSON string) resolver.Builder
- func NewEtcdBuilder(ctx context.Context, rng *rand.Rand, etcd *v3.Client, serviceConfigJSON string) resolver.Builder
- func NewIPBuilder(rng *rand.Rand, serviceConfigJSON string) resolver.Builder
- func NewSRVBuilder(ctx context.Context, rng *rand.Rand, serviceConfigJSON string) resolver.Builder
- func NewZKBuilder(ctx context.Context, rng *rand.Rand, zkconn *zk.Conn, serviceConfigJSON string) resolver.Builder
- func SetLogger(logger zerolog.Logger)
- func WithATCClient(ctx context.Context, client *atcclient.ATCClient) context.Context
- func WithEtcdV3Client(ctx context.Context, etcd *v3.Client) context.Context
- func WithMembership(addr resolver.Address, r *membership.Roxy) resolver.Address
- func WithResolved(addr resolver.Address, data Resolved) resolver.Address
- func WithShardID(ctx context.Context, shardID int32) context.Context
- func WithStandardResolvers(ctx context.Context) grpc.DialOption
- func WithZKConn(ctx context.Context, zkconn *zk.Conn) context.Context
- type BalancerType
- func ParseATCTarget(rt Target) (lbName, lbLocation, lbUnique string, balancer BalancerType, isDSC bool, ...)
- func ParseDNSTarget(rt Target, defaultPort string) (res *net.Resolver, host string, port string, balancer BalancerType, ...)
- func ParseEtcdTarget(rt Target) (etcdPath string, etcdPort string, balancer BalancerType, serverName string, ...)
- func ParseIPTarget(rt Target, defaultPort string) (tcpAddrs []*net.TCPAddr, balancer BalancerType, serverName string, err error)
- func ParseSRVTarget(rt Target) (res *net.Resolver, name string, service string, balancer BalancerType, ...)
- func ParseUnixTarget(rt Target) (unixAddr *net.UnixAddr, balancer BalancerType, serverName string, err error)
- func ParseZKTarget(rt Target) (zkPath string, zkPort string, balancer BalancerType, serverName string, ...)
- type Dynamic
- type Event
- type EventType
- type Options
- type PollingResolveFunc
- type PollingResolver
- func (res *PollingResolver) CancelWatch(id WatchID)
- func (res *PollingResolver) Close()
- func (res *PollingResolver) Err() error
- func (res *PollingResolver) Resolve() (Resolved, error)
- func (res *PollingResolver) ResolveAll() ([]Resolved, error)
- func (res *PollingResolver) ResolveNow(opts resolver.ResolveNowOptions)
- func (res *PollingResolver) Update(opts UpdateOptions)
- func (res *PollingResolver) Watch(fn WatchFunc) WatchID
- type PollingResolverOptions
- type Resolved
- type ResolvedList
- type Resolver
- func New(opts Options) (Resolver, error)
- func NewATCResolver(opts Options) (Resolver, error)
- func NewDNSResolver(opts Options) (Resolver, error)
- func NewEtcdResolver(opts Options) (Resolver, error)
- func NewIPResolver(opts Options) (Resolver, error)
- func NewSRVResolver(opts Options) (Resolver, error)
- func NewUnixResolver(opts Options) (Resolver, error)
- func NewZKResolver(opts Options) (Resolver, error)
- type StaticResolver
- func (res *StaticResolver) CancelWatch(id WatchID)
- func (res *StaticResolver) Close()
- func (res *StaticResolver) Err() error
- func (res *StaticResolver) Resolve() (Resolved, error)
- func (res *StaticResolver) ResolveAll() ([]Resolved, error)
- func (res *StaticResolver) ResolveNow(opts resolver.ResolveNowOptions)
- func (res *StaticResolver) Update(opts UpdateOptions)
- func (res *StaticResolver) Watch(fn WatchFunc) WatchID
- type StaticResolverOptions
- type StatusError
- type Target
- func (rt Target) AppendTo(out *strings.Builder)
- func (rt Target) AsGRPCTarget() resolver.Target
- func (rt *Target) FromGRPCTarget(target resolver.Target) error
- func (rt Target) MarshalJSON() ([]byte, error)
- func (rt *Target) Parse(str string) error
- func (rt Target) String() string
- func (rt *Target) UnmarshalJSON(raw []byte) error
- type UpdateOptions
- type WatchFunc
- type WatchID
- type WatchingResolveFunc
- func MakeATCResolveFunc(client *atcclient.ATCClient, lbName, lbLocation, lbUnique string, dsc bool, ...) WatchingResolveFunc
- func MakeEtcdResolveFunc(etcdClient *v3.Client, etcdPath string, etcdPort string, serverName string) WatchingResolveFunc
- func MakeZKResolveFunc(zkconn *zk.Conn, zkPath string, zkPort string, serverName string) WatchingResolveFunc
- type WatchingResolver
- func (res *WatchingResolver) CancelWatch(id WatchID)
- func (res *WatchingResolver) Close()
- func (res *WatchingResolver) Err() error
- func (res *WatchingResolver) Resolve() (Resolved, error)
- func (res *WatchingResolver) ResolveAll() ([]Resolved, error)
- func (res *WatchingResolver) ResolveNow(opts resolver.ResolveNowOptions)
- func (res *WatchingResolver) Update(opts UpdateOptions)
- func (res *WatchingResolver) Watch(fn WatchFunc) WatchID
- type WatchingResolverOptions
Constants ¶
const ( // MembershipAttrKey is the gRPC attributes.Attributes key for // retrieving the original *membership.Roxy, if any. MembershipAttrKey = attrKey("roxy.Membership") // ResolvedAttrKey is the gRPC attributes.Attributes key for retrieving // the Resolved address. ResolvedAttrKey = attrKey("roxy.Resolved") )
const ( // ShardIDContextKey is the context.Context key for attaching a shard ID. ShardIDContextKey = contextKey("roxy.ShardID") // ZKConnContextKey is the context.Context key for attaching a *zk.Conn. ZKConnContextKey = contextKey("roxy.zk.Conn") // V3ClientContextKey is the context.Context key for attaching an etcd.io *v3.Client. V3ClientContextKey = contextKey("roxy.etcd.V3Client") // ATCClientContextKey is the context.Context key for attaching an *atcclient.ATCClient. ATCClientContextKey = contextKey("roxy.atc.Client") )
const DefaultCooldownInterval = 30 * time.Second
DefaultCooldownInterval is the default value of CooldownInterval if not specified.
const DefaultPollInterval = 5 * time.Minute
DefaultPollInterval is the default value of PollInterval if not specified.
const MaxPollInterval = 24 * time.Hour
MaxPollInterval is the maximum permitted value of PollInterval.
Variables ¶
This section is empty.
Functions ¶
func EnableCheck ¶
func EnableCheck()
EnableCheck enables performance-degrading data integrity checks. Meant only for internal use.
func GetATCClient ¶
GetATCClient retrieves the attached ATC client.
func GetEtcdV3Client ¶
GetEtcdV3Client retrieves the attached etcd.io client.
func GetMembership ¶
func GetMembership(addr resolver.Address) *membership.Roxy
GetMembership retrieves the attached *membership.Roxy, or nil if none attached.
func GetShardID ¶
GetShardID retrieves the attached shard ID.
func MapEtcdError ¶
MapEtcdError converts an etcd.io-specific error to a generic error.
func MapZKError ¶
MapZKError converts a ZooKeeper-specific error to a generic error.
func NewATCBalancerBuilder ¶
NewATCBalancerBuilder returns a gRPC balancer.Builder for the ATC load balancing algorithm.
func NewATCBuilder ¶
func NewATCBuilder(ctx context.Context, rng *rand.Rand, client *atcclient.ATCClient) resolver.Builder
NewATCBuilder constructs a new gRPC resolver.Builder for the "atc" scheme.
func NewDNSBuilder ¶
NewDNSBuilder constructs a new gRPC resolver.Builder for the "dns" scheme.
func NewEtcdBuilder ¶
func NewEtcdBuilder(ctx context.Context, rng *rand.Rand, etcd *v3.Client, serviceConfigJSON string) resolver.Builder
NewEtcdBuilder constructs a new gRPC resolver.Builder for the "etcd" scheme.
func NewIPBuilder ¶
NewIPBuilder constructs a new gRPC resolver.Builder for the "ip" scheme.
func NewSRVBuilder ¶
NewSRVBuilder constructs a new gRPC resolver.Builder for the "srv" scheme.
func NewZKBuilder ¶
func NewZKBuilder(ctx context.Context, rng *rand.Rand, zkconn *zk.Conn, serviceConfigJSON string) resolver.Builder
NewZKBuilder constructs a new gRPC resolver.Builder for the "zk" scheme.
func WithATCClient ¶
WithATCClient attaches an ATC client to the given context.
func WithEtcdV3Client ¶
WithEtcdV3Client attaches an etcd.io client to the given context.
func WithMembership ¶
WithMembership returns a copy of addr with the given *membership.Roxy attached.
func WithResolved ¶
WithResolved returns a copy of addr with the given Resolved attached.
func WithShardID ¶
WithShardID attaches a shard ID to the given context.
func WithStandardResolvers ¶
func WithStandardResolvers(ctx context.Context) grpc.DialOption
WithStandardResolvers returns a gRPC DialOption that enables as many Target schemes as possible on the gRPC ClientConn being created.
Types ¶
type BalancerType ¶
type BalancerType uint8
BalancerType indicates which load balancer algorithm is in use.
const ( // RandomBalancer chooses an address with uniform probability. RandomBalancer BalancerType = iota // RoundRobinBalancer chooses an address from a random permutation. // The permutation changes each time an address is added, changed, or // deleted. RoundRobinBalancer // WeightedRandomBalancer chooses an address with weighted probability. WeightedRandomBalancer // WeightedRoundRobinBalancer chooses an address from a random shuffle // that has zero or more copies of each address, each in proportion to // that address's weight. The shuffle changes each time an address is // added, changed, or deleted. WeightedRoundRobinBalancer // SRVBalancer chooses an address using the rules for DNS SRV records. SRVBalancer )
func ParseATCTarget ¶
func ParseATCTarget(rt Target) (lbName, lbLocation, lbUnique string, balancer BalancerType, isDSC bool, serverName string, err error)
ParseATCTarget breaks apart a Target into component data.
func ParseDNSTarget ¶
func ParseDNSTarget(rt Target, defaultPort string) (res *net.Resolver, host string, port string, balancer BalancerType, pollInterval time.Duration, cdInterval time.Duration, serverName string, err error)
ParseDNSTarget breaks apart a Target into component data.
func ParseEtcdTarget ¶
func ParseEtcdTarget(rt Target) (etcdPath string, etcdPort string, balancer BalancerType, serverName string, err error)
ParseEtcdTarget breaks apart a Target into component data.
func ParseIPTarget ¶
func ParseIPTarget(rt Target, defaultPort string) (tcpAddrs []*net.TCPAddr, balancer BalancerType, serverName string, err error)
ParseIPTarget breaks apart a Target into component data.
func ParseSRVTarget ¶
func ParseSRVTarget(rt Target) (res *net.Resolver, name string, service string, balancer BalancerType, pollInterval time.Duration, cdInterval time.Duration, serverName string, err error)
ParseSRVTarget breaks apart a Target into component data.
func ParseUnixTarget ¶
func ParseUnixTarget(rt Target) (unixAddr *net.UnixAddr, balancer BalancerType, serverName string, err error)
ParseUnixTarget breaks apart a Target into component data.
func ParseZKTarget ¶
func ParseZKTarget(rt Target) (zkPath string, zkPort string, balancer BalancerType, serverName string, err error)
ParseZKTarget breaks apart a Target into component data.
func (BalancerType) GoString ¶
func (t BalancerType) GoString() string
GoString returns the Go constant name.
func (BalancerType) MarshalJSON ¶
func (t BalancerType) MarshalJSON() ([]byte, error)
MarshalJSON fulfills json.Marshaler.
func (*BalancerType) Parse ¶
func (t *BalancerType) Parse(str string) error
Parse parses the string representation.
func (BalancerType) String ¶
func (t BalancerType) String() string
String returns the string representation.
func (*BalancerType) UnmarshalJSON ¶
func (t *BalancerType) UnmarshalJSON(raw []byte) error
UnmarshalJSON fulfills json.Unmarshaler.
type Dynamic ¶
type Dynamic struct {
// contains filtered or unexported fields
}
Dynamic represents the mutable, mutex-protected data associated with one or more Resolved addresses.
func (*Dynamic) Update ¶
func (dynamic *Dynamic) Update(opts UpdateOptions)
Update changes the status of this server.
type Event ¶
type Event struct { // Type is the type of event, i.e. which data has changed. Type EventType // Err is the global error. // // Valid for: ErrorEvent. Err error // Key is the unique identifier for this address. // // Valid for: UpdateEvent, DeleteEvent, BadDataEvent, StatusChangeEvent. Key string // Data is the resolved address data. // // Valid for: UpdateEvent, StatusChangeEvent. Data Resolved // ServiceConfigJSON is the new gRPC service config. // // Valid for: NewServiceConfigEvent. ServiceConfigJSON string }
Event represents the Resolver state changes triggered by some event.
type EventType ¶
type EventType uint8
EventType indicates the type of an Event.
const ( // NoOpEvent is an Event with no data. NoOpEvent EventType = iota // ErrorEvent is an Event with a global error. ErrorEvent // UpdateEvent is an Event with a new or changed address. UpdateEvent // DeleteEvent is an Event with a deleted address. DeleteEvent // BadDataEvent is an Event with an erroneous address. BadDataEvent // StatusChangeEvent is an Event with an address whose metadata has // changed. StatusChangeEvent // NewServiceConfigEvent is an Event with a new gRPC service config. NewServiceConfigEvent )
func (EventType) MarshalJSON ¶
MarshalJSON fulfills json.Marshaler.
func (*EventType) UnmarshalJSON ¶
UnmarshalJSON fulfills json.Unmarshaler.
type Options ¶
type Options struct { // Context is the context within which the resolver runs. If this // context is cancelled or reaches its deadline, the resolver will // stop. // // This field is mandatory. Context context.Context // Random is the source of randomness for balancer algorithms that need // one. // // If provided, it MUST be thread-safe; see the syncrand package for // more information. If nil, the syncrand.Global() instance will be // used. Random *rand.Rand // Target is the resolve target. The target's Scheme field determines // which Resolver implementation will be used. // // This field is mandatory. Target Target // IsTLS should be set to true iff the consumer of the resolved // addresses will be using TLS to communicate with them. It is used // for automatic port guessing. IsTLS bool }
Options holds options related to constructing a new Resolver.
type PollingResolveFunc ¶
PollingResolveFunc represents a closure that will be called periodically to resolve addresses. It will be called at least once every PollInterval, and no less than CooldownInterval will pass between calls.
func MakeDNSResolveFunc ¶
func MakeDNSResolveFunc(ctx context.Context, res *net.Resolver, host string, port string, serverName string) PollingResolveFunc
MakeDNSResolveFunc constructs a PollingResolveFunc for building your own custom PollingResolver with the "dns" scheme.
func MakeSRVResolveFunc ¶
func MakeSRVResolveFunc(ctx context.Context, res *net.Resolver, name string, service string, serverName string) PollingResolveFunc
MakeSRVResolveFunc constructs a PollingResolveFunc for building your own custom PollingResolver with the "srv" scheme.
type PollingResolver ¶
type PollingResolver struct {
// contains filtered or unexported fields
}
PollingResolver is an implementation of the Resolver interface that periodically polls for record changes.
func NewPollingResolver ¶
func NewPollingResolver(opts PollingResolverOptions) (*PollingResolver, error)
NewPollingResolver constructs a new PollingResolver.
func (*PollingResolver) CancelWatch ¶
func (res *PollingResolver) CancelWatch(id WatchID)
CancelWatch cancels a previous call to Watch.
func (*PollingResolver) Close ¶
func (res *PollingResolver) Close()
Close stops the resolver and frees all resources.
func (*PollingResolver) Err ¶
func (res *PollingResolver) Err() error
Err returns any errors encountered since the last call to Err or ResolveAll.
func (*PollingResolver) Resolve ¶
func (res *PollingResolver) Resolve() (Resolved, error)
Resolve returns the resolved address of a healthy backend, if one is available, or else returns the error that prevented it from doing so.
func (*PollingResolver) ResolveAll ¶
func (res *PollingResolver) ResolveAll() ([]Resolved, error)
ResolveAll returns all resolved addresses, plus any errors encountered since the last call to Err or ResolveAll.
func (*PollingResolver) ResolveNow ¶
func (res *PollingResolver) ResolveNow(opts resolver.ResolveNowOptions)
ResolveNow forces a poll immediately, or as soon as possible if an immediate poll would violate the CooldownInterval.
func (*PollingResolver) Update ¶
func (res *PollingResolver) Update(opts UpdateOptions)
Update changes the status of a server.
func (*PollingResolver) Watch ¶
func (res *PollingResolver) Watch(fn WatchFunc) WatchID
Watch registers a WatchFunc. The WatchFunc will be called immediately with synthetic events for each resolved address currently known, plus it will be called whenever the Resolver's state changes.
type PollingResolverOptions ¶
type PollingResolverOptions struct { // Context is the context within which the resolver runs. If this // context is cancelled or reaches its deadline, the resolver will // stop. // // This field is mandatory. Context context.Context // Random is the source of randomness for balancer algorithms that need // one. // // If provided, it MUST be thread-safe; see the syncrand package for // more information. If nil, the syncrand.Global() instance will be // used. Random *rand.Rand // PollInterval is the interval between automatic calls to ResolveFunc. // If zero, DefaultPollInterval is used. If negative, MaxPollInterval // is used. PollInterval time.Duration // CooldownInterval is the minimum interval between calls to // ResolveFunc, whether automatic or triggered by ResolveNow. If zero, // DefaultCooldownInterval is used. If negative, the final value of // PollInterval is used. CooldownInterval time.Duration // Balancer selects which load balancer algorithm to use. Balancer BalancerType // ResolveFunc will be called periodically to resolve addresses. // // This field is mandatory. ResolveFunc PollingResolveFunc // ClientConn is a gRPC ClientConn that will receive state updates. ClientConn resolver.ClientConn // ServiceConfigJSON is the gRPC Service Config which will be provided // to ClientConn on each state update. ServiceConfigJSON string }
PollingResolverOptions holds options related to constructing a new PollingResolver.
type Resolved ¶
type Resolved struct { // Unique is a stable unique identifier for this server. Unique string // Location is a string denoting the geographic location of this server. // // This field is only set by the ATC resolver. Location string // ServerName is either the empty string or the recommended value of // the "crypto/tls".(*Config).ServerName field. ServerName string // SRVPriority is the priority field of this SRV record. // // This field is only set by the SRV resolver. SRVPriority uint16 // SRVWeight is the weight field of this SRV record. // // This field is only set by the SRV resolver. SRVWeight uint16 // ShardID is the shard ID number. // // This field is only set by some resolvers. ShardID uint32 // Weight is the proportional weight for this server. // // This field is only set by some resolvers. Weight float32 // HasSRV is true if both SRVPriority and SRVWeight are set. HasSRV bool // HasShardID is true if ShardID is set. HasShardID bool // HasWeight is true if Weight is set. HasWeight bool // Err is the error encountered while resolving this server's address. Err error // Addr is the address of this server. Addr net.Addr // Address is the address of this server, in gRPC format. Address resolver.Address // Dynamic points to mutable, mutex-protected data associated with this // server. Two Resolved addresses can share the same *Dynamic if they // point to the same server (e.g. have the same IP address). Dynamic *Dynamic }
Resolved represents a resolved address.
func GetResolved ¶
GetResolved retrieves the attached Resolved.
func (Resolved) Check ¶
func (data Resolved) Check()
Check verifies the data integrity of all fields.
type ResolvedList ¶
type ResolvedList []Resolved
ResolvedList is a sorted list of Resolved addresses.
func (ResolvedList) Less ¶
func (list ResolvedList) Less(i, j int) bool
Less fulfills sort.Interface.
func (ResolvedList) Sort ¶
func (list ResolvedList) Sort()
Sort is a convenience method for sort.Sort(list).
type Resolver ¶
type Resolver interface { // Err returns any errors encountered since the last call to Err or // ResolveAll. Err() error // ResolveAll returns all resolved addresses, plus any errors // encountered since the last call to Err or ResolveAll. ResolveAll() ([]Resolved, error) // Resolve returns the resolved address of a healthy backend, if one is // available, or else returns the error that prevented it from doing // so. Resolve() (Resolved, error) // Update changes the status of a server. Update(opts UpdateOptions) // Watch registers a WatchFunc. The WatchFunc will be called // immediately with synthetic events for each resolved address // currently known, plus it will be called whenever the Resolver's // state changes. Watch(WatchFunc) WatchID // CancelWatch cancels a previous call to Watch. CancelWatch(WatchID) // ResolveNow requests that the resolver issue a re-resolve poll ASAP, // if that makes sense for the particular Resolver implementation. ResolveNow(resolver.ResolveNowOptions) // Close stops the resolver and frees all resources. Close() }
Resolver is an interface for obtaining resolved addresses and/or watching for address resolution changes.
func NewATCResolver ¶
NewATCResolver constructs a new Resolver for the "atc" scheme.
func NewDNSResolver ¶
NewDNSResolver constructs a new Resolver for the "dns" scheme.
func NewEtcdResolver ¶
NewEtcdResolver constructs a new Resolver for the "etcd" scheme.
func NewIPResolver ¶
NewIPResolver constructs a new Resolver for the "ip" scheme.
func NewSRVResolver ¶
NewSRVResolver constructs a new Resolver for the "srv" scheme.
func NewUnixResolver ¶
NewUnixResolver constructs a new Resolver for the "unix" scheme.
func NewZKResolver ¶
NewZKResolver constructs a new Resolver for the "zk" scheme.
type StaticResolver ¶
type StaticResolver struct {
// contains filtered or unexported fields
}
StaticResolver is an implementation of the Resolver interface that returns the same static records every time.
func NewStaticResolver ¶
func NewStaticResolver(opts StaticResolverOptions) (*StaticResolver, error)
NewStaticResolver constructs a new StaticResolver.
func (*StaticResolver) CancelWatch ¶
func (res *StaticResolver) CancelWatch(id WatchID)
CancelWatch cancels a previous call to Watch.
func (*StaticResolver) Close ¶
func (res *StaticResolver) Close()
Close stops the resolver and frees all resources.
func (*StaticResolver) Err ¶
func (res *StaticResolver) Err() error
Err returns any errors encountered since the last call to Err or ResolveAll.
func (*StaticResolver) Resolve ¶
func (res *StaticResolver) Resolve() (Resolved, error)
Resolve returns the resolved address of a healthy backend, if one is available, or else returns the error that prevented it from doing so.
func (*StaticResolver) ResolveAll ¶
func (res *StaticResolver) ResolveAll() ([]Resolved, error)
ResolveAll returns all resolved addresses, plus any errors encountered since the last call to Err or ResolveAll.
func (*StaticResolver) ResolveNow ¶
func (res *StaticResolver) ResolveNow(opts resolver.ResolveNowOptions)
ResolveNow is a no-op.
func (*StaticResolver) Update ¶
func (res *StaticResolver) Update(opts UpdateOptions)
Update changes the status of a server.
func (*StaticResolver) Watch ¶
func (res *StaticResolver) Watch(fn WatchFunc) WatchID
Watch registers a WatchFunc. The WatchFunc will be called immediately with synthetic events for each resolved address currently known, plus it will be called whenever the Resolver's state changes.
type StaticResolverOptions ¶
type StaticResolverOptions struct { // Records lists the Resolved addresses for this resolver to return. Records []Resolved // Random is the source of randomness for balancer algorithms that need // one. // // If provided, it MUST be thread-safe; see the syncrand package for // more information. If nil, the syncrand.Global() instance will be // used. Random *rand.Rand // Balancer selects which load balancer algorithm to use. Balancer BalancerType // ClientConn is a gRPC ClientConn that will receive state updates. ClientConn resolver.ClientConn // ServiceConfigJSON is the gRPC Service Config which will be provided // to ClientConn on each state update. ServiceConfigJSON string }
StaticResolverOptions holds options related to constructing a new StaticResolver.
type StatusError ¶ added in v0.4.6
type StatusError struct {
Status membership.ServerSetStatus
}
StatusError indicates that a server is in a bad state.
func (StatusError) Error ¶ added in v0.4.6
func (err StatusError) Error() string
Error fulfills the error interface.
func (StatusError) Is ¶ added in v0.4.6
func (err StatusError) Is(other error) bool
Is returns true for fs.ErrNotExist.
type Target ¶
type Target struct { // Scheme indicates which Resolver implementation to use. // // If not specified, "dns" is assumed. Scheme string // Authority provides information about which server to query to do the // resolving. // // Most schemes do not permit the Authority field to be specified. Authority string // Endpoint provides information about which name to resolve. // // This field is mandatory. Endpoint string // ServerName is the value to use for the // "crypto/tls".(*Config).ServerName field. ServerName string // Query is a collection of key-value mappings. Query url.Values }
Target represents a parsed Resolver target name.
func (Target) AppendTo ¶ added in v0.4.6
AppendTo appends the string representation of this Target to the provided Builder.
func (Target) AsGRPCTarget ¶ added in v0.4.6
AsGRPCTarget converts this Target to an equivalent resolver.Target.
func (*Target) FromGRPCTarget ¶ added in v0.4.6
FromGRPCTarget tries to make this Target identical to the given resolver.Target.
func (Target) MarshalJSON ¶ added in v0.4.6
MarshalJSON fulfills json.Marshaler.
func (*Target) UnmarshalJSON ¶ added in v0.4.6
UnmarshalJSON fulfills json.Unmarshaler.
type UpdateOptions ¶
type UpdateOptions struct { // Addr is the address of the server to act upon. Addr net.Addr // HasHealthy is true if Healthy has a value. HasHealthy bool // Healthy is true if the server is ready to serve, false if it is not. Healthy bool }
UpdateOptions holds options for the Resolver.Update method.
type WatchFunc ¶
type WatchFunc func([]Event)
WatchFunc denotes a callback which will be called whenever a Resolver's state changes.
type WatchingResolveFunc ¶
type WatchingResolveFunc func(ctx context.Context, wg *sync.WaitGroup, backoff expbackoff.ExpBackoff) (<-chan []Event, error)
WatchingResolveFunc represents a closure that will be called as needed to start a resolver subscription. If it spawns any goroutines, they should register themselves with the provided WaitGroup. If it needs to retry any external I/O, it should use the provided ExpBackoff.
func MakeATCResolveFunc ¶
func MakeATCResolveFunc(client *atcclient.ATCClient, lbName, lbLocation, lbUnique string, dsc bool, serverName string) WatchingResolveFunc
MakeATCResolveFunc constructs a WatchingResolveFunc for building your own custom WatchingResolver with the "atc" scheme.
func MakeEtcdResolveFunc ¶
func MakeEtcdResolveFunc(etcdClient *v3.Client, etcdPath string, etcdPort string, serverName string) WatchingResolveFunc
MakeEtcdResolveFunc constructs a WatchingResolveFunc for building your own custom WatchingResolver with the "etcd" scheme.
func MakeZKResolveFunc ¶
func MakeZKResolveFunc(zkconn *zk.Conn, zkPath string, zkPort string, serverName string) WatchingResolveFunc
MakeZKResolveFunc constructs a WatchingResolveFunc for building your own custom WatchingResolver with the "zk" scheme.
type WatchingResolver ¶
type WatchingResolver struct {
// contains filtered or unexported fields
}
WatchingResolver is an implementation of the Resolver interface that subscribes to an event-oriented resolution source.
func NewWatchingResolver ¶
func NewWatchingResolver(opts WatchingResolverOptions) (*WatchingResolver, error)
NewWatchingResolver constructs a new WatchingResolver.
func (*WatchingResolver) CancelWatch ¶
func (res *WatchingResolver) CancelWatch(id WatchID)
CancelWatch cancels a previous call to Watch.
func (*WatchingResolver) Close ¶
func (res *WatchingResolver) Close()
Close stops the resolver and frees all resources.
func (*WatchingResolver) Err ¶
func (res *WatchingResolver) Err() error
Err returns any errors encountered since the last call to Err or ResolveAll.
func (*WatchingResolver) Resolve ¶
func (res *WatchingResolver) Resolve() (Resolved, error)
Resolve returns the resolved address of a healthy backend, if one is available, or else returns the error that prevented it from doing so.
func (*WatchingResolver) ResolveAll ¶
func (res *WatchingResolver) ResolveAll() ([]Resolved, error)
ResolveAll returns all resolved addresses, plus any errors encountered since the last call to Err or ResolveAll.
func (*WatchingResolver) ResolveNow ¶
func (res *WatchingResolver) ResolveNow(opts resolver.ResolveNowOptions)
ResolveNow is a no-op.
func (*WatchingResolver) Update ¶
func (res *WatchingResolver) Update(opts UpdateOptions)
Update changes the status of a server.
func (*WatchingResolver) Watch ¶
func (res *WatchingResolver) Watch(fn WatchFunc) WatchID
Watch registers a WatchFunc. The WatchFunc will be called immediately with synthetic events for each resolved address currently known, plus it will be called whenever the Resolver's state changes.
type WatchingResolverOptions ¶
type WatchingResolverOptions struct { // Context is the context within which the resolver runs. If this // context is cancelled or reaches its deadline, the resolver will // stop. // // This field is mandatory. Context context.Context // Random is the source of randomness for balancer algorithms that need // one. // // If provided, it MUST be thread-safe; see the syncrand package for // more information. If nil, the syncrand.Global() instance will be // used. Random *rand.Rand // Balancer selects which load balancer algorithm to use. Balancer BalancerType // ResolveFunc will be called as needed to (re)start the event stream. // // This field is mandatory. ResolveFunc WatchingResolveFunc // ClientConn is a gRPC ClientConn that will receive state updates. ClientConn resolver.ClientConn // ServiceConfigJSON is the gRPC Service Config which will be provided // to ClientConn on each state update. ServiceConfigJSON string }
WatchingResolverOptions holds options related to constructing a new WatchingResolver.
Source Files ¶
- attributes.go
- balancer.go
- balancer_atc.go
- context.go
- dialopts.go
- doc.go
- enums.go
- errors.go
- globals.go
- impl_polling.go
- impl_static.go
- impl_watching.go
- parse.go
- resolver.go
- roxytarget.go
- scheme_atc.go
- scheme_dns.go
- scheme_etcd.go
- scheme_ip.go
- scheme_srv.go
- scheme_unix.go
- scheme_zk.go
- sort.go
- struct_event.go
- struct_resolved.go
- util.go