Skip to content

chore: disable pyroscope for primary process in cluster mode - #4756

Merged
shekhar-rudder merged 2 commits into
developfrom
int-4203-pyroscope
Nov 10, 2025
Merged

shekhar-rudder merged 2 commits into
developfrom
int-4203-pyroscope

Conversation

@shekhar-rudder

Copy link
Copy Markdown
Member

Summary

Disables Pyroscope profiling for the primary (master) process when running in cluster mode, while keeping it enabled for worker processes.

Changes

  • Modified Pyroscope initialization logic to skip profiling on the primary process when clustering is enabled
  • Renamed cluster import to clusterUtil to avoid naming conflict with Node.js native cluster module
  • Added explicit import of Node.js cluster module to check cluster.isPrimary

Motivation

In cluster mode, the primary process acts as a coordinator and doesn't handle actual requests - only worker processes do. Profiling the primary process provides no useful performance insights and wastes resources. This change ensures Pyroscope only profiles the worker processes that actually handle application traffic.

Any changes to existing capabilities/behaviour, mention the reason & what are the changes ?

N/A

Any new dependencies introduced with this change?

N/A

Any new generic utility introduced or modified. Please explain the changes.

N/A

Any technical or performance related pointers to consider with the change?

N/A

@coderabbitai review


Developer checklist

  • My code follows the style guidelines of this project

  • No breaking changes are being introduced.

  • All related docs linked with the PR?

  • All changes manually tested?

  • Any documentation changes needed with this change?

  • Is the PR limited to 10 file changes?

  • Is the PR limited to one linear task?

  • Are relevant unit and component test-cases added in new readability format?

Reviewer checklist

  • Is the type of change in the PR title appropriate as per the changes?

  • Verified that there are no credentials or confidential data exposed with the changes.

@shekhar-rudder
shekhar-rudder requested a review from a team as a code owner November 7, 2025 09:05
@coderabbitai

coderabbitai Bot commented Nov 7, 2025 •

Copy link
Copy Markdown
Contributor

Note

.coderabbit.yaml has unrecognized properties

CodeRabbit is using all valid settings from your configuration. Unrecognized properties (listed below) have been ignored and may indicate typos or deprecated fields that can be removed.

⚠️ Parsing warnings (1)
Validation error: Unrecognized key(s) in object: 'auto_resolve_threads'
⚙️ Configuration instructions
  • Please see the configuration documentation for more information.
  • You can also validate your configuration using the online YAML validator.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Summary by CodeRabbit

  • Refactor
    • Updated internal cluster initialization logic to use a new utility namespace.
    • Refined profiling service initialization to be conditional based on cluster configuration, ensuring it only runs when appropriate for the deployment environment.

Walkthrough

Switches cluster import to a clusterUtil namespace and gates Pyroscope startup with a new enablePyroscope condition that requires PYROSCOPE_SERVER_ADDRESS and either clustering disabled or the node not primary; uses clusterUtil.start(...) when CLUSTER_ENABLED is true.

Changes

Cohort / File(s) Summary
Cluster & Pyroscope changes
src/index.ts
Replaced direct cluster usage with a clusterUtil namespace import; added enablePyroscope which requires PYROSCOPE_SERVER_ADDRESS and cluster state (primary + CLUSTER_ENABLED); conditionalized Pyroscope init/start on enablePyroscope; call clusterUtil.start(port, app, metricsApp) when clustering is enabled.

Sequence Diagram

sequenceDiagram
    participant Entry as src/index.ts
    participant ClusterUtil as clusterUtil
    participant Cluster as cluster
    participant Pyroscope as Pyroscope
    participant App as App / metricsApp

    Entry->>Cluster: read CLUSTER_ENABLED, cluster.isPrimary
    Entry->>Entry: compute enablePyroscope = PYROSCOPE_SERVER_ADDRESS && (!CLUSTER_ENABLED || !cluster.isPrimary)
    
    alt enablePyroscope == true
        Entry->>Pyroscope: initialize & start
        Pyroscope-->>Entry: running
    else enablePyroscope == false
        Entry->>Entry: log pyroscope disabled
    end

    alt CLUSTER_ENABLED == true
        Entry->>ClusterUtil: clusterUtil.start(port, app, metricsApp)
        ClusterUtil-->>Cluster: spawn/manage workers
    else
        Entry->>App: start server directly
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Areas to focus on:

  • Confirm enablePyroscope logic prevents duplicate profiling (primary vs worker) and matches intended semantics.
  • Verify clusterUtil.start(port, app, metricsApp) signature and behavior match previous cluster.start semantics (args, lifecycle, exit handling).
  • Ensure no code paths elsewhere assume Pyroscope was initialized unconditionally (startup ordering and error handling).
  • Check logging and observability for clarity when Pyroscope is disabled.

Possibly related PRs

Suggested reviewers

  • vinayteki95
  • maheshkutty
  • chandumlg

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately captures the main change: disabling Pyroscope for the primary process in cluster mode, which aligns with the raw summary and PR objectives.
Description check ✅ Passed The description covers all required template sections including changes, motivation, and related checklists, providing clear context for the Pyroscope cluster-mode optimization.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch int-4203-pyroscope

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/index.ts (1)

34-64: Update the log message to reflect all reasons Pyroscope may be disabled.

The log message on line 63 is now misleading. Pyroscope can be disabled either because PYROSCOPE_SERVER_ADDRESS is not set, or because the process is running as the primary in cluster mode. The current message only mentions the former.

Consider updating the log message to be more accurate:

 } else {
-  logger.info('Pyroscope disabled (PYROSCOPE_SERVER_ADDRESS not set)');
+  logger.info(
+    `Pyroscope disabled (${
+      !process.env.PYROSCOPE_SERVER_ADDRESS
+        ? 'PYROSCOPE_SERVER_ADDRESS not set'
+        : 'running as primary process in cluster mode'
+    })`,
+  );
 }
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1651d21 and c21af96.

📒 Files selected for processing (1)
  • src/index.ts (3 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/index.ts (1)
src/util/prometheus.js (1)
  • clusterEnabled (5-5)
🪛 GitHub Actions: Verify
src/index.ts

[error] 1-1: git diff --exit-code failed: differences detected in src/index.ts (added/removed import 'cluster'). Process completed with exit code 1.

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (9)
  • GitHub Check: Build User Transformer Docker Image - PR / Build Transformer Docker Image ARM64
  • GitHub Check: Build User Transformer Docker Image - PR / Build Transformer Docker Image AMD64
  • GitHub Check: Build Transformer Docker Image - PR / Build Transformer Docker Image AMD64
  • GitHub Check: Build Transformer Docker Image - PR / Build Transformer Docker Image ARM64
  • GitHub Check: Code Coverage
  • GitHub Check: test_and_publish
  • GitHub Check: UT Tests
  • GitHub Check: Analyze (go)
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (2)
src/index.ts (2)

31-32: Logic correctly implements cluster-aware Pyroscope gating.

The condition properly disables Pyroscope for the primary process in cluster mode while enabling it for workers and non-cluster deployments:

  • Non-cluster mode: Pyroscope enabled (as before)
  • Cluster primary: Pyroscope disabled (new behavior)
  • Cluster workers: Pyroscope enabled (profiling the processes that handle traffic)

116-116: Correctly updated to use the renamed cluster utility.

The call properly uses clusterUtil.start to match the renamed import, maintaining the existing cluster startup behavior.

Comment thread src/index.ts Resolved
@codecov

codecov Bot commented Nov 7, 2025 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.94%. Comparing base (80b80b1) to head (cf14895).
⚠️ Report is 28 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #4756      +/-   ##
===========================================
+ Coverage    91.91%   91.94%   +0.02%     
===========================================
  Files          651      652       +1     
  Lines        34613    34630      +17     
  Branches      8131     8147      +16     
===========================================
+ Hits         31816    31840      +24     
+ Misses        2548     2541       -7     
  Partials       249      249              

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@devops-github-rudderstack

Copy link
Copy Markdown
Contributor

Allure Test reports for this run are available at:

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/index.ts (1)

34-64: Pyroscope initialization correctly gated by enablePyroscope.

The conditional initialization at line 34 properly uses the new enablePyroscope variable, ensuring Pyroscope is only started when both the server address is configured and the process is not a cluster primary.

However, the log message at line 63 should be updated to reflect all reasons Pyroscope might be disabled.

Apply this diff to improve the log message accuracy:

 } else {
-  logger.info('Pyroscope disabled (PYROSCOPE_SERVER_ADDRESS not set)');
+  logger.info(
+    'Pyroscope disabled' +
+      (!process.env.PYROSCOPE_SERVER_ADDRESS
+        ? ' (PYROSCOPE_SERVER_ADDRESS not set)'
+        : ' (running as primary process in cluster mode)'),
+  );
 }
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c21af96 and cf14895.

📒 Files selected for processing (1)
  • src/index.ts (3 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/index.ts (1)
src/util/prometheus.js (1)
  • clusterEnabled (5-5)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (9)
  • GitHub Check: Build Transformer Docker Image - PR / Build Transformer Docker Image ARM64
  • GitHub Check: Build Transformer Docker Image - PR / Build Transformer Docker Image AMD64
  • GitHub Check: Build User Transformer Docker Image - PR / Build Transformer Docker Image ARM64
  • GitHub Check: Build User Transformer Docker Image - PR / Build Transformer Docker Image AMD64
  • GitHub Check: Code Coverage
  • GitHub Check: UT Tests
  • GitHub Check: test_and_publish
  • GitHub Check: Analyze (go)
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (3)
src/index.ts (3)

8-8: Import order now complies with ESLint rules.

The native cluster module import at line 8 now correctly precedes all local imports (including the renamed clusterUtil at line 16). This resolves the pipeline failure mentioned in the previous review.

Also applies to: 16-16


31-32: Cluster-aware Pyroscope gating logic is correct.

The enablePyroscope condition correctly implements the requirement: Pyroscope is disabled on the primary process when clustering is enabled, while remaining enabled for worker processes and for non-clustered deployments.


116-116: Correct usage of renamed clusterUtil.

The call to clusterUtil.start(...) correctly references the renamed local cluster utility import, avoiding the naming conflict with the native Node.js cluster module.

@devops-github-rudderstack

Copy link
Copy Markdown
Contributor

Allure Test reports for this run are available at:

@sonarqubecloud

sonarqubecloud Bot commented Nov 7, 2025

Copy link
Copy Markdown

@shekhar-rudder
shekhar-rudder merged commit c462af3 into develop Nov 10, 2025
@shekhar-rudder
shekhar-rudder deleted the int-4203-pyroscope branch November 10, 2025 05:36
ItsSudip added a commit that referenced this pull request Nov 12, 2025
* feat: introduce e2e tests UT (#4686)

* chore: update slack notification list (#4706)

* chore: skip pushing docker images for dependabot (#4714)

* chore: skip building images for debendabot

* chore: review comments

* chore: skip docker login for dependabot

* chore: skip docker login for dependabot

* chore: misc

* chore: misc

* chore: misc

* chore: misc

* chore: review comments

* chore: review comments

* chore: review comments

* chore: review comments

* chore: review comments

* chore: add dub to new test structure (#4717)

* chore: add readme for campaign_manager (#4710)

* chore: update GAOC readme with quota link (#4723)

* chore: apply security best practices (#4708)

[StepSecurity] Apply security best practices

Signed-off-by: StepSecurity Bot <[email protected]>

* feat: add validation of diff in staging deployment workflow (#4722)

* chore(deps-dev): bump commander from 10.0.1 to 14.0.2

Bumps [commander](https://github.com/tj/commander.js) from 10.0.1 to 14.0.2.
- [Release notes](https://github.com/tj/commander.js/releases)
- [Changelog](https://github.com/tj/commander.js/blob/master/CHANGELOG.md)
- [Commits](tj/commander.js@v10.0.1...v14.0.2)

---
updated-dependencies:
- dependency-name: commander
  dependency-version: 14.0.2
  dependency-type: direct:development
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <[email protected]>

* chore(deps-dev): bump supertest from 6.3.4 to 7.1.4 (#4525)

---
updated-dependencies:
- dependency-name: supertest
  dependency-version: 7.1.4
  dependency-type: direct:development
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* chore: add env vars for controlling the connection pooling on python transformations (#4738)

* chore: update facebook conversion api version from 22.0 to 24.0 (#4734)

* chore: update facebook conversion api version from 22.0 to 23.0

* chore: update facebook conversion api version from 23.0 to 45.0

* chore: fix typo

* chore: update facebook custom audience api version from 22.0 to 23.0 (#4735)

* chore: update facebook custom audience api version from 22.0 to 23.0

* chore: update facebook custom audience api version from 23.0 to 24.0

* chore: update facebook custom audience api version from 24.0 to 23.0 as it has some breaking changes

* chore: update facebook pixel api version from 22.0 to 24.0 (#4737)

* chore: update facebook pixel api version from 22.0 to 24.0

* chore: update facebook app events api version from 22.0 to 24.0 (#4736)

* chore: move rs-ai memory bank to transformer

* chore: add nodemon for hot reloading (#4748)

* chore: refactor code to update variable name in more readable format (#4747)

* feat: source transformation endpoint for facebook_lead_ads_native source (#4746)

* chore: disable clustering in nodemon configuration (#4749)

* chore: run format check on all files (#4750)

* fix: intercom rETL flow when user_id only provided as identifier (#4739)

* chore: apply security best practices from step security (#4727)

[StepSecurity] Apply security best practices

Signed-off-by: StepSecurity Bot <[email protected]>
Co-authored-by: stepsecurity-app[bot] <188008098+stepsecurity-app[bot]@users.noreply.github.com>

* chore(deps): bump actions/setup-node from 5.0.0 to 6.0.0

Bumps [actions/setup-node](https://github.com/actions/setup-node) from 5.0.0 to 6.0.0.
- [Release notes](https://github.com/actions/setup-node/releases)
- [Commits](actions/setup-node@v5.0.0...v6.0.0)

---
updated-dependencies:
- dependency-name: actions/setup-node
  dependency-version: 6.0.0
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <[email protected]>

* chore: remove logs logging request/response body (#4754)

* chore: disable pyroscope for primary process in cluster mode (#4756)

* feat(reddit): onboard v3 api (#4699)

* feat(reddit): onboard v3 api

* chore: implement router batching flow

* feat: enable batching scenario

* chore: add test cases

* chore: address coderabbit comments

* chore: add mock for timestamp

* chore: add documentation for reddit

* fix: use crypto for hashing

* chore: address coderabbit comment

* chore: address comments

* chore: add validation and remove double type assertion

* chore: remove undefined files from final palyload

* chore: fix test case

* feat(reddit): onboard v3 api

* chore: implement router batching flow

* feat: enable batching scenario

* chore: add test cases

* chore: address coderabbit comments

* chore: add mock for timestamp

* chore: add documentation for reddit

* fix: use crypto for hashing

* chore: address coderabbit comment

* chore: address comments

* chore: add validation and remove double type assertion

* chore: remove undefined files from final palyload

* chore: fix test case

* chore: apply format

* chore: apply format

* chore(deps): bump actions/checkout from 4.3.0 to 5.0.0

Bumps [actions/checkout](https://github.com/actions/checkout) from 4.3.0 to 5.0.0.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](actions/checkout@v4.3.0...08c6903)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-version: 5.0.0
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <[email protected]>

* feat: add advertiser_tracking_enabled mapping for pinterest without featureFlag (#4740)

* chore(deps): bump actions/stale from 10.0.0 to 10.1.0

Bumps [actions/stale](https://github.com/actions/stale) from 10.0.0 to 10.1.0.
- [Release notes](https://github.com/actions/stale/releases)
- [Changelog](https://github.com/actions/stale/blob/main/CHANGELOG.md)
- [Commits](actions/stale@v10.0.0...v10.1.0)

---
updated-dependencies:
- dependency-name: actions/stale
  dependency-version: 10.1.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>

* chore: handle breaking changes for commander

* chore: fix breaking commander changes

* chore(release): 1.112.0

---------

Signed-off-by: StepSecurity Bot <[email protected]>
Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: Rohith BCS <[email protected]>
Co-authored-by: Vinay Teki <[email protected]>
Co-authored-by: Mahesh Kutty <[email protected]>
Co-authored-by: Sudip Paul <[email protected]>
Co-authored-by: stepsecurity-app[bot] <188008098+stepsecurity-app[bot]@users.noreply.github.com>
Co-authored-by: Krishna Chaitanya <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Jayachand Mopidevi <[email protected]>
Co-authored-by: GitHub Actions <[email protected]>
Co-authored-by: shekhar-rudder <[email protected]>
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.

3 participants