hub

package
v0.0.0-...-af321b4 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2023 License: MPL-2.0 Imports: 25 Imported by: 1

Documentation

Index

Constants

View Source
const ServicesPerAccount = 100

Variables

View Source
var (
	// The maximum time to run a blocking query to the catalog for.
	DefaultRefreshTime = 30 * time.Second

	// How long to configured the consul TTL check with. This is the maximum time
	// the service has to update it's TTL again before it's marked as failed.
	CheckTTL = "30s"

	// ConsulService is the service name that is used to identify hubs. Each
	// instance of ConsulHealth identifies itself as a separate instance of this service.
	ConsulService = "hub"
)
View Source
var (
	ErrProtocolError   = errors.New("protocol error")
	ErrWrongService    = errors.New("wrong service")
	ErrTooManyServices = errors.New("too many services per account")
)
View Source
var ErrNoAvailableAddresses = errors.New("no addresses available for hub")
View Source
var ErrNoRoutes = errors.New("no routes to any service available")
View Source
var ErrNoSuchSession = errors.New("no session found")

Functions

This section is empty.

Types

type ConsulHealth

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

ConsulHealth advertises an instance of the hub service to consul and also monitors the service catalog for other instances. It provides the ability for each hub to know which other hubs are currently available to send traffic to.

func NewConsulHealth

func NewConsulHealth(id string, cfg *consul.Config) (*ConsulHealth, error)

NewConsulHealth creates a ConsulHealth instance, identified by id.

func (*ConsulHealth) Available

func (c *ConsulHealth) Available(id string) bool

Available checks the local catalog cache and indicates if the given hub is currently available.

func (*ConsulHealth) Start

func (c *ConsulHealth) Start(ctx context.Context, L hclog.Logger) error

Start registers the service, begins updating the TTL check, and runs Watch to update the local catalog view in the background.

func (*ConsulHealth) Watch

func (c *ConsulHealth) Watch(ctx context.Context, refreshTime time.Duration)

Watch runs forever, updating the local view of all hub instances. refreshTime controls how often the refresh queries wait for updates before trying again. The lower the value, the more this function will loop internally.

type Hub

type Hub struct {
	L hclog.Logger
	// contains filtered or unexported fields
}

func NewHub

func NewHub(L hclog.Logger, client *control.Client, feToken string) (*Hub, error)

func (*Hub) ConnectToService

func (h *Hub) ConnectToService(
	ctx context.Context,
	target *pb.ServiceRoute,
	account *pb.Account,
	proto string,
	token string,
) (wire.Context, error)

func (*Hub) ListenHTTP

func (hub *Hub) ListenHTTP(addr string) error

func (*Hub) Run

func (hub *Hub) Run(ctx context.Context, li net.Listener) error

Run blocks, handling requests until the context is canceled.

func (*Hub) Serve

func (h *Hub) Serve(ctx context.Context, l net.Listener) error

func (*Hub) ServeHTTP

func (h *Hub) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*Hub) ValidateToken

func (h *Hub) ValidateToken(stoken string) (*token.ValidToken, error)

func (*Hub) WaitToDrain

func (hub *Hub) WaitToDrain() error

Jump to

Keyboard shortcuts

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