consul icon indicating copy to clipboard operation
consul copied to clipboard

[DRAFT] [NEED FEEDBACK] Support websocket through envoy

Open davide-baldo opened this issue 2 years ago • 4 comments

This PR aim to implement websocket support, referenced here https://github.com/hashicorp/consul/issues/8283 .

Rather than always enable the websocket support for everything (like in this old PR https://github.com/hashicorp/consul/pull/9639), I've created a new websocket parameter which can be used wherever protocol can be used, usually when you specify the service protocol of the service or when you override the path. In this patch, websocket it's disabled by default.

Basic unit testing was added but I couldn't validate them since i couldn't perform a clean test run with intellij, make test or make test-docker. I've manually tested in a 2 node server installation and envoy configuration gets created correctly and it's routing correctly.

Since this is the first time I approach consul codebase i ask, if possible, for guidance before committing more time, especially if the overall approach is correct.

davide-baldo avatar Jun 10 '22 15:06 davide-baldo

CLA assistant check
All committers have signed the CLA.

hashicorp-cla avatar Jun 10 '22 15:06 hashicorp-cla

Hey @davide-baldo

Really excited to see this come through, as you can see in #8283 this would help a lot of people. We'll try to get some feedback on this shortly. Since this is a draft it might help us to know what you think is left on the TODO list?

Amier3 avatar Jun 13 '22 16:06 Amier3

Hi @Amier3,

Unfortunately the config guide doesn't cover the service-defaults and apply only partially (I've added websocket attribute in the exposed paths in proxy configuration as well).

CLI and struct changes and envoy generation should be complete AFAIK.

  • [ ] Tests
  • [ ] PR Changelog
  • [ ] Docs
    • [ ] Update docs in website/source/docs/agent/services.html.md
    • [ ] Consider if it's worth adding examples to feature docs or API docs that show the new field's usage.

davide-baldo avatar Jun 15 '22 14:06 davide-baldo

just rebased against lastest main branch. @Amier3 Could you give me some feedback on whether this is the right approach? thanks,

davide-baldo avatar Aug 02 '22 12:08 davide-baldo

@davide-baldo how do you deal with this requirement internally? do you maintain a fork with your patches? Embarrassing show on Hashicorp's part on that front, really.

simonctrlz avatar Feb 10 '23 20:02 simonctrlz

@simonctrlz If you don't need any routing/filter you can proxy websocket as TCP, if you need more control you need to patch consul (and rebuild it, luckily in go it's really easy to compile/cross-compile) in order to generate the right envoy configuration.

the smallest patch you can apply is this: https://github.com/hashicorp/consul/pull/9639/files#diff-3f5a22a74e450c254308e27dccb905bdce627f0a29ec602ca66df792d1dbf5ce

		UpgradeConfigs: []*envoyhttp.HttpConnectionManager_UpgradeConfig{
			{
				UpgradeType: "websocket",
			},
		},

This PR is mainly about enabling/disabling websocket capabilities through service configuration. You might also find a way to modify envoy configuration directly from the consul proxy configuration to avoid any consul patch, but it's undocumented I don't know how to do it, or even if it's possible.

davide-baldo avatar Feb 13 '23 10:02 davide-baldo