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

AutoScaling: adding status type #1853

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 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
39 changes: 38 additions & 1 deletion pkg/apis/pingcap/v1alpha1/tidbclusterautoscaler_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,43 @@ type TidbMonitorRef struct {
Name string `json:"name"`
}

// TODO: sync status
// BasicAutoScalerSpec describes the basic status for auto-scaling
type BaseAutoScalerStatus struct {
// name is the name of the given metric
Name string `json:"name,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The metrics property in AutoScaler is a list. If we need to show the metrics value, we should make the metrics status as list.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, We use one metric to calculate the autoscaling. So i think it is just show the metric in effect.


// CurrentValue is the current value of the metric.
CurrentValue float64 `json:"currentValue,omitempty"`

// TargetValue is the target value of the metric.
TargetValue float64 `json:"targetValue,omitempty"`

// lastScaleTime is the last time the HorizontalPodAutoscaler scaled the number of pods,
// used by the autoscaler to control how often the number of pods is changed.
// +optional
LastScaleTime string `json:"lastScaleTime,omitempty" protobuf:"bytes,2,opt,name=lastScaleTime"`

// currentReplicas is current number of replicas of pods managed by this autoscaler,
// as last seen by the autoscaler.
CurrentReplicas int32 `json:"currentReplicas" protobuf:"varint,3,opt,name=currentReplicas"`

// desiredReplicas is the desired number of replicas of pods managed by this autoscaler,
// as last calculated by the autoscaler.
DesiredReplicas int32 `json:"desiredReplicas" protobuf:"varint,4,opt,name=desiredReplicas"`
qiffang marked this conversation as resolved.
Show resolved Hide resolved
}

// TiKVAutoScalerStatus describes the status for tikv auto-scaling
type TiKVAutoScalerStatus struct {
BaseAutoScalerStatus `json:"tikv,omitempty"`
}

// TiDBAutoScalerStatus describes the status for tidb auto-scaling
type TiDBAutoScalerStatus struct {
BaseAutoScalerStatus `json:"tidb,omitempty"`
}

// TidbClusterAutoSclaerStatus describes the status for TidbClusterAutoScaler
type TidbClusterAutoSclaerStatus struct {
TikvStatus TiKVAutoScalerStatus `json:"tikv,omitempty"`
TiDBStatus TiDBAutoScalerStatus `json:"tidb,omitempty"`
}
52 changes: 52 additions & 0 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.

19 changes: 19 additions & 0 deletions pkg/autoscaler/autoscaler/calculate/cpu.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ package calculate

import (
"fmt"
"k8s.io/klog"
qiffang marked this conversation as resolved.
Show resolved Hide resolved
"time"

"github.com/pingcap/tidb-operator/pkg/apis/pingcap/v1alpha1"
Expand Down Expand Up @@ -65,6 +66,24 @@ func CalculateRecomendedReplicasByCpuCosts(tac *v1alpha1.TidbClusterAutoScaler,
if err != nil {
return -1, err
}

switch memberType {
case v1alpha1.TiDBMemberType:
tac.Status.TiDBStatus.Name = string(MetricTypeCPU)
tac.Status.TiDBStatus.CurrentValue = cpuSecsTotal
tac.Status.TiDBStatus.TargetValue = expectedCpuSecsTotal
qiffang marked this conversation as resolved.
Show resolved Hide resolved
tac.Status.TiDBStatus.CurrentReplicas = int32(currentReplicas)
tac.Status.TiDBStatus.DesiredReplicas = rc
case v1alpha1.TiKVMemberType:
tac.Status.TikvStatus.Name = string(MetricTypeCPU)
tac.Status.TikvStatus.CurrentValue = cpuSecsTotal
tac.Status.TikvStatus.TargetValue = expectedCpuSecsTotal
tac.Status.TikvStatus.CurrentReplicas = int32(currentReplicas)
tac.Status.TikvStatus.DesiredReplicas = rc
default:
klog.Errorf("unsupport type - %s", memberType)
}

return rc, nil
}

Expand Down
1 change: 1 addition & 0 deletions pkg/autoscaler/autoscaler/tidb_autoscaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,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.TikvStatus.LastScaleTime = time.Now().Format(time.RFC3339)
qiffang marked this conversation as resolved.
Show resolved Hide resolved
return nil
}

Expand Down
1 change: 1 addition & 0 deletions pkg/autoscaler/autoscaler/tikv_autoscaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ func updateTcTiKVIfScale(tc *v1alpha1.TidbCluster, tac *v1alpha1.TidbClusterAuto
}
}
tc.Spec.TiKV.Replicas = recommendedReplicas
tac.Status.TikvStatus.LastScaleTime = time.Now().Format(time.RFC3339)
return nil
}

Expand Down