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

checker: unify checker name and checker type #8316

Closed
wants to merge 23 commits into from
Closed
Show file tree
Hide file tree
Changes from 15 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
12 changes: 12 additions & 0 deletions metrics/alertmanager/pd.rules.yml
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,18 @@ groups:
value: '{{ $value }}'
summary: PD_no_store_for_making_replica

- alert: PD_no_store_for_making_replica_v2
expr: increase(pd_checker_event_count{type="replica-checker", name="no_target_store"}[1m]) > 0
for: 1m
labels:
env: ENV_LABELS_ENV
level: warning
expr: increase(pd_checker_event_count{type="replica-checker", name="no_target_store"}[1m]) > 0
annotations:
description: 'cluster: ENV_LABELS_ENV, type: {{ $labels.type }}, instance: {{ $labels.instance }}, values: {{ $value }}'
value: '{{ $value }}'
summary: PD_no_store_for_making_replica

- alert: PD_node_restart
expr: changes(process_start_time_seconds{job="pd"}[5m]) > 0
for: 1m
Expand Down
24 changes: 24 additions & 0 deletions metrics/grafana/pd.json
Original file line number Diff line number Diff line change
Expand Up @@ -7980,6 +7980,14 @@
"legendFormat": "{{name}}",
"refId": "A",
"step": 10
},
{
"expr": "sum(rate(pd_checker_event_count{k8s_cluster=\"$k8s_cluster\", tidb_cluster=\"$tidb_cluster\", type=\"rule-checker\"}[1m])) by (name)",
"format": "time_series",
"intervalFactor": 2,
"legendFormat": "{{name}}",
"refId": "B",
"step": 10
}
],
"thresholds": [],
Expand Down Expand Up @@ -8072,6 +8080,14 @@
"legendFormat": "{{name}}",
"refId": "A",
"step": 10
},
{
"expr": "sum(rate(pd_checker_event_count{k8s_cluster=\"$k8s_cluster\", tidb_cluster=\"$tidb_cluster\", type=\"replica-checker\"}[1m])) by (name)",
"format": "time_series",
"intervalFactor": 2,
"legendFormat": "{{name}}",
"refId": "B",
"step": 10
}
],
"thresholds": [],
Expand Down Expand Up @@ -8165,6 +8181,14 @@
"legendFormat": "{{name}}",
"refId": "A",
"step": 10
},
{
"expr": "sum(rate(pd_checker_event_count{k8s_cluster=\"$k8s_cluster\", tidb_cluster=\"$tidb_cluster\", type=\"merge-checker\"}[1m])) by (name)",
"format": "time_series",
"intervalFactor": 2,
"legendFormat": "{{name}}",
"refId": "B",
"step": 10
}
],
"thresholds": [],
Expand Down
26 changes: 22 additions & 4 deletions pkg/mcs/scheduling/server/apis/v1/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
scheserver "github.com/tikv/pd/pkg/mcs/scheduling/server"
mcsutils "github.com/tikv/pd/pkg/mcs/utils"
"github.com/tikv/pd/pkg/response"
"github.com/tikv/pd/pkg/schedule/config"
sche "github.com/tikv/pd/pkg/schedule/core"
"github.com/tikv/pd/pkg/schedule/handler"
"github.com/tikv/pd/pkg/schedule/operator"
Expand All @@ -44,6 +45,7 @@ import (
"github.com/tikv/pd/pkg/utils/logutil"
"github.com/tikv/pd/pkg/utils/typeutil"
"github.com/unrolled/render"
"go.uber.org/zap"
)

// APIPathPrefix is the prefix of the API path.
Expand Down Expand Up @@ -573,11 +575,19 @@ func getSchedulerConfigByName(c *gin.Context) {
}
handlers := sc.GetSchedulerHandlers()
name := c.Param("name")
if _, ok := handlers[name]; !ok {
schedulerName, err := config.ConvertSchedulerStr2Name(name)
if err != nil {
log.Error("failed to convert scheduler name",
zap.String("scheduler", name),
errs.ZapError(err))
c.String(http.StatusNotFound, errs.ErrSchedulerNotFound.GenWithStackByArgs().Error())
return
}
if _, ok := handlers[schedulerName]; !ok {
c.String(http.StatusNotFound, errs.ErrSchedulerNotFound.GenWithStackByArgs().Error())
return
}
isDisabled, err := sc.IsSchedulerDisabled(name)
isDisabled, err := sc.IsSchedulerDisabled(schedulerName)
if err != nil {
c.String(http.StatusInternalServerError, err.Error())
return
Expand All @@ -587,7 +597,7 @@ func getSchedulerConfigByName(c *gin.Context) {
return
}
c.Request.URL.Path = "/list"
handlers[name].ServeHTTP(c.Writer, c.Request)
handlers[schedulerName].ServeHTTP(c.Writer, c.Request)
}

// @Tags schedulers
Expand All @@ -599,7 +609,15 @@ func getSchedulerConfigByName(c *gin.Context) {
func getDiagnosticResult(c *gin.Context) {
handler := c.MustGet(handlerKey).(*handler.Handler)
name := c.Param("name")
result, err := handler.GetDiagnosticResult(name)
schedulerName, err := config.ConvertSchedulerStr2Name(name)
if err != nil {
log.Error("failed to convert scheduler name",
zap.String("scheduler", name),
errs.ZapError(err))
c.String(http.StatusNotFound, errs.ErrSchedulerNotFound.GenWithStackByArgs().Error())
return
}
result, err := handler.GetDiagnosticResult(schedulerName)
if err != nil {
c.String(http.StatusInternalServerError, err.Error())
return
Expand Down
26 changes: 16 additions & 10 deletions pkg/mcs/scheduling/server/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,54 +308,60 @@ func (c *Cluster) updateScheduler() {
)
// Create the newly added schedulers.
for _, scheduler := range latestSchedulersConfig {
name, err := sc.ConvertSchedulerStr2Name(scheduler.Type)
if err != nil {
log.Error("failed to convert scheduler name",
zap.String("scheduler", scheduler.Type),
errs.ZapError(err))
continue
}
s, err := schedulers.CreateScheduler(
scheduler.Type,
name,
c.coordinator.GetOperatorController(),
c.storage,
schedulers.ConfigSliceDecoder(scheduler.Type, scheduler.Args),
schedulers.ConfigSliceDecoder(name, scheduler.Args),
schedulersController.RemoveScheduler,
)
if err != nil {
log.Error("failed to create scheduler",
zap.String("scheduler-type", scheduler.Type),
zap.String("scheduler", scheduler.Type),
zap.Strings("scheduler-args", scheduler.Args),
errs.ZapError(err))
continue
}
name := s.GetName()
if existed, _ := schedulersController.IsSchedulerExisted(name); existed {
log.Info("scheduler has already existed, skip adding it",
zap.String("scheduler-name", name),
zap.Stringer("scheduler", name),
zap.Strings("scheduler-args", scheduler.Args))
continue
}
if err := schedulersController.AddScheduler(s, scheduler.Args...); err != nil {
log.Error("failed to add scheduler",
zap.String("scheduler-name", name),
zap.Stringer("scheduler", name),
zap.Strings("scheduler-args", scheduler.Args),
errs.ZapError(err))
continue
}
log.Info("add scheduler successfully",
zap.String("scheduler-name", name),
zap.Stringer("scheduler-name", name),
zap.Strings("scheduler-args", scheduler.Args))
}
// Remove the deleted schedulers.
for _, name := range schedulersController.GetSchedulerNames() {
scheduler := schedulersController.GetScheduler(name)
if slice.AnyOf(latestSchedulersConfig, func(i int) bool {
return latestSchedulersConfig[i].Type == scheduler.GetType()
return latestSchedulersConfig[i].Type == scheduler.Name()
}) {
continue
}
if err := schedulersController.RemoveScheduler(name); err != nil {
log.Error("failed to remove scheduler",
zap.String("scheduler-name", name),
zap.Stringer("scheduler-name", name),
errs.ZapError(err))
continue
}
log.Info("remove scheduler successfully",
zap.String("scheduler-name", name))
zap.Stringer("scheduler-name", name))
}
}
}
Expand Down
12 changes: 10 additions & 2 deletions pkg/mcs/scheduling/server/config/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (

"github.com/coreos/go-semver/semver"
"github.com/pingcap/log"
"github.com/tikv/pd/pkg/errs"
sc "github.com/tikv/pd/pkg/schedule/config"
"github.com/tikv/pd/pkg/schedule/schedulers"
"github.com/tikv/pd/pkg/storage"
Expand Down Expand Up @@ -199,8 +200,15 @@ func (cw *Watcher) initializeSchedulerConfigWatcher() error {
return err
}
// Ensure the scheduler config could be updated as soon as possible.
if sc := cw.getSchedulersController(); sc != nil {
return sc.ReloadSchedulerConfig(name)
if schedulersController := cw.getSchedulersController(); schedulersController != nil {
schedulerName, err := sc.ConvertSchedulerStr2Name(name)
if err != nil {
log.Error("failed to convert scheduler name",
zap.String("scheduler", name),
errs.ZapError(err))
return errs.ErrSchedulerNotFound.GenWithStackByArgs()
}
return schedulersController.ReloadSchedulerConfig(schedulerName)
}
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/mock/mockconfig/mockconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
func NewTestOptions() *config.PersistOptions {
// register default schedulers in case config check fail.
for _, d := range sc.DefaultSchedulers {
sc.RegisterScheduler(d.Type)
sc.RegisterScheduler(sc.CheckerSchedulerName(d.Type))
}
c := config.NewConfig()
c.Adjust(nil, false)
Expand Down
6 changes: 3 additions & 3 deletions pkg/schedule/checker/checker_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func (c *Controller) CheckRegion(region *core.RegionInfo) []*operator.Operator {
if opController.OperatorCount(operator.OpReplica) < c.conf.GetReplicaScheduleLimit() {
return []*operator.Operator{op}
}
operator.OperatorLimitCounter.WithLabelValues(c.ruleChecker.GetType(), operator.OpReplica.String()).Inc()
operator.OperatorLimitCounter.WithLabelValues(c.ruleChecker.Name(), operator.OpReplica.String()).Inc()
c.regionWaitingList.Put(region.GetID(), nil)
}
}
Expand All @@ -116,7 +116,7 @@ func (c *Controller) CheckRegion(region *core.RegionInfo) []*operator.Operator {
if opController.OperatorCount(operator.OpReplica) < c.conf.GetReplicaScheduleLimit() {
return []*operator.Operator{op}
}
operator.OperatorLimitCounter.WithLabelValues(c.replicaChecker.GetType(), operator.OpReplica.String()).Inc()
operator.OperatorLimitCounter.WithLabelValues(c.replicaChecker.Name(), operator.OpReplica.String()).Inc()
c.regionWaitingList.Put(region.GetID(), nil)
}
}
Expand All @@ -133,7 +133,7 @@ func (c *Controller) CheckRegion(region *core.RegionInfo) []*operator.Operator {
if c.mergeChecker != nil {
allowed := opController.OperatorCount(operator.OpMerge) < c.conf.GetMergeScheduleLimit()
if !allowed {
operator.OperatorLimitCounter.WithLabelValues(c.mergeChecker.GetType(), operator.OpMerge.String()).Inc()
operator.OperatorLimitCounter.WithLabelValues(c.mergeChecker.Name(), operator.OpMerge.String()).Inc()
} else if ops := c.mergeChecker.Check(region); ops != nil {
// It makes sure that two operators can be added successfully altogether.
return ops
Expand Down
18 changes: 11 additions & 7 deletions pkg/schedule/checker/joint_state_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/tikv/pd/pkg/core"
"github.com/tikv/pd/pkg/core/constant"
"github.com/tikv/pd/pkg/errs"
"github.com/tikv/pd/pkg/schedule/config"
sche "github.com/tikv/pd/pkg/schedule/core"
"github.com/tikv/pd/pkg/schedule/operator"
)
Expand All @@ -29,15 +30,13 @@ type JointStateChecker struct {
cluster sche.CheckerCluster
}

const jointStateCheckerName = "joint_state_checker"

var (
// WithLabelValues is a heavy operation, define variable to avoid call it every time.
jointCheckCounter = checkerCounter.WithLabelValues(jointStateCheckerName, "check")
jointCheckerPausedCounter = checkerCounter.WithLabelValues(jointStateCheckerName, "paused")
jointCheckerFailedCounter = checkerCounter.WithLabelValues(jointStateCheckerName, "create-operator-fail")
jointCheckerNewOpCounter = checkerCounter.WithLabelValues(jointStateCheckerName, "new-operator")
jointCheckerTransferLeaderCounter = checkerCounter.WithLabelValues(jointStateCheckerName, "transfer-leader")
jointCheckCounter = counterWithEvent(config.JointStateCheckerName, "check")
jointCheckerPausedCounter = counterWithEvent(config.JointStateCheckerName, "paused")
jointCheckerFailedCounter = counterWithEvent(config.JointStateCheckerName, "create-operator-fail")
jointCheckerNewOpCounter = counterWithEvent(config.JointStateCheckerName, "new-operator")
jointCheckerTransferLeaderCounter = counterWithEvent(config.JointStateCheckerName, "transfer-leader")
)

// NewJointStateChecker creates a joint state checker.
Expand All @@ -47,6 +46,11 @@ func NewJointStateChecker(cluster sche.CheckerCluster) *JointStateChecker {
}
}

// Name returns the checker name.
func (*JointStateChecker) Name() string {
return config.JointStateCheckerName.String()
}

// Check verifies a region's role, creating an Operator if need.
func (c *JointStateChecker) Check(region *core.RegionInfo) *operator.Operator {
jointCheckCounter.Inc()
Expand Down
8 changes: 7 additions & 1 deletion pkg/schedule/checker/learner_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/pingcap/log"
"github.com/tikv/pd/pkg/core"
"github.com/tikv/pd/pkg/errs"
"github.com/tikv/pd/pkg/schedule/config"
sche "github.com/tikv/pd/pkg/schedule/core"
"github.com/tikv/pd/pkg/schedule/operator"
)
Expand All @@ -30,7 +31,7 @@ type LearnerChecker struct {

var (
// WithLabelValues is a heavy operation, define variable to avoid call it every time.
learnerCheckerPausedCounter = checkerCounter.WithLabelValues("learner_checker", "paused")
learnerCheckerPausedCounter = counterWithEvent(config.LearnerCheckerName, "paused")
)

// NewLearnerChecker creates a learner checker.
Expand All @@ -40,6 +41,11 @@ func NewLearnerChecker(cluster sche.CheckerCluster) *LearnerChecker {
}
}

// Name returns the checker name.
func (*LearnerChecker) Name() string {
return config.LearnerCheckerName.String()
}

// Check verifies a region's role, creating an Operator if need.
func (l *LearnerChecker) Check(region *core.RegionInfo) *operator.Operator {
if l.IsPaused() {
Expand Down
Loading
Loading