Skip to content

[OSDEV-1467] Releases. Block API create facility endpoint if "disable_list_uploading" switch is enabled in Admin panel#426

Closed
Innavin369 wants to merge 2 commits intomainfrom
OSDEV-1467-block-post-api-facilities-endpoint-via-switch
Closed

[OSDEV-1467] Releases. Block API create facility endpoint if "disable_list_uploading" switch is enabled in Admin panel#426
Innavin369 wants to merge 2 commits intomainfrom
OSDEV-1467-block-post-api-facilities-endpoint-via-switch

Conversation

@Innavin369
Copy link
Contributor

@Innavin369 Innavin369 commented Nov 26, 2024

OSDEV-1467 Implemented disabling endpoint POST /api/facilities/ during the release process. It is raising an error message with status code 503.

Screenshot 2024-11-26 at 14 38 20 Screenshot 2024-11-26 at 14 38 33

@Innavin369 Innavin369 temporarily deployed to Quality Environment November 26, 2024 13:39 — with GitHub Actions Inactive
@Innavin369 Innavin369 temporarily deployed to Quality Environment November 26, 2024 13:39 — with GitHub Actions Inactive
@Innavin369 Innavin369 temporarily deployed to Quality Environment November 26, 2024 13:39 — with GitHub Actions Inactive
@Innavin369 Innavin369 temporarily deployed to Quality Environment November 26, 2024 13:39 — with GitHub Actions Inactive
@Innavin369 Innavin369 temporarily deployed to Quality Environment November 26, 2024 13:39 — with GitHub Actions Inactive
@Innavin369 Innavin369 temporarily deployed to Quality Environment November 26, 2024 13:39 — with GitHub Actions Inactive
@Innavin369 Innavin369 temporarily deployed to Quality Environment November 26, 2024 13:39 — with GitHub Actions Inactive
@Innavin369 Innavin369 temporarily deployed to Quality Environment November 26, 2024 13:39 — with GitHub Actions Inactive
@Innavin369 Innavin369 temporarily deployed to Quality Environment November 26, 2024 13:39 — with GitHub Actions Inactive
@Innavin369 Innavin369 temporarily deployed to Quality Environment November 26, 2024 13:39 — with GitHub Actions Inactive
@Innavin369 Innavin369 temporarily deployed to Quality Environment November 26, 2024 13:39 — with GitHub Actions Inactive
@Innavin369 Innavin369 temporarily deployed to Quality Environment November 26, 2024 13:39 — with GitHub Actions Inactive
@Innavin369 Innavin369 temporarily deployed to Quality Environment November 26, 2024 13:39 — with GitHub Actions Inactive
@Innavin369 Innavin369 temporarily deployed to Quality Environment November 26, 2024 13:41 — with GitHub Actions Inactive
@barecheck
Copy link

barecheck bot commented Nov 26, 2024

React App | Jest test suite - Code coverage report

Total: 27.8%

Your code coverage diff: 0.00% ▴

✅ All code changes are covered

@coderabbitai
Copy link

coderabbitai bot commented Nov 26, 2024

📝 Walkthrough
📝 Walkthrough

Walkthrough

The pull request updates the RELEASE-NOTES.md file to document changes across multiple releases of the Open Supply Hub project, with a focus on Release 1.26.0's introduction of a custom waiter and various enhancements in previous releases. It also includes a new exception handling mechanism in the FacilitiesViewSet class to manage service availability during maintenance. Overall, the changes enhance documentation clarity and improve error handling in the application.

Changes

File Path Change Summary
doc/release/RELEASE-NOTES.md Updated to include details for releases 1.26.0, 1.25.0, and earlier, highlighting new features, bug fixes, and architecture changes.
src/django/api/views/facility/facilities_view_set.py Added exception handling in create method to raise ServiceUnavailableException based on feature toggle for list uploading.
src/django/api/exceptions.py Introduced ServiceUnavailableException.

Possibly related PRs

Suggested reviewers

  • vladsha-dev
  • roman-stolar
  • mazursasha1990

Warning

Rate limit exceeded

@Innavin369 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 0 minutes and 19 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 21087ba and c2ac7c1.


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 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: 0

🧹 Outside diff range and nitpick comments (2)
src/django/api/views/facility/facilities_view_set.py (1)

581-583: Consider moving the maintenance message to a constants file.

The maintenance message could be reused across different endpoints. Consider moving it to a constants file for better maintainability and consistency.

Example implementation:

# api/constants.py
+MAINTENANCE_MESSAGES = {
+    'UPLOADING_DISABLED': ('Open Supply Hub is undergoing maintenance and '
+                          'not accepting new data at the moment. Please '
+                          'try again in a few minutes.')
+}

# facilities_view_set.py
+from api.constants import MAINTENANCE_MESSAGES

-            block_message = ('Open Supply Hub is undergoing maintenance and '
-                             'not accepting new data at the moment. Please '
-                             'try again in a few minutes.')
+            block_message = MAINTENANCE_MESSAGES['UPLOADING_DISABLED']
doc/release/RELEASE-NOTES.md (1)

Line range hint 1-24: Release 1.26.0 sections need completion.

Several critical sections are incomplete:

  • Release date is set to future (December 14, 2024)
  • Database migrations section contains placeholder text
  • Code/API changes section contains placeholder text
  • Architecture/Environment changes section contains placeholder text
  • Release instructions section contains placeholder text

Please update these sections with actual implementation details before release.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 9885c44 and 21087ba.

📒 Files selected for processing (2)
  • doc/release/RELEASE-NOTES.md (1 hunks)
  • src/django/api/views/facility/facilities_view_set.py (2 hunks)
🔇 Additional comments (3)
src/django/api/views/facility/facilities_view_set.py (1)

580-584: LGTM! Implementation aligns with requirements.

The code correctly implements the requirement to block the facility creation endpoint when the 'disable_list_uploading' switch is enabled. The implementation:

  • Uses appropriate error handling with ServiceUnavailableException
  • Returns a clear user-friendly message
  • Checks the feature flag early to prevent unnecessary processing

Let's verify the error handling implementation:

✅ Verification successful

Implementation is correct and consistent across the codebase

The verification confirms that:

  • ServiceUnavailableException is properly defined in src/django/api/exceptions.py with correct HTTP 503 status code
  • The disable_list_uploading feature flag is properly defined via a migration and managed through waffle switches
  • The same error handling pattern is consistently used in both facilities_view_set.py and facility_list_view_set.py to block uploads during maintenance
  • The implementation is tested as evidenced by the test file test_facility_list_create.py
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify ServiceUnavailableException is properly imported and used

# Check if ServiceUnavailableException is defined in api/exceptions.py
rg -A 5 "class ServiceUnavailableException" api/exceptions.py

# Verify no other endpoints are using this exception for the same purpose
rg "disable_list_uploading.*ServiceUnavailableException" --type py

Length of output: 190


Script:

#!/bin/bash
# Let's try searching in the src directory structure
# Check for ServiceUnavailableException definition
rg -A 5 "class ServiceUnavailableException" src/

# Check imports of ServiceUnavailableException
rg "from.*import.*ServiceUnavailableException" src/

# Check all usages of ServiceUnavailableException
rg "ServiceUnavailableException" src/

Length of output: 1313


Script:

#!/bin/bash
# Let's check the context of disable_list_uploading usage in facility_list_view_set.py
rg -B 2 -A 2 "disable_list_uploading" src/django/api/views/facility/facility_list_view_set.py

# Check if the switch is defined in a central location
rg "disable_list_uploading" src/ --type py

Length of output: 1696

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

Line range hint 25-27: Provide implementation details for the waiter replacement.

The bugfix section mentions replacing boto3 waiter with a custom one but doesn't provide:

  • The reason why boto3 waiter couldn't wait more than half an hour
  • The implementation details of the custom waiter
  • The impact of this change on existing functionality

53-53: Verify the API endpoint disabling implementation.

The release notes mention disabling the endpoint POST /api/facilities/?public=true&create=true during release process, but don't provide details about:

  • The specific error message returned with 503 status code
  • The conditions under which the endpoint is disabled
  • The impact on existing API consumers
✅ Verification successful

Let me analyze the verification results:

  1. Found the implementation of disabling endpoint POST /api/facilities/?public=true&create=true in multiple files:
  • src/django/api/views/facility/facilities_view_set.py - Checks the disable_list_uploading switch and returns 503 with message "Open Supply Hub is undergoing maintenance and not accepting new data at the moment. Please try again in a few minutes."

  • src/django/api/migrations/0161_create_bdisable_list_uploading.py - Creates the disable_list_uploading switch in Django admin panel

  1. The implementation includes:
  • Proper error message with 503 status code
  • Switch in Django admin panel to control the feature
  • Migration to create the switch
  • Tests verifying the functionality

The endpoint disabling implementation is properly done with all necessary components.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the implementation of endpoint disabling functionality

# Test: Search for the endpoint implementation and error handling
rg -A 10 "disable_list_uploading"

# Test: Search for the error message implementation
rg -A 5 "503"

Length of output: 142863

@Innavin369 Innavin369 self-assigned this Nov 26, 2024
@Innavin369 Innavin369 changed the base branch from main to releases/v.1.25 November 26, 2024 13:43
@Innavin369 Innavin369 temporarily deployed to Quality Environment November 26, 2024 13:46 — with GitHub Actions Inactive
@barecheck
Copy link

barecheck bot commented Nov 26, 2024

Dedupe Hub App | Unittest test suite - Code coverage report

Total: 56.14%

Your code coverage diff: 0.00% ▴

✅ All code changes are covered

@Innavin369 Innavin369 temporarily deployed to Quality Environment November 26, 2024 13:47 — with GitHub Actions Inactive
@barecheck
Copy link

barecheck bot commented Nov 26, 2024

Countries App | Unittest test suite - Code coverage report

Total: 100%

Your code coverage diff: 0.00% ▴

✅ All code changes are covered

@barecheck
Copy link

barecheck bot commented Nov 26, 2024

Contricleaner App | Unittest test suite - Code coverage report

Total: 98.91%

Your code coverage diff: 0.00% ▴

✅ All code changes are covered

@Innavin369 Innavin369 changed the base branch from releases/v.1.25 to main November 26, 2024 13:51
@Innavin369 Innavin369 temporarily deployed to Quality Environment November 26, 2024 13:56 — with GitHub Actions Inactive
@barecheck
Copy link

barecheck bot commented Nov 26, 2024

Django App | Unittest test suite - Code coverage report

Total: 79.14%

Your code coverage diff: -0.02% ▾

✅ All code changes are covered

@Innavin369 Innavin369 temporarily deployed to Quality Environment November 26, 2024 13:58 — with GitHub Actions Inactive
@Innavin369 Innavin369 temporarily deployed to Quality Environment November 26, 2024 14:09 — with GitHub Actions Inactive
@Innavin369 Innavin369 temporarily deployed to Quality Environment November 26, 2024 14:09 — with GitHub Actions Inactive
@Innavin369 Innavin369 temporarily deployed to Quality Environment November 26, 2024 14:09 — with GitHub Actions Inactive
@Innavin369 Innavin369 temporarily deployed to Quality Environment November 26, 2024 14:09 — with GitHub Actions Inactive
@Innavin369 Innavin369 temporarily deployed to Quality Environment November 26, 2024 14:09 — with GitHub Actions Inactive
@Innavin369 Innavin369 temporarily deployed to Quality Environment November 26, 2024 14:09 — with GitHub Actions Inactive
@Innavin369 Innavin369 temporarily deployed to Quality Environment November 26, 2024 14:09 — with GitHub Actions Inactive
@Innavin369 Innavin369 temporarily deployed to Quality Environment November 26, 2024 14:09 — with GitHub Actions Inactive
@Innavin369 Innavin369 temporarily deployed to Quality Environment November 26, 2024 14:09 — with GitHub Actions Inactive
@Innavin369 Innavin369 temporarily deployed to Quality Environment November 26, 2024 14:09 — with GitHub Actions Inactive
@Innavin369 Innavin369 temporarily deployed to Quality Environment November 26, 2024 14:09 — with GitHub Actions Inactive
@Innavin369 Innavin369 temporarily deployed to Quality Environment November 26, 2024 14:09 — with GitHub Actions Inactive
@Innavin369 Innavin369 temporarily deployed to Quality Environment November 26, 2024 14:09 — with GitHub Actions Inactive
@Innavin369 Innavin369 temporarily deployed to Quality Environment November 26, 2024 14:09 — with GitHub Actions Inactive
@sonarqubecloud
Copy link

@Innavin369 Innavin369 temporarily deployed to Quality Environment November 26, 2024 14:11 — with GitHub Actions Inactive
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: 0

🧹 Outside diff range and nitpick comments (1)
doc/release/RELEASE-NOTES.md (1)

Line range hint 1124-1131: Release instructions need to be more specific

The release instructions should include:

  1. The exact order of operations
  2. Any required system state checks between steps
  3. Potential rollback procedures

Consider updating the release instructions to:

### Release instructions:
- apply migrations up to 0124_itroduce_raw_json
- execute command fill_raw_json
- apply migrations up to 0129_delete_facility_index
- apply command index_facilities_new
+### Release instructions:
+1. Pre-deployment checks:
+   - Ensure database backup is available
+   - Verify system is in a stable state
+
+2. Migration steps (in order):
+   a. Apply migrations up to 0124_itroduce_raw_json
+   b. Execute command: fill_raw_json
+   c. Verify raw_json data population completed successfully
+   d. Apply remaining migrations up to 0129_delete_facility_index
+   e. Execute command: index_facilities_new
+
+3. Post-deployment verification:
+   - Verify all migrations completed successfully
+   - Check system logs for any errors
+   - Verify API endpoints are responding correctly
+
+4. Rollback procedure (if needed):
+   - Restore from pre-deployment backup
+   - Revert code to previous version
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 21087ba and c2ac7c1.

📒 Files selected for processing (1)
  • doc/release/RELEASE-NOTES.md (1 hunks)
🔇 Additional comments (2)
doc/release/RELEASE-NOTES.md (2)

Line range hint 1-24: LGTM! Clear and well-structured release notes header

The header section follows best practices by:

  • Clearly stating adherence to Semantic Versioning
  • Including a reference to the template file
  • Providing proper formatting for version numbers

58-58: Verify the implementation of the API endpoint disabling functionality

The note indicates a critical change where the POST /api/facilities/ endpoint will be disabled during release process, returning a 503 error. This needs careful verification to ensure proper error handling and minimal disruption to users.

✅ Verification successful

Implementation of API endpoint disabling functionality is properly implemented and verified

The verification shows a complete and robust implementation:

  • A waffle switch disable_list_uploading is properly implemented:
    • Migration file 0161_create_bdisable_list_uploading.py creates the switch
    • Switch is used in both FacilityViewSet and FacilityListViewSet
    • Proper error handling with ServiceUnavailableException returning 503 status code
    • Consistent error message across endpoints
    • Unit tests verify the functionality
    • Frontend components handle the switch state
    • Management command exists to control the switch

The implementation matches what's described in the release notes and includes all necessary components for a reliable feature.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the implementation of the API endpoint disabling functionality

# Test: Check if the disable_list_uploading switch exists in the waffle_switch table
echo "Checking for disable_list_uploading switch..."
rg -A 5 "disable_list_uploading" 

# Test: Check the error handling implementation
echo "Checking error handling implementation..."
rg -A 10 "ServiceUnavailableException"

Length of output: 11160

@Innavin369 Innavin369 temporarily deployed to Quality Environment November 26, 2024 14:16 — with GitHub Actions Inactive
@Innavin369 Innavin369 temporarily deployed to Quality Environment November 26, 2024 14:16 — with GitHub Actions Inactive
@Innavin369 Innavin369 temporarily deployed to Quality Environment November 26, 2024 14:17 — with GitHub Actions Inactive
@Innavin369 Innavin369 closed this Nov 26, 2024
@Innavin369 Innavin369 temporarily deployed to Quality Environment November 26, 2024 14:26 — with GitHub Actions Inactive
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