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

fix(heimdall): update snapshot download #440

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

calinah
Copy link
Contributor

@calinah calinah commented Dec 20, 2024

Summary by CodeRabbit

  • New Features

    • Enhanced initialization process for the Heimdall application with improved snapshot management.
    • Added a new init container for snapshot bootstrapping.
  • Bug Fixes

    • Corrected a typo in the configuration file check from "boostrapped" to "bootstrapped".
  • Version Updates

    • Updated Heimdall chart version from 1.2.4 to 1.2.5.
    • Updated snapshot URL in configuration and documentation.

Copy link

coderabbitai bot commented Dec 20, 2024

Walkthrough

The pull request modifies the Heimdall application's configuration files, specifically enhancing the init container functionality within the statefulset.yaml. The changes include renaming the existing init container and adding a new one for snapshot management. Additionally, the chart version is incremented, and the README and values files are updated to reflect a new snapshot URL. These modifications aim to improve the initialization process and provide better error handling and configuration management.

Changes

File Change Summary
charts/heimdall/templates/heimdall/statefulset.yaml - Renamed init container from heimdall-init to heimdall-init-config
- Added new init container heimdall-init-snapshot for snapshot management
- Updated command to check for configuration file existence and corrected typo from "boostrapped" to "bootstrapped"
- Specified volume mounts and environment variables for init containers
charts/heimdall/Chart.yaml - Incremented version from 1.2.4 to 1.2.5
charts/heimdall/README.md - Updated version from 1.2.4 to 1.2.5
- Changed snapshot URL from https://snapshots.matic.today to https://publicnode.com/snapshots#polygon
charts/heimdall/values.yaml - Updated snapshotUrl from https://snapshots.matic.today to https://publicnode.com/snapshots#polygon

Suggested reviewers

  • cjorge-graphops
  • i0n

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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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: 2

🧹 Nitpick comments (2)
charts/heimdall/templates/heimdall/statefulset.yaml (2)

71-76: Enhance lz4 installation robustness

The installation logic has good error handling but could be improved:

Consider these enhancements:

               # Install lz4 dynamically
               if ! apk add --no-cache lz4; then
                 echo "Failed to install lz4. Trying manual download..."
-                wget https://dl-cdn.alpinelinux.org/alpine/v3.14/main/x86_64/lz4-1.9.3-r0.apk
-                apk add --allow-untrusted lz4-1.9.3-r0.apk || { echo "Failed to install lz4 manually. Exiting."; exit 1; }
+                wget --timeout=30 --tries=3 https://dl-cdn.alpinelinux.org/alpine/v3.14/main/x86_64/lz4-1.9.3-r0.apk
+                apk add --allow-untrusted lz4-1.9.3-r0.apk || { echo "Failed to install lz4 manually. Exiting."; exit 1; }
+                rm -f lz4-1.9.3-r0.apk  # Cleanup
               fi

Consider:

  1. Making the lz4 version configurable through Helm values
  2. Adding package verification using apk keys

110-110: Remove trailing whitespace

-              fi 
+              fi
🧰 Tools
🪛 yamllint (1.35.1)

[error] 110-110: trailing spaces

(trailing-spaces)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between d1c42b3 and ee62ec9.

📒 Files selected for processing (1)
  • charts/heimdall/templates/heimdall/statefulset.yaml (2 hunks)
🧰 Additional context used
🪛 yamllint (1.35.1)
charts/heimdall/templates/heimdall/statefulset.yaml

[error] 110-110: trailing spaces

(trailing-spaces)

Comment on lines 67 to 70
echo "https://mirror.csclub.uwaterloo.ca/alpine/v3.14/main" > /etc/apk/repositories
echo "https://mirror.csclub.uwaterloo.ca/alpine/v3.14/community" >> /etc/apk/repositories
apk update

Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider improving APK repository configuration reliability

The current configuration has several potential issues:

  1. Single mirror point of failure
  2. Hardcoded Alpine version
  3. No fallback repositories

Consider this more resilient approach:

-              echo "https://mirror.csclub.uwaterloo.ca/alpine/v3.14/main" > /etc/apk/repositories
-              echo "https://mirror.csclub.uwaterloo.ca/alpine/v3.14/community" >> /etc/apk/repositories
+              # Use official repositories first, then mirrors
+              cat > /etc/apk/repositories << EOF
+              https://dl-cdn.alpinelinux.org/alpine/v3.14/main
+              https://dl-cdn.alpinelinux.org/alpine/v3.14/community
+              https://mirror.csclub.uwaterloo.ca/alpine/v3.14/main
+              https://mirror.csclub.uwaterloo.ca/alpine/v3.14/community
+              EOF

Consider making the Alpine version configurable through Helm values for better maintainability.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
echo "https://mirror.csclub.uwaterloo.ca/alpine/v3.14/main" > /etc/apk/repositories
echo "https://mirror.csclub.uwaterloo.ca/alpine/v3.14/community" >> /etc/apk/repositories
apk update
# Use official repositories first, then mirrors
cat > /etc/apk/repositories << EOF
https://dl-cdn.alpinelinux.org/alpine/v3.14/main
https://dl-cdn.alpinelinux.org/alpine/v3.14/community
https://mirror.csclub.uwaterloo.ca/alpine/v3.14/main
https://mirror.csclub.uwaterloo.ca/alpine/v3.14/community
EOF
apk update

Comment on lines 105 to 107
wget -c "${SNAPSHOT_URL}" -O snapshot.tar.lz4 || { echo "Download failed. Exiting."; exit 1; }
lz4 -d snapshot.tar.lz4 snapshot.tar || { echo "Decompression failed. Exiting."; exit 1; }
tar -xvf snapshot.tar -C ${HEIMDALLD_HOME}/data || { echo "Extraction failed. Exiting."; exit 1; }
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Improve snapshot download reliability and resource management

While the error handling is good, the snapshot management could be enhanced:

Consider these improvements:

-                  wget -c "${SNAPSHOT_URL}" -O snapshot.tar.lz4 || { echo "Download failed. Exiting."; exit 1; }
-                  lz4 -d snapshot.tar.lz4 snapshot.tar || { echo "Decompression failed. Exiting."; exit 1; }
-                  tar -xvf snapshot.tar -C ${HEIMDALLD_HOME}/data || { echo "Extraction failed. Exiting."; exit 1; }
+                  # Check available disk space
+                  available_space=$(df -P ${HEIMDALLD_HOME} | awk 'NR==2 {print $4}')
+                  required_space=$((20 * 1024 * 1024))  # 20GB in KB
+                  if [ "${available_space}" -lt "${required_space}" ]; then
+                    echo "Insufficient disk space. Required: 20GB, Available: $((available_space/1024/1024))GB. Exiting."; exit 1;
+                  fi
+                  
+                  # Download with progress and timeout
+                  wget --progress=dot:giga --timeout=3600 -c "${SNAPSHOT_URL}" -O snapshot.tar.lz4.tmp || { echo "Download failed. Exiting."; exit 1; }
+                  mv snapshot.tar.lz4.tmp snapshot.tar.lz4
+                  
+                  # Process snapshot with cleanup
+                  lz4 -d snapshot.tar.lz4 snapshot.tar || { rm -f snapshot.tar.lz4; echo "Decompression failed. Exiting."; exit 1; }
+                  rm -f snapshot.tar.lz4
+                  
+                  tar -xf snapshot.tar -C ${HEIMDALLD_HOME}/data || { rm -f snapshot.tar; echo "Extraction failed. Exiting."; exit 1; }
+                  rm -f snapshot.tar

Consider:

  1. Adding SHA256 verification of the downloaded snapshot
  2. Implementing a retry mechanism for failed downloads
  3. Adding progress logging for better observability
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
wget -c "${SNAPSHOT_URL}" -O snapshot.tar.lz4 || { echo "Download failed. Exiting."; exit 1; }
lz4 -d snapshot.tar.lz4 snapshot.tar || { echo "Decompression failed. Exiting."; exit 1; }
tar -xvf snapshot.tar -C ${HEIMDALLD_HOME}/data || { echo "Extraction failed. Exiting."; exit 1; }
# Check available disk space
available_space=$(df -P ${HEIMDALLD_HOME} | awk 'NR==2 {print $4}')
required_space=$((20 * 1024 * 1024)) # 20GB in KB
if [ "${available_space}" -lt "${required_space}" ]; then
echo "Insufficient disk space. Required: 20GB, Available: $((available_space/1024/1024))GB. Exiting."; exit 1;
fi
# Download with progress and timeout
wget --progress=dot:giga --timeout=3600 -c "${SNAPSHOT_URL}" -O snapshot.tar.lz4.tmp || { echo "Download failed. Exiting."; exit 1; }
mv snapshot.tar.lz4.tmp snapshot.tar.lz4
# Process snapshot with cleanup
lz4 -d snapshot.tar.lz4 snapshot.tar || { rm -f snapshot.tar.lz4; echo "Decompression failed. Exiting."; exit 1; }
rm -f snapshot.tar.lz4
tar -xf snapshot.tar -C ${HEIMDALLD_HOME}/data || { rm -f snapshot.tar; echo "Extraction failed. Exiting."; exit 1; }
rm -f snapshot.tar

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

