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 CPU_INFO_FLAGS for Apple Silicon #2694

Merged
merged 2 commits into from
Oct 11, 2024

Conversation

kpango
Copy link
Collaborator

@kpango kpango commented Oct 10, 2024

Description

SSIA

Related Issue

Versions

  • Vald Version: v1.7.13
  • Go Version: v1.23.2
  • Rust Version: v1.81.0
  • Docker Version: v27.3.1
  • Kubernetes Version: v1.31.1
  • Helm Version: v3.16.2
  • NGT Version: v2.2.4
  • Faiss Version: v1.9.0

Checklist

Special notes for your reviewer

Summary by CodeRabbit

  • Chores
    • Improved CPU information gathering for macOS and Linux systems in the build process.
    • Enhanced adaptability of the build process across different operating systems.
    • Added environment variables for Rust toolchain setup in Dockerfiles.
    • Updated dependency versions in the Go module for better compatibility.
    • Incremented the TELEPRESENCE_VERSION from 2.20.0 to 2.20.1.

Copy link
Contributor

coderabbitai bot commented Oct 10, 2024

📝 Walkthrough
📝 Walkthrough

Walkthrough

The changes in the Makefile involve modifications to how CPU information is gathered based on the operating system. The update introduces a conditional assignment for the CPU_INFO_FLAGS variable, which now retrieves the CPU brand string using the sysctl command for macOS, while maintaining an empty string for Linux systems. Additionally, the CORES variable is consistently evaluated for both Linux and macOS, ensuring accurate identification of processing cores across different environments. Changes to Dockerfiles involve setting environment variables for Rust, while the go.mod file updates dependency versions and the TELEPRESENCE_VERSION is incremented.

Changes

File Change Summary
Makefile Modified CPU_INFO_FLAGS to conditionally retrieve CPU brand string for macOS; ensured CORES variable is evaluated for both Linux and macOS.
dockers/agent/core/agent/Dockerfile Added environment variable CARGO_HOME=${RUST_HOME}/cargo.
dockers/ci/base/Dockerfile Added environment variable CARGO_HOME=${RUST_HOME}/cargo; streamlined installation commands.
dockers/dev/Dockerfile Added environment variable RUSTUP_HOME=${RUST_HOME}/rustup.
go.mod Updated Go module version to go 1.23.2; updated gocloud.dev from v0.39.0 to v0.40.0; updated sigs.k8s.io/json dependency.
versions/TELEPRESENCE_VERSION Incremented version from 2.20.0 to 2.20.1.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Makefile
    participant OS

    User->>Makefile: Trigger build process
    Makefile->>OS: Check operating system
    OS-->>Makefile: Return OS type (Linux or macOS)
    alt macOS
        Makefile->>OS: Retrieve CPU brand string using sysctl
        OS-->>Makefile: Return CPU brand string
    else Linux
        Makefile->>Makefile: Set CPU_INFO_FLAGS to empty
    end
    Makefile->>OS: Evaluate number of processing cores
    OS-->>Makefile: Return number of cores
    Makefile->>User: Complete build process
Loading

Possibly related PRs

Suggested labels

type/feature, area/internal, area/agent/core/faiss, area/agent/core/ngt, size/L, priority/medium, actions/e2e-deploy, actions/fossa, actions/e2e-chaos, actions/e2e-profiling, actions/e2e-max-dim, area/index/job/correction, area/index/job/creation, area/index/job/save, area/index/job/readreplica

Suggested reviewers

  • hlts2
  • datelier

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.

@vdaas-ci
Copy link
Collaborator

[CHATOPS:HELP] ChatOps commands.

  • 🙆‍♀️ /approve - approve
  • 🍱 /format - format codes and add licenses
  • /gen-test - generate test codes
  • 🏷️ /label - add labels
  • 🔚 2️⃣ 🔚 /label actions/e2e-deploy - run E2E deploy & integration test

Copy link
Contributor

@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)
Makefile (1)

130-131: LGTM! Consider minor improvement for consistency.

The changes to CPU_INFO_FLAGS for Darwin systems look good. It now properly handles Apple Silicon by attempting to get the CPU brand string and falling back to "Apple Silicon" if that fails.

