Skip to content

chore: pyroscope default sampling rates - #4596

Merged
vinayteki95 merged 2 commits into
developfrom
chore.pyroscope-setup-defaults
Sep 2, 2025
Merged

vinayteki95 merged 2 commits into
developfrom
chore.pyroscope-setup-defaults

Conversation

@vinayteki95

Copy link
Copy Markdown
Contributor

What are the changes introduced in this PR?

  • Less aggressive default pyroscope sampling configuration setup
  • Static labels for pyroscope setup ( Namespace and Instance )

What is the related Linear task?

Resolves INT-3894

Please explain the objectives of your changes below

Put down any required details on the broader aspect of your changes. If there are any dependent changes, mandatorily mention them here

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

No

Any new dependencies introduced with this change?

No

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

No

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

Yes ( Improves performance - pyroscope's aggressive defaults were consuming too much CPU and memory earlier )

@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.

@vinayteki95
vinayteki95 requested a review from a team August 29, 2025 04:29
@coderabbitai

coderabbitai Bot commented Aug 29, 2025 •

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • New Features

    • Added environment-based tags (namespace, instance, cluster) to telemetry for richer observability.
  • Performance

    • Updated profiling defaults to reduce overhead and improve sampling efficiency.
  • Bug Fixes

    • More reliable detection of integration type using path-based checks.
    • Ensured integration name always resolves to a safe fallback when unavailable.
  • Chores

    • Removed an outdated documentation comment.

Walkthrough

Updated Pyroscope initialization defaults and added env-driven tags in src/index.ts. Adjusted middleware in src/middleware.js to infer integration type via path-based checks and ensured a fallback for integration name.

Changes

Cohort / File(s) Summary
Pyroscope initialization
src/index.ts
Updated default sampling/flush values (flushIntervalMs 1000→60000, heap.samplingIntervalBytes 512→524288, wall.samplingDurationMs 1000→60000, wall.samplingIntervalMicros 1000→10000); flipped collectCpuTime env-logic to treat 'false' as false and otherwise true; added tags object populated from NAMESPACE, INSTANCE_ID, CLUSTER env vars; removed a docs URL comment; initialization flow unchanged (only when PYROSCOPE_SERVER_ADDRESS set).
Request labeling middleware
src/middleware.js
Switched integration_type detection from ctx.request.url.includes('source') to ctx.path.includes('/source'); set integration_name to `getDestTypeFromContext(ctx)

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor Process
  participant Env as Env Vars
  participant Pyro as Pyroscope SDK

  Process->>Env: Read PYROSCOPE_SERVER_ADDRESS
  alt Address present
    Process->>Env: Read NAMESPACE / INSTANCE_ID / CLUSTER
    note over Process,Env: Build tags { namespace, instance, cluster } (defaults "")
    Process->>Pyro: Initialize with updated defaults
    note right of Pyro: flushIntervalMs=60000\nheap.samplingIntervalBytes=524288\nwall.samplingDurationMs=60000\nwall.samplingIntervalMicros=10000\ncollectCpuTime default true (unless 'false')
    Pyro-->>Process: pyroscopeStart / initialized flag
  else No address
    note over Process: Skip Pyroscope initialization
  end
Loading
sequenceDiagram
  autonumber
  actor Client
  participant Koa as Middleware
  participant Ctx as ctx
  participant Util as getDestTypeFromContext
  participant Wrap as wrapWithLabels
  participant Next as Downstream Handler

  Client->>Koa: HTTP request
  Koa->>Ctx: Inspect ctx.path
  alt ctx.path includes "/source"
    Koa-->>Koa: integration_type = "source"
  else
    Koa-->>Koa: integration_type = "destination"
  end
  Koa->>Util: getDestTypeFromContext(ctx)
  Util-->>Koa: name or falsy
  Koa-->>Koa: integration_name = result || "unknown"
  Koa->>Wrap: Apply labels {type, name}
  Wrap->>Next: Invoke next middleware/handler
  Next-->>Client: Response
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested reviewers

  • sivashanmukh
  • koladilip
  • maheshkutty

Suggestions

  • Confirm the flipped collectCpuTime default is intentional and add a brief code comment.
  • Add a small integration/unit test verifying middleware sets integration_name to 'unknown' when getDestTypeFromContext returns falsy, and that /source path detection behaves as expected.
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch chore.pyroscope-setup-defaults

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.
    • 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.
  • 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 the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit 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.

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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.

@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 (3)
src/middleware.js (2)

57-57: Anchor the path check to avoid false positives.

includes('/source') may misclassify paths such as /internal/source-cache as source. Prefer an anchored test that matches our API shape.

-        integration_type: ctx.path.includes('/source') ? 'source' : 'destination',
+        // Match `/v{n}/source` or `/v{n}/sources` at the start of the path
+        integration_type: /^\/v\d+\/sources?\b/.test(ctx.path) ? 'source' : 'destination',

58-58: Clarify fallback behavior for empty strings.

If getDestTypeFromContext(ctx) returns '', || 'unknown' assigns 'unknown'. If that’s intentional, keep as-is. If you only want to fallback on null/undefined, switch to ??.

-        integration_name: getDestTypeFromContext(ctx) || 'unknown',
+        // Use `??` if you only want to fallback for null/undefined
+        integration_name: getDestTypeFromContext(ctx) ?? 'unknown',

ESLint focus (JS file):

  • Warning: prefer-nullish-coalescing (if enabled) for nullish-only fallback.
src/index.ts (1)

50-54: Avoid emitting empty-string tags; build tags dynamically.

Empty values can bloat label cardinality and clutter Pyroscope UI. Emit only tags that are set.

-    tags: {
-      namespace: process.env.NAMESPACE || '',
-      instance: process.env.INSTANCE_ID || '',
-      cluster: process.env.CLUSTER || '',
-    }
+    tags: buildPyroscopeTags(),

Add this helper (outside the shown range, e.g., above the if (process.env.PYROSCOPE_SERVER_ADDRESS) { block):

function buildPyroscopeTags(): Record<string, string> {
  const tags: Record<string, string> = {};
  if (process.env.NAMESPACE) tags.namespace = process.env.NAMESPACE!;
  if (process.env.INSTANCE_ID) tags.instance = process.env.INSTANCE_ID!;
  if (process.env.CLUSTER) tags.cluster = process.env.CLUSTER!;
  return tags;
}
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between b50b749 and 5ac1ef9.

📒 Files selected for processing (2)
  • src/index.ts (1 hunks)
  • src/middleware.js (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.js

⚙️ CodeRabbit configuration file

Focus on ESLint errors (max 3) and warnings (max 5).

Files:

  • src/middleware.js
🧬 Code graph analysis (1)
src/middleware.js (1)
src/testRouter.js (1)
  • ctx (179-179)
🪛 GitHub Actions: Verify
src/index.ts

[error] 49-50: git diff --exit-code failed with exit code 1 due to unstaged changes in src/index.ts (collectCpuTime line change).

⏰ 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). (5)
  • GitHub Check: Code Coverage
  • GitHub Check: test_and_publish
  • GitHub Check: UT Tests
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: Analyze (go)
🔇 Additional comments (2)
src/index.ts (2)

34-46: Defaults change looks good for lowering overhead.

The higher intervals (flush: 60s, heap sampling: 512 KiB, wall: 60s/10,000 µs) align with the PR goal to reduce CPU/memory. No functional concerns here.


48-48: Simplify the boolean and eliminate CI formatting diffs

  • Change the ternary to a direct inequality:
    - collectCpuTime: process.env.PYROSCOPE_WALL_COLLECT_CPU_TIME === 'false' ? false : true,
    + collectCpuTime: process.env.PYROSCOPE_WALL_COLLECT_CPU_TIME !== 'false',
  • After applying that change, re-run Prettier and commit any resulting formatting updates so CI passes without unstaged diffs.

@devops-github-rudderstack

Copy link
Copy Markdown
Contributor

Allure Test reports for this run are available at:

1 similar comment
@devops-github-rudderstack

Copy link
Copy Markdown
Contributor

Allure Test reports for this run are available at:

@manish339k
manish339k force-pushed the chore.pyroscope-setup-defaults branch from 2ce4892 to 9be4b2c Compare September 2, 2025 09:43
@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: 3

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

50-54: Avoid emitting empty tag values; send only populated tags

Empty-string tag values add noise/cardinality without value. Filter them out.

-    tags: {
-      namespace: process.env.NAMESPACE || '',
-      instance: process.env.INSTANCE_ID || '',
-      cluster: process.env.CLUSTER || '',
-    }
+    tags: Object.fromEntries(
+      Object.entries({
+        namespace: process.env.NAMESPACE,
+        instance: process.env.INSTANCE_ID,
+        cluster: process.env.CLUSTER,
+      }).filter(([, v]) => v && v.trim() !== '')
+    ) as Record<string, string>

Optional: if INSTANCE_ID isn’t provided, consider defaulting to ${process.pid} or a hostname+pid to distinguish workers.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 2ce4892 and 9be4b2c.

📒 Files selected for processing (2)
  • src/index.ts (1 hunks)
  • src/middleware.js (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/middleware.js
⏰ 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 AMD64
  • GitHub Check: Build User Transformer Docker Image - PR / Build Transformer Docker Image ARM64
  • 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: Code Coverage
  • GitHub Check: test_and_publish
  • GitHub Check: UT Tests
  • GitHub Check: Analyze (go)
  • GitHub Check: Analyze (javascript-typescript)

Comment thread src/index.ts Resolved
Comment thread src/index.ts Resolved
Comment thread src/index.ts Resolved
@codecov

codecov Bot commented Sep 2, 2025 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.78%. Comparing base (e9a4ebd) to head (9be4b2c).
⚠️ Report is 15 commits behind head on develop.

Files with missing lines Patch % Lines
src/middleware.js 0.00% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #4596      +/-   ##
===========================================
- Coverage    91.79%   91.78%   -0.01%     
===========================================
  Files          642      642              
  Lines        33928    33931       +3     
  Branches      8040     8041       +1     
===========================================
+ Hits         31143    31145       +2     
- Misses        2533     2534       +1     
  Partials       252      252              

☔ 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.

@sonarqubecloud

sonarqubecloud Bot commented Sep 2, 2025

Copy link
Copy Markdown

@vinayteki95
vinayteki95 merged commit 4869a64 into develop Sep 2, 2025
@vinayteki95
vinayteki95 deleted the chore.pyroscope-setup-defaults branch September 2, 2025 09:57
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.

4 participants