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

chore: log states via redux #421

Merged
merged 6 commits into from
Aug 9, 2024
Merged

chore: log states via redux #421

merged 6 commits into from
Aug 9, 2024

Conversation

Shahroz16
Copy link
Contributor

closes: https://linear.app/customerio/issue/MBL-454/improve-debug-logs-for-in-app-android

Changes:

  • Added domain layer for redux to store state changes and have a single source of truth
  • No change in business logic, but now we can verify which component deviated from the current state
  • Right now this redux structure is just used for logging states.

More details on the structure can be followed: https://www.notion.so/custio/InAppMessaging-revamp-A-brave-new-event-driven-world-7422938d647944999defc9cca9f113a3?pvs=4

Copy link

github-actions bot commented Aug 9, 2024

Sample app builds 📱

Below you will find the list of the latest versions of the sample apps. It's recommended to always download the latest builds of the sample apps to accurately test the pull request.


  • java_layout: shahroz/logging-via-redux (1723225628)
  • kotlin_compose: shahroz/logging-via-redux (1723225632)


abstract class DiGraph {
/**
* Map of dependencies that can be overridden with mocks in test functions.
*/
val overrides: MutableMap<String, Any> = mutableMapOf()
val overrides = ConcurrentHashMap<String, Any>()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

To ensure synchronization.

Copy link

github-actions bot commented Aug 9, 2024

Build available to test
Version: shahroz-logging-via-redux-SNAPSHOT
Repository: https://s01.oss.sonatype.org/content/repositories/snapshots/

Copy link

github-actions bot commented Aug 9, 2024

📏 SDK Binary Size Comparison Report

No changes detected in SDK binary size ✅

@Shahroz16 Shahroz16 requested a review from a team August 9, 2024 13:56
Copy link

codecov bot commented Aug 9, 2024

Codecov Report

Attention: Patch coverage is 26.75159% with 115 lines in your changes missing coverage. Please review.

Project coverage is 41.98%. Comparing base (7794cd4) to head (8b30804).
Report is 3 commits behind head on main.

Files Patch % Lines
...stomer/messaginginapp/gist/data/listeners/Queue.kt 4.34% 22 Missing ⚠️
...tomer/messaginginapp/gist/presentation/GistView.kt 0.00% 16 Missing ⚠️
...omer/messaginginapp/domain/InAppMessagingAction.kt 17.64% 14 Missing ⚠️
...stomer/messaginginapp/gist/presentation/GistSdk.kt 12.50% 14 Missing ⚠️
...ssaginginapp/gist/presentation/GistModalManager.kt 15.38% 11 Missing ⚠️
...tomer/messaginginapp/domain/InAppMessageReducer.kt 33.33% 0 Missing and 10 partials ⚠️
...saginginapp/gist/presentation/GistModalActivity.kt 0.00% 10 Missing ⚠️
...inginapp/gist/presentation/engine/EngineWebView.kt 0.00% 6 Missing ⚠️
...io/customer/messaginginapp/ModuleMessagingInApp.kt 37.50% 5 Missing ⚠️
...omer/messaginginapp/gist/utilities/ElapsedTimer.kt 0.00% 3 Missing ⚠️
... and 2 more
Additional details and impacted files
@@             Coverage Diff              @@
##               main     #421      +/-   ##
============================================
- Coverage     41.99%   41.98%   -0.01%     
- Complexity      256      259       +3     
============================================
  Files            94       99       +5     
  Lines          2229     2320      +91     
  Branches        319      344      +25     
============================================
+ Hits            936      974      +38     
- Misses         1204     1247      +43     
- Partials         89       99      +10     

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

Copy link
Contributor

@mrehan27 mrehan27 left a comment

Choose a reason for hiding this comment

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

Looks promising. Given that no business logic has changed and testing results were positive, I'm happy shipping this to customers 👍🏻

is InAppMessagingAction.ProcessMessage -> state.copy(currentMessageBeingProcessed = action.message)
is InAppMessagingAction.EmbedMessage -> state.copy(currentMessageBeingProcessed = null, currentModalMessage = null)
is InAppMessagingAction.ClearUser -> state.copy(currentUser = null, messages = emptyList())
else -> state // For actions that don't change state
Copy link
Contributor

Choose a reason for hiding this comment

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

While this saves some efforts, but it can lead to unexpected results as well for new states. Shouldn't we combine remaining states here instead of else block? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup, this would change, when we start adding more actions, right now scope was just logging,

import org.reduxkotlin.applyMiddleware
import org.reduxkotlin.threadsafe.createThreadSafeStore

internal object InAppMessagingStore {
Copy link
Contributor

Choose a reason for hiding this comment

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

Any particular reason for making this object. Why couldn't we leverage singleton from SDKComponent for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We are levering it from singleton, this was added as a precaution and since it doesn't need constructor.

GIST_TAG,
"Found ${latestMessagesResponse.body()?.count()} messages for user"
)
inAppMessagingManager.dispatch(InAppMessagingAction.LogEvent("Found ${latestMessagesResponse.body()?.count()} messages for user"))
Copy link
Contributor

Choose a reason for hiding this comment

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

Can't we extract latestMessagesResponse.body() to single variable and reuse in the line below?

GistSdk.removeListener(this)
super.onPause()
overridePendingTransition(0, 0)
}

override fun finish() {
inAppMessagingManager.dispatch(InAppMessagingAction.LogEvent("GisModelActivity finish"))
runOnUiThread {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we log on animations end too?

Copy link
Contributor

Choose a reason for hiding this comment

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

I have some suggestions that apply to code in several areas so adding here.

  • I think we can now remove GIST_TAG?
  • For logging the code looks to heavy at the moment
inAppMessagingManager.dispatch(InAppMessagingAction.LogEvent("message"))

Can we create some extension to reduce only for logging as it is used extensively? Something like this:

inAppMessagingManager.dispatchLogEvent("message")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For logging the code looks too heavy at the moment

This would go away, we would not need to log anymore, We are going to log each action and state afterward. This is just a manual action added to let the current logging come through.

@Shahroz16 Shahroz16 merged commit 927ba7b into main Aug 9, 2024
33 of 35 checks passed
@Shahroz16 Shahroz16 deleted the shahroz/logging-via-redux branch August 9, 2024 20:25
Shahroz16 added a commit that referenced this pull request Aug 9, 2024
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.

2 participants