For consistency, you might want to consider using the same error handling approach for the CORES assignment:

-CORES := $(eval CORES := $(shell sysctl -n hw.ncpu 2>/dev/null || getconf _NPROCESSORS_ONLN 2>/dev/null))$(CORES)
+CORES := $(eval CORES := $(shell sysctl -n hw.ncpu 2>/dev/null || getconf _NPROCESSORS_ONLN 2>/dev/null || echo "1"))$(CORES)

This ensures that CORES always has a value, even if both sysctl and getconf fail.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between a4ae440 and 4c76685.

📒 Files selected for processing (1)
  • Makefile (1 hunks)
🧰 Additional context used

coderabbitai[bot]
coderabbitai bot previously approved these changes Oct 10, 2024
Copy link

codecov bot commented Oct 10, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 24.04%. Comparing base (a4ae440) to head (467d469).
Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2694   +/-   ##
=======================================
  Coverage   24.04%   24.04%           
=======================================
  Files         539      539           
  Lines       46792    46792           
=======================================
+ Hits        11250    11253    +3     
+ Misses      34766    34762    -4     
- Partials      776      777    +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@kpango kpango requested review from a team, vankichi and datelier and removed request for a team October 10, 2024 23:32
@kpango kpango force-pushed the refactor/makefile/build-cpu-info-for-apple-silicon branch from 4c76685 to d64e797 Compare October 10, 2024 23:51
Copy link

cloudflare-workers-and-pages bot commented Oct 10, 2024

Deploying vald with  Cloudflare Pages  Cloudflare Pages

Latest commit: 467d469
Status: ✅  Deploy successful!
Preview URL: https://7c3952de.vald.pages.dev
Branch Preview URL: https://refactor-makefile-build-cpu.vald.pages.dev

View logs

@github-actions github-actions bot added size/M and removed size/S labels Oct 10, 2024
Copy link
Contributor

@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 (3)
dockers/agent/core/agent/Dockerfile (1)

Line range hint 1-1: Consider removing unused UPX_OPTIONS argument

The Dockerfile defines an UPX_OPTIONS argument in the first line:

ARG UPX_OPTIONS=-9

However, this argument is not used anywhere else in the Dockerfile. If it's not needed for other parts of the build process or in scripts that use this Dockerfile, consider removing it to keep the Dockerfile clean and avoid confusion.

If it is used elsewhere, it might be helpful to add a comment explaining its purpose and where it's used.

dockers/ci/base/Dockerfile (1)

Line range hint 1-124: Consider security enhancements and image size optimization

The Dockerfile follows many best practices, such as using multi-stage builds, caching mechanisms, and grouping installation commands. However, consider the following suggestions for further improvement:

  1. Security: Add a non-root user for running the container. While the current setup uses root, it's generally recommended to use a non-root user for security reasons.

  2. Image size: Consider using a smaller base image if possible, such as debian:slim or alpine, to reduce the overall image size.

  3. Clean-up: Although you're using multi-stage builds, ensure all unnecessary build dependencies are removed in the final stage to minimize the image size.

  4. Version pinning: For better reproducibility, consider pinning specific versions of installed packages where possible.

  5. HEALTHCHECK: Consider adding a HEALTHCHECK instruction to allow Docker to test if your container is still working.

Here's an example of how you might implement some of these suggestions:

# Use a non-root user
RUN useradd -m appuser
USER appuser

# Add a HEALTHCHECK
HEALTHCHECK CMD curl --fail http://localhost:8080/health || exit 1

# Example of version pinning (adjust versions as needed)
RUN apt-get install -y --no-install-recommends \
    curl=7.68.0-1ubuntu2.7 \
    git=1:2.25.1-1ubuntu3.5 \
    # ... other packages

These changes can enhance the security and efficiency of your Docker image while maintaining its functionality.

dockers/dev/Dockerfile (1)

Line range hint 1-48: Overall impact is positive, consider adding a comment for clarity

The addition of the RUSTUP_HOME environment variable is a good improvement to the Dockerfile. It aligns well with the existing Rust-related configurations and doesn't introduce any conflicts or issues with other parts of the file.

While this change is consistent with best practices for Rust development environments, it's not directly related to the PR objective of adding CPU_INFO_FLAGS for Apple Silicon. However, it's a valuable addition that enhances the overall quality of the development environment.

Consider adding a comment above the Rust-related environment variables to explain their purpose and relationship. This could improve readability for future maintainers. For example:

+# Rust-related environment variables
ENV RUST_HOME=/usr/local/lib/rust
ENV CARGO_HOME=${RUST_HOME}/cargo
ENV RUSTUP_HOME=${RUST_HOME}/rustup
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 4c76685 and d64e797.

⛔ Files ignored due to path filters (2)
  • go.sum is excluded by !**/*.sum
  • rust/Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (6)
  • Makefile (1 hunks)
  • dockers/agent/core/agent/Dockerfile (1 hunks)
  • dockers/ci/base/Dockerfile (1 hunks)
  • dockers/dev/Dockerfile (1 hunks)
  • go.mod (2 hunks)
  • versions/TELEPRESENCE_VERSION (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • versions/TELEPRESENCE_VERSION
🚧 Files skipped from review as they are similar to previous changes (1)
  • Makefile
🧰 Additional context used
🔇 Additional comments (5)
dockers/agent/core/agent/Dockerfile (2)

43-43: LGTM: Proper setup of Rust environment variables

The addition of ENV CARGO_HOME=${RUST_HOME}/cargo is correct and aligns with best practices for Rust development environments. This change ensures that Cargo (Rust's package manager) has a specific home directory, which is essential for proper functioning of Rust tools and dependencies.

The CARGO_HOME is correctly set based on the previously defined RUST_HOME, and the PATH is appropriately updated to include the Cargo binary directory. This setup will allow for consistent and predictable behavior of Rust tools within the Docker container.


Line range hint 1-93: Overall, the Dockerfile looks well-structured and follows good practices

The Dockerfile uses multi-stage builds, caching mechanisms, and a minimal distroless image for the final stage, which are all excellent practices for creating efficient and secure Docker images. The addition of the CARGO_HOME environment variable improves the Rust development environment setup.

The only minor suggestion is to consider removing the unused UPX_OPTIONS argument if it's not needed elsewhere in the build process.

Great job on maintaining a clean and efficient Dockerfile!

dockers/ci/base/Dockerfile (1)

48-48: LGTM: Addition of CARGO_HOME environment variable

The addition of the CARGO_HOME environment variable is a good practice for Rust development environments. It ensures that Cargo's files are stored in a consistent location, which is particularly important in containerized environments. This change aligns well with Rust's recommended setup and complements the existing RUSTUP_HOME variable.

dockers/dev/Dockerfile (1)

48-48: LGTM: Explicit definition of RUSTUP_HOME enhances clarity

The addition of ENV RUSTUP_HOME=${RUST_HOME}/rustup is a positive change. It explicitly defines the location for Rust toolchain installations, which enhances clarity and follows best practices for Rust development environments. This change is consistent with the existing structure and complements the previously defined CARGO_HOME.

Moreover, it ensures that the ${RUSTUP_HOME}/bin directory included in the PATH (defined in the next line) points to a specific, well-defined location. This can help prevent potential issues related to Rust toolchain discovery and usage within the container.

go.mod (1)

296-296: LGTM: Dependency version updates

The updates to gocloud.dev (v0.39.0 to v0.40.0) and sigs.k8s.io/json (v0.0.0-20241009153224-e386a8af8d30 to v0.0.0-20241010143419-9aa6b5e7a4b3) are minor version changes, which typically indicate bug fixes or small improvements. These updates are appropriate and align with good dependency management practices.

Also applies to: 345-345

@kpango kpango requested review from kmrmt and removed request for vankichi October 11, 2024 01:51
@datelier datelier merged commit 67ebe73 into main Oct 11, 2024
190 checks passed
@datelier datelier deleted the refactor/makefile/build-cpu-info-for-apple-silicon branch October 11, 2024 02:43
vdaas-ci pushed a commit that referenced this pull request Oct 11, 2024
kpango added a commit that referenced this pull request Oct 11, 2024
@kpango kpango mentioned this pull request Oct 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants