Skip to content

Commit

Permalink
cherry pick pingcap#2862 to release-1.1
Browse files Browse the repository at this point in the history
Signed-off-by: ti-srebot <[email protected]>
  • Loading branch information
Yisaer authored and ti-srebot committed Jul 6, 2020
1 parent 4871269 commit 3bf11be
Show file tree
Hide file tree
Showing 12 changed files with 98 additions and 427 deletions.
31 changes: 0 additions & 31 deletions docs/api-references/docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -1760,10 +1760,6 @@ TidbMonitorStatus
</table>
<h3 id="autoscalerphase">AutoScalerPhase</h3>
<p>
(<em>Appears on:</em>
<a href="#basicautoscalerstatus">BasicAutoScalerStatus</a>)
</p>
<p>
</p>
<h3 id="brconfig">BRConfig</h3>
<p>
Expand Down Expand Up @@ -2619,19 +2615,6 @@ to fetch the recommended replicas for TiKV/TiDB</p>
<tbody>
<tr>
<td>
<code>phase</code></br>
<em>
<a href="#autoscalerphase">
AutoScalerPhase
</a>
</em>
</td>
<td>
<p>Phase describes cluster auto scaling phase</p>
</td>
</tr>
<tr>
<td>
<code>metrics</code></br>
<em>
<a href="#metricsstatus">
Expand Down Expand Up @@ -16167,20 +16150,6 @@ BasicAutoScalerSpec
</p>
</td>
</tr>
<tr>
<td>
<code>readyToScaleThresholdSeconds</code></br>
<em>
int32
</em>
</td>
<td>
<em>(Optional)</em>
<p>ReadyToScaleThresholdSeconds represents duration that the ReadyToScale phase
should last for before auto scaling.
If not set, the default ReadyToScaleThresholdSeconds will be set to 30.</p>
</td>
</tr>
</tbody>
</table>
<h3 id="tikvautoscalerstatus">TikvAutoScalerStatus</h3>
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ require (
github.com/grpc-ecosystem/go-grpc-middleware v1.0.1-0.20190118093823-f849b5445de4 // indirect
github.com/grpc-ecosystem/grpc-gateway v1.13.0 // indirect
github.com/imdario/mergo v0.3.7 // indirect
github.com/jonboulle/clockwork v0.1.0
github.com/juju/errors v0.0.0-20180806074554-22422dad46e1
github.com/juju/loggo v0.0.0-20180524022052-584905176618 // indirect
github.com/juju/testing v0.0.0-20180920084828-472a3e8b2073 // indirect
Expand Down
7 changes: 0 additions & 7 deletions manifests/crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13955,9 +13955,6 @@ spec:
minReplicas:
format: int32
type: integer
readyToScaleThresholdSeconds:
format: int32
type: integer
scaleInIntervalSeconds:
format: int32
type: integer
Expand Down Expand Up @@ -13995,8 +13992,6 @@ spec:
- thresholdValue
type: object
type: array
phase:
type: string
recommendedReplicas:
format: int32
type: integer
Expand Down Expand Up @@ -14026,8 +14021,6 @@ spec:
- thresholdValue
type: object
type: array
phase:
type: string
recommendedReplicas:
format: int32
type: integer
Expand Down
28 changes: 0 additions & 28 deletions pkg/apis/pingcap/v1alpha1/openapi_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 0 additions & 8 deletions pkg/apis/pingcap/v1alpha1/tidbclusterautoscaler_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,6 @@ type TidbClusterAutoScalerSpec struct {
// TikvAutoScalerSpec describes the spec for tikv auto-scaling
type TikvAutoScalerSpec struct {
BasicAutoScalerSpec `json:",inline"`

// ReadyToScaleThresholdSeconds represents duration that the ReadyToScale phase
// should last for before auto scaling.
// If not set, the default ReadyToScaleThresholdSeconds will be set to 30.
// +optional
ReadyToScaleThresholdSeconds *int32 `json:"readyToScaleThresholdSeconds,omitempty"`
}

// +k8s:openapi-gen=true
Expand Down Expand Up @@ -183,8 +177,6 @@ type TikvAutoScalerStatus struct {
// +k8s:openapi-gen=true
// BasicAutoScalerStatus describe the basic auto-scaling status
type BasicAutoScalerStatus struct {
// Phase describes cluster auto scaling phase
Phase AutoScalerPhase `json:"phase,omitempty"`
// MetricsStatusList describes the metrics status in the last auto-scaling reconciliation
// +optional
MetricsStatusList []MetricsStatus `json:"metrics,omitempty"`
Expand Down
5 changes: 0 additions & 5 deletions pkg/apis/pingcap/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 6 additions & 4 deletions pkg/autoscaler/autoscaler/calculate/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@ const (

// currently, we only choose one metrics to be computed.
// If there exists several metrics, we tend to choose ResourceMetricSourceType metric
func FilterMetrics(metrics []autoscalingv2beta2.MetricSpec) autoscalingv2beta2.MetricSpec {
func FilterMetrics(metrics []autoscalingv2beta2.MetricSpec, name corev1.ResourceName) []autoscalingv2beta2.MetricSpec {
var list []autoscalingv2beta2.MetricSpec
for _, m := range metrics {
if m.Type == autoscalingv2beta2.ResourceMetricSourceType && m.Resource != nil {
return m
if m.Type == autoscalingv2beta2.ResourceMetricSourceType && m.Resource != nil && m.Resource.Name == name {
list = append(list, m)
break
}
}
return metrics[0]
return list
}

// genMetricType return the supported MetricType in Operator by kubernetes auto-scaling MetricType
Expand Down
28 changes: 11 additions & 17 deletions pkg/autoscaler/autoscaler/tidb_autoscaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
operatorUtils "github.com/pingcap/tidb-operator/pkg/util"
promClient "github.com/prometheus/client_golang/api"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/klog"
)

Expand Down Expand Up @@ -97,29 +98,22 @@ func calculateTidbMetrics(tac *v1alpha1.TidbClusterAutoScaler, sts *appsv1.State
if err != nil {
return -1, err
}
metric := calculate.FilterMetrics(tac.Spec.TiDB.Metrics)
mType, err := calculate.GenMetricType(tac, metric)
if err != nil {
return -1, err
}
duration, err := time.ParseDuration(*tac.Spec.TiDB.MetricsTimeDuration)
if err != nil {
return -1, err
}
sq := &calculate.SingleQuery{
Endpoint: ep,
Timestamp: time.Now().Unix(),
Instances: instances,
Metric: metric,
Quary: fmt.Sprintf(calculate.TidbSumCpuMetricsPattern, tac.Spec.Cluster.Name, *tac.Spec.TiDB.MetricsTimeDuration),
}

switch mType {
case calculate.MetricTypeCPU:
metrics := calculate.FilterMetrics(tac.Spec.TiDB.Metrics, corev1.ResourceCPU)
if len(metrics) > 0 {
sq := &calculate.SingleQuery{
Endpoint: ep,
Timestamp: time.Now().Unix(),
Instances: instances,
Metric: metrics[0],
Quary: fmt.Sprintf(calculate.TidbSumCpuMetricsPattern, tac.Spec.Cluster.Name, *tac.Spec.TiDB.MetricsTimeDuration),
}
return calculate.CalculateRecomendedReplicasByCpuCosts(tac, sq, sts, client, v1alpha1.TiDBMemberType, duration)
default:
return -1, fmt.Errorf(calculate.InvalidTacMetricConfigureMsg, tac.Namespace, tac.Name)
}
return -1, fmt.Errorf(calculate.InvalidTacMetricConfigureMsg, tac.Namespace, tac.Name)
}

func filterTidbInstances(tc *v1alpha1.TidbCluster) []string {
Expand Down
Loading

0 comments on commit 3bf11be

Please sign in to comment.