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

agent: implement ps command#90

Merged
sboeuf merged 1 commit intoclearcontainers:masterfrom
devimc:topic/psCommand
Nov 28, 2017
Merged

agent: implement ps command#90
sboeuf merged 1 commit intoclearcontainers:masterfrom
devimc:topic/psCommand

Conversation

@devimc
Copy link
Copy Markdown

@devimc devimc commented Aug 28, 2017

ps command is used to list the processes running inside
the container, this command is called by docker top

fixes #91
partially fixes clearcontainers/runtime#95

Signed-off-by: Julio Montes julio.montes@intel.com

@devimc devimc force-pushed the topic/psCommand branch 2 times, most recently from d60d1cd to bd7c555 Compare August 28, 2017 19:03
}
}
}

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 get that this whole function is about duplicating what runc does here https://github.com/opencontainers/runc/blob/master/ps.go#L41-L95, but I think we should add an added value, that is gather all those data inside a structure dedicated to this. This structure would be then marshalled so that it would become a JSON byte array that we can send to the runtime(virtcontainers basically).

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

do you mean to put all output inside a struct?

type psOutput struct {
    output byte[]
}

I wonder if this is really needed

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@devimc no, I meant having something nicer than only an array of byte already in the expected format. Basically, I was thinking that the agent could parse the output of the ps command to put it into a structure like:

type processInfo struct {
        Name string
        PID     string
        ...
}

type processListInfo []processInfo

And this would be marshalled into a json byte array through the response. Then we would have virtcontainers relying on this specific structure to unmarshal the byte array. And then, this structure would be passed back to the runtime. The runtime wrapper being the only one doing the formatting.

I am saying all of this because if we think about virtcontainers as a generic library, we want to return a process list as a standardized structure that any consumer of virtcontainers could format the way it wants.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

@sboeuf the problem with the structure that you propose is that we don't know the options user will provide

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 why we need to have every potential output covered by this structure. The output will depend on the options, I agree, but eventually we would be sending the same structure.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@devimc I'd agree with @sboeuf here. The agent should send data without assuming anything about the end user expected format. The runtime should be the one doing the formatting/filtering, not the agent.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

@sameo great! , so can we merge?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@devimc I don't think you're marshalling an actual structure that the runtime/virtcontainers could unmarshal and format filter, right ?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

runc doesn't format/filter the output because docker does that [1], I consider we should have a similar implementation and leave to docker decide the output format.

[1] - https://github.com/moby/moby/blob/402540708c9a0c35dc0b279a0f330455633537b8/daemon/top_unix.go#L63

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

All right, let's get this one in.

agent.go Outdated
hyper.ReadyCmd: readyCb,
hyper.PingCmd: pingCb,
hyper.WinsizeCmd: winsizeCb,
hyper.PsContainerCmd: processListCb,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Because it has to return a reply, it should be part of a different map. Create a new one called callbackWithReplyList

func (p *pod) runCmd(cmd hyper.HyperCmd, data []byte) error {
func (p *pod) runCmd(cmd hyper.HyperCmd, data []byte) ([]byte, error) {
cb, exist := callbackList[cmd]
if exist == false {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This check should not return an error anymore. Indeed, relying on what I have mentioned above, if we add this new Hyper command to a new map called callbackWithReplyList, we should not fail but instead, we should try this other list. If we cannot find for both lists, then we can really fail this time.
This would allow not to force all the other commands to return nil all the time because they have no byte to send back.

ps command is used to list the processes running inside
the container, this command is called by ```docker top```

fixes clearcontainers#91
partially fixes clearcontainers/runtime#95

Signed-off-by: Julio Montes <julio.montes@intel.com>
@devimc
Copy link
Copy Markdown
Author

devimc commented Nov 13, 2017

@sameo ping

@sameo
Copy link
Copy Markdown

sameo commented Nov 27, 2017

LGTM

Approved with PullApprove Approved with PullApprove

@sameo
Copy link
Copy Markdown

sameo commented Nov 28, 2017

@sboeuf Please let us know if you're ready to LGTM that PR.

@sboeuf
Copy link
Copy Markdown

sboeuf commented Nov 28, 2017

LGTM

Approved with PullApprove Approved with PullApprove

@sboeuf sboeuf merged commit b1d92e2 into clearcontainers:master Nov 28, 2017
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.

implement ps command Implement the runtime ps command

3 participants