Documentation
¶
Index ¶
- Variables
- func BeegoOnAbort(bctx *beegoctx.Context, err error)
- func BeegoWithIP(bctx *beegoctx.Context) context.Context
- func EchoOnAbort(ectx echo.Context, err error) error
- func EchoWithIP(ectx echo.Context) context.Context
- func FastOnAbort(fctx *fasthttp.RequestCtx, err error)
- func FastWithIPBackground(fctx *fasthttp.RequestCtx) context.Context
- func GRPCStreamAbort(err error) error
- func GRPCStreamWithEmpty(ctx context.Context, msg interface{}) context.Context
- func GinOnAbort(gctx *gin.Context, err error)
- func GinWithIP(gctx *gin.Context) context.Context
- func IrisOnAbort(ictx iris.Context, err error)
- func IrisWithIP(ictx iris.Context) context.Context
- func KitOnAbort(err error) (interface{}, error)
- func KitWithEmpty(ctx context.Context, req interface{}) context.Context
- func MicroClientWithEmpty(ctx context.Context, req client.Request) context.Context
- func MicroOnAbort(err error) error
- func MicroServerEmpty(ctx context.Context, req server.Request) context.Context
- func MuxOnAbort(w http.ResponseWriter, err error)
- func MuxWithIP(req *http.Request) context.Context
- func NetConnAbort(err error) error
- func NetConnWithBackground() context.Context
- func NewGRPCClientStream(cs grpc.ClientStream, thr Throttler, with GRPCStreamWith, on GRPCStreamOn) grpc.ClientStream
- func NewGrpServerStream(ss grpc.ServerStream, thr Throttler, with GRPCStreamWith, on GRPCStreamOn) grpc.ServerStream
- func NewMicroClient(thr Throttler, with MicroClientWith, on MicroOn) client.Wrapper
- func NewMicroHandler(thr Throttler, with MicroServerWith, on MicroOn) server.HandlerWrapper
- func NewMiddlewareBeego(thr Throttler, with BeegoWith, on BeegoOn) beego.FilterFunc
- func NewMiddlewareEcho(thr Throttler, with EchoWith, on EchoOn) echo.MiddlewareFunc
- func NewMiddlewareFast(h fasthttp.RequestHandler, thr Throttler, with FastWith, on FastOn) fasthttp.RequestHandler
- func NewMiddlewareGin(thr Throttler, with GinWith, on GinOn) gin.HandlerFunc
- func NewMiddlewareIris(thr Throttler, with IrisWith, on IrisOn) iris.Handler
- func NewMiddlewareKit(thr Throttler, with KitWith, on KitOn) endpoint.Middleware
- func NewMiddlewareMux(h http.Handler, thr Throttler, with MuxWith, on MuxOn) http.Handler
- func NewMiddlewareRevel(thr Throttler, with RevealWith, on RevealOn) revel.Filter
- func NewMiddlewareRouter(h http.Handler, thr Throttler, with RouterWith, on RouterOn) http.Handler
- func NewMiddlewareStd(h http.Handler, thr Throttler, with StdWith, on StdOn) http.Handler
- func NewNetConn(conn net.Conn, thr Throttler, with NetConnWith, on NetConnOn, mode NetConnMode) net.Conn
- func NewRPCClientCodec(cc rpc.ClientCodec, thr Throttler, with RPCCodecWith, on RPCCodecOn) rpc.ClientCodec
- func NewRPCServerCodec(sc rpc.ServerCodec, thr Throttler, with RPCCodecWith, on RPCCodecOn) rpc.ServerCodec
- func NewReader(r io.Reader, thr Throttler, with RWWith, on RWOn) io.Reader
- func NewRoundTripperStd(rt http.RoundTripper, thr Throttler, with RoundTripperStdWith, ...) http.RoundTripper
- func NewWriter(w io.Writer, thr Throttler, with RWWith, on RWOn) io.Writer
- func RPCCodecOnAbort(err error) error
- func RPCCodecWithBackground(req *rpc.Request, resp *rpc.Response, msg interface{}) context.Context
- func RWAbort(err error) error
- func RWWithBackground() context.Context
- func RevealOnAbort(rc *revel.Controller, err error) revel.Result
- func RevealWithIP(rc *revel.Controller) context.Context
- func RoundTripperFastBackground(req *fasthttp.Request) context.Context
- func RoundTripperFastOnAbort(err error) error
- func RoundTripperStdOnAbort(err error) error
- func RoundTripperStdWithEmpty(req *http.Request) context.Context
- func RouterOnAbort(w http.ResponseWriter, err error)
- func RouterWithIP(req *http.Request) context.Context
- func SQLClientAbort(err error) error
- func SQLClientQuery(ctx context.Context, query string, args ...interface{}) context.Context
- func StdOnAbort(w http.ResponseWriter, err error)
- func StdWithIP(req *http.Request) context.Context
- func WithKey(ctx context.Context, key string) context.Context
- func WithMarshaler(ctx context.Context, mrsh Marshaler) context.Context
- func WithMessage(ctx context.Context, message interface{}) context.Context
- func WithParams(ctx context.Context, ts time.Time, priority uint8, key string, ...) context.Context
- func WithPriority(ctx context.Context, priority uint8) context.Context
- func WithThrottler(ctx context.Context, thr Throttler, freq time.Duration) context.Context
- func WithTimestamp(ctx context.Context, ts time.Time) context.Context
- type BeegoOn
- type BeegoWith
- type EchoOn
- type EchoWith
- type Enqueuer
- type FastOn
- type FastWith
- type GRPCStreamOn
- type GRPCStreamWith
- type GinOn
- type GinWith
- type IrisOn
- type IrisWith
- type KitOn
- type KitWith
- type Logger
- type Marshaler
- type Metric
- type MicroClientWith
- type MicroOn
- type MicroServerWith
- type Monitor
- type MuxOn
- type MuxWith
- type NetConnMode
- type NetConnOn
- type NetConnWith
- type Pattern
- type RPCCodecOn
- type RPCCodecWith
- type RWOn
- type RWWith
- type RevealOn
- type RevealWith
- type RoundTripperFast
- type RoundTripperFastOn
- type RoundTripperFastWith
- type RoundTripperStdOn
- type RoundTripperStdWith
- type RouterOn
- type RouterWith
- type Runnable
- type Runner
- type SQLClient
- type SQLClientOn
- type SQLClientWith
- type Stats
- type StdOn
- type StdWith
- type Throttler
- func NewThrottlerAdaptive(threshold uint64, interval time.Duration, quantum time.Duration, step uint64, ...) Throttler
- func NewThrottlerAfter(threshold uint64) Throttler
- func NewThrottlerAll(thrs ...Throttler) Throttler
- func NewThrottlerAny(thrs ...Throttler) Throttler
- func NewThrottlerBefore(threshold uint64) Throttler
- func NewThrottlerBuffered(threshold uint64) Throttler
- func NewThrottlerCache(thr Throttler, cache time.Duration) Throttler
- func NewThrottlerChance(threshold float64) Throttler
- func NewThrottlerContext() Throttler
- func NewThrottlerEach(threshold uint64) Throttler
- func NewThrottlerEcho(err error) Throttler
- func NewThrottlerEnqueue(enq Enqueuer) Throttler
- func NewThrottlerJitter(initial time.Duration, limit time.Duration, reset bool, jitter float64) Throttler
- func NewThrottlerLatency(threshold time.Duration, retention time.Duration) Throttler
- func NewThrottlerMetric(mtc Metric) Throttler
- func NewThrottlerMonitor(mnt Monitor, threshold Stats) Throttler
- func NewThrottlerNot(thr Throttler) Throttler
- func NewThrottlerPanic() Throttler
- func NewThrottlerPattern(patterns ...Pattern) Throttler
- func NewThrottlerPercentile(threshold time.Duration, capacity uint8, percentile float64, ...) Throttler
- func NewThrottlerPriority(threshold uint64, levels uint8) Throttler
- func NewThrottlerRetry(thr Throttler, retries uint64) Throttler
- func NewThrottlerRing(thrs ...Throttler) Throttler
- func NewThrottlerRunning(threshold uint64) Throttler
- func NewThrottlerSquare(initial time.Duration, limit time.Duration, reset bool) Throttler
- func NewThrottlerSuppress(thr Throttler) Throttler
- func NewThrottlerTimed(threshold uint64, interval time.Duration, quantum time.Duration) Throttler
- func NewThrottlerWait(duration time.Duration) Throttler
Constants ¶
This section is empty.
Variables ¶
var DefaultRetriedDuration = 100 * time.Millisecond
DefaultRetriedDuration defines default initial duration for `square` throttler used by default. By default DefaultRetriedDuration is set to use `100 * time.Millisecond`.
Functions ¶
func BeegoOnAbort ¶
func FastOnAbort ¶
func FastOnAbort(fctx *fasthttp.RequestCtx, err error)
func FastWithIPBackground ¶
func FastWithIPBackground(fctx *fasthttp.RequestCtx) context.Context
func GRPCStreamAbort ¶
func GRPCStreamWithEmpty ¶
func GinOnAbort ¶
func IrisOnAbort ¶
func KitOnAbort ¶
func MicroClientWithEmpty ¶
func MicroOnAbort ¶
func MicroServerEmpty ¶
func MuxOnAbort ¶
func MuxOnAbort(w http.ResponseWriter, err error)
func NetConnAbort ¶
func NetConnWithBackground ¶
func NewGRPCClientStream ¶
func NewGRPCClientStream(cs grpc.ClientStream, thr Throttler, with GRPCStreamWith, on GRPCStreamOn) grpc.ClientStream
func NewGrpServerStream ¶
func NewGrpServerStream(ss grpc.ServerStream, thr Throttler, with GRPCStreamWith, on GRPCStreamOn) grpc.ServerStream
func NewMicroClient ¶
func NewMicroClient(thr Throttler, with MicroClientWith, on MicroOn) client.Wrapper
func NewMicroHandler ¶
func NewMicroHandler(thr Throttler, with MicroServerWith, on MicroOn) server.HandlerWrapper
func NewMiddlewareBeego ¶
func NewMiddlewareBeego(thr Throttler, with BeegoWith, on BeegoOn) beego.FilterFunc
func NewMiddlewareEcho ¶
func NewMiddlewareEcho(thr Throttler, with EchoWith, on EchoOn) echo.MiddlewareFunc
func NewMiddlewareFast ¶
func NewMiddlewareFast(h fasthttp.RequestHandler, thr Throttler, with FastWith, on FastOn) fasthttp.RequestHandler
func NewMiddlewareGin ¶
func NewMiddlewareGin(thr Throttler, with GinWith, on GinOn) gin.HandlerFunc
func NewMiddlewareIris ¶
func NewMiddlewareKit ¶
func NewMiddlewareKit(thr Throttler, with KitWith, on KitOn) endpoint.Middleware
func NewMiddlewareMux ¶
func NewMiddlewareRevel ¶
func NewMiddlewareRevel(thr Throttler, with RevealWith, on RevealOn) revel.Filter
func NewMiddlewareRouter ¶
func NewMiddlewareStd ¶
func NewNetConn ¶
func NewNetConn(conn net.Conn, thr Throttler, with NetConnWith, on NetConnOn, mode NetConnMode) net.Conn
func NewRPCClientCodec ¶
func NewRPCClientCodec(cc rpc.ClientCodec, thr Throttler, with RPCCodecWith, on RPCCodecOn) rpc.ClientCodec
func NewRPCServerCodec ¶
func NewRPCServerCodec(sc rpc.ServerCodec, thr Throttler, with RPCCodecWith, on RPCCodecOn) rpc.ServerCodec
func NewRoundTripperStd ¶
func NewRoundTripperStd( rt http.RoundTripper, thr Throttler, with RoundTripperStdWith, on RoundTripperStdOn, ) http.RoundTripper
func RPCCodecOnAbort ¶
func RPCCodecWithBackground ¶
func RWWithBackground ¶
func RevealOnAbort ¶
func RevealOnAbort(rc *revel.Controller, err error) revel.Result
func RevealWithIP ¶
func RevealWithIP(rc *revel.Controller) context.Context
func RoundTripperFastOnAbort ¶
func RoundTripperStdOnAbort ¶
func RouterOnAbort ¶
func RouterOnAbort(w http.ResponseWriter, err error)
func SQLClientAbort ¶
func SQLClientQuery ¶
func StdOnAbort ¶
func StdOnAbort(w http.ResponseWriter, err error)
func WithKey ¶
WithKey adds the provided key to the provided context to add additional call identifier to context. Resulted context is used by: `pattern` throtttler.
func WithMarshaler ¶
WithMarshaler adds the provided marshaler to the provided context to add additional message marshaler that need to be used to context. Resulted context is used by: `enqueue` throtttler. Used in pair with `WithMessage`.
func WithMessage ¶
WithMessage adds the provided message to the provided context to add additional message that need to be used to context. Resulted context is used by: `enqueue` throtttler. Used in pair with `WithMarshaler`.
func WithParams ¶
func WithParams( ctx context.Context, ts time.Time, priority uint8, key string, message interface{}, marshaler Marshaler, ) context.Context
WithParams facade call that respectively calls: - `WithTimestamp` - `WithPriority` - `WithKey` - `WithMessage` - `WithMarshaler`
func WithPriority ¶
WithPriority adds the provided priority to the provided context to differ `Acquire` priority levels. Resulted context is used by: `priority` throtttler.
func WithThrottler ¶
WithThrottler adds the provided thr to the provided context and defines context implementation that uses parrent context plus throttler internally that closes context done chanel if internal throttler throttles.
Types ¶
type Enqueuer ¶
type Enqueuer interface { // Enqueue enqueues provided message or returns internal error if any happened. Enqueue(context.Context, []byte) error }
Enqueuer defines abstract message enqueuing interface.
func NewEnqueuerKafka ¶
NewEnqueuerKafka creates Kafka enqueuer instance with cached connection and failure retries which enqueues provided message to the specified topic. New unique message key `gohalt_enqueue_{{uuid}}` is created for each new message. Only successful connections are cached.
func NewEnqueuerRabbit ¶
NewEnqueuerRabbit creates RabbitMQ enqueuer instance with cached connection and failure retries which enqueues provided message to the specified queue. New unique exchange `gohalt_exchange_{{uuid}}` is created for each new enqueuer, new unique message id `gohalt_enqueue_{{uuid}}` is created for each new message. Only successful connections are cached.
type FastOn ¶
type FastOn func(*fasthttp.RequestCtx, error)
type GRPCStreamOn ¶
type Logger ¶
type Logger func(string, ...interface{})
Logger defined by typical logger func signature.
type Metric ¶
type Metric interface { // Query returns the result of the query or internal error if any happened. Query(context.Context) (bool, error) }
Metric defines single metric querier interface that returns the metric query result.
func NewMetricPrometheus ¶
NewMetricPrometheus creates prometheus metric querier instance with cache interval defined by the provided duration which executes provided prometheus boolean metric query and cache it. Only successful metric results are cached.
type Monitor ¶
type Monitor interface { // Stats returns system stats or internal error if any happened. Stats(context.Context) (Stats, error) }
Monitor defines system monitor interface that returns the system stats.
type NetConnMode ¶
type NetConnMode int
const ( NetConnModeRead NetConnMode = iota NetConnModeWrite NetConnMode = iota )
type NetConnWith ¶
type RPCCodecOn ¶
type RPCCodecWith ¶
type RevealWith ¶
type RevealWith func(*revel.Controller) context.Context
type RoundTripperFast ¶
func NewRoundTripperFast ¶
func NewRoundTripperFast( rt RoundTripperFast, thr Throttler, with RoundTripperFastWith, on RoundTripperFastOn, ) RoundTripperFast
type RoundTripperFastOn ¶
type RoundTripperStdOn ¶
type RouterWith ¶
type RouterWith StdWith
type Runnable ¶
Runnable defined by typical abstract async func signature. Runnable is used by `Runner` as a subject for execution.
type Runner ¶
type Runner interface { // Run executes single prodived `Runnable` instance. Run(Runnable) // Result returns possible execution error back. Result() error }
Runner defines abstraction to execute a set of `Runnable` and return possible execution error back. Runner is designed to simplify work with throttlers by managing `Acquire`/`Release` loop.
func NewRunnerAsync ¶
NewRunnerAsync creates asynchronous runner instance that runs a set of `Runnable` simultaneously with regard to the provided context and throttler. First occurred error is returned from result.
type SQLClient ¶
type SQLClient interface { ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error) PrepareContext(ctx context.Context, query string) (*sql.Stmt, error) QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error) QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row }
func NewSQLClient ¶
func NewSQLClient(cli SQLClient, thr Throttler, with SQLClientWith, on SQLClientOn) SQLClient
type SQLClientOn ¶
type SQLClientWith ¶
type Stats ¶
Stats defines typical set of metrics returned by system monitor: - MEMAlloc shows how many bytes are allocated by heap objects. - MEMSystem shows how many bytes are obtained from the OS. - CPUPause shows average GC stop-the-world pause in nanoseconds. - CPUUsage shows average CPU utilization in percents.
type StdOn ¶
type StdOn func(http.ResponseWriter, error)
type Throttler ¶
type Throttler interface { // Acquire takes a part of throttling quota or returns error if throttling quota is drained // it needs to be called right before shared resource acquire. Acquire(context.Context) error // Release puts a part of throttling quota back or returns error if this is not possible // it needs to be called just after shared resource release. Release(context.Context) error }
Throttler defines core gohalt throttler abstraction and exposes pair of counterpart methods: `Acquire` and `Release`.
func NewThrottlerAdaptive ¶
func NewThrottlerAdaptive( threshold uint64, interval time.Duration, quantum time.Duration, step uint64, thr Throttler, ) Throttler
NewThrottlerAdaptive creates new throttler instance that throttles each call which exeeds the running quota acquired - release q defined by the specified threshold in the specified interval. Periodically each specified interval the running quota number is reseted. If quantum is set then quantum will be used instead of interval to provide the running quota delta updates. Provided adapted throttler adjusts the running quota of adapter throttler by changing the value by d defined by the specified step, it subtracts *d^2* from the running quota if adapted throttler throttles or adds *d* to the running quota if it doesn't.
func NewThrottlerAfter ¶
NewThrottlerAfter creates new throttler instance that throttles each call after the i-th call defined by the specified threshold.
func NewThrottlerAll ¶
NewThrottlerAll creates new throttler instance that throttles call if all provided throttlers throttle.
func NewThrottlerAny ¶
NewThrottlerAny creates new throttler instance that throttles call if any of provided throttlers throttle.
func NewThrottlerBefore ¶
NewThrottlerBefore creates new throttler instance that throttles each call below the i-th call defined by the specified threshold.
func NewThrottlerBuffered ¶
NewThrottlerBuffered creates new throttler instance that waits on call which exeeds the running quota acquired - release q defined by the specified threshold until the running quota is available again.
func NewThrottlerCache ¶ added in v0.2.0
NewThrottlerCache creates new throttler instance that caches provided throttler calls for the provided cache duration, throttler release resulting resets cache. Only non throttling calls are cached for the provided cache duration.
func NewThrottlerChance ¶
NewThrottlerChance creates new throttler instance that throttles each call with the chance p defined by the specified threshold. Chance value is normalized to [0.0, 1.0] range. Implementation uses `math/rand` as PRNG function and expects rand seeding by a client.
func NewThrottlerContext ¶
func NewThrottlerContext() Throttler
NewThrottlerContext creates new throttler instance that always throttless on done context.
func NewThrottlerEach ¶
NewThrottlerEach creates new throttler instance that throttles each periodic i-th call defined by the specified threshold.
func NewThrottlerEcho ¶
NewThrottlerEcho creates new throttler instance that always throttles with the specified error back.
func NewThrottlerEnqueue ¶
NewThrottlerEnqueue creates new throttler instance that always enqueues message to the specified queue throttles only if any internal error occurred. Use `WithMessage` to specify context message for enqueued message and `WithMarshaler` to specify context message marshaler. Builtin `Enqueuer` implementations come with connection reuse and retries by default. Use builtin `NewEnqueuerRabbit` to create RabbitMQ enqueuer instance or `NewEnqueuerKafka` to create Kafka enqueuer instance.
func NewThrottlerJitter ¶ added in v0.2.0
func NewThrottlerJitter(initial time.Duration, limit time.Duration, reset bool, jitter float64) Throttler
NewThrottlerJitter creates new throttler instance that waits accordingly to undelying square throttler but also adds the provided jitter delta distribution on top. Jitter value is normalized to [0.0, 1.0] range and defines which part of square delay could be randomized in percents. Implementation uses `math/rand` as PRNG function and expects rand seeding by a client.
func NewThrottlerLatency ¶
NewThrottlerLatency creates new throttler instance that throttles each call after the call latency l defined by the specified threshold was exeeded once. If retention is set then throttler state will be reseted after retention duration. Use `WithTimestamp` to specify running duration between throttler acquire and release.
func NewThrottlerMetric ¶
NewThrottlerMetric creates new throttler instance that throttles call ifboolean metric defined by the specified boolean metric is reached or if any internal error occurred. Builtin `Metric` implementations come with boolean metric caching by default. Use builtin `NewMetricPrometheus` to create Prometheus metric instance.
func NewThrottlerMonitor ¶
NewThrottlerMonitor creates new throttler instance that throttles call if any of the stats returned by provided monitor exceeds any of the stats defined by the specified threshold or if any internal error occurred. Builtin `Monitor` implementations come with stats caching by default. Use builtin `NewMonitorSystem` to create go system monitor instance.
func NewThrottlerNot ¶
NewThrottlerNot creates new throttler instance that throttles call if provided throttler doesn't throttle.
func NewThrottlerPanic ¶
func NewThrottlerPanic() Throttler
NewThrottlerPanic creates new throttler instance that always panics.
func NewThrottlerPattern ¶
NewThrottlerPattern creates new throttler instance that throttles if matching throttler from provided patterns throttles. Use `WithKey` to specify key for regexp pattern throttler matching. See `Pattern` which defines a pair of regexp and related throttler.
func NewThrottlerPercentile ¶
func NewThrottlerPercentile( threshold time.Duration, capacity uint8, percentile float64, retention time.Duration, ) Throttler
NewThrottlerPercentile creates new throttler instance that throttles each call after the call latency l defined by the specified threshold was exeeded once considering the specified percentile. Percentile values are kept in bounded buffer with capacity c defined by the specified capacity. If retention is set then throttler state will be reseted after retention duration. Use `WithTimestamp` to specify running duration between throttler acquire and release.
func NewThrottlerPriority ¶
NewThrottlerPriority creates new throttler instance that waits on call which exeeds the running quota acquired - release q defined by the specified threshold until the running quota is available again. Running quota is not equally distributed between n levels of priority defined by the specified levels. Use `WithPriority` to override context call priority, 1 by default.
func NewThrottlerRetry ¶ added in v0.2.0
NewThrottlerRetry creates new throttler instance that retries provided throttler error up until the provided retries threshold. Internally retry uses square throttler with `DefaultRetriedDuration` initial duration.
func NewThrottlerRing ¶
NewThrottlerRing creates new throttler instance that throttles if the i-th call throttler from provided list throttle.
func NewThrottlerRunning ¶
NewThrottlerRunning creates new throttler instance that throttles each call which exeeds the running quota acquired - release q defined by the specified threshold.
func NewThrottlerSquare ¶
NewThrottlerSquare creates new throttler instance that always waits for square growing [1, 4, 9, 16, ...] multiplier on the specified initial duration, up until the specified duration limit is reached. If reset is set then after throttler riches the specified duration limit next multiplier value will be reseted.
func NewThrottlerSuppress ¶
NewThrottlerSuppress creates new throttler instance that suppresses provided throttler to never throttle.
func NewThrottlerTimed ¶
NewThrottlerTimed creates new throttler instance that throttles each call which exeeds the running quota acquired - release q defined by the specified threshold in the specified interval. Periodically each specified interval the running quota number is reseted. If quantum is set then quantum will be used instead of interval to provide the running quota delta updates.
func NewThrottlerWait ¶
NewThrottlerWait creates new throttler instance that always waits for the specified duration.