[EXPERIMENTAL] new mount type: introspection#26331
[EXPERIMENTAL] new mount type: introspection#26331AkihiroSuda wants to merge 1 commit intomoby:masterfrom
Conversation
|
Hi, thanks, taking a look. I really think |
|
@justincormack Is there a way we can do that without having user input become filenames? |
|
@stevvooe hmm, probably no. We might have to filter keys that are not within the recommended guidelines for naming too. |
|
Thank you for the comment and it makes sense 😃 2 questions:
If we support updating multiple lables at once, I suggest creating a symlink from |
|
|
Ok, trying it out a bit more, re other discussion points:
My other concern at present is the container can't see where its introspection mountpoint is, so if it is mounted in a place it does not expect the scripts in the container won't work. I wonder if we should have a cli option |
|
One other thing people have asked for is host port info for published ports. We could add eg |
|
The test failures don 't like the imports: |
|
Also needs a rebase... |
|
@AkihiroSuda I think generally I like the overall design now. There is a bunch of stuff to resolve still and some decisions to make, but I think it is the right general direction... |
|
@justincormack Thank you, I'll update this PR ASAP |
2ee4fb6 to
4fffea9
Compare
|
@justincormack Updated PR, please look into this? ChangesFilesystem ViewFor #26331 (comment), #26331 (comment)
For #26331 (comment)
Others (RFC!):
Build
Future work (IMO they should be separate PRs?)
DEMO $ docker run --rm -v docker_introspection:/foo busybox sh -c 'for f in $(find /foo -type f);do echo ===$f===; cat $f; done'
===/foo/container/name===
romantic_noether
===/foo/container/id===
3b5f9e1bacf85424dbbbbd1373a0ae17ae00504fa1618059fa85bf9f4ad29e30
===/foo/container/fullname===
/romantic_noether
===/foo/daemon/name===
ws01$ docker service create --name nginx --replicas 3 --mount type=volume,src=docker_introspection,dst=/foo nginx
$ docker exec $SOME_NGINX_CONTAINER bash -c 'for f in $(find /foo -type f);do echo ===$f===; cat $f; done'
===/foo/container/name===
nginx.1.8toszsdz7duypbbl8uwehlrbs
===/foo/container/labels/com.docker.swarm.service.id===
0g8upo0xzr0l7pnw41jcdpt1d
===/foo/container/labels/com.docker.swarm.node.id===
clhlkxk2gzbk3edhropygbknq
===/foo/container/labels/com.docker.swarm.task.name===
nginx.1
===/foo/container/labels/com.docker.swarm.task===
===/foo/container/labels/com.docker.swarm.task.id===
8toszsdz7duypbbl8uwehlrbs
===/foo/container/labels/com.docker.swarm.service.name===
nginx
===/foo/container/id===
e7a6c58f3cbfd6754158d8db284e08396df0cadafa1a4c0e338826a012d9ef67
===/foo/container/fullname===
/nginx.1.8toszsdz7duypbbl8uwehlrbs
===/foo/task/name===
nginx.1
===/foo/task/slot===
1
===/foo/task/id===
8toszsdz7duypbbl8uwehlrbs
===/foo/service/name===
nginx
===/foo/service/id===
0g8upo0xzr0l7pnw41jcdpt1d
===/foo/daemon/name===
ws01
Now I'm going to add tests and docs |
|
The tests need tweaking to special case this volume driver: |
10ca8a1 to
9324360
Compare
|
Now CI is almost passing except a flaky test #26506 . A basic integration test is added as |
9324360 to
147862e
Compare
147862e to
0463798
Compare
|
@AkihiroSuda one thing we discussed, and is (almost) possible now that #22373 is merged is that rather than using a volume driver we could use a special mount type (this would also require CLI support for swarm style mounts, but I think this is planned now). ie |
|
There is an issue here #8427 that wants to know memory allocation. Just linking - I don't think we should necessarily try to get everything into the initial PR. |
|
Discussing this in the maintainers meeting, and we seem to agree that option 1 ("explicit") is the way to go; make "scope" a required option Also discussed |
8245595 to
e2c325c
Compare
|
Implemented scope. Examples:
Error if no scope is set: $ docker run -it --rm --mount type=introspection,target=/foo busybox
invalid argument "type=introspection,target=/foo" for --mount: at least one 'introspection-scope' is required. e.g. '.' (denotes all), '.containers.labels', '.task'
See 'docker run --help'.Error if invalid scope is set: $ docker run -it --rm --mount type=introspection,target=/foo,introspection-scope=foo busybox
docker: Error response from daemon: invalid scope: foo (valid scopes: [. .container .container.id .container.name .container.fullname .container.labels .daemon .daemon.name .daemon.labels]).A scope name needs to start with a period |
This commit introduces a new mount type called "introspection".
The introspection mount allows users to introspect the metadata about the
container from the container itself, via a procfs-like filesystem.
How to test:
$ docker service create --name nginx --replicas 3 --mount type=introspection,introspection-scope=.,dst=/foo nginx
$ for f in $(docker ps -q -f label=com.docker.swarm.service.name=nginx);do docker exec $f sh -c 'for g in $(find /foo -type f); do echo ===$g===; cat $g; done'; done
Signed-off-by: Akihiro Suda <[email protected]>
e2c325c to
50eb554
Compare
|
It was mentioned higher up that DNS records would be a valid introspection API. I assume this would be done with TEXT records on individual hosts entries, and would completely drop the need to add |
|
Not yet. |
|
@thaJeztah PTAL? |
|
@thaJeztah PTAL? |
|
kindly ping 😃 @thaJeztah |
|
What's the status here? Hard to follow along. This is labeled with code-review but some of the comments would suggest otherwise. |
|
@thaJeztah suggested implementing "scope" before merging this PR I implemented that feature in #26331 (comment) and waiting for his feedback 😅
If I can get SGTM, I'll split CLI part from this PR. |
|
Is there an estimate for when it will be simple to determine a container's ID from within the container? |
|
It is implemented in this PR but still waiting for review 😅 |
|
Ping @AkihiroSuda I like this. |
SGTM |
|
@AkihiroSuda SGTM 👼 |
|
Trying to get my head round the Go template;
|
|
@thaJeztah My thought was to have the actual object created by the template in the mount target (which must be specified for the mount). |
|
As Kubernetes has got dominance now, I'd suggest using
However,
I'm going to close this PR (Thank you all for spending your time on this PR!), but if somebody else wants to get this PR merged, please feel free to carry or just ping me. |
CURRENT STATUS (Apr 6, 2017): discussing the design about "scope": #26331 (comment)
What I did
Introduced a new mount type: "introspection".
The introspection mount is a new feature that allows you to introspect the
metadata about the container from the container itself, via a procfs-like
filesystem.
Hierarchy
If you enable the introspection mount, following files are created under the mount point:
container/id: ID string of the container. e.g.2f3cc2b029e0ca46564d5a5e38772b09947056f3b22b6a114054a468382e872e\ncontainer/name: Name of the container. e.g.nginx.3.8tc0va0kw59rbbdh5x3iqc3v9\ncontainer/fullname: Full name of the container. e.g./nginx.3.8tc0va0kw59rbbdh5x3iqc3v9\ncontainer/labels/{LABELNAME}: Label of the container. e.g. the content ofcontainer/labels/com.docker.swarm.service.namewould benginx\ndaemon/name: Hostname of the daemon node. e.g.host01\nFor Swarm task containers running on a manager node, following files appear as well:
service/id: ID string of the service. e.g.6h7nic7tsv16cfo0qhywj7bsh\nservice/name: Name of the service .e.g.nginx\ntask/id: ID string of the task. e.g.8tc0va0kw59rbbdh5x3iqc3v9\ntask/name: Name of the task. e.g.nginx.3.8tc0va0kw59rbbdh5x3iqc3v9task/slot: Slot number (1-based index for replicas) of the task. e.g.1\n. Please also refer to the documentation of the Swarmkit. Note that there are cases where a slot may have multiple tasks with the desired state of
RUNNING.Use cases for the introspection mount
Below are some example use cases for the introspection mount.
Deploying a service that requires the task slot number (e.g. Apache ZooKeeper)
Apache ZooKeeper is a highly available coordination service that is used by
distributed systems such as Hadoop. A typical configuration file (
zoo.cfg)for ZooKeeper would be as follows:
ZooKeeper also requires a file named
myidto be located underdataDir.The content of
myidis1\nforserver.1,2forserver.2, and so on.The
task/slotfile under the introspection mount can be used for generatingthe
myidfile.See also #24110
3rd party job scheduler
A 3rd party job scheduler can be built on a Docker service using the
introspection mount.
For example, the
task/slotfile under the introspection mount can be used forimplementing a scheduler that executes multiple batch jobs in parallel.
(Similar to the
{%}symbol in the GNU parallel.)See also #23843
3rd party orchestration/monitoring tool
A container can send the
container/idfile under the introspection mount tosome 3rd party orchestration/monitoring tool. Then such a tool take appropriate
action using the ID information.
See also #7685
How I did it
Added a new mount type called "introspection".
The filesystem hiearchy is defined as the
RuntimeContextstruct indaemon/rtcontext.go.The struct is mapped to the actual files via
daemon/introspection.go.How to verify it
Start the daemon with
--experimentalflag.Then create a service with the introspection mount
/foo:Enter a container and read the files under
/foo:Note that the
servicedirectory and thetaskdirectory can be seen on manager nodes in the current implementation.Description for the changelog
new mount type: introspection
A picture of a cute animal (not mandatory but encouraged)
Replaces #24893
Fix #24110
Update #23843, #24113, #26318
CC (those whose name appeared at #24893):
@stevvooe @justincormack @SvenDowideit @thaJeztah @dweomer @vbatts @dmcgowan @crosbymichael @tonistiigi
The code works, but maybe merging this PR should be deferred until several relevant PRs get merged (e.g. moby/swarmkit#1563, #26837, #26825)
TODOs
docker run, via long-type volume option e.g.--volume type=introspection,dst=...([UX] Guidelines for short/long syntax flags #28527)Some ideas might worth adding in future (in another PR)
--introspection) for--volume type=introspection,dst=$DEFAULT_DST. We need to determine the default mount point for both UNIX and Windows./node/labels(dynamic)/service/labels(dynamic)/serviceand/taskfor containers running on worker nodes/ports/tcp/80/HostPort. suggested by @justincormack: [EXPERIMENTAL] new mount type: introspection #26331 (comment)/container/cgroup/memory?. suggested by @justincormack: [EXPERIMENTAL] new mount type: introspection #26331 (comment)nslookup tasks.nginx. e.g./service/tasks? [EXPERIMENTAL] new mount type: introspection #26331 (comment)For reference, an older version of this PR (which was implemented as a built-in volume driver) is available at https://web.archive.org/web/20161014053843/https://github.com/docker/docker/pull/26331 .
Signed-off-by: Akihiro Suda [email protected]