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

Breaking: Replace Callbacks interface by Callbacks struct #324

Merged
merged 1 commit into from
Dec 19, 2024

Conversation

tigrannajaryan
Copy link
Member

@tigrannajaryan tigrannajaryan commented Dec 18, 2024

The interface has the following downsides:

  • Impossible to define non-trivial default behavior. Here is an example where it was needed: Add CheckRedirect callback #269 (comment)
  • Adding new callbacks requires expanding the interface, which is a breaking change for existing client users.

Getting rid of the interface and keeping just a struct for callbacks solves both problems:

  • Arbitrarily complex default behavior can be now defined on the struct if the user does not provide the particular callback func.
  • Adding new callback funcs is not a breaking change, existing users won't be affected.

Copy link

codecov bot commented Dec 18, 2024

Codecov Report

Attention: Patch coverage is 88.65979% with 11 lines in your changes missing coverage. Please review.

Project coverage is 77.29%. Comparing base (f7d56df) to head (2204615).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
client/internal/receivedprocessor.go 90.90% 4 Missing and 3 partials ⚠️
client/types/callbacks.go 76.47% 0 Missing and 4 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #324      +/-   ##
==========================================
+ Coverage   77.24%   77.29%   +0.04%     
==========================================
  Files          25       25              
  Lines        2303     2281      -22     
==========================================
- Hits         1779     1763      -16     
+ Misses        420      410      -10     
- Partials      104      108       +4     

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

@tigrannajaryan
Copy link
Member Author

@open-telemetry/opamp-go-approvers please take a look, I would like to know what your opinion is.

The interface has the following downsides:
- Impossible to define non-trivial default behavior. Here is an example where it was needed: open-telemetry#269 (comment)
- Adding new callbacks requires expanding the interface, which is a breaking change for existing client users.

Getting rid of the interface and keeping just a struct
for callbacks solves both problems:
- Arbitrarily complex default behavior can be now defined on the struct if the user does not provide the particular callback func.
- Adding new callback funcs is not a braking change, existing users won't be affected.
@tigrannajaryan
Copy link
Member Author

If we like this direction I will also make similar changes to Server callbacks.

@echlebek
Copy link
Contributor

Thanks @tigrannajaryan, I think this is a nice simplification of the callbacks API!

I might suggest preserving the CallbacksStruct type name (although the name is a bit awkward now) for backwards compatibility.

Perhaps add a type alias, to avoid breaking the API for people using CallbacksStruct. It could also be given a "Deprecated" comment, so that users can be made aware of its deprecated status by static analysis tools. (https://go.dev/wiki/Deprecated)

// Callbacks is blah blah
type Callbacks struct { ... }

// CallbacksStruct is an alias for Callbacks
// Deprecated: CallbacksStruct will be removed in the future
type CallbacksStruct = Callbacks

@andykellr
Copy link
Contributor

Thanks, LGTM

@tigrannajaryan
Copy link
Member Author

I might suggest preserving the CallbacksStruct type name (although the name is a bit awkward now) for backwards compatibility.

I am not sure about this. It is not just the struct name, we also have to preserve the field names, which all have the "Func" suffix now, otherwise it is a breaking change anyway.

@echlebek
Copy link
Contributor

That's a good point, I didn't notice the field names had changed as well.

@tigrannajaryan tigrannajaryan marked this pull request as ready for review December 18, 2024 20:18
@tigrannajaryan tigrannajaryan requested a review from a team as a code owner December 18, 2024 20:18
@tigrannajaryan tigrannajaryan changed the title Eliminate Callbacks interface Breaking: Eliminate Callbacks interface Dec 19, 2024
@tigrannajaryan tigrannajaryan changed the title Breaking: Eliminate Callbacks interface Breaking: Replace Callbacks interface by Callbacks struct Dec 19, 2024
@tigrannajaryan tigrannajaryan merged commit b7beae5 into open-telemetry:main Dec 19, 2024
12 checks passed
@tigrannajaryan tigrannajaryan deleted the tigran/callbacks branch December 19, 2024 15:17
tigrannajaryan added a commit to tigrannajaryan/opamp-go that referenced this pull request Dec 19, 2024
This continues work start in open-telemetry#324 for Client.

The interface has the following downsides:
- Impossible to define non-trivial default behavior. Here is an example where it was needed: open-telemetry#269 (comment)
- Adding new callbacks requires expanding the interface, which is a breaking change for existing client users.

Getting rid of the interface and keeping just a struct
for callbacks solves both problems:
- Arbitrarily complex default behavior can be now defined on the struct if the user does not provide the particular callback func.
- Adding new callback funcs is not a braking change, existing users won't be affected.
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.

3 participants