Skip to content

add field bytes_added_packed in status file etc.#519

Merged
creativeprojects merged 1 commit intocreativeprojects:masterfrom
jeinwag:bytes_added_packed
Jun 23, 2025
Merged

add field bytes_added_packed in status file etc.#519
creativeprojects merged 1 commit intocreativeprojects:masterfrom
jeinwag:bytes_added_packed

Conversation

@jeinwag
Copy link
Copy Markdown
Contributor

@jeinwag jeinwag commented Jun 23, 2025

Adds the field bytes_added_packed, which represents the amount of data added after compression to the status file and prometheus metrics.

Closes #518.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 23, 2025

Walkthrough

A new metric, bytes_added_packed, representing the total number of bytes added to the repository after compression, was introduced throughout the codebase. This field was added to relevant structs, parsing logic, Prometheus metrics, and tests to ensure it is captured, reported, and validated from both JSON and plain output formats.

Changes

File(s) Change Summary
monitor/prom/backup.go Added bytesAddedPacked gauge vector to BackupMetrics and initialised it in the constructor.
monitor/prom/metrics.go Registered and updated the new metric in Metrics; set value from summary in BackupResults.
monitor/status/profile.go Added BytesAddedPacked to BackupStatus; set in both success and error cases.
monitor/summary.go Added BytesAddedPacked field to Summary struct.
shell/json_summary.go Added DataAddedPacked to ResticJsonSummary; parsed and assigned to summary.
shell/json_summary_test.go Updated test to include and validate data_added_packed field.
shell/plain_summary.go Enhanced parsing to extract packed bytes from summary line and assign to summary.
shell/plain_summary_test.go Updated test data and assertions for BytesAddedPacked.

Sequence Diagram(s)

sequenceDiagram
    participant Restic as restic (backup)
    participant Shell as shell/json_summary.go or shell/plain_summary.go
    participant Monitor as monitor/summary.go
    participant Prom as monitor/prom/metrics.go
    participant Status as monitor/status/profile.go

    Restic->>Shell: Output (JSON or plain) with data_added_packed
    Shell->>Monitor: Parse and assign BytesAddedPacked to Summary
    Monitor->>Prom: Summary passed to metrics (BackupResults)
    Prom->>Prom: Set bytesAddedPacked gauge from Summary.BytesAddedPacked
    Monitor->>Status: Write BytesAddedPacked to status file
Loading

Assessment against linked issues

Objective Addressed Explanation
Add field bytes_added_packed to status file (#518)
Parse and propagate data_added_packed from restic JSON/plain output (#518)
Update metrics and tests to include the new field (#518)

Assessment against linked issues: Out-of-scope changes

No out-of-scope changes were found.

Suggested reviewers

  • creativeprojects

📜 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 25c2f06 and fcf57e0.

📒 Files selected for processing (8)
  • monitor/prom/backup.go (2 hunks)
  • monitor/prom/metrics.go (3 hunks)
  • monitor/status/profile.go (3 hunks)
  • monitor/summary.go (1 hunks)
  • shell/json_summary.go (2 hunks)
  • shell/json_summary_test.go (2 hunks)
  • shell/plain_summary.go (2 hunks)
  • shell/plain_summary_test.go (2 hunks)
🔇 Additional comments (17)
monitor/summary.go (1)

16-16: LGTM! Well-positioned new field.

The BytesAddedPacked field is appropriately placed between related byte metrics and uses the correct type for representing byte counts.

shell/plain_summary_test.go (2)

23-23: Test data correctly reflects new restic output format.

The updated format "Added to the repository: 282.768 MiB (70.691 MiB stored)" accurately represents restic's enhanced output showing both total and packed bytes.


64-64: Correct test assertion for packed bytes.

The assertion value 74124886 correctly corresponds to 70.691 MiB stored, ensuring accurate validation of the parsing logic.

monitor/status/profile.go (3)

41-41: Consistent JSON field naming.

The bytes_added_packed JSON tag follows the established snake_case convention used by other fields in the struct.


62-62: Proper field population in success case.

The field is correctly populated from summary.BytesAddedPacked, maintaining consistency with other metric fields.


86-86: Appropriate default value for error case.

Setting BytesAddedPacked to 0 in the error case is logical since no data would be successfully added during a failed backup.

shell/json_summary_test.go (2)

22-22: JSON test data includes required packed bytes field.

The data_added_packed field is correctly added to match restic's actual JSON output format.


67-67: Accurate validation of JSON parsing.

The assertion correctly verifies that the BytesAddedPacked field is properly extracted from the JSON summary.

shell/json_summary.go (2)

24-24: Consistent field definition for JSON parsing.

The DataAddedPacked field with JSON tag data_added_packed correctly matches restic's output format and follows established patterns.


60-60: Proper assignment of parsed packed bytes.

The assignment summary.BytesAddedPacked = jsonSummary.DataAddedPacked correctly propagates the parsed value to the summary structure.

monitor/prom/backup.go (2)

25-25: LGTM! New field properly integrated into struct.

The bytesAddedPacked field is correctly added to the BackupMetrics struct following the established naming convention and type pattern.


87-92: LGTM! Prometheus metric correctly configured.

The new gauge metric is properly configured with:

  • Consistent namespace and subsystem
  • Clear, descriptive metric name (added_bytes_packed)
  • Appropriate help text explaining the compressed bytes metric
  • Same label scheme as other backup metrics
shell/plain_summary.go (2)

20-20: LGTM! Variables properly declared for stored bytes parsing.

The new variables rawBytesStored and unitStored are appropriately added to handle the packed bytes data from the restic output.


31-35: Verify parsing format compatibility across restic versions.

The parsing logic correctly handles the new format "Added to the repository: %f %3s (%f %3s stored)" and gracefully falls back when the format doesn't match. However, the specific format assumption may be brittle.

#!/bin/bash
# Description: Check if the parsing format is used consistently across the codebase and verify restic output format documentation.

# Search for similar parsing patterns to ensure consistency
rg -A 3 -B 3 "Added to the repository" --type go

# Look for any existing tests that might show expected formats
rg -A 5 -B 5 "Added to the repository.*stored" --type go

# Check for any documentation about restic output formats
fd -t f -e md -e txt | xargs rg -l "Added to the repository" 2>/dev/null || echo "No documentation found"
monitor/prom/metrics.go (3)

75-75: LGTM! Metric properly registered with Prometheus.

The bytesAddedPacked metric is correctly registered alongside other backup metrics in the registry.


96-96: LGTM! Gauge value correctly updated from summary.

The bytesAddedPacked gauge is properly updated with the value from summary.BytesAddedPacked, following the same pattern as other backup metrics with appropriate type conversion to float64.


55-56: LGTM! Minor formatting improvements.

The extra spaces around Name and Help fields have been cleaned up without affecting functionality.

✨ Finishing Touches
  • 📝 Generate Docstrings

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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 23, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 79.29%. Comparing base (25c2f06) to head (fcf57e0).
Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #519      +/-   ##
==========================================
+ Coverage   79.27%   79.29%   +0.02%     
==========================================
  Files         136      136              
  Lines       13252    13264      +12     
==========================================
+ Hits        10505    10517      +12     
  Misses       2326     2326              
  Partials      421      421              
Flag Coverage Δ
unittests 79.29% <100.00%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

@creativeprojects
Copy link
Copy Markdown
Owner

Thanks for this PR!
It looks good to me 👍🏻

@creativeprojects creativeprojects merged commit 63dee21 into creativeprojects:master Jun 23, 2025
8 of 9 checks passed
@creativeprojects creativeprojects added this to the v0.32.0 milestone Jul 28, 2025
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.

[feature] add field bytes_added_packed to status file

2 participants