roxyresolver

package
v0.6.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 14, 2022 License: Apache-2.0 Imports: 36 Imported by: 0

Documentation

Overview

Package roxyresolver provides advanced implementations of gRPC-compatible address resolution strategies.

Index

Constants

View Source
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")
)
View Source
const (
	// 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")
)
View Source
const DefaultCooldownInterval = 30 * time.Second

DefaultCooldownInterval is the default value of CooldownInterval if not specified.

View Source
const DefaultPollInterval = 5 * time.Minute

DefaultPollInterval is the default value of PollInterval if not specified.

View Source
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

func GetATCClient(ctx context.Context) *atcclient.ATCClient

GetATCClient retrieves the attached ATC client.

func GetEtcdV3Client

func GetEtcdV3Client(ctx context.Context) *v3.Client

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 GetZKConn

func GetZKConn(ctx context.Context) *zk.Conn

GetZKConn retrieves the attached ZooKeeper client connection.

func Logger

func Logger() *zerolog.Logger

Logger returns the global logger to use for Resolver background threads.

func MapEtcdError

func MapEtcdError(err error) error

MapEtcdError converts an etcd.io-specific error to a generic error.

func MapZKError

func MapZKError(err error) error

MapZKError converts a ZooKeeper-specific error to a generic error.

func NewATCBalancerBuilder

func NewATCBalancerBuilder() balancer.Builder

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

func NewDNSBuilder(ctx context.Context, rng *rand.Rand, serviceConfigJSON string) resolver.Builder

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

func NewIPBuilder(rng *rand.Rand, serviceConfigJSON string) resolver.Builder

NewIPBuilder constructs a new gRPC resolver.Builder for the "ip" scheme.

func NewSRVBuilder

func NewSRVBuilder(ctx context.Context, rng *rand.Rand, serviceConfigJSON string) resolver.Builder

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 SetLogger

func SetLogger(logger zerolog.Logger)

SetLogger sets the global logger to use for Resolver background threads.

func WithATCClient

func WithATCClient(ctx context.Context, client *atcclient.ATCClient) context.Context

WithATCClient attaches an ATC client to the given context.

func WithEtcdV3Client

func WithEtcdV3Client(ctx context.Context, etcd *v3.Client) context.Context

WithEtcdV3Client attaches an etcd.io client to the given context.

func WithMembership

func WithMembership(addr resolver.Address, r *membership.Roxy) resolver.Address

WithMembership returns a copy of addr with the given *membership.Roxy attached.

func WithResolved

func WithResolved(addr resolver.Address, data Resolved) resolver.Address

WithResolved returns a copy of addr with the given Resolved attached.

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.

func WithZKConn

func WithZKConn(ctx context.Context, zkconn *zk.Conn) context.Context

WithZKConn attaches a ZooKeeper client connection to the given context.

Types

type ATCTarget added in v0.5.1

type ATCTarget struct {
	ServiceName    string
	ShardNumber    uint32
	HasShardNumber bool
	UniqueID       string
	Location       string
	ServerName     string
	Balancer       BalancerType
	CPS            float64
}

ATCTarget represents a parsed target spec for the "atc" scheme.

func (ATCTarget) AsTarget added in v0.5.1

func (t ATCTarget) AsTarget() Target

AsTarget recombines the component data into a Target.

func (*ATCTarget) FromTarget added in v0.5.1

func (t *ATCTarget) FromTarget(rt Target) error

FromTarget breaks apart a Target into component data.

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 (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 DNSTarget added in v0.5.1

type DNSTarget struct {
	ResolverAddr     *net.TCPAddr
	Host             string
	Port             string
	ServerName       string
	Balancer         BalancerType
	PollInterval     time.Duration
	CooldownInterval time.Duration
}

DNSTarget represents a parsed target spec for the "dns" scheme.

func (DNSTarget) AsTarget added in v0.5.1

func (t DNSTarget) AsTarget() Target

AsTarget recombines the component data into a Target.

func (*DNSTarget) FromTarget added in v0.5.1

func (t *DNSTarget) FromTarget(rt Target, defaultPort string) error

FromTarget breaks apart a Target into component data.

func (DNSTarget) NetResolver added in v0.5.1

func (t DNSTarget) NetResolver() *net.Resolver

NetResolver returns the appropriate *net.Resolver for this target.

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) IsHealthy

func (dynamic *Dynamic) IsHealthy() bool

IsHealthy returns true if this server is healthy.

func (*Dynamic) Update

func (dynamic *Dynamic) Update(opts UpdateOptions)

Update changes the status of this server.

type EtcdTarget added in v0.5.1

type EtcdTarget struct {
	Path       string
	Port       string
	ServerName string
	Balancer   BalancerType
}

EtcdTarget represents a parsed target spec for the "etcd" scheme.

