Documentation
¶
Index ¶
- Constants
- Variables
- type CheckFlags
- type CheckResult
- type Client
- func (c *Client) Throttle(ctx context.Context)
- func (c *Client) ThrottleCheckOK(ctx context.Context, overrideAppName throttlerapp.Name) (checkResult *CheckResult, throttleCheckOK bool)
- func (c *Client) ThrottleCheckOKOrWait(ctx context.Context) (checkResult *CheckResult, throttleCheckOK bool)
- func (c *Client) ThrottleCheckOKOrWaitAppName(ctx context.Context, appName throttlerapp.Name) (checkResult *CheckResult, throttleCheckOK bool)
- type MetricResult
- type Throttler
- func (throttler *Throttler) AppRequestMetricResult(ctx context.Context, appName string, metricResultFunc base.MetricResultFunc, ...) (metricResult base.MetricResult, threshold float64, matchedApp string)
- func (throttler *Throttler) Check(ctx context.Context, appName string, metricNames base.MetricNames, ...) (checkResult *CheckResult)
- func (throttler *Throttler) CheckIsOpen() error
- func (throttler *Throttler) Close()
- func (throttler *Throttler) Disable() bool
- func (throttler *Throttler) Enable() *sync.WaitGroup
- func (throttler *Throttler) GetCustomMetricsQuery() string
- func (throttler *Throttler) GetMetricsQuery() string
- func (throttler *Throttler) GetMetricsThreshold() float64
- func (throttler *Throttler) InitDBConfig(keyspace, shard string)
- func (throttler *Throttler) IsAppExempted(appName string) (bool, string)
- func (throttler *Throttler) IsAppThrottled(appName string) (bool, string)
- func (throttler *Throttler) IsEnabled() bool
- func (throttler *Throttler) IsOpen() bool
- func (throttler *Throttler) IsRunning() bool
- func (throttler *Throttler) MetricName(s string) base.MetricName
- func (throttler *Throttler) MetricNames(s []string) base.MetricNames
- func (throttler *Throttler) Open() error
- func (throttler *Throttler) Operate(ctx context.Context, wg *sync.WaitGroup)
- func (throttler *Throttler) Status() *ThrottlerStatus
- func (throttler *Throttler) StoreMetricsThreshold(threshold float64)
- func (throttler *Throttler) ThrottleApp(appName string, expireAt time.Time, ratio float64, exempt bool) (appThrottle *base.AppThrottle)
- func (throttler *Throttler) ThrottledApps() (result []base.AppThrottle)
- func (throttler *Throttler) ThrottledAppsMap() (result map[string](*base.AppThrottle))
- func (throttler *Throttler) UnthrottleApp(appName string) (appThrottle *base.AppThrottle)
- func (throttler *Throttler) WatchSrvKeyspaceCallback(srvks *topodatapb.SrvKeyspace, err error) bool
- type ThrottlerCheck
- type ThrottlerStatus
Constants ¶
const ( DefaultAppThrottleDuration = time.Hour DefaultThrottleRatio = 1.0 )
Variables ¶
var (
ErrThrottlerNotOpen = errors.New("throttler not open")
)
var NoSuchMetricCheckResult = NewErrorCheckResult(tabletmanagerdatapb.CheckThrottlerResponseCode_UNKNOWN_METRIC, base.ErrNoSuchMetric)
NoSuchMetricCheckResult is a result returns when a metric is unknown
Functions ¶
This section is empty.
Types ¶
type CheckFlags ¶
type CheckFlags struct {
Scope base.Scope
ReadCheck bool
OverrideThreshold float64
OKIfNotExists bool
SkipRequestHeartbeats bool
}
CheckFlags provide hints for a check
type CheckResult ¶
type CheckResult struct {
ResponseCode tabletmanagerdatapb.CheckThrottlerResponseCode `json:"ResponseCode"`
Value float64 `json:"Value"`
Threshold float64 `json:"Threshold"`
Error error `json:"-"`
Message string `json:"Message"`
RecentlyChecked bool `json:"RecentlyChecked"`
AppName string `json:"AppName"`
MetricName string `json:"MetricName"`
Scope string `json:"Scope"`
Metrics map[string]*MetricResult `json:"Metrics"` // New in multi-metrics support. Will eventually replace the above fields.
}
CheckResult is the result for an app inquiring on a metric. It also exports as JSON via the API
func NewCheckResult ¶
func NewCheckResult(responseCode tabletmanagerdatapb.CheckThrottlerResponseCode, value float64, threshold float64, appName string, err error) *CheckResult
NewCheckResult returns a CheckResult
func NewErrorCheckResult ¶
func NewErrorCheckResult(responseCode tabletmanagerdatapb.CheckThrottlerResponseCode, err error) *CheckResult
NewErrorCheckResult returns a check result that indicates an error
func (*CheckResult) IsOK ¶
func (c *CheckResult) IsOK() bool
func (*CheckResult) Summary ¶
func (c *CheckResult) Summary() string
Summary returns a human-readable summary of the check result
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client construct is used by apps who wish to consult with a throttler. It encapsulates the check/throttling/backoff logic
func NewBackgroundClient ¶
NewBackgroundClient creates a client suitable for background jobs, which have low priority over production traffic, e.g. migration, table pruning, vreplication
func (*Client) Throttle ¶
Throttle throttles until the throttler is satisfied, or until context is cancelled. The function sleeps between throttle checks. The function is not thread safe.
func (*Client) ThrottleCheckOK ¶
func (c *Client) ThrottleCheckOK(ctx context.Context, overrideAppName throttlerapp.Name) (checkResult *CheckResult, throttleCheckOK bool)
ThrottleCheckOK checks the throttler, and returns 'true' when the throttler is satisfied. It does not sleep. The function caches results for a brief amount of time, hence it's safe and efficient to be called very frequently. The function is not thread safe.
func (*Client) ThrottleCheckOKOrWait ¶
func (c *Client) ThrottleCheckOKOrWait(ctx context.Context) (checkResult *CheckResult, throttleCheckOK bool)
ThrottleCheckOKOrWait checks the throttler; if throttler is satisfied, the function returns 'true' immediately, otherwise it briefly sleeps and returns 'false'. The function is not thread safe.
func (*Client) ThrottleCheckOKOrWaitAppName ¶
func (c *Client) ThrottleCheckOKOrWaitAppName(ctx context.Context, appName throttlerapp.Name) (checkResult *CheckResult, throttleCheckOK bool)
ThrottleCheckOKOrWait checks the throttler; if throttler is satisfied, the function returns 'true' immediately, otherwise it briefly sleeps and returns 'false'. Non-empty appName overrides the default appName. The function is not thread safe.
type MetricResult ¶
type MetricResult struct {
ResponseCode tabletmanagerdatapb.CheckThrottlerResponseCode `json:"ResponseCode"`
Scope string `json:"Scope"`
Value float64 `json:"Value"`
Threshold float64 `json:"Threshold"`
Error error `json:"-"`
Message string `json:"Message"`
AppName string `json:"AppName"`
}
func (*MetricResult) IsOK ¶
func (m *MetricResult) IsOK() bool
type Throttler ¶
Throttler is the main entity in the throttling mechanism. This service runs, probes, collects data, aggregates, reads inventory, provides information, etc.
func NewThrottler ¶
func NewThrottler(env tabletenv.Env, srvTopoServer srvtopo.Server, ts *topo.Server, tabletAlias *topodatapb.TabletAlias, heartbeatWriter heartbeat.HeartbeatWriter, tabletTypeFunc func() topodatapb.TabletType) *Throttler
NewThrottler creates a Throttler
func (*Throttler) AppRequestMetricResult ¶
func (throttler *Throttler) AppRequestMetricResult(ctx context.Context, appName string, metricResultFunc base.MetricResultFunc, denyApp bool) (metricResult base.MetricResult, threshold float64, matchedApp string)
AppRequestMetricResult gets a metric result in the context of a specific app
func (*Throttler) Check ¶
func (throttler *Throttler) Check(ctx context.Context, appName string, metricNames base.MetricNames, flags *CheckFlags) (checkResult *CheckResult)
Check runs a check by requested check type
func (*Throttler) CheckIsOpen ¶
CheckIsOpen checks if this throttler is ready to serve. If not, it returns an error.
func (*Throttler) Disable ¶
Disable deactivates the probes and associated operations. When disabled, the throttler responds to check queries with "200 OK" irrespective of lag or any other metrics.
func (*Throttler) Enable ¶
Enable activates the throttler probes; when enabled, the throttler responds to check queries based on the collected metrics. The function returns a WaitGroup that can be used to wait for the throttler to be fully disabled, ie when the Operate() goroutine function terminates and caches are invalidated.
func (*Throttler) GetCustomMetricsQuery ¶
func (*Throttler) GetMetricsQuery ¶
func (*Throttler) GetMetricsThreshold ¶
func (*Throttler) InitDBConfig ¶
InitDBConfig initializes keyspace and shard
func (*Throttler) IsAppExempted ¶
IsAppExempt
func (*Throttler) IsAppThrottled ¶
IsAppThrottled tells whether some app should be throttled. Assuming an app is throttled to some extend, it will randomize the result based on the throttle ratio
func (*Throttler) MetricName ¶
func (throttler *Throttler) MetricName(s string) base.MetricName
func (*Throttler) MetricNames ¶
func (throttler *Throttler) MetricNames(s []string) base.MetricNames
func (*Throttler) Operate ¶
Operate is the main entry point for the throttler operation and logic. It will run the probes, collect metrics, refresh inventory, etc.
func (*Throttler) Status ¶
func (throttler *Throttler) Status() *ThrottlerStatus
Status exports a status breakdown
func (*Throttler) StoreMetricsThreshold ¶
func (*Throttler) ThrottleApp ¶
func (throttler *Throttler) ThrottleApp(appName string, expireAt time.Time, ratio float64, exempt bool) (appThrottle *base.AppThrottle)
ThrottleApp instructs the throttler to begin throttling an app, to some period and with some ratio.
func (*Throttler) ThrottledApps ¶
func (throttler *Throttler) ThrottledApps() (result []base.AppThrottle)
ThrottledAppsSnapshot returns a snapshot (a copy) of current throttled apps
func (*Throttler) ThrottledAppsMap ¶
func (throttler *Throttler) ThrottledAppsMap() (result map[string](*base.AppThrottle))
ThrottledAppsMap returns a (copy) map of currently throttled apps
func (*Throttler) UnthrottleApp ¶
func (throttler *Throttler) UnthrottleApp(appName string) (appThrottle *base.AppThrottle)
UnthrottleApp cancels any throttling, if any, for a given app
func (*Throttler) WatchSrvKeyspaceCallback ¶
func (throttler *Throttler) WatchSrvKeyspaceCallback(srvks *topodatapb.SrvKeyspace, err error) bool
type ThrottlerCheck ¶
type ThrottlerCheck struct {
// contains filtered or unexported fields
}
ThrottlerCheck provides methods for an app checking on metrics
func NewThrottlerCheck ¶
func NewThrottlerCheck(throttler *Throttler) *ThrottlerCheck
NewThrottlerCheck creates a ThrottlerCheck
func (*ThrottlerCheck) AggregatedMetrics ¶
func (check *ThrottlerCheck) AggregatedMetrics(ctx context.Context) map[string]base.MetricResult
AggregatedMetrics is a convenience access method into throttler's `aggregatedMetricsSnapshot`
func (*ThrottlerCheck) Check ¶
func (check *ThrottlerCheck) Check(ctx context.Context, appName string, scope base.Scope, metricNames base.MetricNames, flags *CheckFlags) (checkResult *CheckResult)
Check is the core function that runs when a user wants to check a metric
func (*ThrottlerCheck) SelfChecks ¶
func (check *ThrottlerCheck) SelfChecks(ctx context.Context)
SelfChecks runs checks on all known metrics as if we were an app. This runs asynchronously, continuously, and independently of any user interaction
type ThrottlerStatus ¶
type ThrottlerStatus struct {
Keyspace string
Shard string
IsLeader bool
IsOpen bool
IsEnabled bool
IsDormant bool
RecentlyChecked bool
Query string
CustomQuery string
Threshold float64
MetricNameUsedAsDefault string
AggregatedMetrics map[string]base.MetricResult
MetricsThresholds map[string]float64
MetricsHealth base.MetricHealthMap
ThrottledApps []base.AppThrottle
AppCheckedMetrics map[string]string
RecentApps map[string](*base.RecentApp)
}
ThrottlerStatus published some status values from the throttler
Directories
¶
| Path | Synopsis |
|---|---|
|
This codebase originates from https://github.com/github/freno, See https://github.com/github/freno/blob/master/LICENSE
|
This codebase originates from https://github.com/github/freno, See https://github.com/github/freno/blob/master/LICENSE |