Skip to content

chore: remove analytics execution from the critical path#39757

Merged
vsvamsi1 merged 3 commits intoreleasefrom
test62
Mar 18, 2025
Merged

chore: remove analytics execution from the critical path#39757
vsvamsi1 merged 3 commits intoreleasefrom
test62

Conversation

@vsvamsi1
Copy link
Contributor

@vsvamsi1 vsvamsi1 commented Mar 17, 2025

Description

  • Pushed out the sendExecuteAnalyticsEvent from the critical path of returning action's execution result.
  • Improved the critical Path of sendExecuteAnalyticsEvent by running the application mono concurrent to other events.
  • Added more telemetry code around the execution flow.

Fixes #Issue Number
or
Fixes Issue URL

Warning

If no issue exists, please create an issue first, and check with the maintainers if the issue is valid.

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/13919689126
Commit: ddf93dd
Cypress dashboard.
Tags: @tag.All
Spec:


Tue, 18 Mar 2025 10:28:52 UTC

Communication

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

  • Yes
  • No

Summary by CodeRabbit

  • New Features
    • Introduced additional action tracking identifiers to support enhanced analytics and authentication validation.
  • Refactor
    • Optimized asynchronous operations for data retrieval to improve responsiveness.
    • Enhanced the flow and error handling of action execution, ensuring smoother and more reliable performance.

…f the action's execution result and also optimised analystics to execute the application mono concurrently
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 17, 2025

Walkthrough

This update adds three new constants in the action span definitions to support additional identifiers. It refines the reactive execution in the datasource context service by scheduling blocking calls on a bounded elastic thread. In the action execution solution, the control flow is modified to enhance observability and error handling by integrating new reactive operations, including asynchronous analytics event sending.

Changes

File Change Summary
app/.../ActionSpanCE.java Added three new public static constants: VALIDATE_AUTHENTICATION_DATASOURCE_STORAGE, VERIFY_DATASOURCE_AND_MAKE_REQUEST, and SEND_EXECUTE_ANALYTICS_EVENT to define new action span identifiers.
app/.../DatasourceContextServiceCEImpl.java Modified the getRemoteDatasourceContext method to include subscribeOn(Schedulers.boundedElastic()) in the reactive chain for retrieving the instance ID.
app/.../ActionExecutionSolutionCEImpl.java Updated reactive chain in executeAction and verifyDatasourceAndMakeRequest for improved observability; refactored sendExecuteAnalyticsEvent to use an applicationMono zip operation and non-blocking async execution using bounded elastic scheduling.

Sequence Diagram(s)

sequenceDiagram
    participant Client as Client
    participant DSContext as DatasourceContextServiceCEImpl
    participant Config as configService
    Client->>DSContext: getRemoteDatasourceContext()
    DSContext->>Config: getInstanceId()
    Config-->>DSContext: Instance ID
    DSContext->>DSContext: subscribeOn(Schedulers.boundedElastic())
    DSContext-->>Client: DatasourceContext
Loading
sequenceDiagram
    participant Client as Client
    participant ActionExec as ActionExecutionSolutionCEImpl
    participant Analytics as sendExecuteAnalyticsEvent (Async)
    
    Client->>ActionExec: executeAction(...)
    ActionExec->>ActionExec: Process reactive chain with map & doOnSuccess
    ActionExec-->>Analytics: Trigger analytics event asynchronously 
    Analytics-->>ActionExec: Event processed
    ActionExec-->>Client: ActionExecutionResult
Loading

Possibly related PRs

Suggested labels

Task, Enhancement, skip-changelog, ok-to-test, Query & JS Pod

Suggested reviewers

  • ApekshaBhosale
  • NilanshBansal
  • dvj1988

Poem

In code we trust, new constants unfurled,
Threads shift smoothly in a reactive world,
Observability shines in every function call,
Analytics dance while async tasks enthrall,
CodeRabbit cheers as new features stand tall!

Tip

⚡🧪 Multi-step agentic review comment chat (experimental)
  • We're introducing multi-step agentic chat in review comments. This experimental feature enhances review discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments.
    - To enable this feature, set early_access to true under in the settings.

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5364a6c and 3c32cb1.

📒 Files selected for processing (3)
  • app/server/appsmith-interfaces/src/main/java/com/appsmith/external/constants/spans/ce/ActionSpanCE.java (1 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/DatasourceContextServiceCEImpl.java (1 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/solutions/ce/ActionExecutionSolutionCEImpl.java (5 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: perform-test / rts-build / build
  • GitHub Check: perform-test / client-build / client-build
  • GitHub Check: perform-test / server-build / server-unit-tests
  • GitHub Check: server-unit-tests / server-unit-tests
  • GitHub Check: server-spotless / spotless-check
🔇 Additional comments (8)
app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/DatasourceContextServiceCEImpl.java (1)

560-573: Good reactive pattern usage.
Your approach with subscribeOn(Schedulers.boundedElastic()) for the blocking getInstanceId() call and then mapping into the new ExecutePluginDTO looks correct. If needed, you may consider catching potential errors and handling them upstream.

app/server/appsmith-interfaces/src/main/java/com/appsmith/external/constants/spans/ce/ActionSpanCE.java (1)

25-30: Clean addition of new span constants.
They appear consistent with the existing naming convention under APPSMITH_SPAN_PREFIX.

app/server/appsmith-server/src/main/java/com/appsmith/server/solutions/ce/ActionExecutionSolutionCEImpl.java (6)

71-72: Imports align with new concurrency and tuple usage.
Imported Schedulers and Tuple2 integrally support your asynchronous transformations.


769-770: Appropriate naming for metric observation.
name(VALIDATE_AUTHENTICATION_DATASOURCE_STORAGE) clearly distinguishes this stage in your reactive flow.


916-921: Handle zero or negative timeout edge cases.
Consider validating timeoutDuration to avoid unintended behavior if it's null or negative.

Do you want to confirm usage of timeoutDuration across the codebase to ensure no invalid values cause unhandled timeouts?


928-937: Time measurement logic is clear.
Using .elapsed() followed by a debug log is a neat approach for tracking execution duration.


938-955: Separate-thread analytics approach is well-structured.
Executing sendExecuteAnalyticsEvent on a bounded elastic thread ensures non-blocking. Error handling inside the event method looks fine.


1112-1115: Silent fallback on missing application.
Using .defaultIfEmpty(new Application()) avoids errors if the application is not found, but it could mask missed references or configuration issues.

Would you like to confirm that returning an empty Application is the intended design, or should we surface a warning or error?

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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 generate docstrings to generate docstrings for this 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.

@vsvamsi1 vsvamsi1 self-assigned this Mar 17, 2025
@vsvamsi1 vsvamsi1 added the ok-to-test Required label for CI label Mar 17, 2025
@vsvamsi1 vsvamsi1 marked this pull request as draft March 17, 2025 19:13
@github-actions github-actions bot added the skip-changelog Adding this label to a PR prevents it from being listed in the changelog label Mar 17, 2025
@vsvamsi1 vsvamsi1 marked this pull request as ready for review March 18, 2025 05:47
});
return configService
.getInstanceId()
.subscribeOn(Schedulers.boundedElastic())
Copy link
Contributor

Choose a reason for hiding this comment

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

@vsvamsi1 why did you introduced new thread here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because this is a configService.getInstanceId() a db call, Schedulers.boundedElastic() threads are designed blocking/longer execution tasks.

Copy link
Contributor

Choose a reason for hiding this comment

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

@NilanshBansal then why here? here as well only datasourceContext getting returned

Copy link
Contributor

@NilanshBansal NilanshBansal Mar 18, 2025

Choose a reason for hiding this comment

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

@vsvamsi1 we can avoid subscribing this on a scheduler as the ReactiveCrudRepository is already non blocking and handling the database calls. Also, the instanceId is already cached and it is only the first time that a database call is made
cc: @ApekshaBhosale

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@NilanshBansal Cool i will remove the scheduler part of it but can you point me to where the instanceId is cached?

@vsvamsi1 vsvamsi1 requested a review from ApekshaBhosale March 18, 2025 06:49
NilanshBansal
NilanshBansal previously approved these changes Mar 18, 2025
Copy link
Contributor

@NilanshBansal NilanshBansal left a comment

Choose a reason for hiding this comment

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

LGTM

@vsvamsi1 vsvamsi1 requested a review from NilanshBansal March 18, 2025 09:24
@vsvamsi1 vsvamsi1 added ok-to-test Required label for CI and removed ok-to-test Required label for CI labels Mar 18, 2025
@vsvamsi1 vsvamsi1 requested a review from ApekshaBhosale March 18, 2025 09:53
@vsvamsi1 vsvamsi1 enabled auto-merge (squash) March 18, 2025 10:29
});
return configService
.getInstanceId()
.subscribeOn(Schedulers.boundedElastic())
Copy link
Contributor

Choose a reason for hiding this comment

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

@NilanshBansal then why here? here as well only datasourceContext getting returned

@vsvamsi1 vsvamsi1 merged commit 20317c5 into release Mar 18, 2025
90 of 91 checks passed
@vsvamsi1 vsvamsi1 deleted the test62 branch March 18, 2025 11:51
vsvamsi1 added a commit that referenced this pull request Mar 19, 2025
github-actions bot pushed a commit to Zeral-Zhang/appsmith that referenced this pull request Apr 12, 2025
…#39757)

## Description

- Pushed out the sendExecuteAnalyticsEvent from the critical path of
returning action's execution result.
- Improved the critical Path of sendExecuteAnalyticsEvent by running the
application mono concurrent to other events.
- Added more telemetry code around the execution flow.


Fixes #`Issue Number`  
_or_  
Fixes `Issue URL`
> [!WARNING]  
> _If no issue exists, please create an issue first, and check with the
maintainers if the issue is valid._

## 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/13919689126>
> Commit: ddf93dd
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=13919689126&attempt=1"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.All`
> Spec:
> <hr>Tue, 18 Mar 2025 10:28:52 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**
- Introduced additional action tracking identifiers to support enhanced
analytics and authentication validation.
- **Refactor**
- Optimized asynchronous operations for data retrieval to improve
responsiveness.
- Enhanced the flow and error handling of action execution, ensuring
smoother and more reliable performance.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ok-to-test Required label for CI skip-changelog Adding this label to a PR prevents it from being listed in the changelog

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants