selector

package
v0.0.0-...-5dc8409 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2018 License: Apache-2.0, Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package loadbalance is a way to load balance service nodes

Index

Constants

View Source
const (
	ZoneAware = "zoneaware"
)

constant string for zoneaware

Variables

View Source
var (
	// ErrNoneAvailable is to represent load balance error
	ErrNoneAvailable = LBError{Message: "No available"}
)

Functions

func GetStrategyPlugin

func GetStrategyPlugin(name string) (func([]*registry.MicroServiceInstance, interface{}) Next, error)

GetStrategyPlugin get strategy plugin

func InstallStrategy

func InstallStrategy(name string, strategy func([]*registry.MicroServiceInstance, interface{}) Next)

InstallStrategy install strategy

Types

type Filter

Filter is used to filter a service during the selection process

func FilterEndpoint

func FilterEndpoint(target string) Filter

FilterEndpoint is an endpoint based Select Filter which will only return services with the endpoint specified.

func FilterMD

func FilterMD(key, val string) Filter

FilterMD is a filtering instances based meta data

func FilterProtocol

func FilterProtocol(protocol string) Filter

FilterProtocol is for filtering the instances based on protocol

type LBError

type LBError struct {
	Message string
}

LBError load balance error

func (LBError) Error

func (e LBError) Error() string

Error for to return load balance error message

type Next

type Next func() (*registry.MicroServiceInstance, error)

Next is a function that returns the next node based on the selector's strategy

func Random

func Random(instances []*registry.MicroServiceInstance, metadata interface{}) Next

Random is a random strategy algorithm for node selection

func RoundRobin

func RoundRobin(instances []*registry.MicroServiceInstance, metadata interface{}) Next

RoundRobin is a roundrobin strategy algorithm for node selection

type Option

type Option func(*Options)

Option used to initialise Options struct

func Registry

func Registry(r registry.Registry) Option

Registry sets the registry that selector used

func SetStrategy

func SetStrategy(fn Strategy) Option

SetStrategy sets the default strategy that selector used

type Options

type Options struct {
	Registry registry.Registry
	Strategy Strategy

	// Other options can be stored in a context
	Context context.Context
}

Options is having registry, strategy, context variables

type SelectOption

type SelectOption func(*SelectOptions)

SelectOption used to initialise SelectOptions struct

func WithAppID

func WithAppID(a string) SelectOption

WithAppID adds a application id to the function

func WithConsumerID

func WithConsumerID(id string) SelectOption

WithConsumerID consumer id is added to the selectoptions

func WithFilter

func WithFilter(fns []Filter) SelectOption

WithFilter adds a filter func to the list of filters

func WithMetadata

func WithMetadata(a interface{}) SelectOption

WithMetadata sets the selector metadata

func WithStrategy

func WithStrategy(fn Strategy) SelectOption

WithStrategy sets the selector strategy

type SelectOptions

type SelectOptions struct {
	Filters    []Filter
	Strategy   Strategy
	AppID      string
	Metadata   interface{}
	ConsumerID string
	// Other options can be stored in a context
	Context context.Context
}

SelectOptions is having micro-service filters, strategy, appid, consumerid, context

type Selector

type Selector interface {
	Init(opts ...Option) error
	Options() Options
	// Select returns a function which should return the next node
	Select(microserviceName, version string, opts ...SelectOption) (Next, error)
	// Name of the selector
	String() string
}

Selector builds on the registry as a mechanism to pick nodes and mark their status. This allows host pools and other things to be built using various algorithms.

type Strategy

type Strategy func([]*registry.MicroServiceInstance, interface{}) Next

Strategy is a selection strategy e.g random, round robin

Jump to

Keyboard shortcuts

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