Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add size in bytes to backups #5473

Merged
merged 1 commit into from
Dec 7, 2024
Merged

Add size in bytes to backups #5473

merged 1 commit into from
Dec 7, 2024

Conversation

mdegat01
Copy link
Contributor

@mdegat01 mdegat01 commented Dec 7, 2024

Proposed change

Add raw size in bytes to backup info returned from API rather then a float from converting that to mb. The API should return the raw value, converting to larger units should be done in places that value is displayed to humans.

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New feature (which adds functionality to the supervisor)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • The code has been formatted using Ruff (ruff format supervisor tests)
  • Tests have been added to verify that the new code works.

If API endpoints or add-on configuration are added/changed:

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced a new attribute to display the size of backups in bytes, enhancing backup information provided to users.
  • Bug Fixes

    • Improved error handling for backup loading, providing clearer feedback on JSON decoding issues.
  • Tests

    • Enhanced test coverage for backup API, including validations for size attributes and new test cases for detailed backup information.
  • Chores

    • Updated mock backup fixtures to ensure proper tar file formatting and include new attributes for database exclusion.

Copy link

coderabbitai bot commented Dec 7, 2024

📝 Walkthrough

Walkthrough

The changes introduce a new attribute, ATTR_SIZE_BYTES, to the backup data structure in the API, allowing the size of backups to be returned in bytes. This attribute is incorporated into the _list_backups and backup_info methods. Additionally, modifications to the Backup class include the introduction of a size_bytes property and optimization of the existing size property using caching. The test suite for the backups API has been updated to validate these new size attributes, enhancing overall test coverage.

Changes

File Path Change Summary
supervisor/api/backups.py Added ATTR_SIZE_BYTES attribute; updated _list_backups and backup_info methods to include it.
supervisor/api/const.py Added constant ATTR_SIZE_BYTES = "size_bytes".
supervisor/backups/backup.py Changed size to a @cached_property; added size_bytes as a new @cached_property. Enhanced error handling in load method.
tests/api/test_backups.py Updated test_info and test_list methods to include size checks; added new test test_backup_more_info.
tests/conftest.py Added ATTR_EXCLUDE_DATABASE; updated mock backup filename to "test_backup.tar".

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant API
    participant BackupManager

    User->>API: Request backup info
    API->>BackupManager: Fetch backup details
    BackupManager-->>API: Return backup details with ATTR_SIZE_BYTES
    API-->>User: Respond with backup info including size in bytes
Loading

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 or @coderabbitai title 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)
supervisor/backups/backup.py (2)

217-220: Improve size calculation with caching

The size property has been optimized using @cached_property and now derives its value from size_bytes. This change:

  1. Improves performance by caching the calculated size
  2. Maintains consistency by using the new size_bytes property as the source of truth

Consider adding a docstring to clarify that the size is in megabytes:

 @cached_property
 def size(self) -> float:
-    """Return backup size."""
+    """Return backup size in megabytes."""
     return round(self.size_bytes / 1048576, 2)  # calc mbyte

217-227: Consider documenting the size handling changes

The introduction of size_bytes alongside the existing size property represents an architectural improvement that:

  1. Provides more precise size information through raw bytes
  2. Maintains backward compatibility for existing consumers
  3. Improves performance through caching

Consider documenting these changes in the API documentation to help consumers understand the available size representations and their use cases.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 5a22599 and ffebd43.

