Skip to content
This repository was archived by the owner on Apr 3, 2018. It is now read-only.

agent: implement ps command#269

Merged
sboeuf merged 2 commits intocontainers:masterfrom
devimc:topic/psCommand
Oct 25, 2017
Merged

agent: implement ps command#269
sboeuf merged 2 commits intocontainers:masterfrom
devimc:topic/psCommand

Conversation

@devimc
Copy link
Copy Markdown
Collaborator

@devimc devimc commented May 23, 2017

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

partially fixes clearcontainers/runtime#95

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

@coveralls
Copy link
Copy Markdown

coveralls commented May 23, 2017

Coverage Status

Coverage decreased (-1.3%) to 65.069% when pulling b31c842 on devimc:topic/psCommand into 522a9e0 on containers:master.

api.go Outdated

// PsContainer is the virtcontainers entry point to list
// processes running inside a container
func PsContainer(podID, containerID string, psArgs []string) error {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Maybe I am missing something here but you never return anything, right ? How do you plan to get the data back ?

Also I think it could be part of StatusContainer() instead of adding a new function to the exported API. @sameo any thoughts on this one ?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

probably I have to return a string

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I would say that you want to return a new dedicated structure. Something like:

type ProcessInfo struct {
        Name string
        PID string
        PPID string
        ...
}

type PsInfo struct {
        ID string
        ProcessesList []ProcessInfo
}

@jodh-intel
Copy link
Copy Markdown
Collaborator

Related to clearcontainers/runtime#95.

SetupInterface: SetupInterfaceCode,
SetupRoute: SetupRouteCode,
RemoveContainer: RemoveContainerCode,
PsContainer: PsContainerCode,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Where in hyperstart is this defined ?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

It is not defined, not yet I'm working on that clearcontainers/hyperstart#30

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@sameo
Copy link
Copy Markdown
Collaborator

sameo commented May 30, 2017

Depends on an hyperstart PR

@jodh-intel
Copy link
Copy Markdown
Collaborator

Related: clearcontainers/proxy#83

@devimc devimc force-pushed the topic/psCommand branch 2 times, most recently from 60c3834 to 01c1fee Compare August 22, 2017 16:50
@devimc devimc changed the title [WIP] agent: implements ps command agent: implement ps command Aug 22, 2017
@devimc
Copy link
Copy Markdown
Collaborator Author

devimc commented Aug 22, 2017

@sameo @sboeuf @jodh-intel or somebody with superpowers , please remove do-not-merge tag

@coveralls
Copy link
Copy Markdown

coveralls commented Aug 22, 2017

Coverage Status

Coverage decreased (-0.9%) to 65.787% when pulling 82477b6 on devimc:topic/psCommand into 6abb9c6 on containers:master.

@coveralls
Copy link
Copy Markdown

coveralls commented Aug 22, 2017

Coverage Status

Coverage decreased (-0.9%) to 65.772% when pulling 911e469 on devimc:topic/psCommand into 6abb9c6 on containers:master.

agent.go Outdated
killContainer(pod Pod, c Container, signal syscall.Signal, all bool) error

// psContainer will list the processes running inside the container
psContainer(pod Pod, c Container, format string, psArgs []string) ([]byte, error)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

processListContainer seems like a more generic name IMO.
And also I would prefer a function prototype a bit different:

processListContainer(pod Pod, c Container, processListOptions []Param) (ProcessList, error)

The reason here is that I would like to get the same processList structure from any agent implementation and get this structure formatted as expected from the runtime implementation.

api.go Outdated

// PsContainer is the virtcontainers entry point to list
// processes running inside a container
func PsContainer(podID, containerID string, format string, psArgs []string) ([]byte, error) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

s/PsContainer/ProcessListContainer/
Prototype

ProcessListContainer(podID, containerID string, processListOptions []Param) (ProcessList, error)

container.go Outdated
return nil
}

func (c *Container) ps(format string, psArgs []string) ([]byte, error) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Replace

ps(format string, psArgs []string) ([]byte, error)

with

processList(processListOptions []Param) (ProcessList, error)

@devimc
Copy link
Copy Markdown
Collaborator Author

devimc commented Aug 28, 2017

@sboeuf changes applied

@coveralls
Copy link
Copy Markdown

coveralls commented Aug 28, 2017

Coverage Status

Coverage decreased (-0.9%) to 65.057% when pulling 3f520fc on devimc:topic/psCommand into e2c760d on containers:master.

@sboeuf
Copy link
Copy Markdown
Collaborator

sboeuf commented Sep 1, 2017

@devimc Thanks but you've addressed only half of the comments. Here is what you missed:

And also I would prefer a function prototype a bit different:

processListContainer(pod Pod, c Container, processListOptions []Param) (ProcessList, error)

The reason here is that I would like to get the same processList structure from any agent implementation and get this structure formatted as expected from the runtime implementation.

And

Replace

ps(format string, psArgs []string) ([]byte, error)

with

processList(processListOptions []Param) (ProcessList, error)

The important point here is that I think it would be better to return a generic structure that we define inside virtcontainers so that it can be reused by any runtime implementation. That means that I would expect to see the runtime doing the conversion between this structure and the expected format.
Does that make sense ?
@sameo any thought on that ?

