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

etcdctl: support exec watch in v3 #8919

Merged
merged 3 commits into from
Dec 20, 2017
Merged

etcdctl: support exec watch in v3 #8919

merged 3 commits into from
Dec 20, 2017

Conversation

gyuho
Copy link
Contributor

@gyuho gyuho commented Nov 27, 2017

Fix #8814.

@gyuho gyuho force-pushed the exec-watch branch 2 times, most recently from fc8db4f to ca7384b Compare November 27, 2017 08:12
@gyuho gyuho requested a review from xiang90 November 27, 2017 16:19
@gyuho gyuho force-pushed the exec-watch branch 2 times, most recently from 7ffd56f to db00ff0 Compare December 6, 2017 02:48
@xiang90
Copy link
Contributor

xiang90 commented Dec 9, 2017

/cc @jpbetz can you take a look?

@jpbetz
Copy link
Contributor

jpbetz commented Dec 9, 2017

Sure, I’ll have a look

@vikin91
Copy link

vikin91 commented Dec 12, 2017

I'd love to see this released. This blocks migration of APIv2 to APIv3.

Are there any short-term hacks for 3.2.10 or 3.2.11 to run a command on a change of watched value?

@gyuho
Copy link
Contributor Author

gyuho commented Dec 12, 2017

@vikin91 We plan to release this in 3.3 (release candidate will be out this or early next year).
Can you give this branch a try?

@vikin91
Copy link

vikin91 commented Dec 12, 2017

Sure, I will try it soon and report my experience.

@vikin91
Copy link

vikin91 commented Dec 13, 2017

@gyuho , I tried the code and it works good. However, there is one difference between APIv2 and APIv3. In APIv2, the watch-exec command set two (or maybe more?) env variables ETCD_WATCH_KEY and ETCD_WATCH_VALUE that contained respectively key and value of the watched path in etcd. In APIv3 these variables are not being set. It would be great if APIv3 could keep the same behaviour to make the migration as smooth as possible.

@gyuho
Copy link
Contributor Author

gyuho commented Dec 14, 2017

@vikin91 Thanks for trying out!

I would like to keep it as simple as possible for now--environment variable support for watch key/value can be easily added later.

ref.

https://github.com/coreos/etcd/blob/b48cf77abb78755c8654eb8da61bc90a32802e7d/etcdctl/ctlv2/command/exec_watch_command.go#L123-L129

Copy link
Contributor

@jpbetz jpbetz left a comment

Choose a reason for hiding this comment

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

Test coverage looks great. Thanks!

The logic all looks right. Just a couple comments for code readability / simplicity.

The only major thing I noticed is missing is ENV VARS, but looks like the agreement is to hold of on ENV VARS, so that's fine.

return nil, fmt.Errorf("bad number of arguments")
func getWatchChan(c *clientv3.Client, args []string, interactive bool) (clientv3.WatchChan, []string, error) {
if interactive {
args = args[1:] // args[0]=="watch"
Copy link
Contributor

@jpbetz jpbetz Dec 19, 2017

Choose a reason for hiding this comment

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

Move the assertion in this comment into the code, e.g.: if args[0] != "watch { panic("args[0] must be 'watch' for interactive calls") } ?

}
}
osArgs := os.Args[idx+1:]
execArgs, err = findExecArgs(osArgs)
Copy link
Contributor

@jpbetz jpbetz Dec 19, 2017

Choose a reason for hiding this comment

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

Avoid repeating the findExecArgs call by restructuring this as:

if !interactive {
  ...
  args := osArgs
}
execArgs, err = findExecArgs(args)

?

Also, should findExecArgs return both the args before -- as well as the args after -- so that the subsequent code can deal with them as cleanly separated lists? I'm concerned that checks like len(args) == 2 below might not make sense if we don't cleanly separate the two args lists. I add another comment about this below for findExecArgs.

return nil, nil
}

if idx == len(args)-1 {
Copy link
Contributor

@jpbetz jpbetz Dec 19, 2017

Choose a reason for hiding this comment

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

Let's split the args and execArgs into two distinct lists here and then simplify all following, logic, e.g.:

func findExecArgs(args []string) ([]string, []string, error) {

foundSep, idx := false, 0
 for idx = range args {
 	if args[idx] == "--" && idx != 0 {
 		foundSep = true
 		break
 	}
 }
 if !foundSep {
 	return args, nil, nil
 }
watchArgs, execArgs := args[:idx], args[idx+1:]

// check for various invalid states
...

return watchArgs, execArgs, nil

}

Signed-off-by: Gyu-Ho Lee <gyuhox@gmail.com>
Signed-off-by: Gyu-Ho Lee <gyuhox@gmail.com>
Signed-off-by: Gyu-Ho Lee <gyuhox@gmail.com>
@codecov-io
Copy link

Codecov Report

Merging #8919 into master will decrease coverage by 0.17%.
The diff coverage is 58.46%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #8919      +/-   ##
==========================================
- Coverage   76.08%   75.91%   -0.18%     
==========================================
  Files         359      359              
  Lines       29841    29891      +50     
==========================================
- Hits        22704    22691      -13     
- Misses       5559     5619      +60     
- Partials     1578     1581       +3
Impacted Files Coverage Δ
etcdctl/ctlv3/command/watch_command.go 40.51% <58.46%> (+25.36%) ⬆️
etcdserver/api/v3rpc/watch.go 85.38% <0%> (-6.4%) ⬇️
clientv3/namespace/watch.go 87.87% <0%> (-6.07%) ⬇️
proxy/grpcproxy/watch.go 90.06% <0%> (-4.97%) ⬇️
pkg/adt/interval_tree.go 81.68% <0%> (-4.81%) ⬇️
mvcc/watchable_store.go 85.23% <0%> (-4.8%) ⬇️
raft/node.go 89.38% <0%> (-2.22%) ⬇️
auth/range_perm_cache.go 66.17% <0%> (-1.48%) ⬇️
clientv3/concurrency/election.go 79.52% <0%> (-0.79%) ⬇️
pkg/transport/listener_tls.go 65.56% <0%> (-0.67%) ⬇️
... and 11 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 828289d...25222c2. Read the comment docs.

@gyuho gyuho removed the WIP label Dec 20, 2017
@gyuho
Copy link
Contributor Author

gyuho commented Dec 20, 2017

@jpbetz PTAL. Refactored parseWatchArgs function and addressed other feedback as well--logic got a bit more complicated, so I added more test cases. Everything else is the same.

Thanks!

Copy link
Contributor

@jpbetz jpbetz left a comment

Choose a reason for hiding this comment

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

Thanks!

lgtm

@gyuho gyuho merged commit 2212789 into etcd-io:master Dec 20, 2017
@gyuho gyuho deleted the exec-watch branch December 20, 2017 18:53
@debovema
Copy link

As reported by @vikin91, the feature is not usable without the environment variables (ETCD_WATCH_KEY, ETCD_WATCH_VALUE...) being set.
Aside from that it works with v3.3.0-rc.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

6 participants