Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support show numbers of global service in service ls command #27710

Merged

Conversation

allencloud
Copy link
Contributor

@allencloud allencloud commented Oct 25, 2016

fixes #27670

make command docker service ls show numbers for global services, like :

ID            NAME              MODE        REPLICAS  IMAGE         COMMAND
50va1ha64xhi  nauseous_beaver   replicated  1/1       nginx
a430fxzr07iq  nauseous_hodgkin  global      1/1       ubuntu:14.04  sleep 1000

if a sevice's mode is global, actually we can not get the total number of task in this service. Here what I did is that we collect all the tasks, and classify via task.ServiceID. Then we can know that in a service how many tasks are in this service. In addition, we can not simply get the number of nodes to make it the total number of tasks in a service, since user can use constraints in creating global service, then task number in a service may not equal to the number of nodes.

- What I did

- How I did it

- How to verify it

- Description for the changelog

- A picture of a cute animal (not mandatory but encouraged)

Signed-off-by: allencloud allen.sun@daocloud.io

@allencloud allencloud force-pushed the show-num-for-global-service-in-service-ls branch 2 times, most recently from 65c9aea to de687d7 Compare October 25, 2016 03:57
@AkihiroSuda
Copy link
Member

I think MODE column should be introduced because (I feel) it looks pretty

ID            NAME              REPLICAS    MODE           IMAGE         COMMAND
50va1ha64xhi  nauseous_beaver   1/1         replicated     nginx
a430fxzr07iq  nauseous_hodgkin  1/1         global         ubuntu:14.04  sleep 1000

@allencloud
Copy link
Contributor Author

Oh, to be honest, your example is better. @AkihiroSuda
How about moving MODE before REPLICAS?

@AkihiroSuda
Copy link
Member

@allencloud SGTM

@allencloud
Copy link
Contributor Author

It will add a new column for the output maybe need more discussion. WDYT? @thaJeztah @AkihiroSuda @vdemeester

@vdemeester
Copy link
Member

/cc @thaJeztah @aluzzardi @stevvooe any reason why we did not add MODE in the first place ?
If we where to add this, I agree with @AkihiroSuda that we should add a new column.

@thaJeztah
Copy link
Member

I agree with having a separate column as well (#27670 (comment)) 😄

@@ -116,7 +118,7 @@ func printTable(out io.Writer, services []swarm.Service, running map[string]int)
if service.Spec.Mode.Replicated != nil && service.Spec.Mode.Replicated.Replicas != nil {
replicas = fmt.Sprintf("%d/%d", running[service.ID], *service.Spec.Mode.Replicated.Replicas)
} else if service.Spec.Mode.Global != nil {
replicas = "global"
replicas = fmt.Sprintf("%d/%d global", running[service.ID], tasksPerService[service.ID])
Copy link
Member

Choose a reason for hiding this comment

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

Is the "total" here always using the total node count? If so, that should probably be changed to take constraints into account (which is supported for global services)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, actually it is not the total node count. Here is scene:

  1. 5 nodes, 2 managers, 3 workers.
  2. docker service create --constraint node.role==manager ubuntu:14.04 sleep 100000
  3. before 1.13.0, global service will be every node even if the node does not meet the constraint. While since PR Only create global service tasks on nodes that satisfy the constraints swarmkit#1570, task will only be on nodes which satisfies the constraints. However this PR counts all tasks of a global service, and I think it will be OK for docker version both before 1.13- and 1.13+

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since 1.13.0, task of global service will only on node which satisfies constraints. So this PR counts node which only has the corresponding task. PTAL @thaJeztah

@allencloud allencloud force-pushed the show-num-for-global-service-in-service-ls branch 8 times, most recently from 1d94a47 to 5c69224 Compare October 26, 2016 09:15
@allencloud
Copy link
Contributor Author

Added a column already. PTAL @AkihiroSuda @vdemeester @thaJeztah

@thaJeztah
Copy link
Member

design LGTM, but ping @aluzzardi PTAL

@aluzzardi
Copy link
Member

LGTM

/cc @dongluochen


// first key is service id, the value of first key is a map
// In the second map, key is node ID, value is task number of this service on this node.
tasksPerService := map[string]map[string]int{}
Copy link
Member

Choose a reason for hiding this comment

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

can we avoid 2D map because we are just interested in the number of tasks?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, what we are interested in is number of tasks in every Service. I think we should classify tasks via different service.
If you have any better ways to implement this, please feel free to tell me.

Copy link
Contributor

Choose a reason for hiding this comment

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

You can implement the same thing with a struct-keyed map but I don't see this being accessed by taskID, so I don't quite understand what is being attempted here.

This should be called tasksByService or taskCountByService?

@allencloud
Copy link
Contributor Author

ping @dongluochen . PTAL, thanks. 😃

@allencloud allencloud force-pushed the show-num-for-global-service-in-service-ls branch from 1c1fc64 to d166eb8 Compare November 2, 2016 10:20
@@ -95,34 +95,51 @@ func PrintNotQuiet(out io.Writer, services []swarm.Service, nodes []swarm.Node,
}

running := map[string]int{}

// first key is service id, the value of first key is a map
// In the second map, key is task ID, if the task's desired status is not shutdown, it has a value.
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is the map by task ID necessary? Does TaskList return duplicate tasks?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, Yes, It is unnecessary now. Thanks a lot for your review. PTAL

@allencloud allencloud force-pushed the show-num-for-global-service-in-service-ls branch 5 times, most recently from 036671a to 6b2d8d0 Compare November 3, 2016 10:25
```

Copy link
Contributor

Choose a reason for hiding this comment

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

Extra whitespace here. @thaJeztah does this matter in markdown?

Copy link
Member

Choose a reason for hiding this comment

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

Don't think it's a problem here, but @allencloud would be nice to clean up 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done, Thanks. Now cleaned up this. 😄

@stevvooe
Copy link
Contributor

stevvooe commented Nov 3, 2016

LGTM

@allencloud allencloud force-pushed the show-num-for-global-service-in-service-ls branch from 6b2d8d0 to 5021c03 Compare November 3, 2016 23:26
@aaronlehmann
Copy link
Contributor

LGTM

Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

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

LGTM

docs changes are going to conflict with #28029

/cc @mstanleyjones

Signed-off-by: allencloud <allen.sun@daocloud.io>
@allencloud allencloud force-pushed the show-num-for-global-service-in-service-ls branch from 5a6c967 to ea03f09 Compare November 8, 2016 08:17
@allencloud
Copy link
Contributor Author

Solve conflict because merging of #28029
PTAL, my friends.

Copy link
Member

@vdemeester vdemeester left a comment

Choose a reason for hiding this comment

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

LGTM 🐯

Copy link
Contributor

@mdlinville mdlinville left a comment

Choose a reason for hiding this comment

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

LGTM. Leaving the merge for @thaJeztah

@vdemeester vdemeester merged commit a70b1d7 into moby:master Nov 8, 2016
@GordonTheTurtle GordonTheTurtle added this to the 1.13.0 milestone Nov 8, 2016
@thaJeztah
Copy link
Member

oops, late to the party, thanks!

@yank1
Copy link
Contributor

yank1 commented Nov 9, 2016

LGTM

@allencloud allencloud deleted the show-num-for-global-service-in-service-ls branch November 9, 2016 02:12
dnephin pushed a commit to dnephin/docker that referenced this pull request Apr 17, 2017
…vice-in-service-ls

support show numbers of global service in service ls command
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature Request: Show --global instance numbers when docker service ls
10 participants