X Tutup
Skip to content

wsContainersAttach attach to stdin/out/err streams as requested#43322

Merged
thaJeztah merged 1 commit intomoby:masterfrom
ndeloof:websocket_streams
May 18, 2022
Merged

wsContainersAttach attach to stdin/out/err streams as requested#43322
thaJeztah merged 1 commit intomoby:masterfrom
ndeloof:websocket_streams

Conversation

@ndeloof
Copy link
Contributor

@ndeloof ndeloof commented Mar 4, 2022

- What I did
attach/ws API applies stdlin/stdout/stderr parameters to select streams to attach to (as documented)
closes #43272

- How I did it
set parameters on ContainerAttachConfig. Also aligned struct initialization with postContainersAttach for consistency.

- How to verify it

curl -v -H 'Connection: upgrade' -H 'upgrade: websocket' -H 'Sec-Websocket-Key:hello' -H 'Sec-Websocket-Version: 13'tp://localhost:2375/v1.41/containers/$ID/attach/ws?stream=1&stdout=1" --output -

- Description for the changelog
containers/{ID}/attach/ws only attach to streams according by stdin, stdout and stderr parameters.

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

Copy link
Member

@cpuguy83 cpuguy83 left a comment

Choose a reason for hiding this comment

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

While the change is the correct behavior, it breaks older clients completely.

I put the TODO in there originally because it had already been years of the existing broken behavior.
I'd also expect us to take advantage of ws channels rather than doing the muxing on the data.

@ndeloof
Copy link
Contributor Author

ndeloof commented Mar 4, 2022

@cpuguy83 I replaced TODO with a comment, but still multiplex is set to false, so we don't use data multiplexing, but just plain websocket transport
The only change here is to allow clients to select the streams to be attached, so they can only attach to stdout and ignore stderr (for sample)

@cpuguy83
Copy link
Member

cpuguy83 commented Mar 4, 2022

Thanks for clarifying, I see that now. Don't know why I didn't see that before.

@cpuguy83
Copy link
Member

cpuguy83 commented Mar 4, 2022

I think we should keep the existing behavior for old API versions.

@thaJeztah
Copy link
Member

Yes, if this breaks current clients, we should probably make the (default) behavior depend on the API version. (Haven't looked in depth what/how things break)

Perhaps would be good to;

(Happy to help with rephrasing / wording if needed)

@thaJeztah thaJeztah added this to the 21.xx milestone Mar 4, 2022
@ndeloof ndeloof force-pushed the websocket_streams branch from 68439c8 to 91807e8 Compare May 17, 2022 08:24
@ndeloof
Copy link
Contributor Author

ndeloof commented May 17, 2022

I've checked endpoint history, and it actually never supported streams to be selected. Initial implementation used a distinct backend function for HTTP and WS attachment, which was simplified into a single one by a77b7dd (#18943).
I've updated this PR accordingly:

  • parameters are only used to select streams if API >= 1.42
  • API change is documented
  • swagger is already correct

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
@ndeloof ndeloof force-pushed the websocket_streams branch from 91807e8 to ea67601 Compare May 17, 2022 11:23
@thaJeztah
Copy link
Member

and it actually never supported streams to be selected. Initial implementation used a distinct backend function for HTTP and WS attachment, which was simplified into a single one by a77b7dd.

Interesting; so it didn't work before c44f513 (#12120) either? #43272 (comment)

@thaJeztah
Copy link
Member

So, looks like the documentation for existing API versions is incorrect, as it mentions the default to be false; https://docs.docker.com/engine/api/v1.41/#operation/ContainerAttachWebsocket

Screenshot 2022-05-18 at 10 39 09

Comment on lines +697 to +701
if versions.GreaterThanOrEqualTo(version, "1.42") {
useStdin = httputils.BoolValue(r, "stdin")
useStdout = httputils.BoolValue(r, "stdout")
useStderr = httputils.BoolValue(r, "stderr")
}
Copy link
Member

Choose a reason for hiding this comment

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

Trying to think if there's a way to make the change less disruptive, but not sure how to;

  • API < 1.41 enabled these by default (which didn't match the docs (see my other comment)), so I'd consider that to be a bug
  • But has been around for a long time, so we probably shouldn't change for existing API versions

So in the old API versions; if I didn't look at the API docs, and forgot to set ?stdin=1&stdout=1&stderr=1, then I would still have all three attached.

In the new API version; I MUST set all three to preserve the old behavior; which matches what was documented, but (see above) "just worked" before.

So, yeah, I don't see a clear way to migrate between one and the other, other than calling it out explicitly in the release notes 🤔 🤷‍♂️

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

* The `Volume` type, as returned by `Added new `ClusterVolume` fields
* Added a new `PUT /volumes{name}` endpoint to update cluster volumes (CNI).
Cluster volumes are only supported if the daemon is a Swarm manager.
* `/containers/{name}/attach/ws` endpoint only attach to configured streams
Copy link
Member

Choose a reason for hiding this comment

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

nit;

Suggested change
* `/containers/{name}/attach/ws` endpoint only attach to configured streams
* `GET /containers/{name}/attach/ws` endpoint only attach to configured streams

(we can fix that later, not a blocker)

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.

Attaching websocket (/containers/{name:.*}/attach/ws) not configurable as stated in the docs

3 participants

X Tutup