roxyresolver

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: May 13, 2021 License: Apache-2.0 Imports: 34 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MembershipAttrKey = attrKey("roxy.Membership")
	ResolvedAttrKey   = attrKey("roxy.Resolved")
)
View Source
const (
	ShardIDContextKey   = contextKey("roxy.ShardID")
	ZKConnContextKey    = contextKey("roxy.zk.Conn")
	V3ClientContextKey  = contextKey("roxy.etcd.V3Client")
	ATCClientContextKey = contextKey("roxy.atc.Client")
)
View Source
const (
	MaxPollInterval         = 24 * time.Hour
	DefaultPollInterval     = 5 * time.Minute
	DefaultCooldownInterval = 30 * time.Second
)

Variables

This section is empty.

Functions

func EnableCheck

func EnableCheck()

func GetATCClient

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

func GetEtcdV3Client

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

func GetMembership

func GetMembership(addr Address) *membership.Roxy

func GetShardID

func GetShardID(ctx context.Context) (shardID int32, ok bool)

func GetZKConn

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

func Logger

func Logger() *zerolog.Logger

func MapEtcdError

func MapEtcdError(err error) error

func MapZKError

func MapZKError(err error) error

func NewATCBalancerBuilder

func NewATCBalancerBuilder() balancer.Builder

func NewATCBuilder

func NewATCBuilder(ctx context.Context, rng *rand.Rand, client *atcclient.ATCClient) grpcresolver.Builder

func NewDNSBuilder

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

func NewEtcdBuilder

func NewEtcdBuilder(ctx context.Context, rng *rand.Rand, etcd *v3.Client, serviceConfigJSON string) grpcresolver.Builder

func NewIPBuilder

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

func NewSRVBuilder

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

func NewZKBuilder

func NewZKBuilder(ctx context.Context, rng *rand.Rand, zkconn *zk.Conn, serviceConfigJSON string) grpcresolver.Builder

func SetLogger

func SetLogger(logger zerolog.Logger)

func WithATCClient

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

func WithEtcdV3Client

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

func WithShardID

func WithShardID(ctx context.Context, shardID int32) context.Context

func WithStandardResolvers

func WithStandardResolvers(ctx context.Context) grpc.DialOption

func WithZKConn

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

Types

type Address

type Address = grpcresolver.Address

func WithMembership

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

func WithResolved

func WithResolved(addr Address, data Resolved) Address

type BadStatusError

type BadStatusError struct {
	Status membership.ServerSetStatus
}

func (BadStatusError) Error

func (err BadStatusError) Error() string

func (BadStatusError) Is

func (err BadStatusError) Is(other error) bool

type BalancerType

type BalancerType uint8
const (
	RandomBalancer BalancerType = iota
	RoundRobinBalancer
	LeastLoadedBalancer
	SRVBalancer
	WeightedRandomBalancer
	WeightedRoundRobinBalancer
)

func ParseATCTarget

func ParseATCTarget(rt RoxyTarget) (lbName, lbLocation, lbUnique string, balancer BalancerType, isDSC bool, serverName string, err error)

func ParseDNSTarget

func ParseDNSTarget(rt RoxyTarget, defaultPort string) (res *net.Resolver, host string, port string, balancer BalancerType, pollInterval time.Duration, cdInterval time.Duration, serverName string, err error)

func ParseEtcdTarget

func ParseEtcdTarget(rt RoxyTarget) (etcdPath string, etcdPort string, balancer BalancerType, serverName string, err error)

func ParseIPTarget

func ParseIPTarget(rt RoxyTarget, defaultPort string) (tcpAddrs []*net.TCPAddr, balancer BalancerType, serverName string, err error)

func ParseSRVTarget

func ParseSRVTarget(rt RoxyTarget) (res *net.Resolver, name string, service string, balancer BalancerType, pollInterval time.Duration, cdInterval time.Duration, serverName string, err error)

func ParseUnixTarget

func ParseUnixTarget(rt RoxyTarget) (unixAddr *net.UnixAddr, balancer BalancerType, serverName string, err error)

func ParseZKTarget

func ParseZKTarget(rt RoxyTarget) (zkPath string, zkPort string, balancer BalancerType, serverName string, err error)

func (BalancerType) GoString

func (t BalancerType) GoString() string

func (BalancerType) MarshalJSON

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

func (*BalancerType) Parse

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

func (BalancerType) String

func (t BalancerType) String() string

func (*BalancerType) UnmarshalJSON

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

type Dynamic

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

func (*Dynamic) GetLoad

func (dynamic *Dynamic) GetLoad() (load float32, ok bool)

func (*Dynamic) IsHealthy

func (dynamic *Dynamic) IsHealthy() bool

func (*Dynamic) Update

func (dynamic *Dynamic) Update(opts UpdateOptions)

type Event

type Event struct {
	Type              EventType
	Err               error
	Key               string
	Data              Resolved
	ServiceConfigJSON string
}

func (*Event) Check

func (event *Event) Check()

type EventType

type EventType uint8
const (
	NoOpEvent EventType = iota
	ErrorEvent
	UpdateEvent
	DeleteEvent
	BadDataEvent
	StatusChangeEvent
	NewServiceConfigEvent
)

func (EventType) GoString

func (t EventType) GoString() string

func (EventType) MarshalJSON

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

func (*EventType) Parse

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

func (EventType) String

func (t EventType) String() string

func (*EventType) UnmarshalJSON

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

type Options

type Options struct {
	Target  RoxyTarget
	IsTLS   bool
	Context context.Context
	Random  *rand.Rand
}

type PollingResolveFunc

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

func MakeDNSResolveFunc

func MakeDNSResolveFunc(ctx context.Context, res *net.Resolver, host string, port string, serverName string) PollingResolveFunc

func MakeSRVResolveFunc

func MakeSRVResolveFunc(ctx context.Context, res *net.Resolver, name string, service string, serverName string) PollingResolveFunc

type PollingResolver

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

func NewPollingResolver

func NewPollingResolver(opts PollingResolverOptions) (*PollingResolver, error)

func (*PollingResolver) CancelWatch

func (res *PollingResolver) CancelWatch(id WatchID)

func (*PollingResolver) Close

func (res *PollingResolver) Close()

func (*PollingResolver) Err

func (res *PollingResolver) Err() error

func (*PollingResolver) Resolve

func (res *PollingResolver) Resolve() (Resolved, error)

func (*PollingResolver) ResolveAll

func (res *PollingResolver) ResolveAll() ([]Resolved, error)

func (*PollingResolver) ResolveNow

func (res *PollingResolver) ResolveNow(opts ResolveNowOptions)

func (*PollingResolver) Update

func (res *PollingResolver) Update(opts UpdateOptions)

func (*PollingResolver) Watch

func (res *PollingResolver) Watch(fn WatchFunc) WatchID

type PollingResolverOptions

type PollingResolverOptions struct {
	Context           context.Context
	Random            *rand.Rand
	PollInterval      time.Duration
	CooldownInterval  time.Duration
	Balancer          BalancerType
	ResolveFunc       PollingResolveFunc
	ClientConn        grpcresolver.ClientConn
	ServiceConfigJSON string
}

type ResolveNowOptions

type ResolveNowOptions = grpcresolver.ResolveNowOptions

type Resolved

type Resolved struct {
	Unique      string
	Location    string
	ServerName  string
	SRVPriority uint16
	SRVWeight   uint16
	ShardID     uint32
	Weight      float32
	HasSRV      bool
	HasShardID  bool
	HasWeight   bool
	Err         error
	Addr        net.Addr
	Address     Address
	Dynamic     *Dynamic
}

func GetResolved

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

func (Resolved) Check

func (data Resolved) Check()

func (Resolved) Equal

func (data Resolved) Equal(other Resolved) bool

func (Resolved) GetLoad

func (data Resolved) GetLoad() (load float32, ok bool)

func (Resolved) IsHealthy

func (data Resolved) IsHealthy() bool

type ResolvedList

type ResolvedList []Resolved

func (ResolvedList) Len

func (list ResolvedList) Len() int

func (ResolvedList) Less

func (list ResolvedList) Less(i, j int) bool

func (ResolvedList) Sort

func (list ResolvedList) Sort()

func (ResolvedList) Swap

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

type Resolver

type Resolver interface {
	Err() error
	ResolveAll() ([]Resolved, error)
	Resolve() (Resolved, error)

	Update(opts UpdateOptions)

	Watch(WatchFunc) WatchID
	CancelWatch(WatchID)

	ResolveNow(ResolveNowOptions)
	Close()
}

func New

func New(opts Options) (Resolver, error)

func NewATCResolver

func NewATCResolver(opts Options) (Resolver, error)

func NewDNSResolver

func NewDNSResolver(opts Options) (Resolver, error)

func NewEtcdResolver

func NewEtcdResolver(opts Options) (Resolver, error)

func NewIPResolver

func NewIPResolver(opts Options) (Resolver, error)

func NewSRVResolver

func NewSRVResolver(opts Options) (Resolver, error)

func NewUnixResolver

func NewUnixResolver(opts Options) (Resolver, error)

func NewZKResolver

func NewZKResolver(opts Options) (Resolver, error)

type RoxyTarget

type RoxyTarget struct {
	Scheme     string
	Authority  string
	Endpoint   string
	ServerName string
	Query      url.Values
}

func RoxyTargetFromTarget

func RoxyTargetFromTarget(target Target) (RoxyTarget, error)

func (RoxyTarget) AppendTo

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

func (RoxyTarget) AsTarget

func (rt RoxyTarget) AsTarget() Target

func (RoxyTarget) MarshalJSON

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

func (*RoxyTarget) Parse

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

func (RoxyTarget) String

func (rt RoxyTarget) String() string

func (*RoxyTarget) UnmarshalJSON

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

type StaticResolver

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

func NewStaticResolver

func NewStaticResolver(opts StaticResolverOptions) (*StaticResolver, error)

func (*StaticResolver) CancelWatch

func (res *StaticResolver) CancelWatch(id WatchID)

func (*StaticResolver) Close

func (res *StaticResolver) Close()

func (*StaticResolver) Err

func (res *StaticResolver) Err() error

func (*StaticResolver) Resolve

func (res *StaticResolver) Resolve() (Resolved, error)

func (*StaticResolver) ResolveAll

func (res *StaticResolver) ResolveAll() ([]Resolved, error)

func (*StaticResolver) ResolveNow

func (res *StaticResolver) ResolveNow(opts ResolveNowOptions)

func (*StaticResolver) Update

func (res *StaticResolver) Update(opts UpdateOptions)

func (*StaticResolver) Watch

func (res *StaticResolver) Watch(fn WatchFunc) WatchID

type StaticResolverOptions

type StaticResolverOptions struct {
	Random            *rand.Rand
	Balancer          BalancerType
	Records           []Resolved
	ClientConn        grpcresolver.ClientConn
	ServiceConfigJSON string
}

type Target

type Target = grpcresolver.Target

type UpdateOptions

type UpdateOptions struct {
	Addr       net.Addr
	HasHealthy bool
	HasLoad    bool
	Healthy    bool
	Load       float32
}

type WatchFunc

type WatchFunc func([]Event)

type WatchID

type WatchID uint32

type WatchingResolveFunc

type WatchingResolveFunc func(ctx context.Context, wg *sync.WaitGroup, backoff expbackoff.ExpBackoff) (<-chan []Event, error)

func MakeATCResolveFunc

func MakeATCResolveFunc(client *atcclient.ATCClient, lbName, lbLocation, lbUnique string, dsc bool, serverName string) WatchingResolveFunc

func MakeEtcdResolveFunc

func MakeEtcdResolveFunc(etcdClient *v3.Client, etcdPath string, etcdPort string, serverName string) WatchingResolveFunc

func MakeZKResolveFunc

func MakeZKResolveFunc(zkconn *zk.Conn, zkPath string, zkPort string, serverName string) WatchingResolveFunc

type WatchingResolver

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

func NewWatchingResolver

func NewWatchingResolver(opts WatchingResolverOptions) (*WatchingResolver, error)

func (*WatchingResolver) CancelWatch

func (res *WatchingResolver) CancelWatch(id WatchID)

func (*WatchingResolver) Close

func (res *WatchingResolver) Close()

func (*WatchingResolver) Err

func (res *WatchingResolver) Err() error

func (*WatchingResolver) Resolve

func (res *WatchingResolver) Resolve() (Resolved, error)

func (*WatchingResolver) ResolveAll

func (res *WatchingResolver) ResolveAll() ([]Resolved, error)

func (*WatchingResolver) ResolveNow

func (res *WatchingResolver) ResolveNow(opts ResolveNowOptions)

func (*WatchingResolver) Update

func (res *WatchingResolver) Update(opts UpdateOptions)

func (*WatchingResolver) Watch

func (res *WatchingResolver) Watch(fn WatchFunc) WatchID

type WatchingResolverOptions

type WatchingResolverOptions struct {
	Context           context.Context
	Random            *rand.Rand
	Balancer          BalancerType
	ResolveFunc       WatchingResolveFunc
	ClientConn        grpcresolver.ClientConn
	ServiceConfigJSON string
}

Jump to

Keyboard shortcuts

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