Skip to content

Commit

Permalink
check: add error/warn count for check-task (pingcap#1610)
Browse files Browse the repository at this point in the history
  • Loading branch information
GMHDBJD authored Apr 22, 2021
1 parent 64c6419 commit 67b95c0
Show file tree
Hide file tree
Showing 17 changed files with 540 additions and 303 deletions.
53 changes: 28 additions & 25 deletions checker/check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
router "github.com/pingcap/tidb-tools/pkg/table-router"

"github.com/pingcap/dm/dm/config"
"github.com/pingcap/dm/dm/ctl/common"
"github.com/pingcap/dm/pkg/conn"

tc "github.com/pingcap/check"
Expand Down Expand Up @@ -75,16 +76,17 @@ func ignoreExcept(itemMap map[string]struct{}) []string {
}

func (s *testCheckerSuite) TestIgnoreAllCheckingItems(c *tc.C) {
c.Assert(CheckSyncConfig(context.Background(), nil), tc.IsNil)
c.Assert(CheckSyncConfig(context.Background(), nil, common.DefaultErrorCnt, common.DefaultWarnCnt), tc.IsNil)

cfgs := []*config.SubTaskConfig{
{
IgnoreCheckingItems: []string{config.AllChecking},
},
}
c.Assert(CheckSyncConfig(context.Background(), cfgs), tc.IsNil)
c.Assert(CheckSyncConfig(context.Background(), cfgs, common.DefaultErrorCnt, common.DefaultWarnCnt), tc.IsNil)
}

// nolint:dupl
func (s *testCheckerSuite) TestDumpPrivilegeChecking(c *tc.C) {
cfgs := []*config.SubTaskConfig{
{
Expand All @@ -94,16 +96,17 @@ func (s *testCheckerSuite) TestDumpPrivilegeChecking(c *tc.C) {
mock := s.initMockDB(c)
mock.ExpectQuery("SHOW GRANTS").WillReturnRows(sqlmock.NewRows([]string{"Grants for User"}).
AddRow("GRANT USAGE ON *.* TO 'haha'@'%'"))
err := CheckSyncConfig(context.Background(), cfgs)
err := CheckSyncConfig(context.Background(), cfgs, common.DefaultErrorCnt, common.DefaultWarnCnt)
c.Assert(err, tc.ErrorMatches, "(.|\n)*lack.*RELOAD(.|\n)*")
c.Assert(err, tc.ErrorMatches, "(.|\n)*lack.*Select(.|\n)*")

mock = s.initMockDB(c)
mock.ExpectQuery("SHOW GRANTS").WillReturnRows(sqlmock.NewRows([]string{"Grants for User"}).
AddRow("GRANT RELOAD,SELECT ON *.* TO 'haha'@'%'"))
c.Assert(CheckSyncConfig(context.Background(), cfgs), tc.IsNil)
c.Assert(CheckSyncConfig(context.Background(), cfgs, common.DefaultErrorCnt, common.DefaultWarnCnt), tc.IsNil)
}

// nolint:dupl
func (s *testCheckerSuite) TestReplicationPrivilegeChecking(c *tc.C) {
cfgs := []*config.SubTaskConfig{
{
Expand All @@ -113,14 +116,14 @@ func (s *testCheckerSuite) TestReplicationPrivilegeChecking(c *tc.C) {
mock := s.initMockDB(c)
mock.ExpectQuery("SHOW GRANTS").WillReturnRows(sqlmock.NewRows([]string{"Grants for User"}).
AddRow("GRANT USAGE ON *.* TO 'haha'@'%'"))
err := CheckSyncConfig(context.Background(), cfgs)
err := CheckSyncConfig(context.Background(), cfgs, common.DefaultErrorCnt, common.DefaultWarnCnt)
c.Assert(err, tc.ErrorMatches, "(.|\n)*lack.*REPLICATION SLAVE(.|\n)*")
c.Assert(err, tc.ErrorMatches, "(.|\n)*lack.*REPLICATION CLIENT(.|\n)*")

mock = s.initMockDB(c)
mock.ExpectQuery("SHOW GRANTS").WillReturnRows(sqlmock.NewRows([]string{"Grants for User"}).
AddRow("GRANT REPLICATION SLAVE,REPLICATION CLIENT ON *.* TO 'haha'@'%'"))
c.Assert(CheckSyncConfig(context.Background(), cfgs), tc.IsNil)
c.Assert(CheckSyncConfig(context.Background(), cfgs, common.DefaultErrorCnt, common.DefaultWarnCnt), tc.IsNil)
}

func (s *testCheckerSuite) TestVersionChecking(c *tc.C) {
Expand All @@ -133,22 +136,22 @@ func (s *testCheckerSuite) TestVersionChecking(c *tc.C) {
mock := s.initMockDB(c)
mock.ExpectQuery("SHOW GLOBAL VARIABLES LIKE 'version'").WillReturnRows(sqlmock.NewRows([]string{"Variable_name", "Value"}).
AddRow("version", "5.7.26-log"))
c.Assert(CheckSyncConfig(context.Background(), cfgs), tc.IsNil)
c.Assert(CheckSyncConfig(context.Background(), cfgs, common.DefaultErrorCnt, common.DefaultWarnCnt), tc.IsNil)

mock = s.initMockDB(c)
mock.ExpectQuery("SHOW GLOBAL VARIABLES LIKE 'version'").WillReturnRows(sqlmock.NewRows([]string{"Variable_name", "Value"}).
AddRow("version", "10.1.29-MariaDB"))
c.Assert(CheckSyncConfig(context.Background(), cfgs), tc.IsNil)
c.Assert(CheckSyncConfig(context.Background(), cfgs, common.DefaultErrorCnt, common.DefaultWarnCnt), tc.IsNil)

mock = s.initMockDB(c)
mock.ExpectQuery("SHOW GLOBAL VARIABLES LIKE 'version'").WillReturnRows(sqlmock.NewRows([]string{"Variable_name", "Value"}).
AddRow("version", "5.5.26-log"))
c.Assert(CheckSyncConfig(context.Background(), cfgs), tc.ErrorMatches, "(.|\n)*version required at least .* but got 5.5.26(.|\n)*")
c.Assert(CheckSyncConfig(context.Background(), cfgs, common.DefaultErrorCnt, common.DefaultWarnCnt), tc.ErrorMatches, "(.|\n)*version required at least .* but got 5.5.26(.|\n)*")

mock = s.initMockDB(c)
mock.ExpectQuery("SHOW GLOBAL VARIABLES LIKE 'version'").WillReturnRows(sqlmock.NewRows([]string{"Variable_name", "Value"}).
AddRow("version", "10.0.0-MariaDB"))
c.Assert(CheckSyncConfig(context.Background(), cfgs), tc.ErrorMatches, "(.|\n)*version required at least .* but got 10.0.0(.|\n)*")
c.Assert(CheckSyncConfig(context.Background(), cfgs, common.DefaultErrorCnt, common.DefaultWarnCnt), tc.ErrorMatches, "(.|\n)*version required at least .* but got 10.0.0(.|\n)*")
}

func (s *testCheckerSuite) TestServerIDChecking(c *tc.C) {
Expand All @@ -161,12 +164,12 @@ func (s *testCheckerSuite) TestServerIDChecking(c *tc.C) {
mock := s.initMockDB(c)
mock.ExpectQuery("SHOW GLOBAL VARIABLES LIKE 'server_id'").WillReturnRows(sqlmock.NewRows([]string{"Variable_name", "Value"}).
AddRow("server_id", "0"))
c.Assert(CheckSyncConfig(context.Background(), cfgs), tc.ErrorMatches, "(.|\n)*please set server_id greater than 0(.|\n)*")
c.Assert(CheckSyncConfig(context.Background(), cfgs, common.DefaultErrorCnt, common.DefaultWarnCnt), tc.ErrorMatches, "(.|\n)*please set server_id greater than 0(.|\n)*")

mock = s.initMockDB(c)
mock.ExpectQuery("SHOW GLOBAL VARIABLES LIKE 'server_id'").WillReturnRows(sqlmock.NewRows([]string{"Variable_name", "Value"}).
AddRow("server_id", "1"))
c.Assert(CheckSyncConfig(context.Background(), cfgs), tc.IsNil)
c.Assert(CheckSyncConfig(context.Background(), cfgs, common.DefaultErrorCnt, common.DefaultWarnCnt), tc.IsNil)
}

func (s *testCheckerSuite) TestBinlogEnableChecking(c *tc.C) {
Expand All @@ -179,12 +182,12 @@ func (s *testCheckerSuite) TestBinlogEnableChecking(c *tc.C) {
mock := s.initMockDB(c)
mock.ExpectQuery("SHOW GLOBAL VARIABLES LIKE 'log_bin'").WillReturnRows(sqlmock.NewRows([]string{"Variable_name", "Value"}).
AddRow("log_bin", "OFF"))
c.Assert(CheckSyncConfig(context.Background(), cfgs), tc.ErrorMatches, "(.|\n)*log_bin is OFF, and should be ON(.|\n)*")
c.Assert(CheckSyncConfig(context.Background(), cfgs, common.DefaultErrorCnt, common.DefaultWarnCnt), tc.ErrorMatches, "(.|\n)*log_bin is OFF, and should be ON(.|\n)*")

mock = s.initMockDB(c)
mock.ExpectQuery("SHOW GLOBAL VARIABLES LIKE 'log_bin'").WillReturnRows(sqlmock.NewRows([]string{"Variable_name", "Value"}).
AddRow("log_bin", "ON"))
c.Assert(CheckSyncConfig(context.Background(), cfgs), tc.IsNil)
c.Assert(CheckSyncConfig(context.Background(), cfgs, common.DefaultErrorCnt, common.DefaultWarnCnt), tc.IsNil)
}

func (s *testCheckerSuite) TestBinlogFormatChecking(c *tc.C) {
Expand All @@ -197,12 +200,12 @@ func (s *testCheckerSuite) TestBinlogFormatChecking(c *tc.C) {
mock := s.initMockDB(c)
mock.ExpectQuery("SHOW GLOBAL VARIABLES LIKE 'binlog_format'").WillReturnRows(sqlmock.NewRows([]string{"Variable_name", "Value"}).
AddRow("binlog_format", "STATEMENT"))
c.Assert(CheckSyncConfig(context.Background(), cfgs), tc.ErrorMatches, "(.|\n)*binlog_format is STATEMENT, and should be ROW(.|\n)*")
c.Assert(CheckSyncConfig(context.Background(), cfgs, common.DefaultErrorCnt, common.DefaultWarnCnt), tc.ErrorMatches, "(.|\n)*binlog_format is STATEMENT, and should be ROW(.|\n)*")

mock = s.initMockDB(c)
mock.ExpectQuery("SHOW GLOBAL VARIABLES LIKE 'binlog_format'").WillReturnRows(sqlmock.NewRows([]string{"Variable_name", "Value"}).
AddRow("binlog_format", "ROW"))
c.Assert(CheckSyncConfig(context.Background(), cfgs), tc.IsNil)
c.Assert(CheckSyncConfig(context.Background(), cfgs, common.DefaultErrorCnt, common.DefaultWarnCnt), tc.IsNil)
}

func (s *testCheckerSuite) TestBinlogRowImageChecking(c *tc.C) {
Expand All @@ -217,14 +220,14 @@ func (s *testCheckerSuite) TestBinlogRowImageChecking(c *tc.C) {
AddRow("version", "5.7.26-log"))
mock.ExpectQuery("SHOW GLOBAL VARIABLES LIKE 'binlog_row_image'").WillReturnRows(sqlmock.NewRows([]string{"Variable_name", "Value"}).
AddRow("binlog_row_image", "MINIMAL"))
c.Assert(CheckSyncConfig(context.Background(), cfgs), tc.ErrorMatches, "(.|\n)*binlog_row_image is MINIMAL, and should be FULL(.|\n)*")
c.Assert(CheckSyncConfig(context.Background(), cfgs, common.DefaultErrorCnt, common.DefaultWarnCnt), tc.ErrorMatches, "(.|\n)*binlog_row_image is MINIMAL, and should be FULL(.|\n)*")

mock = s.initMockDB(c)
mock.ExpectQuery("SHOW GLOBAL VARIABLES LIKE 'version'").WillReturnRows(sqlmock.NewRows([]string{"Variable_name", "Value"}).
AddRow("version", "10.1.29-MariaDB"))
mock.ExpectQuery("SHOW GLOBAL VARIABLES LIKE 'binlog_row_image'").WillReturnRows(sqlmock.NewRows([]string{"Variable_name", "Value"}).
AddRow("binlog_row_image", "FULL"))
c.Assert(CheckSyncConfig(context.Background(), cfgs), tc.IsNil)
c.Assert(CheckSyncConfig(context.Background(), cfgs, common.DefaultErrorCnt, common.DefaultWarnCnt), tc.IsNil)
}

func (s *testCheckerSuite) TestTableSchemaChecking(c *tc.C) {
Expand Down Expand Up @@ -256,7 +259,7 @@ func (s *testCheckerSuite) TestTableSchemaChecking(c *tc.C) {
mock.ExpectQuery("SHOW VARIABLES LIKE 'sql_mode'").WillReturnRows(sqlmock.NewRows([]string{"Variable_name", "Value"}).AddRow("sql_mode", ""))
mock.ExpectQuery("SHOW CREATE TABLE .*").WillReturnRows(sqlmock.NewRows([]string{"Table", "Create Table"}).AddRow(tb1, fmt.Sprintf(createTable1, tb2)))
mock.ExpectQuery("SHOW VARIABLES LIKE 'sql_mode'").WillReturnRows(sqlmock.NewRows([]string{"Variable_name", "Value"}).AddRow("sql_mode", ""))
c.Assert(CheckSyncConfig(context.Background(), cfgs), tc.ErrorMatches, "(.|\n)*primary/unique key does not exist(.|\n)*")
c.Assert(CheckSyncConfig(context.Background(), cfgs, common.DefaultErrorCnt, common.DefaultWarnCnt), tc.ErrorMatches, "(.|\n)*primary/unique key does not exist(.|\n)*")

mock = s.initMockDB(c)
mock.ExpectQuery("SHOW DATABASES").WillReturnRows(sqlmock.NewRows([]string{"DATABASE"}).AddRow(schema))
Expand All @@ -265,7 +268,7 @@ func (s *testCheckerSuite) TestTableSchemaChecking(c *tc.C) {
mock.ExpectQuery("SHOW VARIABLES LIKE 'sql_mode'").WillReturnRows(sqlmock.NewRows([]string{"Variable_name", "Value"}).AddRow("sql_mode", ""))
mock.ExpectQuery("SHOW CREATE TABLE .*").WillReturnRows(sqlmock.NewRows([]string{"Table", "Create Table"}).AddRow(tb1, fmt.Sprintf(createTable2, tb2)))
mock.ExpectQuery("SHOW VARIABLES LIKE 'sql_mode'").WillReturnRows(sqlmock.NewRows([]string{"Variable_name", "Value"}).AddRow("sql_mode", ""))
c.Assert(CheckSyncConfig(context.Background(), cfgs), tc.IsNil)
c.Assert(CheckSyncConfig(context.Background(), cfgs, common.DefaultErrorCnt, common.DefaultWarnCnt), tc.IsNil)
}

func (s *testCheckerSuite) TestShardTableSchemaChecking(c *tc.C) {
Expand Down Expand Up @@ -303,15 +306,15 @@ func (s *testCheckerSuite) TestShardTableSchemaChecking(c *tc.C) {
mock.ExpectQuery("SHOW VARIABLES LIKE 'sql_mode'").WillReturnRows(sqlmock.NewRows([]string{"Variable_name", "Value"}).AddRow("sql_mode", ""))
mock.ExpectQuery("SHOW CREATE TABLE .*").WillReturnRows(sqlmock.NewRows([]string{"Table", "Create Table"}).AddRow(tb1, fmt.Sprintf(createTable1, tb1)))
mock.ExpectQuery("SHOW CREATE TABLE .*").WillReturnRows(sqlmock.NewRows([]string{"Table", "Create Table"}).AddRow(tb1, fmt.Sprintf(createTable2, tb2)))
c.Assert(CheckSyncConfig(context.Background(), cfgs), tc.ErrorMatches, "(.|\n)*different column definition(.|\n)*")
c.Assert(CheckSyncConfig(context.Background(), cfgs, common.DefaultErrorCnt, common.DefaultWarnCnt), tc.ErrorMatches, "(.|\n)*different column definition(.|\n)*")

mock = s.initMockDB(c)
mock.ExpectQuery("SHOW DATABASES").WillReturnRows(sqlmock.NewRows([]string{"DATABASE"}).AddRow(schema))
mock.ExpectQuery("SHOW FULL TABLES").WillReturnRows(sqlmock.NewRows([]string{"Tables_in_" + schema, "Table_type"}).AddRow(tb1, "BASE TABLE").AddRow(tb2, "BASE TABLE"))
mock.ExpectQuery("SHOW VARIABLES LIKE 'sql_mode'").WillReturnRows(sqlmock.NewRows([]string{"Variable_name", "Value"}).AddRow("sql_mode", ""))
mock.ExpectQuery("SHOW CREATE TABLE .*").WillReturnRows(sqlmock.NewRows([]string{"Table", "Create Table"}).AddRow(tb1, fmt.Sprintf(createTable1, tb1)))
mock.ExpectQuery("SHOW CREATE TABLE .*").WillReturnRows(sqlmock.NewRows([]string{"Table", "Create Table"}).AddRow(tb1, fmt.Sprintf(createTable1, tb2)))
c.Assert(CheckSyncConfig(context.Background(), cfgs), tc.IsNil)
c.Assert(CheckSyncConfig(context.Background(), cfgs, common.DefaultErrorCnt, common.DefaultWarnCnt), tc.IsNil)
}

func (s *testCheckerSuite) TestShardAutoIncrementIDChecking(c *tc.C) {
Expand Down Expand Up @@ -354,15 +357,15 @@ func (s *testCheckerSuite) TestShardAutoIncrementIDChecking(c *tc.C) {
mock.ExpectQuery("SHOW VARIABLES LIKE 'sql_mode'").WillReturnRows(sqlmock.NewRows([]string{"Variable_name", "Value"}).AddRow("sql_mode", ""))
mock.ExpectQuery("SHOW CREATE TABLE .*").WillReturnRows(sqlmock.NewRows([]string{"Table", "Create Table"}).AddRow(tb1, fmt.Sprintf(createTable1, tb1)))
mock.ExpectQuery("SHOW CREATE TABLE .*").WillReturnRows(sqlmock.NewRows([]string{"Table", "Create Table"}).AddRow(tb1, fmt.Sprintf(createTable1, tb2)))
c.Assert(CheckSyncConfig(context.Background(), cfgs), tc.ErrorMatches, "(.|\n)*instance table .* of sharding .* have auto-increment key(.|\n)*")
c.Assert(CheckSyncConfig(context.Background(), cfgs, common.DefaultErrorCnt, common.DefaultWarnCnt), tc.ErrorMatches, "(.|\n)*instance table .* of sharding .* have auto-increment key(.|\n)*")

mock = s.initMockDB(c)
mock.ExpectQuery("SHOW DATABASES").WillReturnRows(sqlmock.NewRows([]string{"DATABASE"}).AddRow(schema))
mock.ExpectQuery("SHOW FULL TABLES").WillReturnRows(sqlmock.NewRows([]string{"Tables_in_" + schema, "Table_type"}).AddRow(tb1, "BASE TABLE").AddRow(tb2, "BASE TABLE"))
mock.ExpectQuery("SHOW VARIABLES LIKE 'sql_mode'").WillReturnRows(sqlmock.NewRows([]string{"Variable_name", "Value"}).AddRow("sql_mode", ""))
mock.ExpectQuery("SHOW CREATE TABLE .*").WillReturnRows(sqlmock.NewRows([]string{"Table", "Create Table"}).AddRow(tb1, fmt.Sprintf(createTable2, tb1)))
mock.ExpectQuery("SHOW CREATE TABLE .*").WillReturnRows(sqlmock.NewRows([]string{"Table", "Create Table"}).AddRow(tb1, fmt.Sprintf(createTable2, tb2)))
c.Assert(CheckSyncConfig(context.Background(), cfgs), tc.IsNil)
c.Assert(CheckSyncConfig(context.Background(), cfgs, common.DefaultErrorCnt, common.DefaultWarnCnt), tc.IsNil)
}

func (s *testCheckerSuite) TestSameTargetTableDetection(c *tc.C) {
Expand Down Expand Up @@ -403,5 +406,5 @@ func (s *testCheckerSuite) TestSameTargetTableDetection(c *tc.C) {
mock.ExpectQuery("SHOW VARIABLES LIKE 'sql_mode'").WillReturnRows(sqlmock.NewRows([]string{"Variable_name", "Value"}).AddRow("sql_mode", ""))
mock.ExpectQuery("SHOW CREATE TABLE .*").WillReturnRows(sqlmock.NewRows([]string{"Table", "Create Table"}).AddRow(tb1, fmt.Sprintf(createTable1, tb1)))
mock.ExpectQuery("SHOW CREATE TABLE .*").WillReturnRows(sqlmock.NewRows([]string{"Table", "Create Table"}).AddRow(tb1, fmt.Sprintf(createTable1, tb2)))
c.Assert(CheckSyncConfig(context.Background(), cfgs), tc.ErrorMatches, "(.|\n)*same table name in case-insensitive(.|\n)*")
c.Assert(CheckSyncConfig(context.Background(), cfgs, common.DefaultErrorCnt, common.DefaultWarnCnt), tc.ErrorMatches, "(.|\n)*same table name in case-insensitive(.|\n)*")
}
22 changes: 19 additions & 3 deletions checker/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,18 @@ type Checker struct {
sync.RWMutex
detail *check.Results
}
errCnt int64
warnCnt int64
}

// NewChecker returns a checker.
func NewChecker(cfgs []*config.SubTaskConfig, checkingItems map[string]string) *Checker {
func NewChecker(cfgs []*config.SubTaskConfig, checkingItems map[string]string, errCnt, warnCnt int64) *Checker {
c := &Checker{
instances: make([]*mysqlInstance, 0, len(cfgs)),
checkingItems: checkingItems,
logger: log.With(zap.String("unit", "task check")),
errCnt: errCnt,
warnCnt: warnCnt,
}

for _, cfg := range cfgs {
Expand Down Expand Up @@ -261,9 +265,21 @@ func (c *Checker) Process(ctx context.Context, pr chan pb.ProcessResult) {

// remove success result if not pass
results := result.Results[:0]
var warnCnt int64 = 0
var errCnt int64 = 0
for _, r := range result.Results {
if r.State != check.StateSuccess {
results = append(results, r)
switch r.State {
case check.StateFailure:
if errCnt < c.errCnt {
errCnt++
results = append(results, r)
}
case check.StateWarning:
if warnCnt < c.warnCnt {
warnCnt++
results = append(results, r)
}
default:
}
}
result.Results = results
Expand Down
6 changes: 3 additions & 3 deletions checker/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ var (
ErrorMsgHeader = "fail to check synchronization configuration with type"

// CheckSyncConfigFunc holds the CheckSyncConfig function.
CheckSyncConfigFunc func(ctx context.Context, cfgs []*config.SubTaskConfig) error
CheckSyncConfigFunc func(ctx context.Context, cfgs []*config.SubTaskConfig, errCnt, warnCnt int64) error
)

func init() {
CheckSyncConfigFunc = CheckSyncConfig
}

// CheckSyncConfig checks synchronization configuration.
func CheckSyncConfig(ctx context.Context, cfgs []*config.SubTaskConfig) error {
func CheckSyncConfig(ctx context.Context, cfgs []*config.SubTaskConfig, errCnt, warnCnt int64) error {
if len(cfgs) == 0 {
return nil
}
Expand All @@ -56,7 +56,7 @@ func CheckSyncConfig(ctx context.Context, cfgs []*config.SubTaskConfig) error {
return nil
}

c := NewChecker(cfgs, checkingItems)
c := NewChecker(cfgs, checkingItems, errCnt, warnCnt)

if err := c.Init(ctx); err != nil {
return terror.Annotate(err, "fail to initial checker")
Expand Down
5 changes: 5 additions & 0 deletions dm/ctl/common/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ const (
keepaliveTimeout = 3 * time.Second
keepaliveTime = 3 * time.Second
syncMasterEndpointsTime = 3 * time.Second

// DefaultErrorCnt represents default count of errors to display for check-task.
DefaultErrorCnt = 10
// DefaultWarnCnt represents count of warns to display for check-task.
DefaultWarnCnt = 10
)

// NewConfig creates a new base config for dmctl.
Expand Down
17 changes: 15 additions & 2 deletions dm/ctl/master/check_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ import (
// NewCheckTaskCmd creates a CheckTask command.
func NewCheckTaskCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "check-task <config-file>",
Use: "check-task <config-file> [--error count] [--warn count]",
Short: "Checks the configuration file of the task.",
RunE: checkTaskFunc,
}
cmd.Flags().Int64P("error", "e", common.DefaultErrorCnt, "max count of errors to display")
cmd.Flags().Int64P("warn", "w", common.DefaultWarnCnt, "max count of warns to display")
return cmd
}

Expand All @@ -47,6 +49,15 @@ func checkTaskFunc(cmd *cobra.Command, _ []string) error {
return err
}

errCnt, err := cmd.Flags().GetInt64("error")
if err != nil {
return err
}
warnCnt, err := cmd.Flags().GetInt64("warn")
if err != nil {
return err
}

ctx, cancel := context.WithCancel(context.Background())
defer cancel()

Expand All @@ -56,7 +67,9 @@ func checkTaskFunc(cmd *cobra.Command, _ []string) error {
ctx,
"CheckTask",
&pb.CheckTaskRequest{
Task: string(content),
Task: string(content),
ErrCnt: errCnt,
WarnCnt: warnCnt,
},
&resp,
)
Expand Down
Loading

0 comments on commit 67b95c0

Please sign in to comment.