Feature management for #88#141
Conversation
3a3a574 to
b440c8e
Compare
| transaction.isResponseBodyPlainText = false | ||
| } | ||
| } | ||
| return if (httpFeature.enabled) captureTransaction(request, chain) |
There was a problem hiding this comment.
What do you think about keeping the same style for if else everywhere?
For example, in the same file there are lines the conditions have braces for if and else cases (like on line 127).
I believe that it could improve readability a little bit.
There was a problem hiding this comment.
We can enable the MandatoryBracesIfStatements detekt rule if you think it's the case
b440c8e to
1f31b8a
Compare
|
|
cortinico
left a comment
There was a problem hiding this comment.
Commenting here to give an high-level feedback on the PR.
First, thanks for taking the time to write it <3
I do like the DSL and I think it clarifies the configuration block a lot :)
On the other hand, I think we should try to:
-
Don't introduce a strong API change. We're changing the public API of Chucker (changes in the constructors of
ChuckerInterceptorand similar classes) in a significant way. The problem is that, while the DSL is really elegant to call in Kotlin, that's not the same for Java users. Moreover, we just released3.xand it's probably too early to do a strong API change. What do you folks think? I'd rather try to create a DSL that can be optionally used instead of the canonical API used to initialize Chucker. -
Rename
Feature. I'd rather call itTaborTabFeatureas the public API it exposes is clearly related to a Tab (e.g.newFragment). AFeatureinterface is probably still useful but it should probably be more abstract (e.g. onlynameand andenabledwould suffice). This would allow for further extensions with features that are not necessarily tabs. -
Think about those
notImplemented()in the-no-oplibrary. Historically we used to use zero values (e.g.override val name: Int = 0). Is there a reason why now we're shifting our approach for the-no-oplibrary?
There was a problem hiding this comment.
Tag is not really clear here what exactly it is
There was a problem hiding this comment.
I've renamed it to id, is it clearer? Each feature should have a unique id.
2444d3d to
1f376bb
Compare
- maxContentLength - headersToRedact
959e164 to
5997246
Compare
5997246 to
b8ba648
Compare
|
@cortinico I still have to:
|
e8b4b8b to
88f4a66
Compare
|
Awesome, please let me know if you need some support :) |
88f4a66 to
0a5cefe
Compare
ea5e371 to
cd4155e
Compare
|
@cortinico Done !
|
cce4ffd to
fa092d0
Compare
fa092d0 to
4fe7207
Compare
| * @param transaction The HTTP transaction sent | ||
| */ | ||
| internal fun onRequestSent(transaction: HttpTransaction) { | ||
| if (!httpFeature.enabled) return |
There was a problem hiding this comment.
I suggest to add braces here for readability and to match other code lines, like below where condition with only one line in it has braces.
There was a problem hiding this comment.
I use braces when there is something to do.
My point of view is this is an early return, in order to do nothing. If I do nothing I have no braces 🤷♂
What do you think of that?
There was a problem hiding this comment.
I use braces when there is something to do.
Agree with @olivierperez
Also the style guide here https://developer.android.com/kotlin/style-guide#braces allows single-line if statements like:
if (condition) effect| * @param transaction The sent HTTP transaction completed with the response | ||
| */ | ||
| internal fun onResponseReceived(transaction: HttpTransaction) { | ||
| if (!httpFeature.enabled) return |
There was a problem hiding this comment.
Same suggestion about braces as above.
| dependencies { | ||
| implementation "com.squareup.okhttp3:okhttp:$okhttp3Version" | ||
| implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlinVersion" | ||
| implementation "androidx.fragment:fragment:$fragmentVersion" |
There was a problem hiding this comment.
Maybe we could think about some other way of implementing feature management, which would allow to not include this dependency?
|
Thanks again for the big work @olivierperez I have to be honest, I'm a bit hesitant on merging this. I have the feeling the whole approach is a bit over engineered. My point of view is that is a bunch of extra code that we will have to maintain for a limited benefit. Ideally we should be able to have some sort of key-value storage used to store/retrieve configurations for specific features. Your approach is based on having a
Moreover, the DSL could be moved to a I generally have the feeling that we should simplify a bit the whole approach. On the other hand I strongly believe that we need some sort of modular infrastructure to make easy to Chucker extend. |
|
From my point of view, this is too much for Chucker at the moment. At the same time I should admit that a great amount of work was done here and thanks a lot for it, but we should probably do something like this later when we have more components, features, etc. |
|
Hi, thanks for the review and the comments and sorry for the delay. I propose to close this PR. BTW It was fun to develop it anyway |
Let's close it 👍 I anyway believe that we might come back to this topic at a certain topic and your PR could be used as material to kickoff the discussion again :) |
💎 Example
Kotlin
configureChucker { http { enabled = true showNotification = true retentionPeriod = RetentionManager.Period.ONE_HOUR maxContentLength = 250000L headers { redact("Authorization") redact("Auth-Token") redact("User-Session") } } error { enabled = true } }Java
📷 Screeshots
📄 Context
📝 Changes
FeatureManageris an object that handle the Features systemFeatureinterface describe what is a FeatureHttpFeatureandErrorsFeatureFeatureManagerto check if feature is enabled📎 Related PR
None
📝 How to test
🔮 Next steps