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

Remove deprecated constructor and use exposed builder pattern #483

Merged
merged 1 commit into from Nov 9, 2020

Conversation

MiSikora
Copy link
Contributor

@MiSikora MiSikora commented Oct 23, 2020

πŸ“„ Context

There is an issue - #462.

πŸ“ Changes

This implementation uses more robust builder pattern in terms of future development. It should be used with 4.x. There is one inconvenience when it comes to default values but it is not that big of a deal. I'll describe it more in the comments to the code.

🚫 Breaking

Yes it breaks both API and ABI, but it is for 4.x.

πŸ› οΈ How to test

I suggest reviewing commits separately. With 5e7d733 you can check if ReplaceWith works correctly.

Nothing special to test.

⏱️ Next steps

Closes #462

Helps with #466. It does not solve it, but I don't think we can fix it unfortunately. We can only make sure that in the future we don't fall into the same trap. Though suggestion with adding ABI compatibility tool would be a nice addition.

We should consider doing the same with ChuckerCollector and RetentionManger. They do not change that dynamically, so there might be no reason to switch there to the builder pattern but on the other hand it might pose at some point in the future same issues as #466.

@MiSikora MiSikora added the enhancement New feature or improvement to the library label Oct 23, 2020
@MiSikora MiSikora added this to the 3.3.1 milestone Oct 23, 2020
Comment on lines +48 to +51
private val collector = builder.collector ?: ChuckerCollector(context)
private val maxContentLength = builder.maxContentLength
private val cacheDirectoryProvider = builder.cacheDirectoryProvider ?: CacheDirectoryProvider { context.filesDir }
Copy link
Contributor Author

@MiSikora MiSikora Oct 23, 2020

Choose a reason for hiding this comment

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

This is the inconvenience that I mentioned. Default fields are declared here instead of in the builder. It is only due to test purposes. Instantiating ChuckerCollector would require a lot of mocking of Context that I don't want to be bothered with.

On the other hand it is nice to not create stuff eagerly in the builder.

@MiSikora MiSikora changed the title Builder pattern Use builder pattern for ChuckerInterceptor Oct 23, 2020
@vbuberen
Copy link
Collaborator

I like that we will have builder patter in Chucker soon.
However, I have a few concerns/suggestions about this PR.

  1. I don't like how we are removing existing constructor without proper deprecation process. It is not necessary that we need ReplaceWith point to something specific, but at least deprecation messages, like we did for throwables would be good.

  2. With introduced changes and added deprecation messages (if we add some) I believe that we should change the version to 3.4.0, not 3.3.1 to follow semantic versioning approach.

  3. While looking through code I thought that ChuckerInterceptor looks quite filled with different stuff now. What if we just create some interface for the public API, which will be the single entry point for user? In such case we could create some separate Builder class to implement this interface and to build and return an actual configured ChuckerInterceptor object. Might be an overkill and lead us to more breaking changes, but we might end up with better separation of concerns.

@MiSikora
Copy link
Contributor Author

MiSikora commented Oct 25, 2020

  1. I don't like how we are removing existing constructor without proper deprecation process. It is not necessary that we need ReplaceWith point to something specific, but at least deprecation messages, like we did for throwables would be good.
  2. With introduced changes and added deprecation messages (if we add some) I believe that we should change the version to 3.4.0, not 3.3.1 to follow semantic versioning approach.

I'm not sure if I understand what you mean by proper deprecation process. If it is connected to your second point I get it. Otherwise can you explain how should it look like? Constructor is marked as @Deprecated and has a message for 3.x.

  1. While looking through code I thought that ChuckerInterceptor looks quite filled with different stuff now. What if we just create some interface for the public API, which will be the single entry point for user? In such case we could create some separate Builder class to implement this interface and to build and return an actual configured ChuckerInterceptor object. Might be an overkill and lead us to more breaking changes, but we might end up with better separation of concerns.

Can you create some snippet? I think I don't get the full picture.

@vbuberen
Copy link
Collaborator

I'm not sure if I understand what you mean by proper deprecation process.

I mean that we are just removing some existing part of our public API without any warnings. Yes, I agree that we don't make people do a ton of changes, but still, it would be better if we had some announcement/warning and some grace period when we have both deprecated constructor and the brand new builder. It feels kind of tricky since we have just one ChuckerInterceptor class which is being edited in this PR, but still.

Can you create some snippet? I think I don't get the full picture.

Yes, I should do some, probably. Also need to connect all dots to prove that the concept is valid.

@MiSikora
Copy link
Contributor Author

I mean that we are just removing some existing part of our public API without any warnings. Yes, I agree that we don't make people do a ton of changes, but still, it would be better if we had some announcement/warning and some grace period when we have both deprecated constructor and the brand new builder.

Maybe it got lost in the whole PR description. After merging this PR without squashing I want to cherry-pick 5e7d733 onto 3.x where old constructor is still present and just deprecated. Users will have a grace period for as long as 4.x is not released.

@vbuberen
Copy link
Collaborator

Yes, looks like I missed the point about deprecations in one of commits.

In such case I am fine with the approach. But still, we would need to use 3.4.0 instead of 3.3.1 as we are introducing some new deprecations and some new API.

@MiSikora
Copy link
Contributor Author

MiSikora commented Oct 26, 2020

Yes, it's a little bit unfortunate that we'd have to make next release with a minor bump but I want to remove the burden of @JvmOverloads constructor from 4.x.

Copy link
Collaborator

@vbuberen vbuberen left a comment

Choose a reason for hiding this comment

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

Reviewed this PR by commits (as it supposed to happen) and everything looks fine and reasonable for me.

As to my suggestion about additional interfaces - we can come back to it later when we do other changes to transaction processing.

@cortinico
Copy link
Member

Great job πŸ‘ Also sorry for being late to the game here.

Though suggestion with adding ABI compatibility tool would be a nice addition.

+1 on this. I actually wanted to take a stab to add https://github.com/Kotlin/binary-compatibility-validator to Chucker in the near future (that will prevent future problems like this one).

2. With introduced changes and added deprecation messages (if we add some) I believe that we should change the version to 3.4.0, not 3.3.1 to follow semantic versioning approach.

Agree here on what @vbuberen mentioned. If we merge this, we need to release 3.4.0 as a deprecation (of our prominent API) is worth a minor bump rather than a patch-fix bump.

Imho this PR should also be split in 2 separate PRs: 5e7d733 should be pointed against master while 6d4a8b4 should be pointed against 4.x (or however we wish to call it). As a rule of thumb is also useful for our users to have separate PRs that are easier to browse.

@MiSikora
Copy link
Contributor Author

MiSikora commented Nov 3, 2020

Imho this PR should also be split in 2 separate PRs: 5e7d733 should be pointed against master while 6d4a8b4 should be pointed against 4.x (or however we wish to call it). As a rule of thumb is also useful for our users to have separate PRs that are easier to browse.

I thought that we treat now our develop as a 4.x. That's why I wanted to merge these two commit without squashing them, and then create a separate PR for 3.x with some of commits that should also land in 3.x cherry-picked from develop.

@cortinico
Copy link
Member

I thought that we treat now our develop as a 4.x.

(I wrote master but I meant develop sorry)

Yup I'm fine either way. But I would still advice we follow this flow:

  • Create a PR with 5e7d733 & Merge it on develop
  • Release version to 3.4.0 (<- this will be the point where we start the 3.x branch).
  • Create a new PR with 6d4a8b4 & Merge it on develop

@MiSikora
Copy link
Contributor Author

MiSikora commented Nov 3, 2020

Ok, got it. I was just a little bit confused because we already have 3.x but I we didn't anticipate next minor bump so it's all fine then. I'll split this into two separate PRs.

@cortinico
Copy link
Member

Ok, got it. I was just a little bit confused because we already have 3.x

Sorry, I also haven't noticed that. In that case, let's create a PR with 5e7d733 & Merge it on 3.x

@MiSikora
Copy link
Contributor Author

MiSikora commented Nov 3, 2020

Ok, I added @VisibleForTesting and created #491. 6d4a8b4 changed to a923a8f.

@MiSikora MiSikora removed this from the 3.4.0 milestone Nov 4, 2020
@MiSikora MiSikora changed the base branch from develop to builder-pattern-3.x November 4, 2020 18:09
@MiSikora MiSikora changed the title Use builder pattern for ChuckerInterceptor Remove deprecated constructor and use expose builder pattern only Nov 4, 2020
@MiSikora MiSikora added the ⛔️ do not merge A PR that should not be merged label Nov 4, 2020
@MiSikora
Copy link
Contributor Author

MiSikora commented Nov 4, 2020

Ok, I changed PR target. I think after merging #491 it will automatically retarget to develop branch. If not I'll update it then.

@MiSikora MiSikora changed the title Remove deprecated constructor and use expose builder pattern only Remove deprecated constructor and use exposed builder pattern Nov 4, 2020
Base automatically changed from builder-pattern-3.x to develop November 5, 2020 13:45
@MiSikora
Copy link
Contributor Author

MiSikora commented Nov 5, 2020

Some conflicts popped up. I'll resolve them after 3.4.0 is released.

@cortinico
Copy link
Member

Let's rebase this on top of #496 once it's merged

@MiSikora MiSikora added this to the 4.0.0 milestone Nov 6, 2020
Copy link
Member

@cortinico cortinico left a comment

Choose a reason for hiding this comment

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

LGTM πŸ‘

@MiSikora MiSikora merged commit ffe771f into develop Nov 9, 2020
@MiSikora MiSikora deleted the builder-pattern branch November 9, 2020 13:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or improvement to the library
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create ChuckerInterceptor from builder
3 participants