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 string) (throttleCheckOK bool)
- func (c *Client) ThrottleCheckOKOrWait(ctx context.Context) bool
- func (c *Client) ThrottleCheckOKOrWaitAppName(ctx context.Context, appName string) bool
- 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) CheckIsReady() error
- func (throttler *Throttler) Close()
- func (throttler *Throttler) Disable(ctx context.Context) bool
- func (throttler *Throttler) Enable(ctx context.Context) bool
- func (throttler *Throttler) GetMetricsQuery() string
- func (throttler *Throttler) InitDBConfig(keyspace, shard string)
- func (throttler *Throttler) IsAppThrottled(appName string) bool
- func (throttler *Throttler) IsEnabled() 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) 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
- 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 (
ErrThrottlerNotReady = errors.New("throttler not enabled/ready")
)
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 SkipRequestHeartbeats 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
func (c *Client) ThrottleCheckOK(ctx context.Context, overrideAppName string) (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 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.
func (*Client) ThrottleCheckOKOrWaitAppName ¶ added in v0.14.0
ThrottleCheckOKOrWait checks the throttler; if throttler is satisfied, the function returns 'true' mmediately, otherwise it briefly sleeps and returns 'false'. Non-empty appName overrides the default appName. The function is not thread safe.
type ThrottleCheckType ¶ added in v0.10.0
type ThrottleCheckType int // nolint:revive
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 { MetricsThreshold sync2.AtomicFloat64 // 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, srvTopoServer srvtopo.Server, ts *topo.Server, cell string, 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)
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) CheckIsReady ¶ added in v0.14.0
CheckIsReady checks if this throttler is ready to serve. If not, it returns an error
func (*Throttler) Disable ¶ added in v0.16.0
Disable deactivates the probes and associated operations. When disabled, the throttler reponds to check queries with "200 OK" irrespective of lag or any other metrics.
func (*Throttler) Enable ¶ added in v0.16.0
Enable activates the throttler probes; when enabled, the throttler responds to check queries based on the collected metrics.
func (*Throttler) GetMetricsQuery ¶ added in v0.16.0
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) ThrottledApps ¶ added in v0.14.0
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 ¶ added in v0.16.0
func (throttler *Throttler) WatchSrvKeyspaceCallback(srvks *topodatapb.SrvKeyspace, err error) bool
WatchSrvKeyspaceCallback gets called whenever SrvKeyspace has been modified. This callback only examines the ThrottlerConfig part of SrvKeyspace, and proceeds to inform the throttler of the new config
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