-
Notifications
You must be signed in to change notification settings - Fork 500
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
Add AutoScalerRef in TidbCluster Status #2791
Conversation
// AnnTiDBConsecutiveScaleOutCount describes the least consecutive count to scale-out for tidb | ||
AnnTiDBConsecutiveScaleOutCount = "tidb.tidb.pingcap.com/consecutive-scale-out-count" | ||
// AnnTiDBConsecutiveScaleInCount describes the least consecutive count to scale-in for tidb | ||
AnnTiDBConsecutiveScaleInCount = "tidb.tidb.pingcap.com/consecutive-scale-in-count" | ||
// AnnTiKVConsecutiveScaleOutCount describes the least consecutive count to scale-out for tikv | ||
AnnTiKVConsecutiveScaleOutCount = "tikv.tidb.pingcap.com/consecutive-scale-out-count" | ||
// AnnTiKVConsecutiveScaleInCount describes the least consecutive count to scale-in for tikv | ||
AnnTiKVConsecutiveScaleInCount = "tikv.tidb.pingcap.com/consecutive-scale-in-count" | ||
// AnnAutoScalingTargetName describes the target TidbCluster Ref Name for the TidbCluserAutoScaler | ||
AnnAutoScalingTargetName = "auto-scaling.tidb.pingcap.com/target-name" | ||
// AnnAutoScalingTargetNamespace describes the target TidbCluster Ref Namespace for the TidbCluserAutoScaler | ||
AnnAutoScalingTargetNamespace = "auto-scaling.tidb.pingcap.com/target-namespace" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove useless code
|
||
// ScaleOutThreshold describe the consecutive threshold for the auto-scaling, | ||
// if the consecutive counts of the scale-out result in auto-scaling reach this number, | ||
// the auto-scaling would be performed. | ||
// If not set, the default value is 3. | ||
// +optional | ||
ScaleOutThreshold *int32 `json:"scaleOutThreshold,omitempty"` | ||
|
||
// ScaleInThreshold describe the consecutive threshold for the auto-scaling, | ||
// if the consecutive counts of the scale-in result in auto-scaling reach this number, | ||
// the auto-scaling would be performed. | ||
// If not set, the default value is 5. | ||
// +optional | ||
ScaleInThreshold *int32 `json:"scaleInThreshold,omitempty"` | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove useless code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
} | ||
tacNamespace := tc.Status.AutoScaler.Namespace | ||
tacName := tc.Status.AutoScaler.Name | ||
_, err := tcsm.cli.PingcapV1alpha1().TidbClusterAutoScalers(tacNamespace).Get(tacName, metav1.GetOptions{}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not use lister?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1, ever raised the same comment for TidbMonitor here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated, and also add the unit test
fix lint fix unit test use lister fix lint use patch instead update fix unit test debug ci fix ci debug ci add log fix ci revise util add default TAC fix ci
493e3b2
to
dc07bb5
Compare
func checkStsAutoScaling(tac *v1alpha1.TidbClusterAutoScaler, thresholdSeconds, intervalSeconds int32, memberType v1alpha1.MemberType) (bool, error) { | ||
realClock := clockwork.NewRealClock() | ||
if tac.Annotations == nil { | ||
tac.Annotations = map[string]string{} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function only used for tikv, move to the checkTiKVStsAutoScaling
func resetAutoScalingAnn(tac *v1alpha1.TidbClusterAutoScaler) { | ||
tac.Annotations[label.AnnAutoScalingTargetNamespace] = tac.Spec.Cluster.Namespace | ||
tac.Annotations[label.AnnAutoScalingTargetName] = tac.Spec.Cluster.Name | ||
} | ||
|
||
// checkAndUpdateTacRef would compare the target tidbcluster ref stored in the annotations | ||
// and in the Spec. It not equal, the previous stored status would be empty and the stored Ref | ||
// would be updated. | ||
func checkAndUpdateTacAnn(tac *v1alpha1.TidbClusterAutoScaler) { | ||
if tac.Annotations == nil { | ||
tac.Annotations = map[string]string{} | ||
resetAutoScalingAnn(tac) | ||
return | ||
} | ||
name := tac.Annotations[label.AnnAutoScalingTargetName] | ||
namespace := tac.Annotations[label.AnnAutoScalingTargetNamespace] | ||
if name == tac.Spec.Cluster.Name && namespace == tac.Spec.Cluster.Namespace { | ||
return | ||
} | ||
// If not satisfied, reset tac Ann | ||
resetAutoScalingAnn(tac) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use patch reference instead of recording in annotations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
/merge |
/run-all-tests |
Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
cherry pick to release-1.1 in PR #2800 |
What problem does this PR solve?
Close #2484
Add Auto-Scaler reference in TidbCluster Status which can avoid avoiding 2 auto-scaler directly take effect to the same tidbcluster.
Related changes
Does this PR introduce a user-facing change?: