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

fix: fixing usage pulse for anon user #37940

Merged
merged 1 commit into from
Dec 4, 2024
Merged

fix: fixing usage pulse for anon user #37940

merged 1 commit into from
Dec 4, 2024

Conversation

brayn003
Copy link
Contributor

@brayn003 brayn003 commented Dec 4, 2024

Description

  • For usage pulse we need pageId
  • URL contains basePageId
  • basePageId needs to be converted to pageId
  • The conversion needs application data to be populated into redux
  • The PR adds a wait for application to initialise first before sending the usage pulse

Fixes 37904

Automation

/ok-to-test tags="@tag.All"

🔍 Cypress test results

Tip

🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/12157463790
Commit: b4c4df1
Cypress dashboard.
Tags: @tag.All
Spec:


Wed, 04 Dec 2024 11:40:43 UTC

Communication

Should the DevRel and Marketing teams inform users about this change?

  • Yes
  • No

Summary by CodeRabbit

  • New Features

    • Enhanced user navigation tracking with improved handling of route changes.
    • Introduced a new function for managing user activity tracking, improving clarity and control flow.
  • Bug Fixes

    • Improved error handling during route changes to ensure proper logging.
  • Refactor

    • Restructured user-related sagas for better organization and separation of concerns.

@brayn003 brayn003 self-assigned this Dec 4, 2024
Copy link
Contributor

coderabbitai bot commented Dec 4, 2024

Walkthrough

The changes in this pull request involve updates to the NavigationSagas.ts and userSagas.tsx files, enhancing the handling of Redux actions and restructuring user-related sagas. In NavigationSagas.ts, the watchForTrackableUrl function now listens for specific actions before proceeding with URL tracking. In userSagas.tsx, the runUserSideEffectsSaga function has been refactored to improve clarity and organization, introducing a new function, restartUserTracking, to manage user tracking more effectively.

Changes

File Path Change Summary
app/client/src/ce/sagas/NavigationSagas.ts Updated import statements, modified watchForTrackableUrl to include yield take for specific actions, and preserved error handling in handleRouteChange.
app/client/src/ce/sagas/userSagas.tsx Refactored runUserSideEffectsSaga into restartUserTracking and original function, improved separation of concerns, and ensured proper tracking management.

Possibly related PRs

Suggested labels

Bug, Task, ok-to-test

Suggested reviewers

  • hetunandu
  • ankitakinger

🎉 In the saga of code, changes unfold,
With actions tracked and stories told.
User journeys now clearer, with paths that align,
In the realm of Redux, our functions shine!
So raise a toast to the code we refine,
For every small change, a victory divine! 🎊


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 1078a03 and b4c4df1.

📒 Files selected for processing (2)
  • app/client/src/ce/sagas/NavigationSagas.ts (2 hunks)
  • app/client/src/ce/sagas/userSagas.tsx (2 hunks)
🔇 Additional comments (5)
app/client/src/ce/sagas/userSagas.tsx (3)

186-194: LGTM: Clean separation of concerns

The refactoring improves code organization by separating tracking logic into its own function while maintaining existing telemetry initialization.


Line range hint 148-184: Consider handling potential race conditions

The function waits for feature flags but doesn't handle the failure case. If feature flags fetch fails, the saga might be stuck.

Consider adding error case handling:

 if (!isFFFetched) {
   yield call(fetchFeatureFlagsInit);
-  yield take(ReduxActionTypes.FETCH_FEATURE_FLAGS_SUCCESS);
+  const result = yield take([
+    ReduxActionTypes.FETCH_FEATURE_FLAGS_SUCCESS,
+    ReduxActionTypes.FETCH_FEATURE_FLAGS_ERROR,
+  ]);
+  if (result.type === ReduxActionTypes.FETCH_FEATURE_FLAGS_ERROR) {
+    // Handle error case
+    return;
+  }
 }

170-175: Verify all initialization paths for anonymous users

The code waits for editor or viewer initialization, but there might be other valid initialization paths.

✅ Verification successful

Let me search for initialization-related code to better understand the flow.


Let me check the actual initialization flows to understand where these actions are dispatched.


The initialization paths for anonymous users are correctly handled

The code appropriately waits for either editor or viewer initialization. From the codebase analysis, these are the only two valid initialization paths:

  • Editor initialization via INITIALIZE_EDITOR_SUCCESS
  • Page viewer initialization via INITIALIZE_PAGE_VIEWER_SUCCESS

Both paths are properly covered in the current implementation. No other initialization paths exist that would need to be considered for anonymous users.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for other initialization actions
rg "INITIALIZE_.*SUCCESS" -t ts

Length of output: 1704


Script:

#!/bin/bash
# Search for initialization saga implementations
ast-grep --pattern 'function* initialize$_($$$) {
  $$$
}'

# Search for initialization action types
rg "INITIALIZE_" app/client/src/ce/constants/ReduxActionConstants.tsx -A 1

Length of output: 590


Script:

#!/bin/bash
# Search for where initialization actions are dispatched
rg "INITIALIZE_EDITOR|INITIALIZE_PAGE_VIEWER" -A 5 -B 5

# Look for any other initialization-related sagas
ast-grep --pattern 'function* $_(action: InitializeEditorPayload) {
  $$$
}'

Length of output: 14983

app/client/src/ce/sagas/NavigationSagas.ts (2)

1-1: LGTM: Import changes are appropriate

The addition of take and ReduxActionTypes imports aligns with the new functionality requirements.

Also applies to: 7-10


92-95: Verify handling of multiple initialization events

The addition of initialization checks is a good solution for ensuring proper application state before URL tracking. However, please verify the behavior when multiple initialization events occur.

Let's check for potential multiple initialization events:

✅ Verification successful

The previous search didn't yield useful results. Let's try with more targeted ripgrep commands to find:

  1. Where these actions are dispatched
  2. Where else they are watched/taken
  3. The action type definitions themselves

This will help us understand the initialization flow and potential for multiple events.


Multiple initialization events are handled correctly - no race condition risk

The code is well-structured to handle initialization events. The take pattern used in NavigationSagas.ts is part of a larger initialization flow where:

  1. Multiple sagas wait for initialization via take() - each handling their own concerns (OnboardingSagas, GlobalSearchSagas, WidgetSelectionSagas)
  2. Initialization is dispatched exactly once per mode by the respective engines (AppEditorEngine.ts, AppViewerEngine.ts)
  3. State updates are handled atomically in reducers (editorReducer.tsx, appViewReducer.tsx)

The current implementation ensures proper sequencing without risk of duplicate processing.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for dispatch of initialization actions
rg "dispatch.*(?:INITIALIZE_EDITOR_SUCCESS|INITIALIZE_PAGE_VIEWER_SUCCESS)" -A 3

# Search for any other watchers of these actions
ast-grep --pattern 'yield take($$$INITIALIZE_EDITOR_SUCCESS$$$)'
ast-grep --pattern 'yield take($$$INITIALIZE_PAGE_VIEWER_SUCCESS$$$)'

Length of output: 66309


Script:

#!/bin/bash
# Search for dispatch of initialization actions with better regex pattern
rg "dispatch.*(?:INITIALIZE_EDITOR_SUCCESS|INITIALIZE_PAGE_VIEWER_SUCCESS)" -A 3 --type ts --type js

# Search for any other watchers of these actions with ripgrep
rg "take\(.*(?:INITIALIZE_EDITOR_SUCCESS|INITIALIZE_PAGE_VIEWER_SUCCESS)" -A 3 --type ts --type js

# Search for the action type definitions
rg "INITIALIZE_EDITOR_SUCCESS|INITIALIZE_PAGE_VIEWER_SUCCESS" -A 1 --type ts --type js

Length of output: 3966


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@brayn003 brayn003 added the ok-to-test Required label for CI label Dec 4, 2024
@github-actions github-actions bot added Billing Billing infrastructure and flows for Business Edition and Trial users Billing & Licensing Product Issues pertaining to licensing, billing and usage across self serve and enterprise customers Bug Something isn't working High This issue blocks a user from building or impacts a lot of users Needs Triaging Needs attention from maintainers to triage Production labels Dec 4, 2024
@brayn003
Copy link
Contributor Author

brayn003 commented Dec 4, 2024

/build-deploy-preview

Copy link

github-actions bot commented Dec 4, 2024

Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/12157578742.
Workflow: On demand build Docker image and deploy preview.
skip-tests: . env: .
PR: 37940.
recreate: .

Copy link

github-actions bot commented Dec 4, 2024

Deploy-Preview-URL: https://ce-37940.dp.appsmith.com

@brayn003 brayn003 merged commit 9c669dd into release Dec 4, 2024
87 checks passed
@brayn003 brayn003 deleted the fix/usage-pulse branch December 4, 2024 14:13
brayn003 added a commit that referenced this pull request Dec 5, 2024
## Description
- For usage pulse we need pageId
- URL contains basePageId
- basePageId needs to be converted to pageId
- The conversion needs application data to be populated into redux
- The PR adds a wait for application to initialise first before sending
the usage pulse


Fixes [37904](#37904)

## Automation

/ok-to-test tags="@tag.All"

### 🔍 Cypress test results
<!-- This is an auto-generated comment: Cypress test results  -->
> [!TIP]
> 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/12157463790>
> Commit: b4c4df1
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=12157463790&attempt=2"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.All`
> Spec:
> <hr>Wed, 04 Dec 2024 11:40:43 UTC
<!-- end of auto-generated comment: Cypress test results  -->


## Communication
Should the DevRel and Marketing teams inform users about this change?
- [ ] Yes
- [ ] No


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **New Features**
- Enhanced user navigation tracking with improved handling of route
changes.
- Introduced a new function for managing user activity tracking,
improving clarity and control flow.

- **Bug Fixes**
- Improved error handling during route changes to ensure proper logging.

- **Refactor**
- Restructured user-related sagas for better organization and separation
of concerns.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
btsgh added a commit that referenced this pull request Dec 5, 2024
brayn003 added a commit that referenced this pull request Dec 5, 2024
- For usage pulse we need pageId
- URL contains basePageId
- basePageId needs to be converted to pageId
- The conversion needs application data to be populated into redux
- The PR adds a wait for application to initialise first before sending
the usage pulse

Fixes [37904](#37904)

/ok-to-test tags="@tag.All"

<!-- This is an auto-generated comment: Cypress test results  -->
> [!TIP]
> 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/12157463790>
> Commit: b4c4df1
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=12157463790&attempt=2"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.All`
> Spec:
> <hr>Wed, 04 Dec 2024 11:40:43 UTC
<!-- end of auto-generated comment: Cypress test results  -->

Should the DevRel and Marketing teams inform users about this change?
- [ ] Yes
- [ ] No

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

- **New Features**
- Enhanced user navigation tracking with improved handling of route
changes.
- Introduced a new function for managing user activity tracking,
improving clarity and control flow.

- **Bug Fixes**
- Improved error handling during route changes to ensure proper logging.

- **Refactor**
- Restructured user-related sagas for better organization and separation
of concerns.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
brayn003 added a commit that referenced this pull request Dec 5, 2024
## Description
- For usage pulse we need pageId
- URL contains basePageId
- basePageId needs to be converted to pageId
- The conversion needs application data to be populated into redux
- The PR adds a wait for application to initialise first before sending
the usage pulse


Fixes [37904](#37904)

## Automation

/ok-to-test tags="@tag.All"

### 🔍 Cypress test results
<!-- This is an auto-generated comment: Cypress test results  -->
> [!TIP]
> 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/12157463790>
> Commit: b4c4df1
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=12157463790&attempt=2"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.All`
> Spec:
> <hr>Wed, 04 Dec 2024 11:40:43 UTC
<!-- end of auto-generated comment: Cypress test results  -->


## Communication
Should the DevRel and Marketing teams inform users about this change?
- [ ] Yes
- [ ] No


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **New Features**
- Enhanced user navigation tracking with improved handling of route
changes.
- Introduced a new function for managing user activity tracking,
improving clarity and control flow.

- **Bug Fixes**
- Improved error handling during route changes to ensure proper logging.

- **Refactor**
- Restructured user-related sagas for better organization and separation
of concerns.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
github-actions bot pushed a commit to Zeral-Zhang/appsmith that referenced this pull request Dec 9, 2024
## Description
- For usage pulse we need pageId
- URL contains basePageId
- basePageId needs to be converted to pageId
- The conversion needs application data to be populated into redux
- The PR adds a wait for application to initialise first before sending
the usage pulse


Fixes [37904](appsmithorg#37904)

## Automation

/ok-to-test tags="@tag.All"

### 🔍 Cypress test results
<!-- This is an auto-generated comment: Cypress test results  -->
> [!TIP]
> 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/12157463790>
> Commit: b4c4df1
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=12157463790&attempt=2"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.All`
> Spec:
> <hr>Wed, 04 Dec 2024 11:40:43 UTC
<!-- end of auto-generated comment: Cypress test results  -->


## Communication
Should the DevRel and Marketing teams inform users about this change?
- [ ] Yes
- [ ] No


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **New Features**
- Enhanced user navigation tracking with improved handling of route
changes.
- Introduced a new function for managing user activity tracking,
improving clarity and control flow.

- **Bug Fixes**
- Improved error handling during route changes to ensure proper logging.

- **Refactor**
- Restructured user-related sagas for better organization and separation
of concerns.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
brayn003 added a commit that referenced this pull request Dec 10, 2024
- For usage pulse we need pageId
- URL contains basePageId
- basePageId needs to be converted to pageId
- The conversion needs application data to be populated into redux
- The PR adds a wait for application to initialise first before sending
the usage pulse

Fixes [37904](#37904)

/ok-to-test tags="@tag.All"

<!-- This is an auto-generated comment: Cypress test results  -->
> [!TIP]
> 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/12157463790>
> Commit: b4c4df1
> <a

href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=12157463790&attempt=2"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.All`
> Spec:
> <hr>Wed, 04 Dec 2024 11:40:43 UTC
<!-- end of auto-generated comment: Cypress test results  -->

Should the DevRel and Marketing teams inform users about this change?
- [ ] Yes
- [ ] No

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

- **New Features**
- Enhanced user navigation tracking with improved handling of route
changes.
- Introduced a new function for managing user activity tracking,
improving clarity and control flow.

- **Bug Fixes**
- Improved error handling during route changes to ensure proper logging.

- **Refactor**
- Restructured user-related sagas for better organization and separation
of concerns.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
brayn003 added a commit that referenced this pull request Dec 10, 2024
- For usage pulse we need pageId
- URL contains basePageId
- basePageId needs to be converted to pageId
- The conversion needs application data to be populated into redux
- The PR adds a wait for application to initialise first before sending
the usage pulse

Fixes [37904](#37904)

/ok-to-test tags="@tag.All"

<!-- This is an auto-generated comment: Cypress test results  -->
> [!TIP]
> 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/12157463790>
> Commit: b4c4df1
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=12157463790&attempt=2"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.All`
> Spec:
> <hr>Wed, 04 Dec 2024 11:40:43 UTC
<!-- end of auto-generated comment: Cypress test results  -->

Should the DevRel and Marketing teams inform users about this change?
- [ ] Yes
- [ ] No

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

- **New Features**
- Enhanced user navigation tracking with improved handling of route
changes.
- Introduced a new function for managing user activity tracking,
improving clarity and control flow.

- **Bug Fixes**
- Improved error handling during route changes to ensure proper logging.

- **Refactor**
- Restructured user-related sagas for better organization and separation
of concerns.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
brayn003 added a commit that referenced this pull request Dec 10, 2024
## Description
- For usage pulse we need pageId
- URL contains basePageId
- basePageId needs to be converted to pageId
- The conversion needs application data to be populated into redux
- The PR adds a wait for application to initialise first before sending
the usage pulse


Fixes [37904](#37904)

## Automation

/ok-to-test tags="@tag.All"

### 🔍 Cypress test results
<!-- This is an auto-generated comment: Cypress test results  -->
> [!TIP]
> 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/12157463790>
> Commit: b4c4df1
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=12157463790&attempt=2"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.All`
> Spec:
> <hr>Wed, 04 Dec 2024 11:40:43 UTC
<!-- end of auto-generated comment: Cypress test results  -->


## Communication
Should the DevRel and Marketing teams inform users about this change?
- [ ] Yes
- [ ] No


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **New Features**
- Enhanced user navigation tracking with improved handling of route
changes.
- Introduced a new function for managing user activity tracking,
improving clarity and control flow.

- **Bug Fixes**
- Improved error handling during route changes to ensure proper logging.

- **Refactor**
- Restructured user-related sagas for better organization and separation
of concerns.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
@coderabbitai coderabbitai bot mentioned this pull request Dec 17, 2024
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Billing & Licensing Product Issues pertaining to licensing, billing and usage across self serve and enterprise customers Billing Billing infrastructure and flows for Business Edition and Trial users Bug Something isn't working High This issue blocks a user from building or impacts a lot of users Needs Triaging Needs attention from maintainers to triage ok-to-test Required label for CI Production
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: The usage pulse is not triggered for a public apps
2 participants