Documentation
¶
Overview ¶
This codebase originates from https://github.com/github/freno, See https://github.com/github/freno/blob/master/LICENSE
MIT License Copyright (c) 2017 GitHub Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Index ¶
- Variables
- func DisaggregateMetricName(aggregatedMetricName string) (scope Scope, metricName MetricName, err error)
- func IsDialTCPError(err error) bool
- func SetupHTTPClient(httpTimeout time.Duration) *http.Client
- type AggregatedMetricName
- type AppThrottle
- type ClusterProbes
- type CustomQuerySelfMetric
- func (m *CustomQuerySelfMetric) DefaultScope() Scope
- func (m *CustomQuerySelfMetric) DefaultThreshold() float64
- func (m *CustomQuerySelfMetric) Name() MetricName
- func (m *CustomQuerySelfMetric) Read(ctx context.Context, throttler ThrottlerMetricsPublisher, conn *connpool.Conn) *ThrottleMetric
- func (m *CustomQuerySelfMetric) RequiresConn() bool
- type DefaultSelfMetric
- func (m *DefaultSelfMetric) DefaultScope() Scope
- func (m *DefaultSelfMetric) DefaultThreshold() float64
- func (m *DefaultSelfMetric) Name() MetricName
- func (m *DefaultSelfMetric) Read(ctx context.Context, throttler ThrottlerMetricsPublisher, conn *connpool.Conn) *ThrottleMetric
- func (m *DefaultSelfMetric) RequiresConn() bool
- type Inventory
- type LagSelfMetric
- func (m *LagSelfMetric) DefaultScope() Scope
- func (m *LagSelfMetric) DefaultThreshold() float64
- func (m *LagSelfMetric) GetQuery() string
- func (m *LagSelfMetric) Name() MetricName
- func (m *LagSelfMetric) Read(ctx context.Context, throttler ThrottlerMetricsPublisher, conn *connpool.Conn) *ThrottleMetric
- func (m *LagSelfMetric) RequiresConn() bool
- func (m *LagSelfMetric) SetQuery(query string)
- type LoadAvgSelfMetric
- func (m *LoadAvgSelfMetric) DefaultScope() Scope
- func (m *LoadAvgSelfMetric) DefaultThreshold() float64
- func (m *LoadAvgSelfMetric) Name() MetricName
- func (m *LoadAvgSelfMetric) Read(ctx context.Context, throttler ThrottlerMetricsPublisher, conn *connpool.Conn) *ThrottleMetric
- func (m *LoadAvgSelfMetric) RequiresConn() bool
- type MetricHealth
- type MetricHealthMap
- type MetricName
- type MetricNames
- type MetricResult
- type MetricResultFunc
- type MetricResultMap
- type MetricsQueryType
- type Probe
- type Probes
- type RecentApp
- type Scope
- type SelfMetric
- type TabletResultMap
- type ThreadsRunningSelfMetric
- func (m *ThreadsRunningSelfMetric) DefaultScope() Scope
- func (m *ThreadsRunningSelfMetric) DefaultThreshold() float64
- func (m *ThreadsRunningSelfMetric) Name() MetricName
- func (m *ThreadsRunningSelfMetric) Read(ctx context.Context, throttler ThrottlerMetricsPublisher, conn *connpool.Conn) *ThrottleMetric
- func (m *ThreadsRunningSelfMetric) RequiresConn() bool
- type ThrottleMetric
- type ThrottleMetrics
- type ThrottlerMetricsPublisher
Constants ¶
This section is empty.
Variables ¶
var AppDeniedMetric = &appDeniedMetric{}
AppDeniedMetric is a special metric indicating a "denied" situation
var ErrAppDenied = errors.New("app denied")
ErrAppDenied is seen when an app is denied access
var ErrInvalidCheckType = errors.New("unknown throttler check type")
ErrInvalidCheckType is an internal error indicating an unknown check type
var ErrNoResultYet = errors.New("metric not collected yet")
var ErrNoSuchMetric = errors.New("no such metric")
ErrNoSuchMetric is for when a user requests a metric by an unknown metric name
var ErrThresholdExceeded = errors.New("threshold exceeded")
ErrThresholdExceeded is the common error one may get checking on metric result
var (
KnownMetricNames = make(MetricNames, 0)
)
var NoHostsMetricResult = &noHostsMetricResult{}
NoHostsMetricResult is a result indicating "no hosts"
var NoMetricResultYet = &noMetricResultYet{}
NoMetricResultYet is a result indicating "no data"
var NoSuchMetric = &noSuchMetric{}
NoSuchMetric is a metric results for an unknown metric name
var (
RegisteredSelfMetrics = make(map[MetricName]SelfMetric)
)
Functions ¶
func DisaggregateMetricName ¶ added in v0.21.0
func DisaggregateMetricName(aggregatedMetricName string) (scope Scope, metricName MetricName, err error)
DisaggregateMetricName splits a metric name into its scope name and metric name aggregated metric name could be in the form: - loadavg - self - self/threads_running - shard - shard/lag
func IsDialTCPError ¶
IsDialTCPError sees if the given error indicates a TCP issue
Types ¶
type AggregatedMetricName ¶ added in v0.21.0
type AggregatedMetricName struct { Scope Scope Metric MetricName }
type AppThrottle ¶
AppThrottle is the definition for an app throttling instruction - Ratio: [0..1], 0 == no throttle, 1 == fully throttle
func NewAppThrottle ¶
NewAppThrottle creates an AppThrottle struct
type ClusterProbes ¶ added in v0.21.0
ClusterProbes has the probes for a specific cluster
type CustomQuerySelfMetric ¶ added in v0.21.0
type CustomQuerySelfMetric struct { }
func (*CustomQuerySelfMetric) DefaultScope ¶ added in v0.21.0
func (m *CustomQuerySelfMetric) DefaultScope() Scope
func (*CustomQuerySelfMetric) DefaultThreshold ¶ added in v0.21.0
func (m *CustomQuerySelfMetric) DefaultThreshold() float64
func (*CustomQuerySelfMetric) Name ¶ added in v0.21.0
func (m *CustomQuerySelfMetric) Name() MetricName
func (*CustomQuerySelfMetric) Read ¶ added in v0.21.0
func (m *CustomQuerySelfMetric) Read(ctx context.Context, throttler ThrottlerMetricsPublisher, conn *connpool.Conn) *ThrottleMetric
func (*CustomQuerySelfMetric) RequiresConn ¶ added in v0.21.0
func (m *CustomQuerySelfMetric) RequiresConn() bool
type DefaultSelfMetric ¶ added in v0.21.0
type DefaultSelfMetric struct { }
func (*DefaultSelfMetric) DefaultScope ¶ added in v0.21.0
func (m *DefaultSelfMetric) DefaultScope() Scope
func (*DefaultSelfMetric) DefaultThreshold ¶ added in v0.21.0
func (m *DefaultSelfMetric) DefaultThreshold() float64
func (*DefaultSelfMetric) Name ¶ added in v0.21.0
func (m *DefaultSelfMetric) Name() MetricName
func (*DefaultSelfMetric) Read ¶ added in v0.21.0
func (m *DefaultSelfMetric) Read(ctx context.Context, throttler ThrottlerMetricsPublisher, conn *connpool.Conn) *ThrottleMetric
func (*DefaultSelfMetric) RequiresConn ¶ added in v0.21.0
func (m *DefaultSelfMetric) RequiresConn() bool
type Inventory ¶ added in v0.21.0
type Inventory struct { ClustersProbes Probes IgnoreHostsCount int IgnoreHostsThreshold float64 TabletMetrics TabletResultMap }
Inventory has the operational data about probes, their metrics, and relevant configuration
func NewInventory ¶ added in v0.21.0
func NewInventory() *Inventory
NewInventory creates a Inventory
type LagSelfMetric ¶ added in v0.21.0
type LagSelfMetric struct {
// contains filtered or unexported fields
}
func (*LagSelfMetric) DefaultScope ¶ added in v0.21.0
func (m *LagSelfMetric) DefaultScope() Scope
func (*LagSelfMetric) DefaultThreshold ¶ added in v0.21.0
func (m *LagSelfMetric) DefaultThreshold() float64
func (*LagSelfMetric) GetQuery ¶ added in v0.21.0
func (m *LagSelfMetric) GetQuery() string
func (*LagSelfMetric) Name ¶ added in v0.21.0
func (m *LagSelfMetric) Name() MetricName
func (*LagSelfMetric) Read ¶ added in v0.21.0
func (m *LagSelfMetric) Read(ctx context.Context, throttler ThrottlerMetricsPublisher, conn *connpool.Conn) *ThrottleMetric
func (*LagSelfMetric) RequiresConn ¶ added in v0.21.0
func (m *LagSelfMetric) RequiresConn() bool
func (*LagSelfMetric) SetQuery ¶ added in v0.21.0
func (m *LagSelfMetric) SetQuery(query string)
SetQuery is only used by unit tests to override the query.
type LoadAvgSelfMetric ¶ added in v0.21.0
type LoadAvgSelfMetric struct { }
func (*LoadAvgSelfMetric) DefaultScope ¶ added in v0.21.0
func (m *LoadAvgSelfMetric) DefaultScope() Scope
func (*LoadAvgSelfMetric) DefaultThreshold ¶ added in v0.21.0
func (m *LoadAvgSelfMetric) DefaultThreshold() float64
func (*LoadAvgSelfMetric) Name ¶ added in v0.21.0
func (m *LoadAvgSelfMetric) Name() MetricName
func (*LoadAvgSelfMetric) Read ¶ added in v0.21.0
func (m *LoadAvgSelfMetric) Read(ctx context.Context, throttler ThrottlerMetricsPublisher, conn *connpool.Conn) *ThrottleMetric
func (*LoadAvgSelfMetric) RequiresConn ¶ added in v0.21.0
func (m *LoadAvgSelfMetric) RequiresConn() bool
type MetricHealth ¶
MetricHealth is a health status for a metric, and more specifically, when it was last checked to be "OK"
func NewMetricHealth ¶
func NewMetricHealth(lastHealthyAt time.Time) *MetricHealth
NewMetricHealth returns a MetricHealth
type MetricHealthMap ¶
type MetricHealthMap map[string](*MetricHealth)
MetricHealthMap maps metric names to metric healths
func (MetricHealthMap) Aggregate ¶
func (m MetricHealthMap) Aggregate(other MetricHealthMap) MetricHealthMap
Aggregate another map into this map, take the worst metric of the two
type MetricName ¶ added in v0.21.0
type MetricName string
MetricName is a formalized name for a metric, such as "lag" or "threads_running". A metric name may include a scope, such as "self/lag" or "shard/threads_running". It is possible to add a scope to a name, or to parse the scope out of a name, and there is also always a default scope associated with a metric name.
const ( DefaultMetricName MetricName = "default" LagMetricName MetricName = "lag" ThreadsRunningMetricName MetricName = "threads_running" CustomMetricName MetricName = "custom" LoadAvgMetricName MetricName = "loadavg" )
func (MetricName) AggregatedName ¶ added in v0.21.0
func (metric MetricName) AggregatedName(scope Scope) string
AggregatedName returns the string representation of this metric in the given scope, e.g.: - "self/loadavg" - "shard/lag"
func (MetricName) DefaultScope ¶ added in v0.21.0
func (metric MetricName) DefaultScope() Scope
func (MetricName) Disaggregated ¶ added in v0.21.0
func (metric MetricName) Disaggregated() (scope Scope, metricName MetricName, err error)
Disaggregated returns a breakdown of this metric into scope + name.
func (MetricName) String ¶ added in v0.21.0
func (metric MetricName) String() string
type MetricNames ¶ added in v0.21.0
type MetricNames []MetricName
MetricNames is a formalized list of metric names
func (MetricNames) Contains ¶ added in v0.21.0
func (names MetricNames) Contains(name MetricName) bool
func (MetricNames) String ¶ added in v0.21.0
func (names MetricNames) String() string
func (MetricNames) Unique ¶ added in v0.21.0
func (names MetricNames) Unique() MetricNames
Unique returns a subset of unique metric names, in same order as the original names
type MetricResult ¶
MetricResult is what we expect our probes to return. This can be a numeric result, or a special type of result indicating more meta-information
func AggregateTabletMetricResults ¶ added in v0.21.0
func AggregateTabletMetricResults( metricName MetricName, tabletResultsMap TabletResultMap, ignoreHostsCount int, IgnoreDialTCPErrors bool, ignoreHostsThreshold float64, ) (worstMetric MetricResult)
func NewSimpleMetricResult ¶
func NewSimpleMetricResult(value float64) MetricResult
NewSimpleMetricResult creates a simpleMetricResult
type MetricResultFunc ¶
type MetricResultFunc func() (metricResult MetricResult, threshold float64)
MetricResultFunc is a function that returns a metric result
type MetricResultMap ¶ added in v0.21.0
type MetricResultMap map[MetricName]MetricResult
func NewMetricResultMap ¶ added in v0.21.0
func NewMetricResultMap() MetricResultMap
type MetricsQueryType ¶ added in v0.21.0
type MetricsQueryType int
MetricsQueryType indicates the type of metrics query on MySQL backend. See following.
const ( // MetricsQueryTypeDefault indicates the default, internal implementation. Specifically, our throttler runs a replication lag query MetricsQueryTypeDefault MetricsQueryType = iota // MetricsQueryTypeShowGlobal indicates SHOW GLOBAL (STATUS|VARIABLES) query MetricsQueryTypeShowGlobal // MetricsQueryTypeSelect indicates a custom SELECT query MetricsQueryTypeSelect // MetricsQueryTypeUnknown is an unknown query type, which we cannot run. This is an error MetricsQueryTypeUnknown )
func GetMetricsQueryType ¶ added in v0.21.0
func GetMetricsQueryType(query string) MetricsQueryType
GetMetricsQueryType analyzes the type of a metrics query
type Probe ¶ added in v0.21.0
type Probe struct { Alias string Tablet *topodatapb.Tablet CacheMillis int QueryInProgress int64 }
Probe is the minimal configuration required to connect to a MySQL server
type RecentApp ¶
type RecentApp struct { AppName string CheckedAt time.Time StatusCode int ResponseCode tabletmanagerdatapb.CheckThrottlerResponseCode }
RecentApp indicates when an app was last checked
func NewRecentApp ¶
func NewRecentApp(appName string, statusCode int, responseCode tabletmanagerdatapb.CheckThrottlerResponseCode) *RecentApp
NewRecentApp creates a RecentApp
type Scope ¶ added in v0.21.0
type Scope string
Scope defines the tablet range from which a metric is collected. This can be the local tablet ("self") or the entire shard ("shard")
func ScopeFromString ¶ added in v0.21.0
type SelfMetric ¶ added in v0.21.0
type SelfMetric interface { Name() MetricName DefaultScope() Scope DefaultThreshold() float64 RequiresConn() bool Read(ctx context.Context, throttler ThrottlerMetricsPublisher, conn *connpool.Conn) *ThrottleMetric }
type TabletResultMap ¶ added in v0.21.0
type TabletResultMap map[string]MetricResultMap
TabletResultMap maps a tablet to a result
func (TabletResultMap) Split ¶ added in v0.21.0
func (m TabletResultMap) Split(alias string) (withAlias TabletResultMap, all TabletResultMap)
type ThreadsRunningSelfMetric ¶ added in v0.21.0
type ThreadsRunningSelfMetric struct { }
func (*ThreadsRunningSelfMetric) DefaultScope ¶ added in v0.21.0
func (m *ThreadsRunningSelfMetric) DefaultScope() Scope
func (*ThreadsRunningSelfMetric) DefaultThreshold ¶ added in v0.21.0
func (m *ThreadsRunningSelfMetric) DefaultThreshold() float64
func (*ThreadsRunningSelfMetric) Name ¶ added in v0.21.0
func (m *ThreadsRunningSelfMetric) Name() MetricName
func (*ThreadsRunningSelfMetric) Read ¶ added in v0.21.0
func (m *ThreadsRunningSelfMetric) Read(ctx context.Context, throttler ThrottlerMetricsPublisher, conn *connpool.Conn) *ThrottleMetric
func (*ThreadsRunningSelfMetric) RequiresConn ¶ added in v0.21.0
func (m *ThreadsRunningSelfMetric) RequiresConn() bool
type ThrottleMetric ¶ added in v0.21.0
type ThrottleMetric struct { Name MetricName Scope Scope Alias string Value float64 Err error }
ThrottleMetric has the probed metric for a tablet
func NewThrottleMetric ¶ added in v0.21.0
func NewThrottleMetric() *ThrottleMetric
NewThrottleMetric creates a new ThrottleMetric
func ReadSelfMySQLThrottleMetric ¶ added in v0.21.0
func ReadSelfMySQLThrottleMetric(ctx context.Context, conn *connpool.Conn, query string) *ThrottleMetric
ReadSelfMySQLThrottleMetric reads a metric using a given MySQL connection and a query.
func (*ThrottleMetric) Get ¶ added in v0.21.0
func (metric *ThrottleMetric) Get() (float64, error)
Get implements MetricResult
func (*ThrottleMetric) GetTabletAlias ¶ added in v0.21.0
func (metric *ThrottleMetric) GetTabletAlias() string
GetClusterTablet returns the ClusterTablet part of the metric
func (*ThrottleMetric) WithError ¶ added in v0.21.0
func (metric *ThrottleMetric) WithError(err error) *ThrottleMetric
WithError returns this metric with given error
type ThrottleMetrics ¶ added in v0.21.0
type ThrottleMetrics map[MetricName]*ThrottleMetric // nolint:revive
func ReadThrottleMetrics ¶ added in v0.21.0
func ReadThrottleMetrics(ctx context.Context, probe *Probe, metricsFunc func(context.Context) ThrottleMetrics) ThrottleMetrics
ReadThrottleMetrics returns a metric for the given probe. Either by explicit query or via SHOW REPLICA STATUS
type ThrottlerMetricsPublisher ¶ added in v0.21.0
type ThrottlerMetricsPublisher interface {
GetCustomMetricsQuery() string
}
ThrottlerMetricsPublisher is implemented by throttler.Throttler and is used by SelfMetric implementations to query the throttler.
Source Files
¶
- app_throttle.go
- http.go
- inventory.go
- metric_cache.go
- metric_health.go
- metric_name.go
- metric_result.go
- metric_scope.go
- probe.go
- recent_app.go
- self_metric.go
- self_metric_custom_query.go
- self_metric_default.go
- self_metric_lag.go
- self_metric_loadavg.go
- self_metric_threads_running.go
- tablet_results.go
- throttler_metrics_publisher.go