Skip to content

Conversation

@bhanvimenghani
Copy link
Contributor

@bhanvimenghani bhanvimenghani commented Dec 26, 2025

Description:

Adds support for displaying environment variable parameters in recommendation configurations.

Changes:

  • Updated 4 recommendation detail components (PerfDetails & CostDetails for LocalMonitoring and RemoteMonitoring)
  • Extracts and displays env parameters from recommendation_engines.{cost|performance}.config.env
  • Conditionally shows env section only when present in API response

Summary by Sourcery

Add UI support to surface environment variable parameters in recommendation details for both cost and performance views across local and remote monitoring.

New Features:

  • Display recommended environment variable parameters in Remote Monitoring cost and performance recommendation details when provided by the API.
  • Display recommended environment variable parameters in Local Monitoring cost and performance recommendation details when provided by the API.

Enhancements:

  • Normalize and tidy YAML-like resource block formatting in cost and performance detail views for current and recommended configurations.

@bhanvimenghani bhanvimenghani self-assigned this Dec 26, 2025
@sourcery-ai
Copy link

sourcery-ai bot commented Dec 26, 2025

Reviewer's Guide

Adds conditional rendering and formatting of environment variable parameters in recommendation detail code snippets for both cost and performance views in Local and Remote Monitoring, while normalizing YAML-like output formatting.

Class diagram for recommendation details components env handling

classDiagram
  class CostDetailsRemote {
    +recommendedData any[]
    +currentData any[]
    +chartData any
    +day any
    +endt any
    +formatEnvParams(recommendedData any[]): string
    +buildRecommendedCode(): string
  }

  class PerfDetailsRemote {
    +recommendedData any[]
    +currentData any[]
    +chartData any
    +day any
    +endt any
    +formatEnvParams(recommendedData any[]): string
    +buildRecommendedCode(): string
  }

  class CostDetailsLocal {
    +recommendedData any[]
    +currentData any[]
    +chartData any
    +day any
    +endt any
    +experimentType string
    +formatEnvParams(recommendedData any[]): string
    +buildRecommendedCode(): string
  }

  class PerfDetailsLocal {
    +recommendedData any[]
    +currentData any[]
    +chartData any
    +day any
    +endt any
    +experimentType string
    +formatEnvParams(recommendedData any[]): string
    +buildRecommendedCode(): string
  }

  class RecommendationData {
    +requests any
    +limits any
    +recommendation_engines RecommendationEngines
  }

  class RecommendationEngines {
    +cost RecommendationEngine
    +performance RecommendationEngine
  }

  class RecommendationEngine {
    +config RecommendationEngineConfig
    +variation any
  }

  class RecommendationEngineConfig {
    +requests any
    +limits any
    +env EnvParam[]
  }

  class EnvParam {
    +name string
    +value string
  }

  CostDetailsRemote --> RecommendationData : uses_recommendedData
  PerfDetailsRemote --> RecommendationData : uses_recommendedData
  CostDetailsLocal --> RecommendationData : uses_recommendedData
  PerfDetailsLocal --> RecommendationData : uses_recommendedData

  RecommendationData --> RecommendationEngines : has
  RecommendationEngines --> RecommendationEngine : cost_and_performance
  RecommendationEngine --> RecommendationEngineConfig : has
  RecommendationEngineConfig --> EnvParam : env_parameters

  CostDetailsRemote ..> EnvParam : formats_env_section
  PerfDetailsRemote ..> EnvParam : formats_env_section
  CostDetailsLocal ..> EnvParam : formats_env_section
  PerfDetailsLocal ..> EnvParam : formats_env_section
Loading

File-Level Changes

Change Details Files
Display env parameters for cost recommendations in Remote Monitoring details when provided by the API.
  • Extract env array from recommended cost recommendation engine config using optional chaining.
  • Build an envSection string in YAML-like format only when env entries exist.
  • Append envSection to the recommended_code snippet so env vars render alongside resource requests and limits.
  • Normalize whitespace in current_code and recommended_code resource blocks.
src/app/Analytics/RemoteMonitoring/RecommendationComponents/CostDetails.tsx
Display env parameters for performance recommendations in Remote Monitoring details when provided by the API.
  • Extract env array from recommended performance recommendation engine config using optional chaining.
  • Build an envSection string in YAML-like format only when env entries exist.
  • Append envSection to the recommended_code snippet so env vars render alongside resource requests and limits.
  • Normalize whitespace in current_code and recommended_code resource blocks.
src/app/Analytics/RemoteMonitoring/RecommendationComponents/PerfDetails.tsx
Display env parameters for cost recommendations in Local Monitoring recommendation details when provided by the API.
  • Extract env array from recommended cost recommendation engine config using optional chaining.
  • Build an envSection string in YAML-like format only when env entries exist.
  • Append envSection to the recommended_code snippet so env vars render below resource requests and limits.
  • Normalize spacing and colons in the YAML-like resource_name block.
