autoscaling

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 15, 2023 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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

func NewHandler

NewHandler creates a HTTP handler for auto scaling.

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

type QueryResult map[string]float64

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

type Strategy struct {
	Rules     []*Rule     `json:"rules"`
	Resources []*Resource `json:"resources"`
}

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

func GetTiDB

func GetTiDB(etcdClient *clientv3.Client, address string) (*TiDBInfo, error)

GetTiDB get TiDB info which registered in PD by address

func GetTiDBs

func GetTiDBs(etcdClient *clientv3.Client) ([]*TiDBInfo, error)

GetTiDBs list TiDB register in PD

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL