push

package
Version: v1.122.0 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2021 License: Apache-2.0 Imports: 18 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type APILimiter

type APILimiter struct {
	// Decodable: must be public
	Limit rate.Limit
	Burst int
	// contains filtered or unexported fields
}

An APILimiter holds the parameters of a *rate.Limiter. It is used to announce a desired rate limit for inconming requests.

type IdentityToAPILimitersRegistry

type IdentityToAPILimitersRegistry map[string]*APILimiter

IdentityToAPILimitersRegistry is a map of elemental.Identity Name to an AnnouncedRateLimits.

type Notifier

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

A Notifier sends ServicePing to the Wutai gateways.

func NewNotifier

func NewNotifier(
	pubsub bahamut.PubSubClient,
	serviceStatusTopic string,
	serviceName string,
	endpoint string,
	opts ...NotifierOption,
) *Notifier

NewNotifier returns a new Wutai notifier.

func (*Notifier) MakeStartHook

func (w *Notifier) MakeStartHook(ctx context.Context) func(server bahamut.Server) error

MakeStartHook returns a bahamut start hook that sends the hello message to the Upstreamer periodically.

func (*Notifier) MakeStopHook

func (w *Notifier) MakeStopHook() func(server bahamut.Server) error

MakeStopHook returns a bahamut stop hook that sends the goodbye message to the Upstreamer.

type NotifierOption

type NotifierOption func(*notifierConfig)

A NotifierOption is the kind of option that can be passed to the notifier.

func OptionNotifierAnnounceRateLimits

func OptionNotifierAnnounceRateLimits(rls IdentityToAPILimitersRegistry) NotifierOption

OptionNotifierAnnounceRateLimits can be used to set a IdentityToAPILimitersRegistry to tell the gateways to instantiate some rate limiters for the current instance of the service.

It is not guaranteed that the gateway will honor the request.

func OptionNotifierPingInterval

func OptionNotifierPingInterval(interval time.Duration) NotifierOption

OptionNotifierPingInterval sets the interval between sending 2 pings. The default is 5s.

type Randomizer

type Randomizer interface {
	Intn(int) int
	Shuffle(n int, swap func(i, j int))
}

A Randomizer reprensents an interface to randomize

type Upstreamer

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

A Upstreamer listens and update the list of the backend services. It also implement gateway.Limiter interface allowing to install the per token rate limiter in an efficient way.

func NewUpstreamer

func NewUpstreamer(
	pubsub bahamut.PubSubClient,
	serviceStatusTopic string,
	peerStatusTopic string,
	options ...UpstreamerOption,
) *Upstreamer

NewUpstreamer returns a new push backed upstreamer latency based

func (*Upstreamer) CollectLatency

func (c *Upstreamer) CollectLatency(address string, responseTime time.Duration)

CollectLatency implement the LatencyBasedUpstreamer interface to add new samples into the latencies sync map

func (*Upstreamer) ExtractRates

func (c *Upstreamer) ExtractRates(r *http.Request) (rate.Limit, int, error)

ExtractRates implements the gateway.Limiter interface.

func (*Upstreamer) Start

func (c *Upstreamer) Start(ctx context.Context) (chan struct{}, *sync.WaitGroup)

Start starts for new backend services.

func (*Upstreamer) Upstream

func (c *Upstreamer) Upstream(req *http.Request) (string, error)

Upstream returns the upstream to go for the given path

type UpstreamerOption

type UpstreamerOption func(*upstreamConfig)

An UpstreamerOption represents a configuration option for the Upstreamer.

func OptionRequiredServices

func OptionRequiredServices(required []string) UpstreamerOption

OptionRequiredServices sets the list of services that must be ready before starting the upstreamer.

func OptionUpstreamerExposePrivateAPIs

func OptionUpstreamerExposePrivateAPIs(enabled bool) UpstreamerOption

OptionUpstreamerExposePrivateAPIs configures the Upstreamer to expose the private APIs.

func OptionUpstreamerGlobalServiceTopic

func OptionUpstreamerGlobalServiceTopic(topic string) UpstreamerOption

OptionUpstreamerGlobalServiceTopic sets the global topic that the gateway will use to listen for service pings coming from global services.

func OptionUpstreamerOverrideEndpointsAddresses

func OptionUpstreamerOverrideEndpointsAddresses(override string) UpstreamerOption

OptionUpstreamerOverrideEndpointsAddresses configures the Upstreamer to always ignore what IP address the services are reporting and always use the provided address.

func OptionUpstreamerPeersCheckInterval

func OptionUpstreamerPeersCheckInterval(t time.Duration) UpstreamerOption

OptionUpstreamerPeersCheckInterval sets the frequency at which the upstreamer will check for outdated peers. The default is 5s.

func OptionUpstreamerPeersPingInterval

func OptionUpstreamerPeersPingInterval(t time.Duration) UpstreamerOption

OptionUpstreamerPeersPingInterval sets how often the upstreamer will ping its peers. The default is 10s.

func OptionUpstreamerPeersTimeout

func OptionUpstreamerPeersTimeout(t time.Duration) UpstreamerOption

OptionUpstreamerPeersTimeout sets for how long a peer ping should stay valid after receiving it. The default is 30s.

func OptionUpstreamerRandomizer

func OptionUpstreamerRandomizer(randomizer Randomizer) UpstreamerOption

OptionUpstreamerRandomizer set a custom Randomizer that must implement the Randomizer interface and be safe for concurrent use by multiple goroutines.

func OptionUpstreamerRegisterEventAPI

func OptionUpstreamerRegisterEventAPI(serviceName string, eventEndpoint string) UpstreamerOption

OptionUpstreamerRegisterEventAPI registers an event API for the given serviceName on the given endpoint. For instance is serviceA exposes an event API on /events, you can use

OptionUpstreamerRegisterEventAPI("serviceA", "events")

func OptionUpstreamerServiceTimeout

func OptionUpstreamerServiceTimeout(timeout time.Duration, checkInterval time.Duration) UpstreamerOption

OptionUpstreamerServiceTimeout sets the time to wait for the upstream to consider a service that did not ping to be outdated and removed in the case no goodbye was sent. Default is 30s. The check interval parameters defines how often the upstream will check for outdated services. The default is 5s.

func OptionUpstreamerTokenRateLimiting

func OptionUpstreamerTokenRateLimiting(rps rate.Limit, burst int) UpstreamerOption

OptionUpstreamerTokenRateLimiting configures the per source rate limiting. The default is cps:500/burst:2000

Jump to

Keyboard shortcuts

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