Documentation ¶
Index ¶
- Constants
- Variables
- type CheckFlags
- type CheckResult
- type Client
- type ThrottleCheckType
- type Throttler
- func (throttler *Throttler) AppRequestMetricResult(ctx context.Context, appName string, metricResultFunc base.MetricResultFunc, ...) (metricResult base.MetricResult, threshold float64)
- func (throttler *Throttler) CheckByType(ctx context.Context, appName string, remoteAddr string, flags *CheckFlags, ...) (checkResult *CheckResult)
- func (throttler *Throttler) Close()
- func (throttler *Throttler) InitDBConfig(keyspace, shard string)
- func (throttler *Throttler) IsAppThrottled(appName string) bool
- func (throttler *Throttler) Open() error
- func (throttler *Throttler) Operate(ctx context.Context)
- func (throttler *Throttler) RecentAppsMap() (result map[string](*base.RecentApp))
- func (throttler *Throttler) Status() *ThrottlerStatus
- func (throttler *Throttler) ThrottleApp(appName string, expireAt time.Time, ratio float64) (appThrottle *base.AppThrottle)
- func (throttler *Throttler) ThrottledAppsMap() (result map[string](*base.AppThrottle))
- func (throttler *Throttler) ThrottledAppsSnapshot() map[string]cache.Item
- func (throttler *Throttler) UnthrottleApp(appName string) (appThrottle *base.AppThrottle)
- type ThrottlerCheck
- func (check *ThrottlerCheck) AggregatedMetrics(ctx context.Context) map[string]base.MetricResult
- func (check *ThrottlerCheck) Check(ctx context.Context, appName string, storeType string, storeName string, ...) (checkResult *CheckResult)
- func (check *ThrottlerCheck) MetricsHealth() map[string](*base.MetricHealth)
- func (check *ThrottlerCheck) SelfChecks(ctx context.Context)
- type ThrottlerStatus
Constants ¶
const (
// DefaultAppName is the app name used by vitess when app doesn't indicate its name
DefaultAppName = "default"
)
Variables ¶
var NoSuchMetricCheckResult = NewErrorCheckResult(http.StatusNotFound, base.ErrNoSuchMetric)
NoSuchMetricCheckResult is a result returns when a metric is unknown
var StandardCheckFlags = &CheckFlags{}
StandardCheckFlags have no special hints
Functions ¶
This section is empty.
Types ¶
type CheckFlags ¶
type CheckFlags struct { ReadCheck bool OverrideThreshold float64 LowPriority bool OKIfNotExists bool }
CheckFlags provide hints for a check
type CheckResult ¶
type CheckResult struct { StatusCode int `json:"StatusCode"` Value float64 `json:"Value"` Threshold float64 `json:"Threshold"` Error error `json:"-"` Message string `json:"Message"` }
CheckResult is the result for an app inquiring on a metric. It also exports as JSON via the API
func NewCheckResult ¶
func NewCheckResult(statusCode int, value float64, threshold float64, err error) *CheckResult
NewCheckResult returns a CheckResult
func NewErrorCheckResult ¶
func NewErrorCheckResult(statusCode int, err error) *CheckResult
NewErrorCheckResult returns a check result that indicates an error
type Client ¶ added in v0.10.0
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 ¶ added in v0.10.0
func NewBackgroundClient(throttler *Throttler, appName string, checkType ThrottleCheckType) *Client
NewBackgroundClient creates a client suitable for background jobs, which have low priority over productio ntraffic, e.g. migration, table pruning, vreplication
func NewProductionClient ¶ added in v0.10.0
func NewProductionClient(throttler *Throttler, appName string, checkType ThrottleCheckType) *Client
NewProductionClient creates a client suitable for foreground/production jobs, which have normal priority.
func (*Client) Throttle ¶ added in v0.10.0
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 ¶ added in v0.10.0
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 frequenty. The function is not thread safe.
func (*Client) ThrottleCheckOKOrWait ¶ added in v0.10.0
ThrottleCheckOKOrWait checks the throttler; if throttler is satisfied, the function returns 'true' mmediately, otherwise it briefly sleeps and returns 'false'. The function is not thread safe.
type ThrottleCheckType ¶ added in v0.10.0
type ThrottleCheckType int
ThrottleCheckType allows a client to indicate what type of check it wants to issue. See available types below.
const ( // ThrottleCheckPrimaryWrite indicates a check before making a write on a primary server ThrottleCheckPrimaryWrite ThrottleCheckType = iota // ThrottleCheckSelf indicates a check on a specific server health ThrottleCheckSelf )
type Throttler ¶
type Throttler struct {
// contains filtered or unexported fields
}
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, ts *topo.Server, 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)
AppRequestMetricResult gets a metric result in the context of a specific app
func (*Throttler) CheckByType ¶ added in v0.10.0
func (throttler *Throttler) CheckByType(ctx context.Context, appName string, remoteAddr string, flags *CheckFlags, checkType ThrottleCheckType) (checkResult *CheckResult)
CheckByType runs a check by requested check type
func (*Throttler) InitDBConfig ¶
InitDBConfig initializes keyspace and shard
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) Operate ¶
Operate is the main entry point for the throttler operation and logic. It will run the probes, colelct metrics, refresh inventory, etc.
func (*Throttler) RecentAppsMap ¶
RecentAppsMap returns a (copy) map of apps which checked for throttling recently
func (*Throttler) Status ¶
func (throttler *Throttler) Status() *ThrottlerStatus
Status exports a status breakdown
func (*Throttler) ThrottleApp ¶
func (throttler *Throttler) ThrottleApp(appName string, expireAt time.Time, ratio float64) (appThrottle *base.AppThrottle)
ThrottleApp instructs the throttler to begin throttling an app, to som eperiod and with some ratio.
func (*Throttler) ThrottledAppsMap ¶
func (throttler *Throttler) ThrottledAppsMap() (result map[string](*base.AppThrottle))
ThrottledAppsMap returns a (copy) map of currently throttled apps
func (*Throttler) ThrottledAppsSnapshot ¶
ThrottledAppsSnapshot returns a snapshot (a copy) of current throttled apps
func (*Throttler) UnthrottleApp ¶
func (throttler *Throttler) UnthrottleApp(appName string) (appThrottle *base.AppThrottle)
UnthrottleApp cancels any throttling, if any, for a given app
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, storeType string, storeName string, remoteAddr string, flags *CheckFlags) (checkResult *CheckResult)
Check is the core function that runs when a user wants to check a metric
func (*ThrottlerCheck) MetricsHealth ¶
func (check *ThrottlerCheck) MetricsHealth() map[string](*base.MetricHealth)
MetricsHealth is a convenience access method into throttler's `metricsHealthSnapshot`
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 IsDormant bool AggregatedMetrics map[string]base.MetricResult MetricsHealth base.MetricHealthMap }
ThrottlerStatus published some status values from the throttler