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

Add AutoScalerRef in TidbCluster Status #2791

Merged
merged 3 commits into from
Jun 23, 2020

Conversation

Yisaer
Copy link
Contributor

@Yisaer Yisaer commented Jun 22, 2020

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

  • Need to cherry-pick to the release branch

Does this PR introduce a user-facing change?:

Support Auto-Scaler Reference in `TidbCluster` Status when there existed `TidbClusterAutoScaler`

Comment on lines -120 to -131
// 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"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

remove useless code

Comment on lines -138 to -152

// 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"`

Copy link
Contributor Author

Choose a reason for hiding this comment

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

remove useless code

DanielZhangQD
DanielZhangQD previously approved these changes Jun 22, 2020
Copy link
Contributor

@DanielZhangQD DanielZhangQD left a 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{})
Copy link
Contributor

Choose a reason for hiding this comment

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

why not use lister?

Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good catch.

Copy link
Contributor Author

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
@Yisaer Yisaer force-pushed the add_auto_scaler_ref branch from 493e3b2 to dc07bb5 Compare June 23, 2020 07:22
Comment on lines -62 to -66
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{}
}
Copy link
Contributor Author

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

Comment on lines -254 to -276
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)
}

Copy link
Contributor Author

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.

Copy link
Contributor

@zjj2wry zjj2wry left a comment

Choose a reason for hiding this comment

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

lgtm

Copy link
Contributor

@DanielZhangQD DanielZhangQD left a comment

Choose a reason for hiding this comment

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

LGTM

@Yisaer
Copy link
Contributor Author

Yisaer commented Jun 23, 2020

/merge

@ti-srebot
Copy link
Contributor

/run-all-tests

@ti-srebot ti-srebot merged commit 41e95ad into pingcap:master Jun 23, 2020
ti-srebot pushed a commit to ti-srebot/tidb-operator that referenced this pull request Jun 23, 2020
Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
@ti-srebot
Copy link
Contributor

cherry pick to release-1.1 in PR #2800

ti-srebot added a commit that referenced this pull request Jun 23, 2020
Signed-off-by: ti-srebot <ti-srebot@pingcap.com>

Co-authored-by: Song Gao <disxiaofei@163.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

UCP: support AutoSclaerRef for TidbCluster
4 participants