📒 Files selected for processing (5)
  • supervisor/api/backups.py (3 hunks)
  • supervisor/api/const.py (1 hunks)
  • supervisor/backups/backup.py (2 hunks)
  • tests/api/test_backups.py (2 hunks)
  • tests/conftest.py (5 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
tests/conftest.py (6)

Pattern */**(html|markdown|md): - For instructional content in documentation, use a direct and authoritative tone. Avoid expressions of politeness such as 'may' or 'please', and ensure the goal of the instruction is fronted.

  • Apply the Microsoft Style Guide to ensure documentation maintains clarity and conciseness.
  • In step-by-step instructions, front the location phrase in the instructional sentence.
  • In step-by-step instructions, front the 'goal' in the instructional sentence.
  • In step-by-step instructions, if in doubt what to front, front the 'goal' before the location phrase in the instructional sentence.
  • do not hyphenate terms like 'top-right' or 'bottom-left' with 'corner'

Pattern */**(html|markdown|md): - Use bold to mark UI strings.

  • If "" are used to mark UI strings, replace them by bold.

Pattern */**(html|markdown|md): - Be brief in your replies and don't add fluff like "thank you for..." and "Please let me know if"


Pattern */**(html|markdown|md): - Use sentence-style capitalization also in headings.


Pattern */**(html|markdown|md): do not comment on HTML used for icons


Pattern */**(html|markdown|md): Avoid flagging inline HTML for embedding videos in future reviews for this repository.

🔇 Additional comments (12)
supervisor/api/const.py (1)

62-62: LGTM: New constant follows conventions

The new constant ATTR_SIZE_BYTES follows the existing naming pattern and is correctly placed in alphabetical order.

supervisor/api/backups.py (3)

57-57: LGTM: Import added to appropriate group

The new constant is correctly imported with other related constants.


149-149: LGTM: Size in bytes added to list response

The raw size in bytes is now included in the backup list response, meeting the PR objective.


221-221: LGTM: Size in bytes added to backup info response

The raw size in bytes is now included in the detailed backup info response, maintaining consistency with the list endpoint.

tests/api/test_backups.py (3)

42-43: LGTM: Size assertions added to info test

The test now properly validates both the formatted size (0.01) and raw size in bytes (10240).


46-66: LGTM: Comprehensive test for backup info endpoint

New test thoroughly validates the backup info endpoint response, including both size representations.


81-82: LGTM: Size assertions added to list test

The test now properly validates both size formats in the list endpoint response.

tests/conftest.py (3)

33-33: LGTM: Import added for new exclude database feature

The addition of ATTR_EXCLUDE_DATABASE to imports is consistent with the new feature for excluding databases from backups.


Line range hint 609-625: LGTM: Consistent mock implementation

The changes to mock_partial_backup mirror those in mock_full_backup, maintaining consistency across test fixtures.


Line range hint 584-600: Verify mock backup file extension

The mock backup file path has been updated to include the .tar extension, which is more accurate. The ATTR_EXCLUDE_DATABASE flag has been added with a default value of False, which is consistent with the feature's implementation.

✅ Verification successful

Mock backup file extension is consistently using .tar

Based on the search results, all mock backup initializations in the test files are using the .tar extension consistently. The changes in the review are aligned with the existing codebase patterns, where mock backups are created with test_backup.tar as the filename.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that all backup file paths in tests use .tar extension

# Test: Search for backup file paths in test files
rg -A 2 'Path\(.*test_backup[^.]' tests/

Length of output: 42


Script:

#!/bin/bash
# Description: Search for backup file paths in test files with a broader pattern
# to ensure we catch all variations of backup path construction

# Search for backup path patterns in test files
rg -A 2 'Path.*backup' tests/

# Also search for mock backup initialization patterns
rg -A 2 'Backup\(.*Path' tests/

Length of output: 2244

supervisor/backups/backup.py (2)

9-9: LGTM: Import for performance optimization

The addition of cached_property from functools is appropriate for optimizing frequently accessed properties.


222-227: LGTM: New size_bytes property implementation

The new size_bytes property is well-implemented with:

  1. Proper error handling for non-existent files
  2. Efficient use of stat() for size retrieval
  3. Clear return type annotation

Copy link
Contributor

@emontnemery emontnemery left a comment

Choose a reason for hiding this comment

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

LGTM

@frenck frenck merged commit d44e995 into main Dec 7, 2024
21 checks passed
@frenck frenck deleted the add-size-bytes-backups branch December 7, 2024 09:27
@github-actions github-actions bot locked and limited conversation to collaborators Dec 9, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants