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(translator): Support extension server hooks for TCP and UDP listeners in addition to HTTP listeners. #3522

Merged
merged 6 commits into from
Jun 14, 2024

Conversation

liorokman
Copy link
Contributor

What this PR does / why we need it:

This PR calls the extension server "Listener" hook for TCP and UDP listeners. The hook is called only once for each XDS listener.

I kept the hook name as it was before (PostHTTPListenerModify) for backwards compatibility reasons.

Which issue(s) this PR fixes:
Fixes #2673

@liorokman liorokman requested a review from a team as a code owner June 3, 2024 08:02
Copy link

codecov bot commented Jun 3, 2024

Codecov Report

Attention: Patch coverage is 84.88372% with 13 lines in your changes missing coverage. Please review.

Project coverage is 68.22%. Comparing base (28e1a48) to head (571111a).

Files Patch % Lines
internal/ir/xds.go 0.00% 8 Missing ⚠️
internal/xds/translator/translator.go 89.13% 2 Missing and 3 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3522      +/-   ##
==========================================
+ Coverage   68.17%   68.22%   +0.05%     
==========================================
  Files         168      168              
  Lines       20496    20560      +64     
==========================================
+ Hits        13973    14027      +54     
- Misses       5513     5521       +8     
- Partials     1010     1012       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@liorokman
Copy link
Contributor Author

/retest

1 similar comment
@liorokman
Copy link
Contributor Author

/retest

errs = errors.Join(errs, err)
}

if err := processTCPListenerXdsTranslation(tCtx, ir.TCP, ir.AccessLog, ir.Metrics); err != nil {
if err := processUDPListenerXdsTranslation(tCtx, xdsIR.UDP, xdsIR.AccessLog, xdsIR.Metrics, listenerExtPolicies); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

looks like we are passing listenerExtPolicies to processUDPListenerXdsTranslation so that we can append per listener type's ExtensionRefs to it. Can we instead move that out of the pure xds translations into an extension specific function like notifyExtensionServerAboutListeners ?

Copy link
Contributor Author

@liorokman liorokman Jun 3, 2024

Choose a reason for hiding this comment

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

The translation functions (processUDPListenerXdsTranslation, processTCPListenerXdsTranslation and processHTTPListenerXdsTranslation) map the relevant ExtensionRefs from the IR listener representation to the xDS listener representation. The listenerExtPolicies is keyed by the xDS listener name, not the IR listener name, where it collects the extension policies from the IR.

Filling up the listenerExtPolicies needs to be done in the xDS translation function - it's not possible to have a notifyExtensionServerAboutListeners that doesn't redo part of the translation code.

if !found {
pols = nil
} else {
slices.SortFunc(pols, func(l, r *ir.UnstructuredRef) int {
Copy link
Contributor

Choose a reason for hiding this comment

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

this looks new, we are trying to ensure we pass in fixed order ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's not about ensuring that we pass the policies in a fixed order. It's so that we don't duplicate them. The code sorts the list of extension policies and then compacts the list with slices.CompactFunc to remove duplicates.

See the extensionpolicy-tcp-udp-http unit test for an example of how this can happen. The TL;DR is that when there are multiple listeners defined in the same gateway resource where the port is the same but one is for HTTP and the other is TCP, then in the translation to xDS the same xDS listener is reused because it's the same port.

This code section is about making sure that if the same extension server policy is attached to different IR level constructs that map to the same xDS level construct, then the extension server won't receive the same policy twice.

Copy link
Contributor

@arkodg arkodg Jun 11, 2024

Choose a reason for hiding this comment

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

ah go it, thoughts on adding a findIRListenesrByHostPort method similar to

func findXdsListenerByHostPort(tCtx *types.ResourceVersionTable, address string, port uint32,
which returns the IR listeners, allowing you to append/send the extensionRefs directly in here

this way we wont need to embed any extension policy code into the listener translator functions, mantain any state in memory, or perform any of these SortFuncs here (which may be hard to comprehend for a new reader)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed the logic to work like this. Not sure it's better, computation-wise.

Copy link
Contributor

Choose a reason for hiding this comment

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

thanks, agree, its not better computation wise, but should improve readability and maintenance

@arkodg arkodg requested a review from Alice-Lilith June 3, 2024 18:51
@liorokman
Copy link
Contributor Author

@envoyproxy/gateway-maintainers PTAL

guydc
guydc previously approved these changes Jun 11, 2024
Copy link
Contributor

@guydc guydc left a comment

Choose a reason for hiding this comment

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

LGTM

@liorokman liorokman force-pushed the support-tcp-udp-listener-hooks branch from a213c4b to 060ace7 Compare June 12, 2024 05:51
@liorokman
Copy link
Contributor Author

/retest

arkodg
arkodg previously approved these changes Jun 14, 2024
Copy link
Contributor

@arkodg arkodg left a comment

Choose a reason for hiding this comment

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

LGTM thanks !

@arkodg arkodg requested a review from guydc June 14, 2024 02:22
@arkodg
Copy link
Contributor

arkodg commented Jun 14, 2024

hey @liorokman can you rebase, the chart generated files have been commited

HTTP listeners.

Signed-off-by: Lior Okman <lior.okman@sap.com>
Signed-off-by: Lior Okman <lior.okman@sap.com>
translation logic.

Signed-off-by: Lior Okman <lior.okman@sap.com>
Signed-off-by: Lior Okman <lior.okman@sap.com>
@liorokman liorokman force-pushed the support-tcp-udp-listener-hooks branch from 0b72ccb to 1551343 Compare June 14, 2024 17:54
Signed-off-by: Lior Okman <lior.okman@sap.com>
Signed-off-by: Lior Okman <lior.okman@sap.com>
@liorokman
Copy link
Contributor Author

/retest

Copy link
Contributor

@guydc guydc left a comment

Choose a reason for hiding this comment

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

LGTM, thanks everyone!

@liorokman
Copy link
Contributor Author

/retest

@arkodg arkodg merged commit 4e5a2c6 into envoyproxy:main Jun 14, 2024
23 checks passed
@liorokman liorokman deleted the support-tcp-udp-listener-hooks branch June 16, 2024 04:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a post translation hook for non-HTTP listener
3 participants