@devimc
Copy link
Copy Markdown
Collaborator Author

devimc commented Sep 18, 2017

@sboeuf imo does not make sense to create a struct just for 1 element, I agree with you I'd expect the conversion of types in the runtime, for this reason I defined the type ProcessList as []byte

@coveralls
Copy link
Copy Markdown

coveralls commented Sep 18, 2017

Coverage Status

Coverage decreased (-0.8%) to 65.104% when pulling 270f7e2 on devimc:topic/psCommand into 6b4015e on containers:master.

Copy link
Copy Markdown
Collaborator

@jodh-intel jodh-intel left a comment

Choose a reason for hiding this comment

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

Just a minor nit.

@sboeuf - what do you think?

hyperstart.go Outdated

response, err := h.proxy.sendCmd(proxyCmd)
if msg, ok := response.([]byte); ok {
return msg, err
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This would be clearer as follows (currently it is unclear if it's an error or not :):

return msg, nil

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

yes I think this should return return msg, nil since this is the right case.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@sboeuf - Once that's done, is this good to merge?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@jodh-intel @devimc Yes after this is cleared up, I think we're good to merge this PR. Please could you implement like this in order to get all this clearer:

response, err := h.proxy.sendCmd(proxyCmd)
if err != nil {
        return nil, err
}
if msg, ok := response.([]byte); !ok {
        return nil, fmt.Errorf("failed to get response message")
}

return msg, nil

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@devimc any progress on this one ?

@devimc
Copy link
Copy Markdown
Collaborator Author

devimc commented Oct 25, 2017

@jodh-intel @sboeuf changes applied , thanks

@coveralls
Copy link
Copy Markdown

coveralls commented Oct 25, 2017

Coverage Status

Coverage decreased (-0.3%) to 65.658% when pulling b398ccc on devimc:topic/psCommand into 981b575 on containers:master.

@sboeuf
Copy link
Copy Markdown
Collaborator

sboeuf commented Oct 25, 2017

LGTM

Approved with PullApprove Approved with PullApprove

agent.go Outdated
Args []string
}

// ProcessList represents the list of running process inside the container
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

s/process/processes/

agent.go Outdated
// ProcessListOptions contains the options used to list running
// processes inside the container
type ProcessListOptions struct {
// Format describes the output format to list the running processes
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I originally thought this might be for ps(1) -o formats, so I think it would be helpful to state somehow that this is unrelated to ps(1) formats (and maybe list some). Looking at clearcontainers/agent#90, I'm wondering if it would be useful if the agent would default to table if Format="".

Copy link
Copy Markdown
Collaborator Author

@devimc devimc Oct 25, 2017

Choose a reason for hiding this comment

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

sure, lemme update the comment to specify format is unrelated to ps.
default value is set in the runtime [1]

[1] - https://github.com/clearcontainers/runtime/pull/444/files#diff-b985e723bb136b291af1a569f76616d4R32

agent.go Outdated
// Format describes the output format to list the running processes
Format string

// Args contains the list of arguments to run ps command
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Again, the agent PR shows that if this isn't set, it default to sane values so I wonder if it would be worth adding "(optional)" at the end of the comment here?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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


// ProcessListContainer is the virtcontainers entry point to list
// processes running inside a container
func ProcessListContainer(podID, containerID string, options ProcessListOptions) (ProcessList, error) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Since this changes the API, you'll need to also do the following:

  • interfaces.go: Add this function to the VC interface).
  • implementation.go: Add a simple wrapper like the one for SetLogger()).
  • pkg/vcMock/types.go: Again, add a function similar to SetLoggerFunc).
  • pkg/vcMock/mock.go: Add a simple wrapper like the one for SetLogger()).
  • pkg/vcMock/mock_test.go: Add a simple TestProcessListContainer().

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

done, thanks

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Wow that was fast! 😄

}

if state.State != StateRunning {
return nil, fmt.Errorf("Container not running, impossible to list processes")
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can you add c.id to the error here? Also, this is racy as the container might be running here, but by the time you call processListContainer() below it might have stopped.

hyperstart.go Outdated

msg, ok := response.([]byte)
if !ok {
return nil, fmt.Errorf("failed to get response message")
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Would be useful to have podID and cID in the error here.

@jodh-intel
Copy link
Copy Markdown
Collaborator

I should have said that above are addressed, I think this is good to land [1].


[1] - I suppose this could land before clearcontainers/agent#90 as the agent will just reject the unknown command.

@devimc
Copy link
Copy Markdown
Collaborator Author

devimc commented Oct 25, 2017

@jodh-intel changes applied, thanks

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

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 72c9de6 to fe38e5a Compare October 25, 2017 16:43
implement mock functions to test processListContainer

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

coveralls commented Oct 25, 2017

Coverage Status

Coverage decreased (-0.4%) to 65.619% when pulling ff99e51 on devimc:topic/psCommand into 981b575 on containers:master.

@sboeuf sboeuf merged commit 20deadb into containers:master Oct 25, 2017
@devimc devimc deleted the topic/psCommand branch March 6, 2018 14:40
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 the runtime ps command

6 participants