🧹 Nitpick comments (3)
charts/heimdall/templates/heimdall/statefulset.yaml (3)

Line range hint 52-97: Consider improving configuration management approach

While the current implementation works, consider these improvements for better maintainability and reliability:

  1. Use a configuration management tool or templating instead of sed
  2. Add validation for environment variables before using them
  3. Add logging for successful configuration updates
 command:
   - sh
   - -c
   - |
     set -ex
     HEIMDALLD_HOME="/storage"
+    # Validate required environment variables
+    : "${SEEDS:?Required environment variable SEEDS is not set}"
+    : "${CORS_ALLOWED_ORIGINS:?Required environment variable CORS_ALLOWED_ORIGINS is not set}"
+
+    echo "Starting Heimdall configuration initialization..."
 
     # If config hasn't been bootstrapped already, do it
     if [ ! -f "$HEIMDALLD_HOME/config/config.toml" ]; then
       heimdalld --home $HEIMDALLD_HOME init
+      echo "Initialized new Heimdall configuration"
     fi
 
     # Replace init genesis with desired network genesis
     cp /genesis-config/genesis.json $HEIMDALLD_HOME/config/genesis.json
+    echo "Updated genesis configuration"
 
     cd $HEIMDALLD_HOME/config
 
     # Patch config.toml
     sed -iE "s#^cors_allowed_origins.*#cors_allowed_origins = ${CORS_ALLOWED_ORIGINS}#" config.toml
     sed -iE "s#^seeds.*#seeds = \"${SEEDS}\"#" config.toml
+    echo "Updated CORS and seeds configuration"
 
     if [ "${METRICS}" = "true" ]; then
       sed -iE "s#^prometheus \?=.*#prometheus = true#" config.toml
       sed -iE "s#^prometheus_listen_addr \?=.*#prometheus_listen_addr = \":${METRICS_PORT}\"#" config.toml
+      echo "Enabled metrics on port ${METRICS_PORT}"
     else
       sed -iE "s#^prometheus \?=.*#prometheus = false#" config.toml
+      echo "Disabled metrics"
     fi

100-101: Address TODO comment regarding image tag

The comment indicates that the image tag needs to be updated. Consider:

  1. Using a versioned tag instead of a SHA for better maintainability
  2. Adding the version to the Helm values for configurability
-          ## TODO: update tag
-          image: ghcr.io/graphops/docker-builds/init-stream-download@sha256:acbe5bff3b273b6e56b7aad20e8368ab9ddb091250b744e41ad66d6e7c2d0901
+          image: {{ $values.initContainer.snapshot.image.repository }}:{{ $values.initContainer.snapshot.image.tag }}

98-122: Consider adding readiness probe for snapshot initialization

The snapshot initialization is a critical step. Consider adding a readiness probe to ensure the snapshot is properly loaded before starting the main container.

         - name: {{ $componentName }}-init-snapshot
           image: ghcr.io/graphops/docker-builds/init-stream-download@sha256:acbe5bff3b273b6e56b7aad20e8368ab9ddb091250b744e41ad66d6e7c2d0901
+          readinessProbe:
+            exec:
+              command:
+              - /bin/sh
+              - -c
+              - |
+                if [ -f "/storage/from_snapshot" ] && [ -d "/storage/data" ]; then
+                  exit 0
+                else
+                  exit 1
+                fi
+            initialDelaySeconds: 10
+            periodSeconds: 30
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between ee62ec9 and 40bb933.

📒 Files selected for processing (4)
  • charts/heimdall/Chart.yaml (1 hunks)
  • charts/heimdall/README.md (2 hunks)
  • charts/heimdall/templates/heimdall/statefulset.yaml (2 hunks)
  • charts/heimdall/values.yaml (1 hunks)
✅ Files skipped from review due to trivial changes (3)
  • charts/heimdall/README.md
  • charts/heimdall/Chart.yaml
  • charts/heimdall/values.yaml
🔇 Additional comments (1)
charts/heimdall/templates/heimdall/statefulset.yaml (1)

109-115: Improve snapshot management reliability

The current snapshot management implementation could be enhanced with better error handling and resource management. A previous review has already suggested improvements including:

  1. Disk space verification
  2. Download progress monitoring
  3. Cleanup of temporary files
  4. SHA256 verification
  5. Retry mechanism

Please refer to the previous review comment for the detailed implementation suggestion.

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