Skip to content
This repository was archived by the owner on Mar 9, 2022. It is now read-only.

Conversation

@Random-Liu
Copy link
Member

This PR:

  1. Fix a potential panic in ContainerStats;
  2. Fix a incorrect check r.GetFilter == nil, GetFilter is a function;
  3. Refactor the code a little bit, so that we only access container store once to avoid the race;
  4. Simplify the code a little bit.

Signed-off-by: Lantao Liu [email protected]

@Random-Liu
Copy link
Member Author

@abhinandanpb

cntr, err := c.containerStore.Get(containerID)
if err != nil {
return nil, fmt.Errorf("failed to find container %q: %v", containerID, err)
return nil, fmt.Errorf("failed to find container: %v", err)
Copy link
Member

Choose a reason for hiding this comment

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

Why remove containerID? We will have not sufficient info to debug when user input a not exist containerID.

Copy link
Member Author

@Random-Liu Random-Liu Sep 27, 2017

Choose a reason for hiding this comment

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

The assumption is that the caller always know what id they are using. We only include information which caller doesn't know in the error message.

@@ -32,19 +32,22 @@ func (c *criContainerdService) ContainerStats(ctx context.Context, in *runtime.C
return nil, fmt.Errorf("invalid container stats request")
Copy link
Member

Choose a reason for hiding this comment

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

We can remove the below code . The "c.containerStore.Get" can catch it.

       if in.GetContainerId() == "" {
		return nil, fmt.Errorf("invalid container stats request")
	}

Copy link
Member Author

Choose a reason for hiding this comment

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

Will do.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

return nil, fmt.Errorf("failed to find container %q: %v", containerID, err)
return nil, fmt.Errorf("failed to find container: %v", err)
}
request := &tasks.MetricsRequest{Filters: []string{"id==" + containerID}}
Copy link
Member

Choose a reason for hiding this comment

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

We should use cntr.Metadata.ID not "containerID".

Copy link
Member Author

Choose a reason for hiding this comment

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

Will do.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

resp, err := c.taskService.Metrics(ctx, request)
if err != nil {
return nil, fmt.Errorf("failed to fetch metrics for tasks: %v", err)
return nil, fmt.Errorf("failed to fetch metrics for task: %v", err)
Copy link
Member

Choose a reason for hiding this comment

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

add containerID

return nil, fmt.Errorf("failed to fetch metrics for task: %v", err)
}
if len(resp.Metrics) != 1 {
return nil, fmt.Errorf("unexpected metrics response: %+v", resp.Metrics)
Copy link
Member

Choose a reason for hiding this comment

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

add containerID

in *runtime.ListContainerStatsRequest,
) (*runtime.ListContainerStatsResponse, error) {
request, candidateContainers, err := c.buildTaskMetricsRequest(in)
request, containers, err := c.buildTaskMetricsRequest(in)
Copy link
Member

Choose a reason for hiding this comment

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

Should we do truncindex here? There is conainerID in filter.

Copy link
Member Author

Choose a reason for hiding this comment

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

Haven't looked at your PR yet. Will do after the v1.0.0-alpha.0 release, and we could discuss there. :)

if r.Filter.GetId() != "" && c.ID != r.Filter.GetId() {
var containers []containerstore.Container
for _, cntr := range c.containerStore.List() {
if r.Filter.GetId() != "" && cntr.ID != r.Filter.GetId() {
Copy link
Member

Choose a reason for hiding this comment

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

I'd prefer to use GetFilter() as above.

Copy link
Member Author

Choose a reason for hiding this comment

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

Will do.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

Copy link
Member

@abhi abhi left a comment

Choose a reason for hiding this comment

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

Lot cleaner. Thanks. LGTM. minor nit

return nil, fmt.Errorf("failed to decode container metrics: %v", err)
cs, err := c.getContainerMetrics(cntr.Metadata, resp.Metrics[0])
if err != nil {
return nil, fmt.Errorf("failed to generate container metrics: %v", err)
Copy link
Member

Choose a reason for hiding this comment

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

I would stick with decode. We are not technically generating :)

Copy link
Member Author

Choose a reason for hiding this comment

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

Will do.

return nil, fmt.Errorf("failed to fetch metrics for task: %v", err)
}
if len(resp.Metrics) != 1 {
return nil, fmt.Errorf("unexpected metrics response: %+v", resp.Metrics)
Copy link
Member

Choose a reason for hiding this comment

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

Thanks for taking care of this

var cs runtime.ContainerStats
if err := c.getContainerMetrics(containerID, resp.Metrics[0], &cs); err != nil {
return nil, fmt.Errorf("failed to decode container metrics: %v", err)
cs, err := c.getContainerMetrics(cntr.Metadata, resp.Metrics[0])
Copy link
Member

Choose a reason for hiding this comment

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

Thats fair :)

@Random-Liu Random-Liu force-pushed the cleanup-container-metrics branch from 622e799 to 97b6e82 Compare September 27, 2017 23:43
@abhi
Copy link
Member

abhi commented Sep 27, 2017

LGTM

@abhi abhi added the lgtm label Sep 27, 2017
@Random-Liu Random-Liu merged commit e723a50 into containerd:master Sep 28, 2017
@Random-Liu Random-Liu deleted the cleanup-container-metrics branch September 28, 2017 00:17
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants