Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor TiKV auto-scaling (#2862) #2871

Merged
merged 1 commit into from
Jul 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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