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: Stopped calling usage pulse in air-gapped instance #38749

Open
wants to merge 3 commits into
base: release
Choose a base branch
from

Conversation

albinAppsmith
Copy link
Collaborator

@albinAppsmith albinAppsmith commented Jan 17, 2025

Description

This PR added fix for not triggering usage pulse for air gapped instances

Fixes https://github.com/appsmithorg/cloud-services/issues/1883

Automation

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

🔍 Cypress test results

Important

🟣 🟣 🟣 Your tests are running.
Tests running at: https://github.com/appsmithorg/appsmith/actions/runs/12861462235
Commit: 1f76f11
Workflow: PR Automation test suite
Tags: @tag.Sanity
Spec: ``


Mon, 20 Jan 2025 05:15:10 UTC

Communication

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

  • Yes
  • No

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced user activity tracking by introducing airgapped environment detection, preventing unnecessary tracking in restricted network settings.
  • Tests
    • Added a new test suite to verify the behavior of the user activity tracking method in airgapped conditions.

Copy link
Contributor

coderabbitai bot commented Jan 17, 2025

Walkthrough

The pull request introduces a modification to the sendPulseAndScheduleNext method in the UsagePulse class. A new check using the isAirgapped() function has been added to prevent sending usage pulse and scheduling activity listeners when the application is in an airgapped state. This change ensures that usage tracking is conditionally executed based on the application's network environment.

Changes

File Change Summary
app/client/src/usagePulse/index.ts Added import for isAirgapped and implemented conditional exit in sendPulseAndScheduleNext method when application is airgapped. Added static property isAirgapped.
ee/utils/airgapHelpers Introduced isAirgapped method to determine application's airgapped status.
app/client/src/usagePulse/usagePulse.test.ts Added a new test suite for sendPulseAndScheduleNext method to verify behavior when isAirgapped is true.

Possibly related PRs

  • feat: Added analytics for pulse failure #37781: This PR adds analytics for pulse failures, which is directly related to the changes in the main PR that modify the sendPulseAndScheduleNext method to handle the airgapped state, potentially affecting how pulse failures are tracked.
  • fix: fixing usage pulse for anon user #37940: This PR addresses the usage pulse for anonymous users, which is relevant as it deals with the conditions under which the usage pulse is sent, similar to the modifications made in the main PR regarding the isAirgapped property.
  • fix: UsagePulse initialisation flow #38555: This PR focuses on the initialization flow of the usage pulse, ensuring that it waits for the correct events before sending, which aligns with the changes in the main PR that modify the control flow of the sendPulseAndScheduleNext method.

Suggested reviewers

  • abhvsn

Poem

🌐 In networks vast and signals bright,
A pulse checks if the path is tight.
Airgapped worlds, silent and clear,
No tracking whispers lingering near.
Code's guardian, watchful and wise! 🛡️

Finishing Touches

  • 📝 Generate Docstrings (Beta)

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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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.

@github-actions github-actions bot added the Bug Something isn't working label Jan 17, 2025
@albinAppsmith albinAppsmith added the ok-to-test Required label for CI label Jan 17, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
app/client/src/usagePulse/index.ts (1)

147-152: Consider adding logging for skipped pulses.

The airgapped check implementation is correct, but consider these improvements:

  1. Rename _isAirgapped to isAirgappedInstance for clarity
  2. Add debug logging when skipping pulse in airgapped mode
-    const _isAirgapped = isAirgapped();
+    const isAirgappedInstance = isAirgapped();
+
+    if (isAirgappedInstance) {
+      log.debug("Skipping usage pulse for air-gapped instance");
+      return;
+    }
-    if (_isAirgapped) {
-      return;
-    }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 19002c3 and fea8de5.

📒 Files selected for processing (1)
  • app/client/src/usagePulse/index.ts (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: client-unit-tests / client-unit-tests
  • GitHub Check: client-lint / client-lint
  • GitHub Check: client-check-cyclic-deps / check-cyclic-dependencies
  • GitHub Check: client-prettier / prettier-check
  • GitHub Check: client-build / client-build
🔇 Additional comments (1)
app/client/src/usagePulse/index.ts (1)

21-21: LGTM! Clean import addition.

Comment on lines 147 to 152
const _isAirgapped = isAirgapped();

if (_isAirgapped) {
return;
}

Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Codebase verification

Add test coverage for air-gapped usage pulse prevention

The air-gapped check implementation is correct, but test coverage is missing for this scenario. Add test cases to verify usage pulse behavior in air-gapped mode.

  • Add test in app/client/src/usagePulse/usagePulse.test.ts to verify that pulse is not sent when system is air-gapped
🔗 Analysis chain

Verify complete coverage of usage pulse prevention.

Let's verify there aren't other places where usage pulse might be triggered in air-gapped instances.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for other potential usage pulse triggers
rg -l "sendPulse|UsagePulse" --type ts

# Search for test coverage of air-gapped scenarios
rg -l "isAirgapped.*test" --type ts

Length of output: 445


Script:

#!/bin/bash
# Check saga implementations
rg "sendPulse|UsagePulse" app/client/src/ce/sagas/userSagas.tsx app/client/src/ce/sagas/NavigationSagas.ts -C 2

# Review test coverage
cat app/client/src/usagePulse/usagePulse.test.ts

# Check air-gapped implementation
cat app/client/src/api/interceptors/request/blockAirgappedRoutes.ts

Length of output: 4876

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
app/client/src/usagePulse/index.ts (1)

21-21: Consider dynamic air-gapped state check

The static initialization of isAirgapped won't reflect runtime changes to the air-gapped state.

 import { isAirgapped } from "ee/utils/airgapHelpers";

 class UsagePulse {
-  static isAirgapped = isAirgapped();
+  static get isAirgapped() {
+    return isAirgapped();
+  }

Also applies to: 30-30

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between fea8de5 and 1f76f11.

📒 Files selected for processing (2)
  • app/client/src/usagePulse/index.ts (3 hunks)
  • app/client/src/usagePulse/usagePulse.test.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: perform-test / client-build / client-build
  • GitHub Check: client-unit-tests / client-unit-tests
  • GitHub Check: client-build / client-build
🔇 Additional comments (1)
app/client/src/usagePulse/index.ts (1)

148-151: LGTM! Clean implementation of air-gapped check

The early return when air-gapped effectively prevents both pulse sending and listener scheduling.

Comment on lines +33 to +39
describe("sendPulseAndScheduleNext", () => {
it("should not send pulse when airgapped", () => {
//set isAirgapped to true
UsagePulse.isAirgapped = true;
UsagePulse.sendPulseAndScheduleNext();
});
});
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Enhance test coverage for air-gapped scenario

The test case needs to verify that the pulse is not sent and clean up the test state.

   describe("sendPulseAndScheduleNext", () => {
     it("should not send pulse when airgapped", () => {
-      //set isAirgapped to true
+      const sendPulseSpy = jest.spyOn(UsagePulse, 'sendPulse');
       UsagePulse.isAirgapped = true;
+      
       UsagePulse.sendPulseAndScheduleNext();
+      
+      expect(sendPulseSpy).not.toHaveBeenCalled();
+      sendPulseSpy.mockRestore();
+    });
+    
+    afterEach(() => {
+      UsagePulse.isAirgapped = false;
     });
   });
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
describe("sendPulseAndScheduleNext", () => {
it("should not send pulse when airgapped", () => {
//set isAirgapped to true
UsagePulse.isAirgapped = true;
UsagePulse.sendPulseAndScheduleNext();
});
});
describe("sendPulseAndScheduleNext", () => {
it("should not send pulse when airgapped", () => {
const sendPulseSpy = jest.spyOn(UsagePulse, 'sendPulse');
UsagePulse.isAirgapped = true;
UsagePulse.sendPulseAndScheduleNext();
expect(sendPulseSpy).not.toHaveBeenCalled();
sendPulseSpy.mockRestore();
});
afterEach(() => {
UsagePulse.isAirgapped = false;
});
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working ok-to-test Required label for CI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant