Documentation ¶
Index ¶
- Variables
- func NewHandler(_ context.Context, svr *server.Server) (http.Handler, apiutil.APIServiceGroup, error)
- type CPURule
- type ComponentType
- type HTTPHandler
- type MetricType
- type Plan
- type PrometheusQuerier
- type Querier
- type QueryOptions
- type QueryResult
- type Resource
- type Rule
- type StorageRule
- type Strategy
- type TiDBInfo
Constants ¶
This section is empty.
Variables ¶
var ( // MetricsTimeDuration is used to get the metrics of a certain time period. // This must be long enough to cover at least 2 scrape intervals // Or you will get nothing when querying CPU usage MetricsTimeDuration = time.Minute // MaxScaleOutStep is used to indicate the maximum number of instance for scaling out operations at once. MaxScaleOutStep uint64 = 1 // MaxScaleInStep is used to indicate the maximum number of instance for scaling in operations at once. MaxScaleInStep uint64 = 1 )
TODO: adjust the value or make it configurable.
Functions ¶
Types ¶
type CPURule ¶
type CPURule struct { MaxThreshold float64 `json:"max_threshold"` MinThreshold float64 `json:"min_threshold"` ResourceTypes []string `json:"resource_types"` }
CPURule is the constraints about CPU.
type ComponentType ¶
type ComponentType int
ComponentType distinguishes different kinds of components.
const ( // TiKV indicates the TiKV component TiKV ComponentType = iota // TiDB indicates the TiDB component TiDB )
func (ComponentType) String ¶
func (c ComponentType) String() string
type HTTPHandler ¶
type HTTPHandler struct {
// contains filtered or unexported fields
}
HTTPHandler is a handler to handle the auto scaling HTTP request.
func NewHTTPHandler ¶
func NewHTTPHandler(svr *server.Server, rd *render.Render) *HTTPHandler
NewHTTPHandler creates a HTTPHandler.
func (*HTTPHandler) ServeHTTP ¶
func (h *HTTPHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
type MetricType ¶
type MetricType int
MetricType distinguishes different kinds of metrics
const ( // CPUUsage is used cpu time in the duration CPUUsage MetricType = iota // CPUQuota is cpu cores quota for each instance CPUQuota )
func (MetricType) String ¶
func (c MetricType) String() string
type Plan ¶
type Plan struct { Component string `json:"component"` Count uint64 `json:"count"` ResourceType string `json:"resource_type"` Labels map[string]string `json:"labels"` }
Plan is the final result of auto scaling, which indicates how to scale in or scale out.
type PrometheusQuerier ¶
type PrometheusQuerier struct {
// contains filtered or unexported fields
}
PrometheusQuerier query metrics from Prometheus
func NewPrometheusQuerier ¶
func NewPrometheusQuerier(client promClient.Client) *PrometheusQuerier
NewPrometheusQuerier returns a PrometheusQuerier
func (*PrometheusQuerier) Query ¶
func (prom *PrometheusQuerier) Query(options *QueryOptions) (QueryResult, error)
Query do the real query on Prometheus and returns metric value for each instance
type Querier ¶
type Querier interface { // Query does the real query with options Query(options *QueryOptions) (QueryResult, error) }
Querier provides interfaces to query metrics
type QueryOptions ¶
type QueryOptions struct {
// contains filtered or unexported fields
}
QueryOptions includes parameters for later metrics query
func NewQueryOptions ¶
func NewQueryOptions(component ComponentType, metric MetricType, addresses []string, timestamp time.Time, duration time.Duration) *QueryOptions
NewQueryOptions constructs a new QueryOptions for metrics The options will be used to query metrics of `duration` long UNTIL `timestamp` which has `metric` type (CPU, Storage) for a specific `component` type and returns metrics value for each instance in `instances`
type QueryResult ¶
QueryResult stores metrics value for each instance
type Resource ¶
type Resource struct { ResourceType string `json:"resource_type"` // The basic unit of CPU is milli-core. CPU uint64 `json:"cpu"` // The basic unit of memory is byte. Memory uint64 `json:"memory"` // The basic unit of storage is byte. Storage uint64 `json:"storage"` Count *uint64 `json:"count,omitempty"` }
Resource represents a kind of resource set including CPU, memory, storage.
type Rule ¶
type Rule struct { Component string `json:"component"` CPURule *CPURule `json:"cpu_rule,omitempty"` StorageRule *StorageRule `json:"storage_rule,omitempty"` }
Rule is a set of constraints for a kind of component.
type StorageRule ¶
type StorageRule struct { MinThreshold float64 `json:"min_threshold"` ResourceTypes []string `json:"resource_types"` }
StorageRule is the constraints about storage.
type Strategy ¶
Strategy within a HTTP request provides rules and resources to help make decision for auto scaling.
type TiDBInfo ¶
type TiDBInfo struct { Version *string `json:"version,omitempty"` StartTimestamp *int64 `json:"start_timestamp,omitempty"` Labels map[string]string `json:"labels"` GitHash *string `json:"git_hash,omitempty"` Address string }
TiDBInfo record the detail tidb info