From 00e9dc80b5a7b4e06621f882208242ba5535726b Mon Sep 17 00:00:00 2001
From: Song Gao
+(Appears on: +TidbAutoScalerStatus, +TikvAutoScalerStatus) +
++
BasicAutoScalerStatus describe the basic auto-scaling status
+ +Field | +Description | +
---|---|
+metrics
+
+
+[]MetricsStatus
+
+
+ |
+
+(Optional)
+ MetricsStatusList describes the metrics status in the last auto-scaling reconciliation + |
+
+currentReplicas
+
+int32
+
+ |
+
+ CurrentReplicas describes the current replicas for the component(tidb/tikv) + |
+
+recommendedReplicas
+
+int32
+
+ |
+
+(Optional)
+ RecommendedReplicas describes the calculated replicas in the last auto-scaling reconciliation for the component(tidb/tikv) + |
+
+lastAutoScalingTimestamp
+
+
+Kubernetes meta/v1.Time
+
+
+ |
+
+(Optional)
+ LastAutoScalingTimestamp describes the last auto-scaling timestamp for the component(tidb/tikv) + |
+
@@ -3873,6 +3944,58 @@ Kubernetes core/v1.ResourceRequirements
MemberType represents member type
++(Appears on: +BasicAutoScalerStatus) +
++
MetricsStatus describe the basic metrics status in the last auto-scaling reconciliation
+ +Field | +Description | +
---|---|
+name
+
+string
+
+ |
+
+ Name indicates the metrics name + |
+
+currentValue
+
+string
+
+ |
+
+ CurrentValue indicates the value calculated in the last auto-scaling reconciliation + |
+
+thresholdValue
+
+string
+
+ |
+
+ TargetValue indicates the threshold value for this metrics in auto-scaling + |
+
@@ -12640,6 +12763,40 @@ BasicAutoScalerSpec +
+(Appears on: +TidbClusterAutoSclaerStatus) +
++
TidbAutoScalerStatus describe the auto-scaling status of tidb
+ +Field | +Description | +
---|---|
+BasicAutoScalerStatus
+
+
+BasicAutoScalerStatus
+
+
+ |
+
+
+(Members of |
+
@@ -12735,8 +12892,46 @@ TidbAutoScalerSpec TidbClusterAutoScaler)
-
TODO: sync status
+TidbClusterAutoSclaerStatus describe the whole status
+Field | +Description | +
---|---|
+tikv
+
+
+TikvAutoScalerStatus
+
+
+ |
+
+(Optional)
+ Tikv describes the status for the tikv in the last auto-scaling reconciliation + |
+
+tidb
+
+
+TidbAutoScalerStatus
+
+
+ |
+
+(Optional)
+ Tidb describes the status for the tidb in the last auto-scaling reconciliation + |
+
@@ -13628,6 +13823,40 @@ BasicAutoScalerSpec +
+(Appears on: +TidbClusterAutoSclaerStatus) +
++
TikvAutoScalerStatus describe the auto-scaling status of tikv
+ +Field | +Description | +
---|---|
+BasicAutoScalerStatus
+
+
+BasicAutoScalerStatus
+
+
+ |
+
+
+(Members of |
+
diff --git a/examples/auto-scale/tidb-cluster.yaml b/examples/auto-scale/tidb-cluster.yaml index f46ba9a659..9c3c94f86b 100644 --- a/examples/auto-scale/tidb-cluster.yaml +++ b/examples/auto-scale/tidb-cluster.yaml @@ -16,6 +16,7 @@ spec: baseImage: pingcap/tikv replicas: 3 requests: + cpu: "1" storage: "1Gi" config: {} tidb: @@ -24,3 +25,5 @@ spec: service: type: ClusterIP config: {} + requests: + cpu: "1" diff --git a/manifests/crd.yaml b/manifests/crd.yaml index 540344f415..b1eb04dbc8 100644 --- a/manifests/crd.yaml +++ b/manifests/crd.yaml @@ -10676,6 +10676,103 @@ spec: required: - cluster type: object - status: {} + status: + description: TidbClusterAutoSclaerStatus describe the whole status + properties: + tidb: + description: TidbAutoScalerStatus describe the auto-scaling status of + tidb + properties: + currentReplicas: + description: CurrentReplicas describes the current replicas for + the component(tidb/tikv) + format: int32 + type: integer + lastAutoScalingTimestamp: + description: Time is a wrapper around time.Time which supports correct + marshaling to YAML and JSON. Wrappers are provided for many of + the factory methods that the time package offers. + format: date-time + type: string + metrics: + description: MetricsStatusList describes the metrics status in the + last auto-scaling reconciliation + items: + description: MetricsStatus describe the basic metrics status in + the last auto-scaling reconciliation + properties: + currentValue: + description: CurrentValue indicates the value calculated in + the last auto-scaling reconciliation + type: string + name: + description: Name indicates the metrics name + type: string + thresholdValue: + description: TargetValue indicates the threshold value for + this metrics in auto-scaling + type: string + required: + - name + - currentValue + - thresholdValue + type: object + type: array + recommendedReplicas: + description: RecommendedReplicas describes the calculated replicas + in the last auto-scaling reconciliation for the component(tidb/tikv) + format: int32 + type: integer + required: + - currentReplicas + type: object + tikv: + description: TikvAutoScalerStatus describe the auto-scaling status of + tikv + properties: + currentReplicas: + description: CurrentReplicas describes the current replicas for + the component(tidb/tikv) + format: int32 + type: integer + lastAutoScalingTimestamp: + description: Time is a wrapper around time.Time which supports correct + marshaling to YAML and JSON. Wrappers are provided for many of + the factory methods that the time package offers. + format: date-time + type: string + metrics: + description: MetricsStatusList describes the metrics status in the + last auto-scaling reconciliation + items: + description: MetricsStatus describe the basic metrics status in + the last auto-scaling reconciliation + properties: + currentValue: + description: CurrentValue indicates the value calculated in + the last auto-scaling reconciliation + type: string + name: + description: Name indicates the metrics name + type: string + thresholdValue: + description: TargetValue indicates the threshold value for + this metrics in auto-scaling + type: string + required: + - name + - currentValue + - thresholdValue + type: object + type: array + recommendedReplicas: + description: RecommendedReplicas describes the calculated replicas + in the last auto-scaling reconciliation for the component(tidb/tikv) + format: int32 + type: integer + required: + - currentReplicas + type: object + type: object type: object version: v1alpha1 diff --git a/pkg/apis/pingcap/v1alpha1/openapi_generated.go b/pkg/apis/pingcap/v1alpha1/openapi_generated.go index 043dcb2ff2..a571bf8c3d 100644 --- a/pkg/apis/pingcap/v1alpha1/openapi_generated.go +++ b/pkg/apis/pingcap/v1alpha1/openapi_generated.go @@ -35,6 +35,7 @@ func GetOpenAPIDefinitions(ref common.ReferenceCallback) map[string]common.OpenA "github.com/pingcap/tidb-operator/pkg/apis/pingcap/v1alpha1.BackupScheduleSpec": schema_pkg_apis_pingcap_v1alpha1_BackupScheduleSpec(ref), "github.com/pingcap/tidb-operator/pkg/apis/pingcap/v1alpha1.BackupSpec": schema_pkg_apis_pingcap_v1alpha1_BackupSpec(ref), "github.com/pingcap/tidb-operator/pkg/apis/pingcap/v1alpha1.BasicAutoScalerSpec": schema_pkg_apis_pingcap_v1alpha1_BasicAutoScalerSpec(ref), + "github.com/pingcap/tidb-operator/pkg/apis/pingcap/v1alpha1.BasicAutoScalerStatus": schema_pkg_apis_pingcap_v1alpha1_BasicAutoScalerStatus(ref), "github.com/pingcap/tidb-operator/pkg/apis/pingcap/v1alpha1.Binlog": schema_pkg_apis_pingcap_v1alpha1_Binlog(ref), "github.com/pingcap/tidb-operator/pkg/apis/pingcap/v1alpha1.CommonConfig": schema_pkg_apis_pingcap_v1alpha1_CommonConfig(ref), "github.com/pingcap/tidb-operator/pkg/apis/pingcap/v1alpha1.ComponentSpec": schema_pkg_apis_pingcap_v1alpha1_ComponentSpec(ref), @@ -48,6 +49,7 @@ func GetOpenAPIDefinitions(ref common.ReferenceCallback) map[string]common.OpenA "github.com/pingcap/tidb-operator/pkg/apis/pingcap/v1alpha1.IsolationRead": schema_pkg_apis_pingcap_v1alpha1_IsolationRead(ref), "github.com/pingcap/tidb-operator/pkg/apis/pingcap/v1alpha1.Log": schema_pkg_apis_pingcap_v1alpha1_Log(ref), "github.com/pingcap/tidb-operator/pkg/apis/pingcap/v1alpha1.LogTailerSpec": schema_pkg_apis_pingcap_v1alpha1_LogTailerSpec(ref), + "github.com/pingcap/tidb-operator/pkg/apis/pingcap/v1alpha1.MetricsStatus": schema_pkg_apis_pingcap_v1alpha1_MetricsStatus(ref), "github.com/pingcap/tidb-operator/pkg/apis/pingcap/v1alpha1.MonitorContainer": schema_pkg_apis_pingcap_v1alpha1_MonitorContainer(ref), "github.com/pingcap/tidb-operator/pkg/apis/pingcap/v1alpha1.OpenTracing": schema_pkg_apis_pingcap_v1alpha1_OpenTracing(ref), "github.com/pingcap/tidb-operator/pkg/apis/pingcap/v1alpha1.OpenTracingReporter": schema_pkg_apis_pingcap_v1alpha1_OpenTracingReporter(ref), @@ -108,10 +110,12 @@ func GetOpenAPIDefinitions(ref common.ReferenceCallback) map[string]common.OpenA "github.com/pingcap/tidb-operator/pkg/apis/pingcap/v1alpha1.TiKVTitanCfConfig": schema_pkg_apis_pingcap_v1alpha1_TiKVTitanCfConfig(ref), "github.com/pingcap/tidb-operator/pkg/apis/pingcap/v1alpha1.TiKVTitanDBConfig": schema_pkg_apis_pingcap_v1alpha1_TiKVTitanDBConfig(ref), "github.com/pingcap/tidb-operator/pkg/apis/pingcap/v1alpha1.TidbAutoScalerSpec": schema_pkg_apis_pingcap_v1alpha1_TidbAutoScalerSpec(ref), + "github.com/pingcap/tidb-operator/pkg/apis/pingcap/v1alpha1.TidbAutoScalerStatus": schema_pkg_apis_pingcap_v1alpha1_TidbAutoScalerStatus(ref), "github.com/pingcap/tidb-operator/pkg/apis/pingcap/v1alpha1.TidbCluster": schema_pkg_apis_pingcap_v1alpha1_TidbCluster(ref), "github.com/pingcap/tidb-operator/pkg/apis/pingcap/v1alpha1.TidbClusterAutoScaler": schema_pkg_apis_pingcap_v1alpha1_TidbClusterAutoScaler(ref), "github.com/pingcap/tidb-operator/pkg/apis/pingcap/v1alpha1.TidbClusterAutoScalerList": schema_pkg_apis_pingcap_v1alpha1_TidbClusterAutoScalerList(ref), "github.com/pingcap/tidb-operator/pkg/apis/pingcap/v1alpha1.TidbClusterAutoScalerSpec": schema_pkg_apis_pingcap_v1alpha1_TidbClusterAutoScalerSpec(ref), + "github.com/pingcap/tidb-operator/pkg/apis/pingcap/v1alpha1.TidbClusterAutoSclaerStatus": schema_pkg_apis_pingcap_v1alpha1_TidbClusterAutoSclaerStatus(ref), "github.com/pingcap/tidb-operator/pkg/apis/pingcap/v1alpha1.TidbClusterList": schema_pkg_apis_pingcap_v1alpha1_TidbClusterList(ref), "github.com/pingcap/tidb-operator/pkg/apis/pingcap/v1alpha1.TidbClusterRef": schema_pkg_apis_pingcap_v1alpha1_TidbClusterRef(ref), "github.com/pingcap/tidb-operator/pkg/apis/pingcap/v1alpha1.TidbClusterSpec": schema_pkg_apis_pingcap_v1alpha1_TidbClusterSpec(ref), @@ -124,6 +128,7 @@ func GetOpenAPIDefinitions(ref common.ReferenceCallback) map[string]common.OpenA "github.com/pingcap/tidb-operator/pkg/apis/pingcap/v1alpha1.TidbMonitorRef": schema_pkg_apis_pingcap_v1alpha1_TidbMonitorRef(ref), "github.com/pingcap/tidb-operator/pkg/apis/pingcap/v1alpha1.TidbMonitorSpec": schema_pkg_apis_pingcap_v1alpha1_TidbMonitorSpec(ref), "github.com/pingcap/tidb-operator/pkg/apis/pingcap/v1alpha1.TikvAutoScalerSpec": schema_pkg_apis_pingcap_v1alpha1_TikvAutoScalerSpec(ref), + "github.com/pingcap/tidb-operator/pkg/apis/pingcap/v1alpha1.TikvAutoScalerStatus": schema_pkg_apis_pingcap_v1alpha1_TikvAutoScalerStatus(ref), "github.com/pingcap/tidb-operator/pkg/apis/pingcap/v1alpha1.TxnLocalLatches": schema_pkg_apis_pingcap_v1alpha1_TxnLocalLatches(ref), "k8s.io/api/core/v1.AWSElasticBlockStoreVolumeSource": schema_k8sio_api_core_v1_AWSElasticBlockStoreVolumeSource(ref), "k8s.io/api/core/v1.Affinity": schema_k8sio_api_core_v1_Affinity(ref), @@ -875,6 +880,55 @@ func schema_pkg_apis_pingcap_v1alpha1_BasicAutoScalerSpec(ref common.ReferenceCa } } +func schema_pkg_apis_pingcap_v1alpha1_BasicAutoScalerStatus(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Description: "BasicAutoScalerStatus describe the basic auto-scaling status", + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "metrics": { + SchemaProps: spec.SchemaProps{ + Description: "MetricsStatusList describes the metrics status in the last auto-scaling reconciliation", + Type: []string{"array"}, + Items: &spec.SchemaOrArray{ + Schema: &spec.Schema{ + SchemaProps: spec.SchemaProps{ + Ref: ref("github.com/pingcap/tidb-operator/pkg/apis/pingcap/v1alpha1.MetricsStatus"), + }, + }, + }, + }, + }, + "currentReplicas": { + SchemaProps: spec.SchemaProps{ + Description: "CurrentReplicas describes the current replicas for the component(tidb/tikv)", + Type: []string{"integer"}, + Format: "int32", + }, + }, + "recommendedReplicas": { + SchemaProps: spec.SchemaProps{ + Description: "RecommendedReplicas describes the calculated replicas in the last auto-scaling reconciliation for the component(tidb/tikv)", + Type: []string{"integer"}, + Format: "int32", + }, + }, + "lastAutoScalingTimestamp": { + SchemaProps: spec.SchemaProps{ + Description: "LastAutoScalingTimestamp describes the last auto-scaling timestamp for the component(tidb/tikv)", + Ref: ref("k8s.io/apimachinery/pkg/apis/meta/v1.Time"), + }, + }, + }, + Required: []string{"currentReplicas"}, + }, + }, + Dependencies: []string{ + "github.com/pingcap/tidb-operator/pkg/apis/pingcap/v1alpha1.MetricsStatus", "k8s.io/apimachinery/pkg/apis/meta/v1.Time"}, + } +} + func schema_pkg_apis_pingcap_v1alpha1_Binlog(ref common.ReferenceCallback) common.OpenAPIDefinition { return common.OpenAPIDefinition{ Schema: spec.Schema{ @@ -1526,6 +1580,41 @@ func schema_pkg_apis_pingcap_v1alpha1_LogTailerSpec(ref common.ReferenceCallback } } +func schema_pkg_apis_pingcap_v1alpha1_MetricsStatus(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Description: "MetricsStatus describe the basic metrics status in the last auto-scaling reconciliation", + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "name": { + SchemaProps: spec.SchemaProps{ + Description: "Name indicates the metrics name", + Type: []string{"string"}, + Format: "", + }, + }, + "currentValue": { + SchemaProps: spec.SchemaProps{ + Description: "CurrentValue indicates the value calculated in the last auto-scaling reconciliation", + Type: []string{"string"}, + Format: "", + }, + }, + "thresholdValue": { + SchemaProps: spec.SchemaProps{ + Description: "TargetValue indicates the threshold value for this metrics in auto-scaling", + Type: []string{"string"}, + Format: "", + }, + }, + }, + Required: []string{"name", "currentValue", "thresholdValue"}, + }, + }, + } +} + func schema_pkg_apis_pingcap_v1alpha1_MonitorContainer(ref common.ReferenceCallback) common.OpenAPIDefinition { return common.OpenAPIDefinition{ Schema: spec.Schema{ @@ -6547,6 +6636,55 @@ func schema_pkg_apis_pingcap_v1alpha1_TidbAutoScalerSpec(ref common.ReferenceCal } } +func schema_pkg_apis_pingcap_v1alpha1_TidbAutoScalerStatus(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Description: "TidbAutoScalerStatus describe the auto-scaling status of tidb", + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "metrics": { + SchemaProps: spec.SchemaProps{ + Description: "MetricsStatusList describes the metrics status in the last auto-scaling reconciliation", + Type: []string{"array"}, + Items: &spec.SchemaOrArray{ + Schema: &spec.Schema{ + SchemaProps: spec.SchemaProps{ + Ref: ref("github.com/pingcap/tidb-operator/pkg/apis/pingcap/v1alpha1.MetricsStatus"), + }, + }, + }, + }, + }, + "currentReplicas": { + SchemaProps: spec.SchemaProps{ + Description: "CurrentReplicas describes the current replicas for the component(tidb/tikv)", + Type: []string{"integer"}, + Format: "int32", + }, + }, + "recommendedReplicas": { + SchemaProps: spec.SchemaProps{ + Description: "RecommendedReplicas describes the calculated replicas in the last auto-scaling reconciliation for the component(tidb/tikv)", + Type: []string{"integer"}, + Format: "int32", + }, + }, + "lastAutoScalingTimestamp": { + SchemaProps: spec.SchemaProps{ + Description: "LastAutoScalingTimestamp describes the last auto-scaling timestamp for the component(tidb/tikv)", + Ref: ref("k8s.io/apimachinery/pkg/apis/meta/v1.Time"), + }, + }, + }, + Required: []string{"currentReplicas"}, + }, + }, + Dependencies: []string{ + "github.com/pingcap/tidb-operator/pkg/apis/pingcap/v1alpha1.MetricsStatus", "k8s.io/apimachinery/pkg/apis/meta/v1.Time"}, + } +} + func schema_pkg_apis_pingcap_v1alpha1_TidbCluster(ref common.ReferenceCallback) common.OpenAPIDefinition { return common.OpenAPIDefinition{ Schema: spec.Schema{ @@ -6714,6 +6852,33 @@ func schema_pkg_apis_pingcap_v1alpha1_TidbClusterAutoScalerSpec(ref common.Refer } } +func schema_pkg_apis_pingcap_v1alpha1_TidbClusterAutoSclaerStatus(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Description: "TidbClusterAutoSclaerStatus describe the whole status", + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "tikv": { + SchemaProps: spec.SchemaProps{ + Description: "Tikv describes the status for the tikv in the last auto-scaling reconciliation", + Ref: ref("github.com/pingcap/tidb-operator/pkg/apis/pingcap/v1alpha1.TikvAutoScalerStatus"), + }, + }, + "tidb": { + SchemaProps: spec.SchemaProps{ + Description: "Tidb describes the status for the tidb in the last auto-scaling reconciliation", + Ref: ref("github.com/pingcap/tidb-operator/pkg/apis/pingcap/v1alpha1.TidbAutoScalerStatus"), + }, + }, + }, + }, + }, + Dependencies: []string{ + "github.com/pingcap/tidb-operator/pkg/apis/pingcap/v1alpha1.TidbAutoScalerStatus", "github.com/pingcap/tidb-operator/pkg/apis/pingcap/v1alpha1.TikvAutoScalerStatus"}, + } +} + func schema_pkg_apis_pingcap_v1alpha1_TidbClusterList(ref common.ReferenceCallback) common.OpenAPIDefinition { return common.OpenAPIDefinition{ Schema: spec.Schema{ @@ -7493,6 +7658,55 @@ func schema_pkg_apis_pingcap_v1alpha1_TikvAutoScalerSpec(ref common.ReferenceCal } } +func schema_pkg_apis_pingcap_v1alpha1_TikvAutoScalerStatus(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Description: "TikvAutoScalerStatus describe the auto-scaling status of tikv", + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "metrics": { + SchemaProps: spec.SchemaProps{ + Description: "MetricsStatusList describes the metrics status in the last auto-scaling reconciliation", + Type: []string{"array"}, + Items: &spec.SchemaOrArray{ + Schema: &spec.Schema{ + SchemaProps: spec.SchemaProps{ + Ref: ref("github.com/pingcap/tidb-operator/pkg/apis/pingcap/v1alpha1.MetricsStatus"), + }, + }, + }, + }, + }, + "currentReplicas": { + SchemaProps: spec.SchemaProps{ + Description: "CurrentReplicas describes the current replicas for the component(tidb/tikv)", + Type: []string{"integer"}, + Format: "int32", + }, + }, + "recommendedReplicas": { + SchemaProps: spec.SchemaProps{ + Description: "RecommendedReplicas describes the calculated replicas in the last auto-scaling reconciliation for the component(tidb/tikv)", + Type: []string{"integer"}, + Format: "int32", + }, + }, + "lastAutoScalingTimestamp": { + SchemaProps: spec.SchemaProps{ + Description: "LastAutoScalingTimestamp describes the last auto-scaling timestamp for the component(tidb/tikv)", + Ref: ref("k8s.io/apimachinery/pkg/apis/meta/v1.Time"), + }, + }, + }, + Required: []string{"currentReplicas"}, + }, + }, + Dependencies: []string{ + "github.com/pingcap/tidb-operator/pkg/apis/pingcap/v1alpha1.MetricsStatus", "k8s.io/apimachinery/pkg/apis/meta/v1.Time"}, + } +} + func schema_pkg_apis_pingcap_v1alpha1_TxnLocalLatches(ref common.ReferenceCallback) common.OpenAPIDefinition { return common.OpenAPIDefinition{ Schema: spec.Schema{ diff --git a/pkg/apis/pingcap/v1alpha1/tidbclusterautoscaler_types.go b/pkg/apis/pingcap/v1alpha1/tidbclusterautoscaler_types.go index a4639eabd8..e38a570fa1 100644 --- a/pkg/apis/pingcap/v1alpha1/tidbclusterautoscaler_types.go +++ b/pkg/apis/pingcap/v1alpha1/tidbclusterautoscaler_types.go @@ -149,6 +149,52 @@ type TidbMonitorRef struct { Name string `json:"name"` } -// TODO: sync status +// +k8s:openapi-gen=true +// TidbClusterAutoSclaerStatus describe the whole status type TidbClusterAutoSclaerStatus struct { + // Tikv describes the status for the tikv in the last auto-scaling reconciliation + // +optional + TiKV *TikvAutoScalerStatus `json:"tikv,omitempty"` + // Tidb describes the status for the tidb in the last auto-scaling reconciliation + // +optional + TiDB *TidbAutoScalerStatus `json:"tidb,omitempty"` +} + +// +k8s:openapi-gen=true +// TidbAutoScalerStatus describe the auto-scaling status of tidb +type TidbAutoScalerStatus struct { + BasicAutoScalerStatus `json:",inline"` +} + +// +k8s:openapi-gen=true +// TikvAutoScalerStatus describe the auto-scaling status of tikv +type TikvAutoScalerStatus struct { + BasicAutoScalerStatus `json:",inline"` +} + +// +k8s:openapi-gen=true +// BasicAutoScalerStatus describe the basic auto-scaling status +type BasicAutoScalerStatus struct { + // MetricsStatusList describes the metrics status in the last auto-scaling reconciliation + // +optional + MetricsStatusList []MetricsStatus `json:"metrics,omitempty"` + // CurrentReplicas describes the current replicas for the component(tidb/tikv) + CurrentReplicas int32 `json:"currentReplicas"` + // RecommendedReplicas describes the calculated replicas in the last auto-scaling reconciliation for the component(tidb/tikv) + // +optional + RecommendedReplicas *int32 `json:"recommendedReplicas,omitempty"` + // LastAutoScalingTimestamp describes the last auto-scaling timestamp for the component(tidb/tikv) + // +optional + LastAutoScalingTimestamp *metav1.Time `json:"lastAutoScalingTimestamp,omitempty"` +} + +// +k8s:openapi-gen=true +// MetricsStatus describe the basic metrics status in the last auto-scaling reconciliation +type MetricsStatus struct { + // Name indicates the metrics name + Name string `json:"name"` + // CurrentValue indicates the value calculated in the last auto-scaling reconciliation + CurrentValue string `json:"currentValue"` + // TargetValue indicates the threshold value for this metrics in auto-scaling + ThresholdValue string `json:"thresholdValue"` } diff --git a/pkg/apis/pingcap/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/pingcap/v1alpha1/zz_generated.deepcopy.go index 77a6baff9f..44da493b4a 100644 --- a/pkg/apis/pingcap/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/pingcap/v1alpha1/zz_generated.deepcopy.go @@ -384,6 +384,36 @@ func (in *BasicAutoScalerSpec) DeepCopy() *BasicAutoScalerSpec { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *BasicAutoScalerStatus) DeepCopyInto(out *BasicAutoScalerStatus) { + *out = *in + if in.MetricsStatusList != nil { + in, out := &in.MetricsStatusList, &out.MetricsStatusList + *out = make([]MetricsStatus, len(*in)) + copy(*out, *in) + } + if in.RecommendedReplicas != nil { + in, out := &in.RecommendedReplicas, &out.RecommendedReplicas + *out = new(int32) + **out = **in + } + if in.LastAutoScalingTimestamp != nil { + in, out := &in.LastAutoScalingTimestamp, &out.LastAutoScalingTimestamp + *out = (*in).DeepCopy() + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new BasicAutoScalerStatus. +func (in *BasicAutoScalerStatus) DeepCopy() *BasicAutoScalerStatus { + if in == nil { + return nil + } + out := new(BasicAutoScalerStatus) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *Binlog) DeepCopyInto(out *Binlog) { *out = *in @@ -1325,6 +1355,22 @@ func (in *LogTailerSpec) DeepCopy() *LogTailerSpec { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *MetricsStatus) DeepCopyInto(out *MetricsStatus) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MetricsStatus. +func (in *MetricsStatus) DeepCopy() *MetricsStatus { + if in == nil { + return nil + } + out := new(MetricsStatus) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *MonitorContainer) DeepCopyInto(out *MonitorContainer) { *out = *in @@ -4734,6 +4780,23 @@ func (in *TidbAutoScalerSpec) DeepCopy() *TidbAutoScalerSpec { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *TidbAutoScalerStatus) DeepCopyInto(out *TidbAutoScalerStatus) { + *out = *in + in.BasicAutoScalerStatus.DeepCopyInto(&out.BasicAutoScalerStatus) + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TidbAutoScalerStatus. +func (in *TidbAutoScalerStatus) DeepCopy() *TidbAutoScalerStatus { + if in == nil { + return nil + } + out := new(TidbAutoScalerStatus) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *TidbCluster) DeepCopyInto(out *TidbCluster) { *out = *in @@ -4768,7 +4831,7 @@ func (in *TidbClusterAutoScaler) DeepCopyInto(out *TidbClusterAutoScaler) { out.TypeMeta = in.TypeMeta in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) in.Spec.DeepCopyInto(&out.Spec) - out.Status = in.Status + in.Status.DeepCopyInto(&out.Status) return } @@ -4863,6 +4926,16 @@ func (in *TidbClusterAutoScalerSpec) DeepCopy() *TidbClusterAutoScalerSpec { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *TidbClusterAutoSclaerStatus) DeepCopyInto(out *TidbClusterAutoSclaerStatus) { *out = *in + if in.TiKV != nil { + in, out := &in.TiKV, &out.TiKV + *out = new(TikvAutoScalerStatus) + (*in).DeepCopyInto(*out) + } + if in.TiDB != nil { + in, out := &in.TiDB, &out.TiDB + *out = new(TidbAutoScalerStatus) + (*in).DeepCopyInto(*out) + } return } @@ -5331,6 +5404,23 @@ func (in *TikvAutoScalerSpec) DeepCopy() *TikvAutoScalerSpec { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *TikvAutoScalerStatus) DeepCopyInto(out *TikvAutoScalerStatus) { + *out = *in + in.BasicAutoScalerStatus.DeepCopyInto(&out.BasicAutoScalerStatus) + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TikvAutoScalerStatus. +func (in *TikvAutoScalerStatus) DeepCopy() *TikvAutoScalerStatus { + if in == nil { + return nil + } + out := new(TikvAutoScalerStatus) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *TxnLocalLatches) DeepCopyInto(out *TxnLocalLatches) { *out = *in diff --git a/pkg/autoscaler/autoscaler/autoscaler_manager.go b/pkg/autoscaler/autoscaler/autoscaler_manager.go index 16784cee1c..6fffa03eb3 100644 --- a/pkg/autoscaler/autoscaler/autoscaler_manager.go +++ b/pkg/autoscaler/autoscaler/autoscaler_manager.go @@ -15,13 +15,16 @@ package autoscaler import ( "fmt" + "strconv" "strings" + "time" "github.com/pingcap/tidb-operator/pkg/apis/pingcap/v1alpha1" "github.com/pingcap/tidb-operator/pkg/client/clientset/versioned" informers "github.com/pingcap/tidb-operator/pkg/client/informers/externalversions" v1alpha1listers "github.com/pingcap/tidb-operator/pkg/client/listers/pingcap/v1alpha1" "github.com/pingcap/tidb-operator/pkg/controller" + "github.com/pingcap/tidb-operator/pkg/label" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -85,7 +88,7 @@ func (am *autoScalerManager) Sync(tac *v1alpha1.TidbClusterAutoScaler) error { if err := am.syncTidbClusterReplicas(tac, tc, oldTc); err != nil { return err } - return am.syncAutoScalingStatus(tc, oldTc, tac) + return am.updateAutoScaling(oldTc, tac) } func (am *autoScalerManager) syncAutoScaling(tc *v1alpha1.TidbCluster, tac *v1alpha1.TidbClusterAutoScaler) error { @@ -125,9 +128,49 @@ func (am *autoScalerManager) syncTidbClusterReplicas(tac *v1alpha1.TidbClusterAu return nil } -//TODO: sync tac status -func (am *autoScalerManager) syncAutoScalingStatus(tc *v1alpha1.TidbCluster, oldTc *v1alpha1.TidbCluster, +func (am *autoScalerManager) updateAutoScaling(oldTc *v1alpha1.TidbCluster, tac *v1alpha1.TidbClusterAutoScaler) error { + if tac.Annotations == nil { + tac.Annotations = map[string]string{} + } + f := func(key string) (*time.Time, error) { + v, ok := tac.Annotations[key] + if ok { + ts, err := strconv.ParseInt(v, 10, 64) + if err != nil { + klog.Errorf("failed to convert label[%s] key to int64, err:%v", key, err) + return nil, err + } + t := time.Unix(ts, 0) + return &t, nil + } + return nil, nil + } + + if tac.Spec.TiKV != nil { + tac.Status.TiKV.CurrentReplicas = oldTc.Status.TiKV.StatefulSet.CurrentReplicas + lastTimestamp, err := f(label.AnnTiKVLastAutoScalingTimestamp) + if err != nil { + return err + } + if lastTimestamp != nil { + tac.Status.TiKV.LastAutoScalingTimestamp = &metav1.Time{Time: *lastTimestamp} + } + } else { + tac.Status.TiKV = nil + } + if tac.Spec.TiDB != nil { + tac.Status.TiDB.CurrentReplicas = oldTc.Status.TiDB.StatefulSet.CurrentReplicas + lastTimestamp, err := f(label.AnnTiDBLastAutoScalingTimestamp) + if err != nil { + return err + } + if lastTimestamp != nil { + tac.Status.TiDB.LastAutoScalingTimestamp = &metav1.Time{Time: *lastTimestamp} + } + } else { + tac.Status.TiDB = nil + } return am.updateTidbClusterAutoScaler(tac) } diff --git a/pkg/autoscaler/autoscaler/calculate/cpu.go b/pkg/autoscaler/autoscaler/calculate/cpu.go index dcad599ded..2d803fe205 100644 --- a/pkg/autoscaler/autoscaler/calculate/cpu.go +++ b/pkg/autoscaler/autoscaler/calculate/cpu.go @@ -65,6 +65,16 @@ func CalculateRecomendedReplicasByCpuCosts(tac *v1alpha1.TidbClusterAutoScaler, if err != nil { return -1, err } + metrics := v1alpha1.MetricsStatus{ + Name: string(MetricTypeCPU), + CurrentValue: fmt.Sprintf("%v", cpuSecsTotal), + ThresholdValue: fmt.Sprintf("%v", expectedCpuSecsTotal), + } + if memberType == v1alpha1.TiKVMemberType { + addMetricsStatusIntoMetricsStatusList(metrics, &tac.Status.TiKV.BasicAutoScalerStatus) + } else if memberType == v1alpha1.TiDBMemberType { + addMetricsStatusIntoMetricsStatusList(metrics, &tac.Status.TiDB.BasicAutoScalerStatus) + } return rc, nil } diff --git a/pkg/autoscaler/autoscaler/calculate/util.go b/pkg/autoscaler/autoscaler/calculate/util.go index 97c3cb5bb1..14ded46ec9 100644 --- a/pkg/autoscaler/autoscaler/calculate/util.go +++ b/pkg/autoscaler/autoscaler/calculate/util.go @@ -59,6 +59,20 @@ func filterContainer(tac *v1alpha1.TidbClusterAutoScaler, sts *appsv1.StatefulSe return nil, fmt.Errorf("tac[%s/%s]'s Target have not %s container", tac.Namespace, tac.Name, containerName) } +func addMetricsStatusIntoMetricsStatusList(metrics v1alpha1.MetricsStatus, basicStatus *v1alpha1.BasicAutoScalerStatus) { + if basicStatus.MetricsStatusList == nil { + basicStatus.MetricsStatusList = []v1alpha1.MetricsStatus{} + } + for id, m := range basicStatus.MetricsStatusList { + if m.Name == metrics.Name { + basicStatus.MetricsStatusList[id] = metrics + return + } + } + basicStatus.MetricsStatusList = append(basicStatus.MetricsStatusList, metrics) + return +} + const ( statusSuccess = "success" ) diff --git a/pkg/autoscaler/autoscaler/tidb_autoscaler.go b/pkg/autoscaler/autoscaler/tidb_autoscaler.go index ef81ab94e3..9b130ec8ce 100644 --- a/pkg/autoscaler/autoscaler/tidb_autoscaler.go +++ b/pkg/autoscaler/autoscaler/tidb_autoscaler.go @@ -29,6 +29,9 @@ func (am *autoScalerManager) syncTiDB(tc *v1alpha1.TidbCluster, tac *v1alpha1.Ti if tac.Spec.TiDB == nil { return nil } + if tac.Status.TiDB == nil { + tac.Status.TiDB = &v1alpha1.TidbAutoScalerStatus{} + } sts, err := am.stsLister.StatefulSets(tc.Namespace).Get(operatorUtils.GetStatefulSetName(tc, v1alpha1.TiDBMemberType)) if err != nil { return err @@ -71,6 +74,7 @@ func syncTiDBAfterCalculated(tc *v1alpha1.TidbCluster, tac *v1alpha1.TidbCluster func updateTcTiDBIfScale(tc *v1alpha1.TidbCluster, tac *v1alpha1.TidbClusterAutoScaler, recommendedReplicas int32) error { tac.Annotations[label.AnnTiDBLastAutoScalingTimestamp] = fmt.Sprintf("%d", time.Now().Unix()) tc.Spec.TiDB.Replicas = recommendedReplicas + tac.Status.TiDB.RecommendedReplicas = &recommendedReplicas return nil } diff --git a/pkg/autoscaler/autoscaler/tikv_autoscaler.go b/pkg/autoscaler/autoscaler/tikv_autoscaler.go index 0d5b519b54..b36c00e601 100644 --- a/pkg/autoscaler/autoscaler/tikv_autoscaler.go +++ b/pkg/autoscaler/autoscaler/tikv_autoscaler.go @@ -30,6 +30,9 @@ func (am *autoScalerManager) syncTiKV(tc *v1alpha1.TidbCluster, tac *v1alpha1.Ti if tac.Spec.TiKV == nil { return nil } + if tac.Status.TiKV == nil { + tac.Status.TiKV = &v1alpha1.TikvAutoScalerStatus{} + } sts, err := am.stsLister.StatefulSets(tc.Namespace).Get(operatorUtils.GetStatefulSetName(tc, v1alpha1.TiKVMemberType)) if err != nil { return err @@ -100,6 +103,7 @@ func updateTcTiKVIfScale(tc *v1alpha1.TidbCluster, tac *v1alpha1.TidbClusterAuto } } tc.Spec.TiKV.Replicas = recommendedReplicas + tac.Status.TiKV.RecommendedReplicas = &recommendedReplicas return nil }