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 changefeed summary in list command, add some shortcut #721

Merged
merged 2 commits into from
Jul 8, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 3 additions & 2 deletions cdc/http_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ type commonResp struct {
Message string `json:"message"`
}

type changefeedResp struct {
// ChangefeedResp holds the most common usage information for a changefeed
type ChangefeedResp struct {
FeedState string `json:"state"`
TSO uint64 `json:"tso"`
Checkpoint string `json:"checkpoint"`
Expand Down Expand Up @@ -205,7 +206,7 @@ func (s *Server) handleChangefeedQuery(w http.ResponseWriter, req *http.Request)
return
}

resp := &changefeedResp{
resp := &ChangefeedResp{
FeedState: string(feedState),
}
if cf != nil {
Expand Down
8 changes: 5 additions & 3 deletions cmd/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/mattn/go-shellwords"
"github.com/pingcap/errors"
pd "github.com/pingcap/pd/v4/client"
"github.com/pingcap/ticdc/cdc"
"github.com/pingcap/ticdc/cdc/kv"
"github.com/pingcap/ticdc/cdc/model"
"github.com/pingcap/ticdc/pkg/util"
Expand Down Expand Up @@ -72,9 +73,10 @@ var (
defaultContext context.Context
)

// cf holds changefeed id, which is used for output only
type cf struct {
ID string `json:"id"`
// changefeedCommonInfo holds some common used information of a changefeed
type changefeedCommonInfo struct {
ID string `json:"id"`
Summary *cdc.ChangefeedResp `json:"summary"`
}

// capture holds capture information
Expand Down
32 changes: 24 additions & 8 deletions cmd/client_changefeed.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ package cmd

import (
"context"
"encoding/json"
"fmt"
"strings"
"time"

"github.com/google/uuid"
"github.com/pingcap/errors"
"github.com/pingcap/log"
"github.com/pingcap/ticdc/cdc"
"github.com/pingcap/ticdc/cdc/model"
"github.com/pingcap/ticdc/pkg/config"
"github.com/pingcap/ticdc/pkg/cyclic"
Expand All @@ -30,6 +32,7 @@ import (
"github.com/pingcap/tidb/store/tikv/oracle"
"github.com/r3labs/diff"
"github.com/spf13/cobra"
"go.uber.org/zap"
)

func newChangefeedCommand() *cobra.Command {
Expand Down Expand Up @@ -93,7 +96,7 @@ func newAdminChangefeedCommand() []*cobra.Command {
}

for _, cmd := range cmds {
cmd.PersistentFlags().StringVar(&changefeedID, "changefeed-id", "", "Replication task (changefeed) ID")
cmd.PersistentFlags().StringVarP(&changefeedID, "changefeed-id", "c", "", "Replication task (changefeed) ID")
_ = cmd.MarkPersistentFlagRequired("changefeed-id")
}
return cmds
Expand All @@ -109,9 +112,22 @@ func newListChangefeedCommand() *cobra.Command {
if err != nil {
return err
}
cfs := make([]*cf, 0, len(raw))
cfs := make([]*changefeedCommonInfo, 0, len(raw))
for id := range raw {
cfs = append(cfs, &cf{ID: id})
cfci := &changefeedCommonInfo{ID: id}
resp, err := applyOwnerChangefeedQuery(ctx, id)
if err != nil {
// if no capture is available, the query will fail, just add a warning here
log.Warn("query changefeed info failed", zap.String("error", err.Error()))
} else {
info := &cdc.ChangefeedResp{}
err = json.Unmarshal([]byte(resp), info)
if err != nil {
return err
}
cfci.Summary = info
}
cfs = append(cfs, cfci)
}
return jsonPrint(cmd, cfs)
},
Expand Down Expand Up @@ -166,8 +182,8 @@ func newQueryChangefeedCommand() *cobra.Command {
return jsonPrint(cmd, meta)
},
}
command.PersistentFlags().BoolVar(&simplified, "simple", false, "Output simplified replication status")
command.PersistentFlags().StringVar(&changefeedID, "changefeed-id", "", "Replication task (changefeed) ID")
command.PersistentFlags().BoolVarP(&simplified, "simple", "s", false, "Output simplified replication status")
command.PersistentFlags().StringVarP(&changefeedID, "changefeed-id", "c", "", "Replication task (changefeed) ID")
_ = command.MarkPersistentFlagRequired("changefeed-id")
return command
}
Expand Down Expand Up @@ -388,7 +404,7 @@ func newUpdateChangefeedCommand() *cobra.Command {
},
}
changefeedConfigVariables(command)
command.PersistentFlags().StringVar(&changefeedID, "changefeed-id", "", "Replication task (changefeed) ID")
command.PersistentFlags().StringVarP(&changefeedID, "changefeed-id", "c", "", "Replication task (changefeed) ID")
command.PersistentFlags().BoolVar(&noConfirm, "no-confirm", false, "Don't ask user whether to confirm update changefeed config")
_ = command.MarkPersistentFlagRequired("changefeed-id")

Expand Down Expand Up @@ -443,8 +459,8 @@ func newStatisticsChangefeedCommand() *cobra.Command {
}
},
}
command.PersistentFlags().StringVar(&changefeedID, "changefeed-id", "", "Replication task (changefeed) ID")
command.PersistentFlags().UintVar(&interval, "interval", 10, "Interval for outputing the latest statistics")
command.PersistentFlags().StringVarP(&changefeedID, "changefeed-id", "c", "", "Replication task (changefeed) ID")
command.PersistentFlags().UintVarP(&interval, "interval", "I", 10, "Interval for outputing the latest statistics")
_ = command.MarkPersistentFlagRequired("changefeed-id")
return command
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/client_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ func newQueryProcessorCommand() *cobra.Command {
return jsonPrint(cmd, meta)
},
}
command.PersistentFlags().StringVar(&changefeedID, "changefeed-id", "", "Replication task (changefeed) ID")
command.PersistentFlags().StringVar(&captureID, "capture-id", "", "Capture ID")
command.PersistentFlags().StringVarP(&changefeedID, "changefeed-id", "c", "", "Replication task (changefeed) ID")
command.PersistentFlags().StringVarP(&captureID, "capture-id", "p", "", "Capture ID")
_ = command.MarkPersistentFlagRequired("changefeed-id")
_ = command.MarkPersistentFlagRequired("capture-id")
return command
Expand Down