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

Add support for sending down service Running and Desired task counts #39231

Merged
merged 1 commit into from
Oct 15, 2019

Conversation

dperny
Copy link
Contributor

@dperny dperny commented May 17, 2019

- What I did

Add an optional ServiceStatus field in Service objects, which is available as part of List operations, and gives the Running and Desired task counts. This is essentially performing a UI operation on the server side, but as this is probably the most common UI operation and it is rather expensive to perform client side, it's worth doing.

- How I did it

Plumbed through the use of a new swarmkit gRPC endpoint (see moby/swarmkit#2856) which allows getting service statuses. This is a separate swarmkit API call because swarmkit's protos function as both the wire format and the persistence format of the objects, and I did not want to add a Status field to the swarmkit Service object. However, because this is much less of a concern in the engine, the ServiceStatus field is present on the engine API type.

Includes updates to swagger.yml, of course.

- How to verify it

The swarmkit code is well-tested to make sure the right values are computed. The Docker code includes an integration test confirming that the values are correctly plumbed through to the API.

- Description for the changelog

GET /services now accepts a status parameter, which instructs the engine to return the number of Running and Desired tasks as part of a service.

@dperny
Copy link
Contributor Author

dperny commented May 17, 2019

includes versioning done with an improper version of vndr; however, versioning should match the changes in #39216

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.

thx! left some comments

integration/service/list_test.go Show resolved Hide resolved
@@ -167,7 +167,16 @@ func (sr *swarmRouter) getServices(ctx context.Context, w http.ResponseWriter, r
return errdefs.InvalidParameter(err)
}

services, err := sr.backend.GetServices(basictypes.ServiceListOptions{Filters: filter})
var status bool
if value := r.URL.Query().Get("status"); value != "" {
Copy link
Member

Choose a reason for hiding this comment

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

Can you gate this by API version, so that setting this query-parameter does not have an effect on older API versions?

api/swagger.yaml Outdated
properties:
RunningTasks:
description: "The number of tasks for the service currently in the Running state"
type: "number"
Copy link
Member

Choose a reason for hiding this comment

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

Can you add an example value here, and set the correct format/type?

Suggested change
type: "number"
type: "integer"
format: "uint64"
example: 7

api/swagger.yaml Outdated
service spec. For global services, this is computed by taking
count of all tasks for the service with a Desired State other
than Shutdown.
type: "number"
Copy link
Member

Choose a reason for hiding this comment

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

Can you add an example value here, and set the correct format/type?

Suggested change
type: "number"
type: "integer"
format: "uint64"
example: 10

Copy link
Member

Choose a reason for hiding this comment

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

Can you also add a mention in the API history doc; https://github.com/moby/moby/blob/master/docs/api/version-history.md

// the Status field is not supported when retrieving an individual service
// because the Backend API changes required to accomodate it would be too
// disruptive, and because that field is so rarely needed as part of an
// individual service inspection.
Copy link
Member

Choose a reason for hiding this comment

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

Position of this comment is a bit confusing (as there is no code visible here for status?)

@codecov
Copy link

codecov bot commented Jun 3, 2019

Codecov Report

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

@@            Coverage Diff            @@
##             master   #39231   +/-   ##
=========================================
  Coverage          ?   37.28%           
=========================================
  Files             ?      609           
  Lines             ?    45261           
  Branches          ?        0           
=========================================
  Hits              ?    16877           
  Misses            ?    26090           
  Partials          ?     2294

@dperny dperny force-pushed the add-service-status branch 3 times, most recently from 312f4ec to 51cdc4c Compare June 3, 2019 21:04
@dperny
Copy link
Contributor Author

dperny commented Jun 4, 2019

to the best of my knowledge, the failure in the experimental build is unrelated.

@thaJeztah updated to reflect your comments.

@dperny dperny force-pushed the add-service-status branch 2 times, most recently from 051f5e2 to b30f83e Compare June 10, 2019 14:17
@dperny dperny force-pushed the add-service-status branch 2 times, most recently from e87c3e1 to b614f25 Compare June 17, 2019 17:18
@dperny dperny force-pushed the add-service-status branch from b614f25 to a7d5d6c Compare July 9, 2019 16:13
@dperny
Copy link
Contributor Author

dperny commented Jul 9, 2019

unreal tournament announcer voice: re-re-re-rebase

RunningTasks:
description: "The number of tasks for the service currently in the Running state"
type: "number"
DesiredTasks:
Copy link
Member

Choose a reason for hiding this comment

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

Isn't desired in the service spec?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not necessarily, for two reasons:

  1. As mentioned in the description, for global services, this must be computed by looking at all tasks in desired state Running, which cannot be done without getting all tasks for the service, and avoiding getting all tasks for the service is the point of this PR.
  2. The implementation of this in Swarmkit was done in such a way that it's a separate gRPC call, which means there could be races with service updates, where the desired task count changes while the status is being computed. This is no worse than the existing behavior, as the ServiceStatus is consistent within itself, which was also true of these values as computed by looking at tasks (all tasks were retrieved at once and the values were computed client-side, which could in the same way be inconsistent with the service spec.).

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 explaining, that makes sense.

if value := r.URL.Query().Get("insertDefaults"); value != "" {
var err error
insertDefaults, err = strconv.ParseBool(value)
if err != nil {
err := fmt.Errorf("invalid value for insertDefaults: %s", value)
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 the error context?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

unsure. It must've gotten removed by accident.

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, because directly below, it would get wrapped again, and the result (I think) would be something like Error: invalid value for insertDefaults: invalid value for insertDefaults: {{ strconv error }}. Am I incorrect on that?

Copy link
Member

Choose a reason for hiding this comment

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

Oh of course :)

services, err := sr.backend.GetServices(basictypes.ServiceListOptions{Filters: filter})
// the status query parameter is only support in API versions >= 1.41. If
// the client is using a lesser version, ignore the parameter.
cliVersion := r.Header.Get("version")
Copy link
Member

Choose a reason for hiding this comment

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

Should be able to use httputils.VersionFromContext

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixing this.

@dperny dperny force-pushed the add-service-status branch 4 times, most recently from bf4cb85 to f016519 Compare July 16, 2019 16:23
@dperny dperny force-pushed the add-service-status branch from f016519 to b817424 Compare September 5, 2019 16:09
@dperny
Copy link
Contributor Author

dperny commented Sep 18, 2019

a test seems to have flaked. i'm going to rebase and push and see if it fails again

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, thanks!

@thaJeztah
Copy link
Member

This will need a follow-up in the docker/cli repository to make use of the new field

@thaJeztah
Copy link
Member

@dperny looks like there's a linting failure;

api/server/router/swarm/cluster_routes.go:205:17: `accomodate` is a misspelling of `accommodate` (misspell)
 	// required to accomodate it would be too disruptive, and because that

Can you also rebase, to get https://github.com/moby/moby/pulls in (flaky test, which has been disabled for Windows)

@thaJeztah thaJeztah added the status/failing-ci Indicates that the PR in its current state fails the test suite label Sep 23, 2019
@dperny dperny force-pushed the add-service-status branch 2 times, most recently from 151a3c6 to 9caf9a1 Compare September 30, 2019 17:30
@dperny
Copy link
Contributor Author

dperny commented Oct 1, 2019

I've rebased this PR but I'm not clear on what's wrong. Something with swagger is failing, but it's panicking, not outputting useful information about the failure.

@thaJeztah
Copy link
Member

Hm... haven't seen that one before;


[2019-09-30T17:33:36.869Z] Congratulations!  "./pkg/..." is safely isolated from internal code.
[2019-09-30T17:33:41.028Z] panic: object has no key "default"
[2019-09-30T17:33:41.028Z] 
[2019-09-30T17:33:41.028Z] goroutine 1 [running]:
[2019-09-30T17:33:41.028Z] github.com/go-swagger/go-swagger/vendor/github.com/go-openapi/validate.NewSchemaValidator(0xc000f9bb00, 0xbaf840, 0xc000f9bb00, 0x0, 0x0, 0xd11940, 0xc0004be9c0, 0x40)
[2019-09-30T17:33:41.028Z] 	/tmp/tmp.KMo0CBcPeP/src/github.com/go-swagger/go-swagger/vendor/github.com/go-openapi/validate/schema.go:55 +0xf68
[2019-09-30T17:33:41.028Z] github.com/go-swagger/go-swagger/vendor/github.com/go-openapi/validate.(*SpecValidator).Validate(0xc00118bb78, 0xb69820, 0xc000ec5480, 0xc000f9bb00, 0xc000e75c80)
[2019-09-30T17:33:41.028Z] 	/tmp/tmp.KMo0CBcPeP/src/github.com/go-swagger/go-swagger/vendor/github.com/go-openapi/validate/spec.go:102 +0x132
[2019-09-30T17:33:41.028Z] github.com/go-swagger/go-swagger/vendor/github.com/go-openapi/validate.Spec(0xc000ec5480, 0xd11940, 0xc0004be9c0, 0x0, 0x0)
[2019-09-30T17:33:41.028Z] 	/tmp/tmp.KMo0CBcPeP/src/github.com/go-swagger/go-swagger/vendor/github.com/go-openapi/validate/spec.go:50 +0xa6
[2019-09-30T17:33:41.028Z] github.com/go-swagger/go-swagger/cmd/swagger/commands.(*ValidateSpec).Execute(0x12305c8, 0xc00043cee0, 0x1, 0x2, 0x12305c8, 0x1)
[2019-09-30T17:33:41.028Z] 	/tmp/tmp.KMo0CBcPeP/src/github.com/go-swagger/go-swagger/cmd/swagger/commands/validate.go:46 +0xf6
[2019-09-30T17:33:41.028Z] github.com/go-swagger/go-swagger/vendor/github.com/jessevdk/go-flags.(*Parser).ParseArgs(0xc00068d680, 0xc000088160, 0x2, 0x2, 0x0, 0xc052b7, 0x2a, 0xa9a820, 0xc00065aae0)
[2019-09-30T17:33:41.028Z] 	/tmp/tmp.KMo0CBcPeP/src/github.com/go-swagger/go-swagger/vendor/github.com/jessevdk/go-flags/parser.go:315 +0x941
[2019-09-30T17:33:41.028Z] github.com/go-swagger/go-swagger/vendor/github.com/jessevdk/go-flags.(*Parser).Parse(...)
[2019-09-30T17:33:41.028Z] 	/tmp/tmp.KMo0CBcPeP/src/github.com/go-swagger/go-swagger/vendor/github.com/jessevdk/go-flags/parser.go:185
[2019-09-30T17:33:41.028Z] main.main()
[2019-09-30T17:33:41.028Z] 	/tmp/tmp.KMo0CBcPeP/src/github.com/go-swagger/go-swagger/cmd/swagger/swagger.go:90 +0x8bd
script returned exit code 2

Let me have a look if I see what's causing it 🤔

api/swagger.yaml Outdated
in: "query"
type: "boolean"
description: "Include service status, with count of running and desired tasks"
default: false
Copy link
Member

Choose a reason for hiding this comment

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

Wonder if this is what's causing the panic. I guess a query-string may not support a "default" value? https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-6.2

This keyword can be used to supply a default JSON value associated with a particular schema. It is RECOMMENDED that a default value be valid against the associated schema.

Copy link
Member

Choose a reason for hiding this comment

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

Perhaps "required": false would achieve the same

Copy link

Choose a reason for hiding this comment

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

Thanks for looking into this @dperny

@dperny dperny force-pushed the add-service-status branch from 9caf9a1 to 87ba762 Compare October 2, 2019 16:18
Adds a new ServiceStatus field to the Service object, which includes the
running and desired task counts. This new field is gated behind a
"status" query parameter.

Signed-off-by: Drew Erny <drew.erny@docker.com>
@dperny dperny force-pushed the add-service-status branch from 87ba762 to f36042d Compare October 14, 2019 15:45
@thaJeztah thaJeztah removed the status/failing-ci Indicates that the PR in its current state fails the test suite label Oct 14, 2019
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.

it's green again, with the go-swagger problem fixed 🎉

LGTM

@dperny
Copy link
Contributor Author

dperny commented Oct 15, 2019

bless you sebastiaan you magnificent man

thaJeztah added a commit to thaJeztah/cli that referenced this pull request Oct 25, 2019
full diff: moby/moby@b6684a4...a30990b

relevant changes:

- moby/moby#39995 Update containerd binary to v1.2.10
- moby/moby#40001 Update runc to v1.0.0-rc8-92-g84373aaa (CVE-2019-16884)
- moby/moby#39999 bump golang 1.13.1 (CVE-2019-16276)
- moby/moby#40102 bump golang 1.13.3 (CVE-2019-17596)
- moby/moby#39994 homedir: add cgo or osusergo buildtag constraints for unix.
  This is to ensure that users of the homedir package cannot compile statically
  (`CGO_ENABLED=0`) without also setting the `osusergo` build tag.
- moby/moby#39983 builder: remove legacy build's session handling
  This feature was used by docker build --stream and it was kept experimental.
  Users of this endpoint should enable BuildKit anyway by setting Version to BuilderBuildKit.
    - Related: docker#2105 build: remove --stream (was experimental)
- moby/moby #40045 Bump logrus 1.4.2, go-shellwords, mergo, flock, creack/pty,
  golang/gddo, gorilla/mux
- moby/moby#39713 bump containerd and dependencies to v1.3.0
- moby/moby#39987 Add ability to handle index acknowledgment with splunk log driver
- moby/moby#40070 Use ocischema package instead of custom handler
    - relates to moby/moby#39727 Docker 19.03 doesn't support OCI image
    - relates to docker/hub-feedback#1871
    - relates to distribution/distribution#3024
- moby/moby#39231 Add support for sending down service Running and Desired task counts
- moby/moby#39822 daemon: Use short libnetwork ID in exec-root

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
thaJeztah added a commit to thaJeztah/cli that referenced this pull request Oct 26, 2019
full diff: moby/moby@b6684a4...a09e6e3

relevant changes:

- moby/moby#39995 Update containerd binary to v1.2.10
- moby/moby#40001 Update runc to v1.0.0-rc8-92-g84373aaa (CVE-2019-16884)
- moby/moby#39999 bump golang 1.13.1 (CVE-2019-16276)
- moby/moby#40102 bump golang 1.13.3 (CVE-2019-17596)
- moby/moby#40134 Revert "homedir: add cgo or osusergo buildtag constraints for unix"
    - reverts moby/moby#39994 homedir: add cgo or osusergo buildtag constraints for unix,
      in favor of documenting when to set the `osusergo` build tag. The `osusergo`
      build-flag must be used when compiling a static binary with `cgo` enabled,
      and linking against `glibc`.
- moby/moby#39983 builder: remove legacy build's session handling
  This feature was used by docker build --stream and it was kept experimental.
  Users of this endpoint should enable BuildKit anyway by setting Version to BuilderBuildKit.
    - Related: docker#2105 build: remove --stream (was experimental)
- moby/moby #40045 Bump logrus 1.4.2, go-shellwords, mergo, flock, creack/pty,
  golang/gddo, gorilla/mux
- moby/moby#39713 bump containerd and dependencies to v1.3.0
- moby/moby#39987 Add ability to handle index acknowledgment with splunk log driver
- moby/moby#40070 Use ocischema package instead of custom handler
    - relates to moby/moby#39727 Docker 19.03 doesn't support OCI image
    - relates to docker/hub-feedback#1871
    - relates to distribution/distribution#3024
- moby/moby#39231 Add support for sending down service Running and Desired task counts
- moby/moby#39822 daemon: Use short libnetwork ID in exec-root
- moby/moby#39100 Use Microsoft/hcsshim constants and deprecate pkg/system.GetOsVersion()
    - updates/requires Microsoft/hscshim@2226e083fc390003ae5aa8325c3c92789afa0e7a

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
thaJeztah added a commit to thaJeztah/cli that referenced this pull request Oct 26, 2019
full diff: moby/moby@b6684a4...a09e6e3

relevant changes:

- moby/moby#39995 Update containerd binary to v1.2.10
- moby/moby#40001 Update runc to v1.0.0-rc8-92-g84373aaa (CVE-2019-16884)
- moby/moby#39999 bump golang 1.13.1 (CVE-2019-16276)
- moby/moby#40102 bump golang 1.13.3 (CVE-2019-17596)
- moby/moby#40134 Revert "homedir: add cgo or osusergo buildtag constraints for unix"
    - reverts moby/moby#39994 homedir: add cgo or osusergo buildtag constraints for unix,
      in favor of documenting when to set the `osusergo` build tag. The `osusergo`
      build-flag must be used when compiling a static binary with `cgo` enabled,
      and linking against `glibc`.
- moby/moby#39983 builder: remove legacy build's session handling
  This feature was used by docker build --stream and it was kept experimental.
  Users of this endpoint should enable BuildKit anyway by setting Version to BuilderBuildKit.
    - Related: docker#2105 build: remove --stream (was experimental)
- moby/moby #40045 Bump logrus 1.4.2, go-shellwords, mergo, flock, creack/pty,
  golang/gddo, gorilla/mux
- moby/moby#39713 bump containerd and dependencies to v1.3.0
- moby/moby#39987 Add ability to handle index acknowledgment with splunk log driver
- moby/moby#40070 Use ocischema package instead of custom handler
    - relates to moby/moby#39727 Docker 19.03 doesn't support OCI image
    - relates to docker/hub-feedback#1871
    - relates to distribution/distribution#3024
- moby/moby#39231 Add support for sending down service Running and Desired task counts
- moby/moby#39822 daemon: Use short libnetwork ID in exec-root
- moby/moby#39100 Use Microsoft/hcsshim constants and deprecate pkg/system.GetOsVersion()
    - updates/requires Microsoft/hscshim@2226e083fc390003ae5aa8325c3c92789afa0e7a

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
docker-jenkins pushed a commit to docker-archive/docker-ce that referenced this pull request Oct 28, 2019
full diff: moby/moby@b6684a4...a09e6e3

relevant changes:

- moby/moby#39995 Update containerd binary to v1.2.10
- moby/moby#40001 Update runc to v1.0.0-rc8-92-g84373aaa (CVE-2019-16884)
- moby/moby#39999 bump golang 1.13.1 (CVE-2019-16276)
- moby/moby#40102 bump golang 1.13.3 (CVE-2019-17596)
- moby/moby#40134 Revert "homedir: add cgo or osusergo buildtag constraints for unix"
    - reverts moby/moby#39994 homedir: add cgo or osusergo buildtag constraints for unix,
      in favor of documenting when to set the `osusergo` build tag. The `osusergo`
      build-flag must be used when compiling a static binary with `cgo` enabled,
      and linking against `glibc`.
- moby/moby#39983 builder: remove legacy build's session handling
  This feature was used by docker build --stream and it was kept experimental.
  Users of this endpoint should enable BuildKit anyway by setting Version to BuilderBuildKit.
    - Related: #2105 build: remove --stream (was experimental)
- moby/moby #40045 Bump logrus 1.4.2, go-shellwords, mergo, flock, creack/pty,
  golang/gddo, gorilla/mux
- moby/moby#39713 bump containerd and dependencies to v1.3.0
- moby/moby#39987 Add ability to handle index acknowledgment with splunk log driver
- moby/moby#40070 Use ocischema package instead of custom handler
    - relates to moby/moby#39727 Docker 19.03 doesn't support OCI image
    - relates to docker/hub-feedback#1871
    - relates to distribution/distribution#3024
- moby/moby#39231 Add support for sending down service Running and Desired task counts
- moby/moby#39822 daemon: Use short libnetwork ID in exec-root
- moby/moby#39100 Use Microsoft/hcsshim constants and deprecate pkg/system.GetOsVersion()
    - updates/requires Microsoft/hscshim@2226e083fc390003ae5aa8325c3c92789afa0e7a

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Upstream-commit: 7f6cd64335dc631efaa8204c01f92aa40939073a
Component: cli
@thaJeztah thaJeztah added this to the 20.03.0 milestone Apr 2, 2020
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.

5 participants