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

Added print-request and dry-run support for subscribe #482

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
21 changes: 21 additions & 0 deletions pkg/app/gnmi_client_subscribe.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,22 @@ CRCLIENT:
a.Logger.Printf("target %q gNMI client created", t.Config.Name)

for _, sreq := range subRequests {
if a.Config.GlobalFlags.PrintRequest || a.Config.LocalFlags.SubscribeDryRun {
err := a.PrintMsg(tc.Name, "Subscribe Request:", sreq.req)
if err != nil {
a.logError(fmt.Errorf("target %q Subscribe Request printing failed: %v", tc.Name, err))
}
}
if a.Config.LocalFlags.SubscribeDryRun {
continue
}
a.Logger.Printf("sending gNMI SubscribeRequest: subscribe='%+v', mode='%+v', encoding='%+v', to %s",
sreq.req, sreq.req.GetSubscribe().GetMode(), sreq.req.GetSubscribe().GetEncoding(), t.Config.Name)
go t.Subscribe(gnmiCtx, sreq.req, sreq.name)
}
if a.Config.LocalFlags.SubscribeDryRun {
os.Exit(0)
}
Comment on lines +227 to +229
Copy link
Collaborator

Choose a reason for hiding this comment

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

In the case the subscribe command is running against multiple targets, the os.Exit(0) will stop the process before all the subscribe requests are printed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

After the return statement, the program is left waiting for something. I was not able to figure out where it waits. Can you help me out here?

return nil
}

Expand Down Expand Up @@ -272,6 +284,15 @@ CRCLIENT:
a.Logger.Printf("target %q gNMI client created", t.Config.Name)
OUTER:
for _, sreq := range subRequests {
if a.Config.GlobalFlags.PrintRequest || a.Config.LocalFlags.SubscribeDryRun {
err := a.PrintMsg(tc.Name, "Subscribe Request:", sreq.req)
if err != nil {
a.logError(fmt.Errorf("target %q Subscribe Request printing failed: %v", tc.Name, err))
}
}
if a.Config.LocalFlags.SubscribeDryRun {
continue
}
a.Logger.Printf("sending gNMI SubscribeRequest: subscribe='%+v', mode='%+v', encoding='%+v', to %s",
sreq.req, sreq.req.GetSubscribe().GetMode(), sreq.req.GetSubscribe().GetEncoding(), t.Config.Name)
rspCh, errCh := t.SubscribeOnceChan(gnmiCtx, sreq.req)
Expand Down
1 change: 1 addition & 0 deletions pkg/app/subscribe.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ func (a *App) InitSubscribeFlags(cmd *cobra.Command) {
cmd.Flags().StringVarP(&a.Config.LocalFlags.SubscribeHistoryStart, "history-start", "", "", "sets the start time in a historical range subscription, nanoseconds since Unix epoch or RFC3339 format")
cmd.Flags().StringVarP(&a.Config.LocalFlags.SubscribeHistoryEnd, "history-end", "", "", "sets the end time in a historical range subscription, nanoseconds since Unix epoch or RFC3339 format")
cmd.Flags().Uint32VarP(&a.Config.LocalFlags.SubscribeDepth, "depth", "", 0, "depth extension value")
cmd.Flags().BoolVarP(&a.Config.LocalFlags.SubscribeDryRun, "dry-run", "", false, "dry-run mode, only print the subscribe request")
//
cmd.LocalFlags().VisitAll(func(flag *pflag.Flag) {
a.Config.FileConfig.BindPFlag(fmt.Sprintf("%s-%s", cmd.Name(), flag.Name), flag)
Expand Down
1 change: 1 addition & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ type LocalFlags struct {
SubscribeHistoryStart string `mapstructure:"subscribe-history-start,omitempty" json:"subscribe-history-start,omitempty" yaml:"subscribe-history-start,omitempty"`
SubscribeHistoryEnd string `mapstructure:"subscribe-history-end,omitempty" json:"subscribe-history-end,omitempty" yaml:"subscribe-history-end,omitempty"`
SubscribeDepth uint32 `mapstructure:"subscribe-depth,omitempty" yaml:"subscribe-depth,omitempty" json:"subscribe-depth,omitempty"`
SubscribeDryRun bool `mapstructure:"subscribe-dry-run,omitempty" json:"subscribe-dry-run,omitempty" yaml:"subscribe-dry-run,omitempty"`
// Path
PathPathType string `mapstructure:"path-path-type,omitempty" json:"path-path-type,omitempty" yaml:"path-path-type,omitempty"`
PathWithDescr bool `mapstructure:"path-descr,omitempty" json:"path-descr,omitempty" yaml:"path-descr,omitempty"`
Expand Down