Add support for sysctl options in services#37701
Conversation
thaJeztah
left a comment
There was a problem hiding this comment.
Thanks! Left comments/thoughts inline. We should also look at the docker/cli side for this (and add this option to the docker-compose file format)
integration/service/create_test.go
Outdated
There was a problem hiding this comment.
Can you add a skip for older daemon versions? (assuming this is planned for inclusion in API 1.39)
skip.If(t, versions.LessThan(testEnv.DaemonAPIVersion(), "1.39"), "feature was added in API version 1.39")There was a problem hiding this comment.
Do we need a separate test for service update ? (perhaps overkill)
There was a problem hiding this comment.
Yes, we should make one, actually, to verify that service update goes through correctly when Sysctls are changed.
integration/service/create_test.go
Outdated
There was a problem hiding this comment.
Wondering if a subtest would make this clearer 🤔
for _, expected := range []string{"0", "1"} {
t.Run(fmt.Sprintf("net.ipv4.ip_nonlocal_bind = %s", expected), func(t *testing.T) {
// store the map we're going to be using everywhere.
sysctlOpts := map[string]string{"net.ipv4.ip_nonlocal_bind": expected}
...
})
}There was a problem hiding this comment.
I don't think that a subtest is useful honestly, because it's just 1 test, we're just trying two values so we don't have to know what the default is.
There was a problem hiding this comment.
Was looking if we should have a more generic service create test where we define a list of specs to create services with. Agreed that it's just a minor issue; advantage would be to more easily find which of the test-cases failed
integration/service/create_test.go
Outdated
There was a problem hiding this comment.
Services should already be removed when the test completes, so I think we can skip this, and just continue with the next iteration
integration/service/create_test.go
Outdated
There was a problem hiding this comment.
We don't need a name for this service, so better remove it, and just use the serviceID (which is already used)
integration/service/create_test.go
Outdated
integration/service/create_test.go
Outdated
There was a problem hiding this comment.
Should we use service logs instead?
There was a problem hiding this comment.
As the person ostensibly responsible for service logs, no.
There was a problem hiding this comment.
In that case, we must skip the test if it's running on a multi-node swarm.
integration/service/create_test.go
Outdated
There was a problem hiding this comment.
Let me think about this;
Instead of using the container's / service's logs to check if the value was set, could we abuse the container's command for this (something like if cat /proc/sys/net/ipv4/ip_nonlocal_bind != expected value; exit 1)?
Thinking a bit further about this; I'm wondering if we need to check this at all. Creating a container with custom sysctl settings is an existing feature. The only thing being added in this PR is that that container is now created through SwarmKit instead of docker run.
Because of that, I think all we need to verify is if the container-spec is correct (the expected sysctl options are set).
There was a problem hiding this comment.
Instead of using the container's / service's logs to check if the value was set, could we abuse the container's command for this (something like if cat /proc/sys/net/ipv4/ip_nonlocal_bind != expected value; exit 1)?
What do you think is better about doing it this way? Having containers exit in a swarm service test leaves us dealing with swarmkit rescheduling those containers.
Thinking a bit further about this; I'm wondering if we need to check this at all. Creating a container with custom
sysctlsettings is an existing feature. The only thing being added in this PR is that that container is now created through SwarmKit instead ofdocker run.
We do, actually, to make sure that the value of the Sysctls is plumbed through correctly. When writing this test, I actually missed a location where the value was plumbed through and so the value was making its way into the container spec, but not into the actual container.
There was a problem hiding this comment.
We do, actually, to make sure that the value of the Sysctls is plumbed through correctly.
Discussed this with @dperny on Slack; inspecting the container should contain enough information that the correct container-spec was created. Creating containers from a spec/config is already covered by other tests, so for this feature we don't have to test that part 👍
api/swagger.yaml
Outdated
There was a problem hiding this comment.
Can you add an example here?
Sysctls:
description: "Set kernel namedspaced parameters (sysctls) in the container."
type: "object"
additionalProperties:
type: "string"
example:
net.ipv4.tcp_keepalive_time: "600"
net.ipv4.tcp_keepalive_intvl: "60"
net.ipv4.tcp_keepalive_probes: "3"
net.ipv4.tcp_timestamps: "0"There was a problem hiding this comment.
Is there a way to reference or crosslink to the documentation for this option on the container HostConfig?
There was a problem hiding this comment.
Hm; good one, perhaps just refer to it in the description 🤔 ("this option accepts the same sysctls as can be specified for containers", or something along those lines 😂)
api/swagger.yaml
Outdated
There was a problem hiding this comment.
Can you update the API version history, and add a bullet for this new option? https://github.com/moby/moby/blob/master/docs/api/version-history.md#v139-api-changes
(make sure to mention all of POST /services/create, POST /services/{id}/update, and GET /services/{id})
There was a problem hiding this comment.
Ah I always forget the API version history.
3ff99e4 to
a8e023b
Compare
docs/api/version-history.md
Outdated
There was a problem hiding this comment.
missed a closing back tic after Sysctls
There was a problem hiding this comment.
👍 Good one; wondering now if creating a service without ContainerSpec is actually a valid request.
Not something to address in this PR, but just wondering that; and if we should validate/error in that situation 🤔
a8e023b to
6a24f7b
Compare
Codecov Report
@@ Coverage Diff @@
## master #37701 +/- ##
==========================================
+ Coverage 36.12% 36.14% +0.01%
==========================================
Files 610 610
Lines 45083 45086 +3
==========================================
+ Hits 16288 16297 +9
+ Misses 26555 26551 -4
+ Partials 2240 2238 -2 |
thaJeztah
left a comment
There was a problem hiding this comment.
LGTM after the t.Skip() is added for API < 1.39
https://github.com/moby/moby/pull/37701/files#r212267159
of course, depends on the upstream swarmkit PR to be merged
|
I forgot to add the t.Skip(), so I'll go back and do so when I revendor swarmkit |
6a24f7b to
1f8f6c3
Compare
|
@thaJeztah updated the swagger.yml description of the |
vendor.conf
Outdated
There was a problem hiding this comment.
Upstream was merged; can you un-fork the dependency?
|
OH, can you also add the example to the swagger YAML (see my comment here; #37701 (comment)) |
1f8f6c3 to
dd7434e
Compare
There was a problem hiding this comment.
Move this to a function and use it here and below.
There was a problem hiding this comment.
i disagree, but mostly because i'm unsure what the best signature for that function would be, and considering it's only like 8 lines duplicated, i don't think there's much of a benefit to the refactoring.
There was a problem hiding this comment.
every duplicated line of code counts :)
But that's borderline bikeshedding
There was a problem hiding this comment.
I would tend to agree with @anshulpundir here (though the question of the fun's signature is indeed interesting!)
Also, I'm a little worried that this file is gonna get littered with version checks really fast if we really want to ensure never adding new features to frozen versions; don't get me wrong, it makes sense, but I'm actually quite surprised there's only one check as of now. There's certainly going to be a lot more if we do all of #25303 . There might be a better way of doing this?
There was a problem hiding this comment.
just for the sake of it, I tend to agree with @dperny : sometimes a little duplication is better than the wrong abstraction… once we find a correct abstraction for those, we'll refactor 😉
There was a problem hiding this comment.
Is this only used in the unit-test?
There was a problem hiding this comment.
Yes (well, it's technically an integration test), but a lot of these functions are only used in one test.
integration/service/create_test.go
Outdated
There was a problem hiding this comment.
Shouldn't we have a similar test for updates too?
There was a problem hiding this comment.
there isn't one for the other things tested here.
|
The pre-req, moby/swarmkit#2729, was already merged into master 22 days ago. How close are we to seeing this in |
|
@vdemeester Just checking if it's possible to get this in |
8e0ce06 to
5785f17
Compare
|
I had an error from not running swagger generation. However, when I ran it, |
|
During a load test against one of our containers, we found that hitting the container directly, outside of swarm mode, resulted in 1.8x more throughput than when that container was running as one service instance in a one node Swarm. Like @dperny and @cballou, we are really looking forward to having performance fixes / sysctl options expedited |
Adds support for sysctl options in docker services. * Adds API plumbing for creating services with sysctl options set. * Adds swagger.yaml documentation for new API field. * Updates the API version history document. * Changes executor package to make use of the Sysctls field on objects * Includes integration test to verify that new behavior works. Essentially, everything needed to support the equivalent of docker run's `--sysctl` option except the CLI. Includes a vendoring of swarmkit for proto changes to support the new behavior. Signed-off-by: Drew Erny <[email protected]>
5785f17 to
14da20f
Compare
thaJeztah
left a comment
There was a problem hiding this comment.
LGTM
ping @vdemeester @anshulpundir PTAL
There was a problem hiding this comment.
just for the sake of it, I tend to agree with @dperny : sometimes a little duplication is better than the wrong abstraction… once we find a correct abstraction for those, we'll refactor 😉
|
So are we finally able to set "sysctl" options for Docker services or is this just the underlying updates required to eventually expose this to the CLI ? |
|
So I see that the API version was changed from |
|
@cballou API v1.40 is not finalised yet (as in; changes will still arrive). That version will be included in the next Docker release (after Docker 18.09, which has API v1.39) |
|
@thaJeztah hey, did the feature make it into the release? I am trying set the sysctl for a stack via Golang code and it doesn't work for me (but works for the regular containers). I set my API version in Golang client code to 1.39 to no avail. Also trying to deploy from command line give me this: |
|
No, this didn't make it for 18.09, so will be in 19.03 |
|
Hi, updated to docker-ce nightly and tried to pass This is the resulting output: Anything required to make this work? @thaJeztah |
|
Opened a PR for the cli and compose-file changes (for |
|
@thaJeztah I have tried with the latest 19.0.3 beta to no avail: Still returns 128. I have copied your test to reproduce the issue programmatically, and it also fails: https://github.com/orbs-network/boyarin/pull/80/files#diff-e5db09d7878227a83cc084a0fd016450 I have tried both API versions |
- What I did
Adds support for sysctl options in docker services.
Essentially, everything needed to support the equivalent of docker run's
--sysctloption except the CLI.Depends on moby/swarmkit#2729, which is not merged yet, and so has my fork branch of swarmkit vendored in to demonstrate passing integration test.
- How I did it
Altered all of the API objects and plumbing to accommodate the new field, which swarmkit blindly passes into the executor.
- How to verify it
Includes an integration test.
Related issues:
- Description for the changelog
Add support for sysctl options on docker services.