func (EtcdTarget) AsTarget added in v0.5.1

func (t EtcdTarget) AsTarget() Target

AsTarget recombines the component data into a Target.

func (*EtcdTarget) FromTarget added in v0.5.1

func (t *EtcdTarget) FromTarget(rt Target) error

FromTarget breaks apart a Target into component data.

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.

func (Event) Check

func (event Event) Check()

Check verifies the data integrity of all fields.

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) GoString

func (t EventType) GoString() string

GoString returns the Go constant name.

func (EventType) MarshalJSON

func (t EventType) MarshalJSON() ([]byte, error)

MarshalJSON fulfills json.Marshaler.

func (*EventType) Parse

func (t *EventType) Parse(str string) error

Parse parses the string representation.

func (EventType) String

func (t EventType) String() string

String returns the string representation.

func (*EventType) UnmarshalJSON

func (t *EventType) UnmarshalJSON(raw []byte) error

UnmarshalJSON fulfills json.Unmarshaler.

type IPTarget added in v0.5.1

type IPTarget struct {
	Addrs      []*net.TCPAddr
	ServerName string
	Balancer   BalancerType
}

IPTarget represents a parsed target spec for the "ip" scheme.

func (IPTarget) AsTarget added in v0.5.1

func (t IPTarget) AsTarget() Target

AsTarget recombines the component data into a Target.

func (*IPTarget) FromTarget added in v0.5.1

func (t *IPTarget) FromTarget(rt Target, defaultPort string) error

FromTarget breaks apart a Target into component data.

type NodeDeletedError added in v0.4.7

type NodeDeletedError struct {
	Path string
}

NodeDeletedError indicates that a server is in a bad state.

func (NodeDeletedError) Error added in v0.4.7

func (err NodeDeletedError) Error() string

Error fulfills the error interface.

func (NodeDeletedError) Is added in v0.4.7

func (err NodeDeletedError) Is(other error) bool

Is returns true for fs.ErrNotExist.

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

type PollingResolveFunc func() ([]Resolved, error)

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, t DNSTarget) PollingResolveFunc

MakeDNSResolveFunc constructs a PollingResolveFunc for building your own custom PollingResolver with the "dns" scheme.

func MakeSRVResolveFunc

func MakeSRVResolveFunc(ctx context.Context, t SRVTarget) 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 ResolveError added in v0.4.7

type ResolveError struct {
	UniqueID string
	Err      error
}

ResolveError indicates a problem with a specific address.

func (ResolveError) Error added in v0.4.7

func (err ResolveError) Error() string

Error fulfills the error interface.

func (ResolveError) Unwrap added in v0.4.7

func (err ResolveError) Unwrap() error

Unwrap returns the underlying cause of this error.

type Resolved

type Resolved struct {
	// UniqueID is a stable unique identifier for this server.
	UniqueID 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

	// ShardNumber is the shard ID number.
	//
	// This field is only set by some resolvers.
	ShardNumber 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

	// HasShardNumber is true if ShardNumber is set.
	HasShardNumber 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

func GetResolved(addr resolver.Address) (data Resolved, ok bool)

GetResolved retrieves the attached Resolved.

func (Resolved) Check

func (data Resolved) Check()

Check verifies the data integrity of all fields.

func (Resolved) Equal

func (data Resolved) Equal(other Resolved) bool

Equal returns true iff the two Resolved addresses are identical.

func (Resolved) IsHealthy

func (data Resolved) IsHealthy() bool

IsHealthy returns true if this server is healthy.

type ResolvedList

type ResolvedList []Resolved

ResolvedList is a sorted list of Resolved addresses.

func (ResolvedList) Len

func (list ResolvedList) Len() int

Len fulfills sort.Interface.

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).

func (ResolvedList) Swap

func (list ResolvedList) Swap(i, j int)

Swap fulfills sort.Interface.

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 New

func New(opts Options) (Resolver, error)

New constructs a new Resolver.

func NewATCResolver

func NewATCResolver(opts Options) (Resolver, error)

NewATCResolver constructs a new Resolver for the "atc" scheme.

func NewDNSResolver

func NewDNSResolver(opts Options) (Resolver, error)

NewDNSResolver constructs a new Resolver for the "dns" scheme.

func NewEtcdResolver

func NewEtcdResolver(opts Options) (Resolver, error)

NewEtcdResolver constructs a new Resolver for the "etcd" scheme.

func NewIPResolver

func NewIPResolver(opts Options) (Resolver, error)

NewIPResolver constructs a new Resolver for the "ip" scheme.

func NewSRVResolver

func NewSRVResolver(opts Options) (Resolver, error)

NewSRVResolver constructs a new Resolver for the "srv" scheme.

func NewUnixResolver

func NewUnixResolver(opts Options) (Resolver, error)

NewUnixResolver constructs a new Resolver for the "unix" scheme.

func NewZKResolver

func NewZKResolver(opts Options) (Resolver, error)

NewZKResolver constructs a new Resolver for the "zk" scheme.

type SRVTarget added in v0.5.1

type SRVTarget struct {
	ResolverAddr     *net.TCPAddr
	Domain           string
	Service          string
	ServerName       string
	Balancer         BalancerType
	PollInterval     time.Duration
	CooldownInterval time.Duration
}

SRVTarget represents a parsed target spec for the "srv" scheme.

func (SRVTarget) AsTarget added in v0.5.1

func (t SRVTarget) AsTarget() Target

AsTarget recombines the component data into a Target.

func (*SRVTarget) FromTarget added in v0.5.1

func (t *SRVTarget) FromTarget(rt Target) error

FromTarget breaks apart a Target into component data.

func (SRVTarget) NetResolver added in v0.5.1

func (t SRVTarget) NetResolver() *net.Resolver

NetResolver returns the appropriate *net.Resolver for this target.

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

	// Query is a collection of key-value mappings.
	Query url.Values

	// ServerName is the suggested value for the
	// "crypto/tls".(*Config).ServerName field.
	//
	// It is filled in by Parse, FromGRPCTarget, or PostProcess.
	ServerName string

	// HasSlash is true if the string representation was originally of the
	// form "scheme://authority/endpoint?query", rather than
	// "scheme:endpoint?query".
	//
	// It is a Scheme-specific hint to PostProcess that a leading slash
	// before Endpoint can be inferred if necessary.
	HasSlash bool
}

Target represents a parsed Resolver target name.

func (Target) AppendTo added in v0.4.6

func (rt Target) AppendTo(out *strings.Builder)

AppendTo appends the string representation of this Target to the provided Builder.

func (Target) AsGRPCTarget added in v0.4.6

func (rt Target) AsGRPCTarget() resolver.Target

AsGRPCTarget converts this Target to an equivalent resolver.Target.

func (*Target) FromGRPCTarget added in v0.4.6

func (rt *Target) FromGRPCTarget(target resolver.Target) error

FromGRPCTarget tries to make this Target identical to the given resolver.Target.

func (Target) MarshalJSON added in v0.4.6

func (rt Target) MarshalJSON() ([]byte, error)

MarshalJSON fulfills json.Marshaler.

func (*Target) Parse added in v0.4.6

func (rt *Target) Parse(str string) error

Parse parses the given string representation.

func (*Target) PostProcess added in v0.4.7

func (rt *Target) PostProcess() error

PostProcess performs data integrity checks and input post-processing.

func (Target) String added in v0.4.6

func (rt Target) String() string

String returns the string representation of this Target.

func (*Target) UnmarshalJSON added in v0.4.6

func (rt *Target) UnmarshalJSON(raw []byte) error

UnmarshalJSON fulfills json.Unmarshaler.

type UnixTarget added in v0.5.1

type UnixTarget struct {
	Addr       *net.UnixAddr
	IsAbstract bool
	ServerName string
	Balancer   BalancerType
}

UnixTarget represents a parsed target spec for the "unix" or "unix-abstract" schemes.

func (UnixTarget) AsTarget added in v0.5.1

func (t UnixTarget) AsTarget() Target

AsTarget recombines the component data into a Target.

func (*UnixTarget) FromTarget added in v0.5.1

func (t *UnixTarget) FromTarget(rt Target) error

FromTarget breaks apart a Target into component data.

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 WatchID

type WatchID uint64

WatchID uniquely identifies a call to Resolver.Watch.

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, t ATCTarget) WatchingResolveFunc

MakeATCResolveFunc constructs a WatchingResolveFunc for building your own custom WatchingResolver with the "atc" scheme.

func MakeEtcdResolveFunc

func MakeEtcdResolveFunc(etcdClient *v3.Client, t EtcdTarget) WatchingResolveFunc

MakeEtcdResolveFunc constructs a WatchingResolveFunc for building your own custom WatchingResolver with the "etcd" scheme.

func MakeZKResolveFunc

func MakeZKResolveFunc(zkConn *zk.Conn, t ZKTarget) 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.

type ZKTarget added in v0.5.1

type ZKTarget struct {
	Path       string
	Port       string
	ServerName string
	Balancer   BalancerType
}

ZKTarget represents a parsed target spec for the "zk" scheme.

func (ZKTarget) AsTarget added in v0.5.1

func (t ZKTarget) AsTarget() Target

AsTarget recombines the component data into a Target.

func (*ZKTarget) FromTarget added in v0.5.1

func (t *ZKTarget) FromTarget(rt Target) error

FromTarget breaks apart a Target into component data.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL