Documentation ¶
Index ¶
- type APILimiter
- type IdentityToAPILimitersRegistry
- type Notifier
- type NotifierOption
- func OptionNotifierAnnounceRateLimits(rls IdentityToAPILimitersRegistry) NotifierOption
- func OptionNotifierPingInterval(interval time.Duration) NotifierOption
- func OptionNotifierPrefix(prefix string) NotifierOption
- func OptionNotifierPrivateAPIOverrides(overrides map[elemental.Identity]bool) NotifierOption
- type Randomizer
- type Upstreamer
- func (c *Upstreamer) CollectLatency(address string, responseTime time.Duration)
- func (c *Upstreamer) ExtractRates(r *http.Request) (rate.Limit, int, error)
- func (c *Upstreamer) Start(ctx context.Context) (chan struct{}, *sync.WaitGroup)
- func (c *Upstreamer) Upstream(req *http.Request) (string, error)
- type UpstreamerOption
- func OptionRequiredServices(required []string) UpstreamerOption
- func OptionUpstreamerExposePrivateAPIs(enabled bool) UpstreamerOption
- func OptionUpstreamerGlobalServiceTopic(topic string) UpstreamerOption
- func OptionUpstreamerOverrideEndpointsAddresses(override string) UpstreamerOption
- func OptionUpstreamerPeersCheckInterval(t time.Duration) UpstreamerOption
- func OptionUpstreamerPeersPingInterval(t time.Duration) UpstreamerOption
- func OptionUpstreamerPeersTimeout(t time.Duration) UpstreamerOption
- func OptionUpstreamerRandomizer(randomizer Randomizer) UpstreamerOption
- func OptionUpstreamerRegisterEventAPI(serviceName string, eventEndpoint string) UpstreamerOption
- func OptionUpstreamerServiceTimeout(timeout time.Duration, checkInterval time.Duration) UpstreamerOption
- func OptionUpstreamerTokenRateLimiting(rps rate.Limit, burst int) UpstreamerOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type APILimiter ¶
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 ¶
MakeStartHook returns a bahamut start hook that sends the hello message to the Upstreamer periodically.
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.
func OptionNotifierPrefix ¶ added in v1.140.0
func OptionNotifierPrefix(prefix string) NotifierOption
OptionNotifierPrefix sets the API prefix that the gateway should add to the API routes for that service.
func OptionNotifierPrivateAPIOverrides ¶ added in v1.140.0
func OptionNotifierPrivateAPIOverrides(overrides map[elemental.Identity]bool) NotifierOption
OptionNotifierPrivateAPIOverrides allows to pass a map of identity to boolean that will be used to override the specificaton's "private" flag. This allows the service to force a public API to be private (or vice versa).
NOTE: this does not change the internal data in bahamut's server RouteInfo. As far as bahamut server is concerned, the route Private flag did not change. This is only affecting the gateway.
type Randomizer ¶
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 ¶
ExtractRates implements the gateway.Limiter interface.
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