Skip to content

[OSDEV-1947] Introduced support for RBA deployment, disabled CSV export in RBA, and fixed FE environment check.#614

Merged
vladsha-dev merged 14 commits intomainfrom
OSDEV-1947-add-new-environment-for-rba
May 9, 2025
Merged

[OSDEV-1947] Introduced support for RBA deployment, disabled CSV export in RBA, and fixed FE environment check.#614
vladsha-dev merged 14 commits intomainfrom
OSDEV-1947-add-new-environment-for-rba

Conversation

@vladsha-dev
Copy link
Contributor

@vladsha-dev vladsha-dev commented May 5, 2025

OSDEV-1947

  • Introduced infrastructure changes to support deployment of the RBA environment. Included it in the CD pipelines in the same way as Production and Staging, which means the RBA environment can now be deployed via Git tags just like Production and Staging.
  • Created the export_csv_enabled infrastructure switch to disable the Amazon EventBridge scheduler for the CSV export job in the RBA environment, as exporting the database to CSV is not needed in that environment.
  • Fixed a bug related to an incorrect environment check in the FE app, which attempted to identify the local environment by comparing it with development. However, the environment had been renamed to local some time ago and was no longer passed as development from the BE during local development

@vladsha-dev vladsha-dev self-assigned this May 5, 2025
@vladsha-dev vladsha-dev marked this pull request as draft May 5, 2025 12:34
@vladsha-dev vladsha-dev temporarily deployed to Quality Environment May 5, 2025 12:34 — with GitHub Actions Inactive
@vladsha-dev vladsha-dev had a problem deploying to Quality Environment May 5, 2025 12:34 — with GitHub Actions Failure
@vladsha-dev vladsha-dev temporarily deployed to Quality Environment May 5, 2025 12:34 — with GitHub Actions Inactive
@vladsha-dev vladsha-dev temporarily deployed to Quality Environment May 5, 2025 12:34 — with GitHub Actions Inactive
@vladsha-dev vladsha-dev temporarily deployed to Quality Environment May 5, 2025 12:34 — with GitHub Actions Inactive
@vladsha-dev vladsha-dev temporarily deployed to Quality Environment May 5, 2025 12:34 — with GitHub Actions Inactive
@vladsha-dev vladsha-dev temporarily deployed to Quality Environment May 5, 2025 12:34 — with GitHub Actions Inactive
@vladsha-dev vladsha-dev temporarily deployed to Quality Environment May 5, 2025 12:34 — with GitHub Actions Inactive
@vladsha-dev vladsha-dev temporarily deployed to Quality Environment May 5, 2025 12:34 — with GitHub Actions Inactive
@vladsha-dev vladsha-dev temporarily deployed to Quality Environment May 5, 2025 12:34 — with GitHub Actions Inactive
@vladsha-dev vladsha-dev temporarily deployed to Quality Environment May 5, 2025 12:34 — with GitHub Actions Inactive
@vladsha-dev vladsha-dev temporarily deployed to Quality Environment May 5, 2025 12:34 — with GitHub Actions Inactive
@vladsha-dev vladsha-dev temporarily deployed to Quality Environment May 5, 2025 12:34 — with GitHub Actions Inactive
@vladsha-dev vladsha-dev temporarily deployed to Quality Environment May 5, 2025 12:34 — with GitHub Actions Inactive
@vladsha-dev vladsha-dev temporarily deployed to Quality Environment May 5, 2025 12:37 — with GitHub Actions Inactive
@barecheck
Copy link

barecheck bot commented May 5, 2025

React App | Jest test suite - Code coverage report

Total: 34.23%

Your code coverage diff: 0.00% ▴

✅ All code changes are covered

@vladsha-dev vladsha-dev temporarily deployed to Quality Environment May 5, 2025 12:41 — with GitHub Actions Inactive
@barecheck
Copy link

barecheck bot commented May 5, 2025

Dedupe Hub App | Unittest test suite - Code coverage report

Total: 56.14%

Your code coverage diff: 0.00% ▴

✅ All code changes are covered

@vladsha-dev vladsha-dev temporarily deployed to Quality Environment May 5, 2025 12:42 — with GitHub Actions Inactive
@barecheck
Copy link

barecheck bot commented May 5, 2025

Countries App | Unittest test suite - Code coverage report

Total: 100%

Your code coverage diff: 0.00% ▴

✅ All code changes are covered

@vladsha-dev vladsha-dev temporarily deployed to Quality Environment May 5, 2025 12:42 — with GitHub Actions Inactive
@barecheck
Copy link

barecheck bot commented May 5, 2025

Contricleaner App | Unittest test suite - Code coverage report

Total: 98.75%

Your code coverage diff: 0.00% ▴

✅ All code changes are covered

@barecheck
Copy link

barecheck bot commented May 6, 2025

Django App | Unittest test suite - Code coverage report

Total: 81.06%

Your code coverage diff: 0.00% ▴

✅ All code changes are covered

@vladsha-dev vladsha-dev temporarily deployed to Quality Environment May 6, 2025 13:10 — with GitHub Actions Inactive
@vladsha-dev vladsha-dev temporarily deployed to Quality Environment May 6, 2025 13:10 — with GitHub Actions Inactive
@coderabbitai
Copy link

coderabbitai bot commented May 8, 2025

📝 Walkthrough

"""

Walkthrough

Support for a new "RBA" environment was added across deployment workflows, infrastructure configuration, and application settings. This includes workflow logic updates, new Terraform variables, ECS environment mapping, and documentation. Additionally, environment checks in the frontend were updated to use "local" instead of "development" for local development, and a toggle for the CSV export scheduler was introduced.

Changes

Files/Paths Change Summary
.github/workflows/deploy_to_aws.yml
.github/workflows/release-deploy.yml
Added "RBA" as a supported deployment environment, updated environment resolution logic, and extended input options and shell script branches to handle "RBA".
deployment/environments/terraform-rba.tfvars Added a new Terraform tfvars file defining all environment-specific variables for the "Rba" environment, including AWS, ECS, RDS, batch, and application parameters.
deployment/terraform/batch.tf
deployment/terraform/variables.tf
Added a boolean variable export_csv_enabled (default: true) to control whether the export CSV scheduled job is enabled, and updated the CloudWatch event rule to use this toggle.
doc/release/RELEASE-NOTES.md Updated release notes for version 2.4.0 to document the RBA environment support, the CSV export scheduler toggle, and a frontend environment check bugfix.
src/django/oar/settings.py Added "Rba" to valid environments and ECS environment mapping, and updated environment variable retrieval for Hubspot credentials to explicitly assign None if unset.
src/django/web/views.py Updated the comment describing possible environment values to include "rba", "local", "preprod", and "test".
src/react/public/index.html
src/react/src/util/util.ga.js
Changed environment checks for Rollbar and Google Analytics initialization from "development" to "local", altering which environments trigger these features.

Sequence Diagram(s)

sequenceDiagram
    participant Developer
    participant GitHub Actions
    participant Terraform
    participant Django App
    participant React App

    Developer->>GitHub Actions: Push branch/tag (e.g., rba-*)
    GitHub Actions->>GitHub Actions: Detect branch prefix or deploy-env input
    GitHub Actions->>GitHub Actions: Set environment to "RBA"
    GitHub Actions->>Terraform: Apply with terraform-rba.tfvars
    Terraform->>AWS: Deploy infrastructure for RBA
    GitHub Actions->>Django App: Deploy with RBA settings
    GitHub Actions->>React App: Deploy with ENVIRONMENT="rba"
    React App->>React App: Initialize Rollbar/GA (skip if ENVIRONMENT="local")
Loading

Suggested reviewers

  • VadimKovalenkoSNF
  • mazursasha1990
    """

Tip

⚡️ Faster reviews with caching
  • CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.

Enjoy the performance boost—your workflow just got faster.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9ecf5a1 and e9b87fe.

📒 Files selected for processing (1)
  • deployment/environments/terraform-rba.tfvars (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • deployment/environments/terraform-rba.tfvars
⏰ Context from checks skipped due to timeout of 90000ms (13)
  • GitHub Check: run-integration-test-code-quality
  • GitHub Check: run-flake8-linter
  • GitHub Check: run-fe-code-quality
  • GitHub Check: run-eslint-linter-and-prettier-formatter
  • GitHub Check: run-django-code-quality
  • GitHub Check: run-dd-code-quality
  • GitHub Check: run-countries-code-quality
  • GitHub Check: run-contricleaner-code-quality
  • GitHub Check: get-base-branch-fe-cov
  • GitHub Check: get-base-branch-dd-cov
  • GitHub Check: get-base-branch-countries-cov
  • GitHub Check: get-base-branch-contricleaner-cov
  • GitHub Check: get-base-branch-django-cov

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.

Support

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

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 generate sequence diagram to generate a sequence diagram of the changes in 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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • 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

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.

Copy link

@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

🔭 Outside diff range comments (1)
.github/workflows/deploy_to_aws.yml (1)

4-8: 💡 Verification agent

🧩 Analysis chain

Verify triggers for RBA branches

While you've added RBA mapping in job environment resolution, the on.push.branches section currently only includes main and releases/**. If you intend to automatically run this workflow on branches prefixed with rba-, you should add a matching pattern (e.g., rba-*). Otherwise, pushes to RBA branches will never trigger the workflow.


🏁 Script executed:

#!/bin/bash
# Check if 'rba-' branch patterns are included in push triggers
rg -n "push:" -A5 .github/workflows/deploy_to_aws.yml

Length of output: 2575


Include RBA branch triggers

The on.push.branches section only covers main and releases/**. Pushes to branches prefixed with rba- won’t trigger this workflow. To enable automatic runs on those branches, update the trigger as follows:

 on:
   push:
     branches:
       - main
       - 'releases/**'
+      - 'rba-*'

File: .github/workflows/deploy_to_aws.yml Lines 4–8

♻️ Duplicate comments (10)
.github/workflows/deploy_to_aws.yml (10)

91-91: Duplicate: RBA environment resolution logic


129-129: Duplicate: RBA environment resolution logic


195-195: Duplicate: RBA environment resolution logic


289-289: Duplicate: RBA environment resolution logic


311-311: Duplicate: RBA environment resolution logic


335-335: Duplicate: RBA environment resolution logic


381-381: Duplicate: RBA environment resolution logic


407-407: Duplicate: RBA environment resolution logic


428-428: Duplicate: RBA environment resolution logic


488-488: Duplicate: RBA environment resolution logic

🧹 Nitpick comments (12)
.github/workflows/deploy_to_aws.yml (1)

42-42: Extend job environment resolution to include RBA

You’ve correctly updated the environment expression to handle branches starting with rba-. Consider refactoring to DRY this logic, for example by defining a top-level env variable or YAML anchor and reusing it across jobs.

+env:
+  RESOLVED_ENV: ${{ inputs.deploy-env || 
+    (github.ref_name == 'main' && 'Development') ||
+    (startsWith(github.ref_name, 'releases/') && 'Pre-prod') ||
+    (startsWith(github.ref_name, 'production-') && 'Production') ||
+    (startsWith(github.ref_name, 'sandbox-') && 'Staging') ||
+    (startsWith(github.ref_name, 'rba-') && 'RBA') ||
+    'None' 
+  }}
 jobs:
   init-and-plan:
-    environment: ${{ inputs.deploy-env || (github.ref_name == 'main' && 'Development') || ... }}
+    environment: ${{ env.RESOLVED_ENV }}
deployment/environments/terraform-rba.tfvars (11)

1-3: Inconsistent environment casing

The environment field is set to "Rba", but other configurations (e.g., GitHub workflows) refer to RBA. For consistency, consider using the same uppercase notation:

-environment = "Rba"
+environment = "RBA"

4-9: Review AWS region and DNS configuration

  • RBA uses two AZs (eu-west-1a, eu-west-1b); if your network and budget allow, adding a third AZ improves resilience.
  • Verify the private (osh.internal) and public (opensupplyhub.org) hosted zones are correct for RBA.

10-11: Optimize CloudFront cost for non-production

cloudfront_price_class = "PriceClass_All" covers all edge locations at higher cost. For RBA, consider PriceClass_100 or PriceClass_200 based on traffic needs.


15-23: Ensure RDS variable types align with Terraform schema

Values like rds_allocated_storage = "256" and rds_engine_version = "16" are strings. Check deployment/terraform/variables.tf to confirm these are declared as string; otherwise remove quotes. Also, since rds_multi_az = false, review if multi-AZ should be enabled for production-like reliability.


24-30: Right-size ECS tasks for RBA

The values (app_ecs_desired_count = "4", app_fargate_cpu = "1024", etc.) mirror production defaults. If RBA is lower-traffic, consider reducing replicas or resource allocations to save cost.


31-37: Review ECS auto-scaling thresholds

CPU thresholds (85%/15%) and capacities (min_capacity = 2, max_capacity = 4) may be over-provisioned. Tailor these to RBA workload patterns.


38-43: Validate CLI and Batch compute sizing

  • cli_fargate_memory = "8192" may be overkill for non-critical tasks.
  • Confirm batch_default_ce_spot_fleet_bid_percentage = 60 and batch_ami_id are correct for RBA workloads.

44-49: Optimize Batch job resource limits

The batch_default_ce_max_vcpus = 128 and instance types ["c5", "m5"] are broad. If RBA jobs are smaller, restrict vCPU limits and instance types to control costs.


50-53: Verify caching and timeout settings

  • Check ec_memcached_identifier = "opensupplyhub-rba" aligns with existing naming conventions.
  • Ensure gunicorn_worker_timeout = "360" is appropriate for RBA application performance.

60-64: Fix formatting on django_log_level

Missing spaces around = reduces readability. Apply:

-django_log_level="DEBUG"
+django_log_level = "DEBUG"

Also verify app_cc_ecs_desired_count and app_dd settings fit RBA load.


66-69: Review OpenSearch and Logstash sizing

  • opensearch_instance_type = "m6g.large.search" may exceed RBA requirements.
  • Check app_logstash_fargate_cpu = 256 and app_logstash_fargate_memory = 2048 are sufficient for log volumes.
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0867474 and 9ecf5a1.

📒 Files selected for processing (10)
  • .github/workflows/deploy_to_aws.yml (13 hunks)
  • .github/workflows/release-deploy.yml (2 hunks)
  • deployment/environments/terraform-rba.tfvars (1 hunks)
  • deployment/terraform/batch.tf (1 hunks)
  • deployment/terraform/variables.tf (1 hunks)
  • doc/release/RELEASE-NOTES.md (1 hunks)
  • src/django/oar/settings.py (3 hunks)
  • src/django/web/views.py (1 hunks)
  • src/react/public/index.html (1 hunks)
  • src/react/src/util/util.ga.js (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (13)
  • GitHub Check: run-integration-test-code-quality
  • GitHub Check: run-flake8-linter
  • GitHub Check: run-eslint-linter-and-prettier-formatter
  • GitHub Check: run-django-code-quality
  • GitHub Check: run-dd-code-quality
  • GitHub Check: run-countries-code-quality
  • GitHub Check: run-contricleaner-code-quality
  • GitHub Check: get-base-branch-fe-cov
  • GitHub Check: get-base-branch-django-cov
  • GitHub Check: get-base-branch-dd-cov
  • GitHub Check: get-base-branch-countries-cov
  • GitHub Check: get-base-branch-contricleaner-cov
  • GitHub Check: run-fe-code-quality
🔇 Additional comments (16)
deployment/terraform/variables.tf (1)

684-688: Good addition of the CSV export toggle variable.

The new export_csv_enabled variable provides a clean way to conditionally enable/disable the CSV export functionality across different environments, which aligns perfectly with the PR's objective to disable this feature in the RBA environment.

src/django/web/views.py (1)

21-22: Documentation update correctly reflects all environments.

The expanded environment list now properly includes all possible values, including the new rba environment and the renamed local environment (previously known as development).

src/react/public/index.html (1)

81-81: Correct fix for environment check.

This change fixes the bug mentioned in the PR objectives by correctly checking for the local environment instead of development, ensuring Rollbar is initialized properly across all environments.

deployment/terraform/batch.tf (1)

287-287: Successfully implemented conditional CSV export scheduling.

Using the new export_csv_enabled variable to control the CloudWatch event rule's is_enabled attribute is a clean implementation that allows disabling the CSV export job in the RBA environment without affecting other environments.

src/react/src/util/util.ga.js (1)

37-37: Fixed environment check for Google Analytics.

This change correctly updates the environment condition from development to local, ensuring that Google Analytics tracking is properly handled across all environments, which aligns with the environment naming changes mentioned in the PR.

.github/workflows/release-deploy.yml (2)

17-17: New deployment environment added successfully.

The 'rba' option has been properly added to the deployment environment choices, making it available as a deployment target alongside existing environments.


49-51: Environment variable assignment for RBA deployment looks good.

The conditional logic correctly sets ENV="RBA" when the deploy-env input is "rba", following the same pattern used for other environments.

doc/release/RELEASE-NOTES.md (2)

28-30: Clear documentation of RBA environment implementation.

The release notes effectively communicate the addition of the RBA environment to the CD pipelines and the introduction of the new infrastructure switch to disable the CSV export job in the RBA environment.


33-33: Frontend environment check bugfix clearly documented.

The note clearly explains how the environment check was fixed to use 'local' instead of 'development', which aligns with the actual environment naming in the backend.

src/django/oar/settings.py (3)

37-37: RBA environment correctly added to valid environments.

The 'Rba' environment has been properly added to the VALID_ENVIRONMENTS tuple, allowing it to pass environment validation.


430-447: RBA ECS environment configuration implemented correctly.

The configuration for the RBA environment in ECSMANAGE_ENVIRONMENTS follows the standard pattern used for other environments, with appropriate naming conventions for AWS resources.


534-538: Improved handling of Hubspot environment variables.

The code now explicitly sets Hubspot-related variables to None when their environment variables are unset or empty, which is more explicit and safer than the previous implementation that used the return value of os.getenv() directly.

.github/workflows/deploy_to_aws.yml (1)

21-21: Approve: Added "RBA" to deploy-env choices

Great addition of the RBA option to the workflow_dispatch inputs, enabling explicit RBA deployments.

deployment/environments/terraform-rba.tfvars (3)

12-14: Validate Bastion host settings

  • Ensure AMI ami-0bb3fad3c0286ebd5 is up-to-date and exists in eu-west-1.
  • Confirm that t3.nano provides adequate performance, or choose t3.micro/t3.small as needed.

54-59: Review deduplication and snapshot naming

  • Confirm rds_final_snapshot_identifier = "opensupplyhub-rds-rba" follows your snapshot naming conventions.
  • Ensure topic_dedup_basic_name, dedupe_hub_name, and dedupe_hub_version correctly isolate RBA data streams.

71-71:

Details

✅ Verification successful

Confirm CSV export toggle usage

You’ve set export_csv_enabled = false to disable CSV exports in RBA. Verify this flag is referenced in deployment/terraform/batch.tf (or relevant modules) to conditionally disable the EventBridge scheduler:


🏁 Script executed:

#!/bin/bash
# Confirm usage of export_csv_enabled in Terraform
rg -n "export_csv_enabled" -A3 deployment/terraform/batch.tf

Length of output: 180


export_csv_enabled flag usage confirmed

The export_csv_enabled variable is referenced in deployment/terraform/batch.tf on line 287:

resource "aws_cloudwatch_event_target" "export_csv" {
  …
  is_enabled = var.export_csv_enabled
}

With export_csv_enabled = false in your RBA tfvars, the EventBridge CSV‐export target will be disabled as intended.

Copy link
Contributor

@VadimKovalenkoSNF VadimKovalenkoSNF left a comment

Choose a reason for hiding this comment

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

Approved, good work!

@sonarqubecloud
Copy link

sonarqubecloud bot commented May 9, 2025

Copy link
Contributor

@mazursasha1990 mazursasha1990 left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@roman-stolar roman-stolar left a comment

Choose a reason for hiding this comment

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

Great! LGTM

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.

5 participants