API: support sandbox monitor operation#252
Conversation
2693f6c to
7329554
Compare
|
@sboeuf @amshinde @jodh-intel @laijs PTAL. |
|
@bergwolf I'll take a look at this tomorrow, could you please fix the CI. |
Codecov Report
@@ Coverage Diff @@
## master #252 +/- ##
=========================================
Coverage ? 65.64%
=========================================
Files ? 75
Lines ? 8008
Branches ? 0
=========================================
Hits ? 5257
Misses ? 2181
Partials ? 570
Continue to review full report at Codecov.
|
virtcontainers/sandbox.go
Outdated
| // Monitor returns a error channel for watcher to watch at | ||
| func (s *Sandbox) Monitor() (chan error, error) { | ||
| if s.state.State != StateRunning { | ||
| return nil, fmt.Errorf("Sandbox not running") |
| m.running = true | ||
|
|
||
| // create and start agent watcher | ||
| go func() { |
There was a problem hiding this comment.
I wonder if you should add this routine to a wait group ?
There was a problem hiding this comment.
Good point! I'll let stop() wait on it.
virtcontainers/sandbox.go
Outdated
|
|
||
| if s.monitor == nil { | ||
| s.Lock() | ||
| if s.monitor == nil { |
There was a problem hiding this comment.
Second time you check if s.monitor is nil, I think that's a bit too much 😃
There was a problem hiding this comment.
It ensures we only create and set the monitor once. Otherwise concurrent callers might race in and we end up setting monitor twice.
There was a problem hiding this comment.
You can simply do the lock and test the monitor value. This is really cheap here.
There was a problem hiding this comment.
Fair enough, I'll change it.
virtcontainers/agent.go
Outdated
| startContainer(sandbox *Sandbox, c *Container) error | ||
|
|
||
| // stopContainer will tell the agent to stop a container related to a Sandbox. | ||
| stopContainer(sandbox Sandbox, c Container) error |
There was a problem hiding this comment.
The rationale behind using pointers versus copies was to make sure the sandbox could not get modified by some functions that obviously didn't need it.
Now I understand your concern about memory being overused because we're generating a lot of copies and I think I pretty okay with changing things into pointers. But please submit this into a separate PR as it is an important change and this way we can discuss properly about it. I don't want this to be hidden through the monitor PR.
There was a problem hiding this comment.
Without it, I got CI errors about copying mutex.
There was a problem hiding this comment.
Ok, but please submit it as a separate PR.
There was a problem hiding this comment.
Then this PR cannot pass CI.
There was a problem hiding this comment.
That's fine, we'll merge the new PR, so that you can rebase this one.
| type reqFunc func(context.Context, interface{}, ...golangGrpc.CallOption) (interface{}, error) | ||
|
|
||
| func (k *kataAgent) installReqFunc(c *kataclient.AgentClient) { | ||
| k.reqHandlers = make(map[string]reqFunc) |
There was a problem hiding this comment.
Yes, in this case, I think the map is the only way to avoid the gocyclo complexity going over 15.
Any reason you didn't use a static map here ?
There was a problem hiding this comment.
Because the agent client is dynamically allocated. I also wanted to use a static map but it turns out there is no static grpc request handler.
| s.Unlock() | ||
| } | ||
|
|
||
| return s.monitor.newWatcher() |
There was a problem hiding this comment.
I am a bit concerned about the way this is handled here. The caller can basically call a million times into Monitor(), this will result into a million go routines being spawned here. If think we should try to handle things better, by returning the existing channel from newWatcher() if it already exists. This means we would always have only one channel, because I don't see the usage for having several channels referring to the same thing. Maybe I am missing something.
There was a problem hiding this comment.
No, the monitor makes sure there is only one watcher goroutine per monitor. We just add more watch channels to it.
There was a problem hiding this comment.
Oh I see. So we'll have one go routine with an infinite number of channels. Sounds good.
|
@bergwolf please rebase (and make sure it removes the last commit that we've already merged in a previous PR) |
It monitors the sandbox status and returns an error channel to let caller watch it. Fixes: kata-containers#251 Signed-off-by: Peng Tao <bergwolf@gmail.com>
CI complains about cyclomatic complexity in sendReq. warning: cyclomatic complexity 16 of function (*kataAgent).sendReq() is high (> 15) (gocyclo) Refactor it a bit to avoid such error. I'm not a big fan of the new code but it is done so because golang does not support generics. Signed-off-by: Peng Tao <bergwolf@gmail.com>
|
PR rebased. |
|
@sboeuf - PTAL and merge when you're happy with the changes. |
Allow frozen containers receive signals in order to avoid runtime waits for shim to finish. fixes kata-containers#252 Signed-off-by: Julio Montes <julio.montes@intel.com>
As described in the API design, we need to support
Sandbox.Monitor()operation that returns an error channel for the caller to watch on sandbox fetal errors.Fixes #251