Skip to content
This repository was archived by the owner on May 12, 2021. It is now read-only.

API: support sandbox monitor operation#252

Merged
sboeuf merged 2 commits intokata-containers:masterfrom
bergwolf:sandbox_api_1
May 1, 2018
Merged

API: support sandbox monitor operation#252
sboeuf merged 2 commits intokata-containers:masterfrom
bergwolf:sandbox_api_1

Conversation

@bergwolf
Copy link
Copy Markdown
Member

@bergwolf bergwolf commented Apr 24, 2018

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

@bergwolf bergwolf force-pushed the sandbox_api_1 branch 2 times, most recently from 2693f6c to 7329554 Compare April 25, 2018 01:28
@bergwolf
Copy link
Copy Markdown
Member Author

@sboeuf @amshinde @jodh-intel @laijs PTAL.

@sboeuf
Copy link
Copy Markdown

sboeuf commented Apr 25, 2018

@bergwolf I'll take a look at this tomorrow, could you please fix the CI.

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 25, 2018

Codecov Report

❗ No coverage uploaded for pull request base (master@70b3c77). Click here to learn what that means.
The diff coverage is 70%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master     #252   +/-   ##
=========================================
  Coverage          ?   65.64%           
=========================================
  Files             ?       75           
  Lines             ?     8008           
  Branches          ?        0           
=========================================
  Hits              ?     5257           
  Misses            ?     2181           
  Partials          ?      570
Impacted Files Coverage Δ
virtcontainers/agent.go 92.15% <ø> (ø)
virtcontainers/hyperstart_agent.go 60.71% <0%> (ø)
virtcontainers/noop_agent.go 85.71% <0%> (ø)
virtcontainers/pkg/vcmock/sandbox.go 0% <0%> (ø)
virtcontainers/kata_agent.go 32.87% <65.78%> (ø)
virtcontainers/sandbox.go 67.72% <66.66%> (ø)
virtcontainers/monitor.go 81.48% <81.48%> (ø)

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 70b3c77...9d1311d. Read the comment docs.

@amshinde
Copy link
Copy Markdown
Member

amshinde commented Apr 25, 2018

lgtm

Approved with PullApprove

// 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")
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Sandbox is not running, might be?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

good point!

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done

m.running = true

// create and start agent watcher
go func() {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I wonder if you should add this routine to a wait group ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Good point! I'll let stop() wait on it.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done.


if s.monitor == nil {
s.Lock()
if s.monitor == nil {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Second time you check if s.monitor is nil, I think that's a bit too much 😃

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

It ensures we only create and set the monitor once. Otherwise concurrent callers might race in and we end up setting monitor twice.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You can simply do the lock and test the monitor value. This is really cheap here.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fair enough, I'll change it.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done.

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
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Without it, I got CI errors about copying mutex.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Ok, but please submit it as a separate PR.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Then this PR cannot pass CI.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

That's fine, we'll merge the new PR, so that you can rebase this one.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

ok, here it is #263

type reqFunc func(context.Context, interface{}, ...golangGrpc.CallOption) (interface{}, error)

func (k *kataAgent) installReqFunc(c *kataclient.AgentClient) {
k.reqHandlers = make(map[string]reqFunc)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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()
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

No, the monitor makes sure there is only one watcher goroutine per monitor. We just add more watch channels to it.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Oh I see. So we'll have one go routine with an infinite number of channels. Sounds good.

@sboeuf
Copy link
Copy Markdown

sboeuf commented May 1, 2018

@bergwolf please rebase (and make sure it removes the last commit that we've already merged in a previous PR)

bergwolf added 2 commits May 1, 2018 22:42
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>
@bergwolf
Copy link
Copy Markdown
Member Author

bergwolf commented May 1, 2018

PR rebased.

@egernst
Copy link
Copy Markdown
Member

egernst commented May 1, 2018

@sboeuf - PTAL and merge when you're happy with the changes.

@sboeuf sboeuf merged commit 87aa1d7 into kata-containers:master May 1, 2018
@sboeuf sboeuf removed the review label May 1, 2018
@bergwolf bergwolf deleted the sandbox_api_1 branch September 13, 2018 03:27
zklei pushed a commit to zklei/runtime that referenced this pull request Jun 13, 2019
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>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants