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

feat: Support UDP listeners in Network Load Balancer #4980

Merged
merged 10 commits into from Jul 14, 2023

Conversation

tjhorner
Copy link
Contributor

@tjhorner tjhorner commented Jun 13, 2023

This PR adds basic UDP support for Network Load Balancers. For example, you can now do this in a Load Balanced Web Service:

nlb:
  port: 1812/udp
  # Run the healthcheck against a different TCP port
  healthcheck:
    port: 8080

Additional listeners are also supported:

nlb:
  # [...]
  additional_listeners:
    - port: 1912/udp
    # healthcheck omitted

I also updated the English documentation to reflect this change, but not the Japanese documentation.

This addresses issue #4767.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the Apache 2.0 License.

@tjhorner tjhorner requested review from hkford and a team as code owners June 13, 2023 16:02
@tjhorner tjhorner requested review from Lou1415926 and removed request for a team June 13, 2023 16:02
@tjhorner tjhorner changed the title Support UDP listeners in Network Load Balancer feat: Support UDP listeners in Network Load Balancer Jun 13, 2023
@github-actions
Copy link

github-actions bot commented Jun 13, 2023

🍕 Here are the new binary sizes!

Name New size (kiB) size (kiB) Delta (%)
macOS (amd) 51376 50748 🥺 +1.24
macOS (arm) 51584 50956 🥺 +1.23
linux (amd) 45224 44680 🥺 +1.22
linux (arm) 43524 43012 🥺 +1.19
windows (amd) 42052 41552 🥺 +1.20

@codecov-commenter
Copy link

codecov-commenter commented Jun 14, 2023

Codecov Report

Merging #4980 (413dbf4) into mainline (d6c5279) will increase coverage by 24.37%.
The diff coverage is n/a.

@@              Coverage Diff              @@
##           mainline    #4980       +/-   ##
=============================================
+ Coverage     70.03%   94.41%   +24.37%     
=============================================
  Files           289       13      -276     
  Lines         42031     1521    -40510     
  Branches        285      285               
=============================================
- Hits          29435     1436    -27999     
+ Misses        11176       80    -11096     
+ Partials       1420        5     -1415     

see 276 files with indirect coverage changes

Copy link
Contributor

@Lou1415926 Lou1415926 left a comment

Choose a reason for hiding this comment

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

Thank you very much for the contribution ❤️ ! This looks great, I just have some small nits!

Comment on lines 518 to 522
protocol := strings.ToLower(aws.StringValue(nlbProtocol))
// Expose TCP port for TLS listeners.
if protocol != strings.ToLower(TLS) {
targetProtocol = protocol
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Yay thanks for taking care of this case!!

Small nit - strings.EqualFold is case-insensitive, so we can use it for the comparison here

Suggested change
protocol := strings.ToLower(aws.StringValue(nlbProtocol))
// Expose TCP port for TLS listeners.
if protocol != strings.ToLower(TLS) {
targetProtocol = protocol
}
// Expose TCP port for TLS listeners.
if !strings.EqualFold(aws.StringValue(nlbProtocol), TLS)
targetProtocol = protocol
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

TIL! Will update to use this

for _, exposedPort := range exposedPorts {
if targetPort == exposedPort.Port {
if targetPort == exposedPort.Port && targetProtocol == exposedPort.Protocol {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit:

Suggested change
if targetPort == exposedPort.Port && targetProtocol == exposedPort.Protocol {
// NOTE: ECS doesn't support exposing the same port twice.
// This is a feature request to support multiple protocols on the same port: https://github.com/aws/containers-roadmap/issues/850.
if targetPort == exposedPort.Port {

ECS doesn't let you expose the same port twice, even if they are different protocols. Although as a client side tool we don't have to do the same validations as the service, I think I'd prefer erroring out early here.

NLB can listen on a port for TPC_UDP traffic - judging by this design pattern, it is possible that when ECS does support this feature, they will support an "additional protocol" called TCP_UDP, instead of letting people expose the same port twice. This is my own personal intuition though. Here is a related feature request to ECS: aws/containers-roadmap#850.

Anyway, based on this observation, it's likely that we won't need to change this if statement even after they'e supported the feature. So maintenance-wise, this probably won't cause burden in the future anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, that makes sense. I'll add that note and revert the change there.

Wouldn't this just silently fail? No err is being returned, but I'm not sure if consumers of this method would interpret a nil []ExposedPort as a failure.

Copy link
Contributor

Choose a reason for hiding this comment

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

My bad!! I somehow was thinking this code was written in manifest/validate.go, and was trying to point out that the "uniqueness" of a port is determined by the port only, not port + protocol.

Now that I've had my coffee, I realize this comment doesn't make sense for the code here. This function is called after we've done all the manifest validation. At this point, it should be assumed that the manifest is totally valid - that is, no port is exposed twice.

Therefore, I think we can keep it as you have (port + protocol). Since the validation already happened, there is effectively no difference between if targetPort == exposedPort.Port and if targetPort == exposedPort.Port && targetProtocol == exposedPort.Protocol; however, the latter is clearly and makes more sense 😂

The validation code already checks that "no port is exposed twice" - it doesn't take protocol into consideration. So we are good there as well.

Sorry for the confusion!!

Copy link
Contributor

Choose a reason for hiding this comment

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

hey there @tjhorner ! Do you want me to take over the code and address the nit, so that this PR can be merged before our next release?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, that's fine. Thanks!

Copy link
Contributor

@dannyrandall dannyrandall left a comment

Choose a reason for hiding this comment

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

awesome! thank you @tjhorner!!!

@@ -241,7 +241,7 @@ List of all available properties for a `'Load Balanced Web Service'` manifest. T

nlb:
port: 8080/tcp # Traffic on port 8080/tcp is forwarded to the main container, on port 8080.
additional_rules:
additional_listeners:
Copy link
Contributor

Choose a reason for hiding this comment

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

good catch!

@mergify mergify bot merged commit 5e6a06e into aws:mainline Jul 14, 2023
12 checks passed
Sprint 🏃‍♀️ automation moved this from In review to Pending release Jul 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Sprint 🏃‍♀️
  
Pending release
Development

Successfully merging this pull request may close these issues.

None yet

4 participants