src/app/Analytics/LocalMonitoring/RecommendationsForLocalMonitoring/RemoteMonitoring/RecommendationComponents/CostDetails.tsx
Display env parameters for performance recommendations in Local Monitoring recommendation details when provided by the API.
  • Extract env array from recommended performance recommendation engine config using optional chaining.
  • Build an envSection string in YAML-like format only when env entries exist.
  • Append envSection to the recommended_code snippet so env vars render below resource requests and limits.
  • Normalize spacing and colons in the YAML-like resource_name block.
src/app/Analytics/LocalMonitoring/RecommendationsForLocalMonitoring/RemoteMonitoring/RecommendationComponents/PerfDetails.tsx

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've found 2 issues, and left some high level feedback:

  • The envParamsenvSection formatting logic is duplicated across four components; consider extracting this into a shared utility/helper to avoid repetition and keep formatting consistent.
  • When interpolating e.value into the YAML-like output, consider escaping or sanitizing values (e.g., embedded quotes or newlines) so that the generated snippet remains valid and copy‑paste‑able.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The `envParams``envSection` formatting logic is duplicated across four components; consider extracting this into a shared utility/helper to avoid repetition and keep formatting consistent.
- When interpolating `e.value` into the YAML-like output, consider escaping or sanitizing values (e.g., embedded quotes or newlines) so that the generated snippet remains valid and copy‑paste‑able.

## Individual Comments

### Comment 1
<location> `src/app/Analytics/RemoteMonitoring/RecommendationComponents/CostDetails.tsx:38-40` </location>
<code_context>
-  const recommended_code = `${resource_name}: 
-  requests: 
+  // Format env parameters if they exist
+  const envParams = props.recommendedData[0]?.recommendation_engines?.cost?.config?.env;
+  const envSection = envParams?.length > 0
+    ? '\nenv:\n' + envParams.map(e => `  - name: ${e.name}\n    value: "${e.value}"`).join('\n')
+    : '';
+
</code_context>

<issue_to_address>
**issue (bug_risk):** Environment values are interpolated without escaping, which can break the rendered YAML when values contain quotes or newlines.

Values containing quotes, newlines, or `#` will produce invalid or misleading YAML in this template. It’d be safer to run each `env` value through a quoting/escaping helper (for example, wrapping in single quotes and escaping internal single quotes, and normalizing/removing newlines) before interpolating into the YAML string.
</issue_to_address>

### Comment 2
<location> `src/app/Analytics/RemoteMonitoring/RecommendationComponents/PerfDetails.tsx:37-39` </location>
<code_context>
-  const recommended_code = `${resource_name}: 
-  requests: 
+  // Format env parameters if they exist
+  const envParams = props.recommendedData[0]?.recommendation_engines?.performance?.config?.env;
+  const envSection = envParams?.length > 0
+    ? '\nenv:\n' + envParams.map(e => `  - name: ${e.name}\n    value: "${e.value}"`).join('\n')
+    : '';
+
</code_context>

<issue_to_address>
**suggestion:** The env formatting logic is duplicated across multiple components and could be centralized.

Similar `envParams` / `envSection` logic now lives in multiple components (including the local monitoring variants). Consider extracting a shared helper (e.g., `formatEnv(envParams)`) to avoid duplication and ensure YAML formatting stays consistent if the behavior changes later.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines +38 to +40
const envParams = props.recommendedData[0]?.recommendation_engines?.cost?.config?.env;
const envSection = envParams?.length > 0
? '\nenv:\n' + envParams.map(e => ` - name: ${e.name}\n value: "${e.value}"`).join('\n')
Copy link

Choose a reason for hiding this comment

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

issue (bug_risk): Environment values are interpolated without escaping, which can break the rendered YAML when values contain quotes or newlines.

Values containing quotes, newlines, or # will produce invalid or misleading YAML in this template. It’d be safer to run each env value through a quoting/escaping helper (for example, wrapping in single quotes and escaping internal single quotes, and normalizing/removing newlines) before interpolating into the YAML string.

Comment on lines +37 to +39
const envParams = props.recommendedData[0]?.recommendation_engines?.performance?.config?.env;
const envSection = envParams?.length > 0
? '\nenv:\n' + envParams.map(e => ` - name: ${e.name}\n value: "${e.value}"`).join('\n')
Copy link

Choose a reason for hiding this comment

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

suggestion: The env formatting logic is duplicated across multiple components and could be centralized.

Similar envParams / envSection logic now lives in multiple components (including the local monitoring variants). Consider extracting a shared helper (e.g., formatEnv(envParams)) to avoid duplication and ensure YAML formatting stays consistent if the behavior changes later.

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.

1 participant