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

listener options merge what translator generates #10578

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

stevenctl
Copy link

@stevenctl stevenctl commented Jan 21, 2025

Description

A translator may generate a Listener with ListenerOptions (it's currently the internal IR).
A user listener opts should not automatically clear unrelated items in ListenerOptions.
This would also apply if another plugin used ListenerOptions.

API changes

ListenerOptions will now act as an overlay to system ones (if the system ones exist).

Code changes

Use proto merge when existing options are on the listener.

Testing steps

Added base options in the unit tests

Notes for reviewers

Open to manually implementing merge logic instead of proto merge

BOT NOTES:
resolves https://github.com/solo-io/solo-projects/issues/7300

@stevenctl stevenctl force-pushed the merge-listener-opts branch from d2beba6 to b563ba7 Compare January 22, 2025 21:33
@solo-changelog-bot
Copy link

Issues linked to changelog:
https://github.com/solo-io/solo-projects/issues/7300

@@ -114,11 +122,10 @@ var _ = Describe("ListenerOptions Plugin", func() {
It("does not add buffer limit", func() {
err := plugin.ApplyListenerPlugin(ctx, listenerCtx, outputListener)
Expect(err).ToNot(HaveOccurred())
Expect(outputListener.GetOptions()).To(BeNil())
Expect(outputListener.GetOptions().GetPerConnectionBufferLimitBytes()).To(BeNil())
Copy link

Choose a reason for hiding this comment

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

can you add a test that shows the merging, (if there isn't already one)?

Copy link
Author

Choose a reason for hiding this comment

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

it's not super explicit; We now have ProxyProtocol set on the base options, expect outputListener.GetOptions() == expectedOptions encodes this.

I can rewrite the tests to be super explicit if we want that.

@@ -47,7 +49,11 @@ func (p *plugin) ApplyListenerPlugin(
// use the first option (highest in priority)
// see for more context: https://github.com/solo-io/solo-projects/issues/6313
optToUse := attachedOptions[0]
outListener.Options = optToUse.Spec.GetOptions()
if outListener.GetOptions() != nil {
proto.Merge(outListener.GetOptions(), optToUse.Spec.GetOptions())
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we note why we use proto merge here given how it handles unset values?

Weve had a variety of merge semantics in the code base and its hard to know why we choose one over another so would prefer erring on the side of a quick comment on why this merge strategy was chosen

Copy link
Author

Choose a reason for hiding this comment

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

changed it to be consistent with other merging logic

@sam-heilbron sam-heilbron requested a review from lgadban February 11, 2025 17:28
@@ -47,7 +49,11 @@ func (p *plugin) ApplyListenerPlugin(
// use the first option (highest in priority)
// see for more context: https://github.com/solo-io/solo-projects/issues/6313
optToUse := attachedOptions[0]
outListener.Options = optToUse.Spec.GetOptions()
if outListener.GetOptions() != nil {

Choose a reason for hiding this comment

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

We have some very similar code for our other policies defined here:

// ShallowMergeRouteOptions merges the top-level fields of src into dst.
. I think it would make sense to co-locate all our merge code to avoid the implementations drifting, if possible. What do you think?

Copy link
Author

Choose a reason for hiding this comment

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

I guess I could write a manual one.. but I think the proto merge semantics make sense here. ListenerOptions has lists and maps, i'd imagine we want those to merge although the specific bug I care about only needs the top level fields to be merged.

Copy link
Author

Choose a reason for hiding this comment

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

okay updated it to do this

@stevenctl stevenctl enabled auto-merge (squash) February 11, 2025 21:01
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.

5 participants