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

Feature management for #88 #141

Closed
wants to merge 14 commits into from
Closed

Feature management for #88 #141

wants to merge 14 commits into from

Conversation

olivierperez
Copy link
Member

@olivierperez olivierperez commented Oct 15, 2019

💎 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

HashSet<String> headersToRedact = new HashSet<>();
headersToRedact.add("Authorization");
headersToRedact.add("Auth-Token");
headersToRedact.add("User-Session");

List<TabFeature> features = Arrays.asList(
        new HttpFeature(
                true,
                true,
                RetentionManager.Period.ONE_HOUR,
                DEFAULT_MAX_CONTENT_LENGTH,
                headersToRedact
        ),
        new ErrorsFeature(
                true,
                true
        )
);

ChuckerJavaConfig.configure(features);

📷 Screeshots

📄 Context

📝 Changes

  • FeatureManager is an object that handle the Features system
    • It helps to know which features are enabled, and get their configurations
  • Feature interface describe what is a Feature
    • Implemented by HttpFeature and ErrorsFeature
  • Every code that concerns HTTP or ERRORS are now calling FeatureManager to check if feature is enabled

📎 Related PR

⚠️ Breaking

None

📝 How to test

  • Change configuration in sample -> ChuckerApplication

🔮 Next steps

  • I still have to add the DSL in library-no-op 🤷‍♂️

@olivierperez olivierperez added enhancement New feature or improvement to the library Draft labels Oct 15, 2019
@olivierperez olivierperez changed the title Feature management for !88 Feature management for #88 Oct 15, 2019
@olivierperez olivierperez force-pushed the feature_management branch 5 times, most recently from 3a3a574 to b440c8e Compare October 15, 2019 20:22
transaction.isResponseBodyPlainText = false
}
}
return if (httpFeature.enabled) captureTransaction(request, chain)
Copy link
Collaborator

Choose a reason for hiding this comment

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

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

👍

Copy link
Member

Choose a reason for hiding this comment

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

We can enable the MandatoryBracesIfStatements detekt rule if you think it's the case

@olivierperez
Copy link
Member Author

⚠️ I haven't put the maxContentLength and headersToRedact, maybe I should. What to you think of it @cortinico @redwarp?

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.

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 ChuckerInterceptor and 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 released 3.x and 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 it Tab or TabFeature as the public API it exposes is clearly related to a Tab (e.g. newFragment). A Feature interface is probably still useful but it should probably be more abstract (e.g. only name and and enabled would suffice). This would allow for further extensions with features that are not necessarily tabs.

  • Think about those notImplemented() in the -no-op library. 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-op library?

README.md Show resolved Hide resolved
README.md Show resolved Hide resolved
interface Feature {
@get:StringRes
val name: Int
val tag: Int
Copy link
Member

Choose a reason for hiding this comment

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

Tag is not really clear here what exactly it is

Copy link
Member Author

Choose a reason for hiding this comment

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

I've renamed it to id, is it clearer? Each feature should have a unique id.

@olivierperez olivierperez force-pushed the feature_management branch 2 times, most recently from 959e164 to 5997246 Compare November 2, 2019 04:00
@olivierperez
Copy link
Member Author

olivierperez commented Nov 2, 2019

@cortinico
I've read your comments and proposed a fix almost each of them.

I still have to:

  • find a nice way avoid big breaking changes
  • offer an API for Java developers to configure Chucker

@cortinico
Copy link
Member

Awesome, please let me know if you need some support :)

@olivierperez
Copy link
Member Author

@cortinico Done !
I've:

  • Add ChuckerJavaConfig (see Example above)
  • Reworked the DSL to redact headers (tell me what version do you prefer)

@olivierperez olivierperez force-pushed the feature_management branch 2 times, most recently from cce4ffd to fa092d0 Compare November 4, 2019 21:05
@@ -48,8 +63,10 @@ class ChuckerCollector @JvmOverloads constructor(
* @param transaction The HTTP transaction sent
*/
internal fun onRequestSent(transaction: HttpTransaction) {
if (!httpFeature.enabled) return
Copy link
Collaborator

Choose a reason for hiding this comment

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

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

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?

Copy link
Member

Choose a reason for hiding this comment

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

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

@@ -61,8 +78,10 @@ class ChuckerCollector @JvmOverloads constructor(
* @param transaction The sent HTTP transaction completed with the response
*/
internal fun onResponseReceived(transaction: HttpTransaction) {
if (!httpFeature.enabled) return
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same suggestion about braces as above.

@@ -21,6 +21,7 @@ artifacts {
dependencies {
implementation "com.squareup.okhttp3:okhttp:$okhttp3Version"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlinVersion"
implementation "androidx.fragment:fragment:$fragmentVersion"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe we could think about some other way of implementing feature management, which would allow to not include this dependency?

@cortinico
Copy link
Member

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 FeatureManager that holds a set of TabFeature. Here we're already making the assumption that every feature is rendered using a Fragment in a ViewPager. This has several side effects:

  • The public API got way bigger (6 files were added in the -no-op library artifact).
  • The androidx.fragment:fragment dependency leaked inside the -no-op library. We should probably avoid having Fragments as part of the public API.
  • Having features that doesn't have a corresponding tab will require a refactoring, as well as features that are shared between two tabs.

Moreover, the DSL could be moved to a library-dsl artifact, and have it as a pluggable add-on.

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.

@cortinico
Copy link
Member

Also I invite the community, as well as @vbuberen @redwarp to provide their point of view on the topic :) Happy to discuss

@vbuberen
Copy link
Collaborator

vbuberen commented Jan 5, 2020

From my point of view, this is too much for Chucker at the moment.
Having 2 tabs with transactions and errors isn't something too complex or requiring some additional efforts from users, who want just watch for transactions or for those, so want to only see throwable
errors.
Moreover, talking about errors - now errors are tracked by default, while with these changes user should explicitly write
error { enabled = true }. For me it seems more like adding more lines to set up the library than adding flexibility.
I agree with @cortinico here on being hesitant on merging this thing, since I am for as effortless experience as we can provide.

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.

@olivierperez
Copy link
Member Author

Hi, thanks for the review and the comments and sorry for the delay.
I think the way I choose is not really the right one. If we want to implement a way to configure features we should talk about it before I go develop it :-)

I propose to close this PR.

BTW It was fun to develop it anyway

@cortinico
Copy link
Member

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 :)

@cortinico cortinico closed this Apr 7, 2020
@vbuberen vbuberen deleted the feature_management branch April 20, 2020 09:40
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.

3 participants