Skip to content

Conversation

@devin-ai-integration
Copy link
Contributor

@devin-ai-integration devin-ai-integration bot commented Jul 22, 2025

Add brev find instance-type command with filtering and Root Disk column

Summary

Implements a new CLI command brev find instance-type that queries the Brev API (https://api.brev.dev/v1/instance/types) to help users find suitable instance types based on various criteria. The command supports filtering by GPU type, count, VRAM, memory, CPU, price, provider, and capabilities, then displays results in a sorted table format.

Key features:

  • Comprehensive filtering: Support for --gpu, --min-gpu-count, --min-node-vram, --min-gpu-vram, --min-ram, --min-cpu, --max-hourly-price, --provider, --capabilities, and --min-disk
  • Smart sorting: Results sorted by hourly price (ascending) to show most cost-effective options first
  • Rich table display: Shows instance type, provider, GPU info, Node VRAM, memory, vCPUs, Root Disk, price, and capabilities
  • Root Disk column: Displays disk size (fixed or range) and cheapest price per TB, handling different storage formats across providers (Crusoe: fixed sizes, AWS/GCP: ranges)

The implementation addresses PR feedback by renaming --min-total-vram to --min-node-vram and adding both "Node VRAM" and "Root Disk" columns to the output.

Review & Testing Checklist for Human

  • Verify price calculations are accurate - Test that the GB-to-TB conversion (×1000) and price parsing logic produces correct $/TB/hr values for different providers
  • Test storage format handling edge cases - Verify Root Disk column correctly handles Crusoe's fixed sizes vs AWS/GCP ranges, and gracefully handles missing/malformed storage data
  • Validate memory parsing across units - Test filtering with various memory formats (GB, GiB, TB, etc.) to ensure parseMemoryToGB correctly converts all units
  • Test filtering logic comprehensively - Verify edge cases like instances with no GPUs, mixed GPU types, and boundary conditions for numeric filters
  • Confirm API error handling - Test behavior when API is unreachable, returns errors, or has malformed responses

Recommended test plan:

# Test different provider storage formats
brev find instance-type --provider crusoe
brev find instance-type --provider aws  
brev find instance-type --provider gcp

# Test edge cases and combinations
brev find instance-type --min-node-vram 100 --max-hourly-price 1.0
brev find instance-type --gpu nonexistent-gpu
brev find instance-type --capabilities invalid-capability

Diagram

%%{ init : { "theme" : "default" }}%%
graph TD
    cmd["pkg/cmd/cmd.go<br/>(Register find command)"]:::minor-edit
    find["pkg/cmd/find/find.go<br/>(Main implementation)"]:::major-edit
    http["pkg/store/http.go<br/>(API client & structs)"]:::major-edit
    api["api.brev.dev/v1/instance/types<br/>(External API)"]:::context
    
    cmd -->|"imports & registers"| find
    find -->|"calls GetInstanceTypes()"| http
    http -->|"HTTP request"| api
    api -->|"JSON response"| http
    http -->|"parsed structs"| find
    find -->|"filtered & sorted table"| user["CLI Output"]:::context

    subgraph Legend
        L1["Major Edit"]:::major-edit
        L2["Minor Edit"]:::minor-edit  
        L3["Context/No Edit"]:::context
    end

    classDef major-edit fill:#90EE90
    classDef minor-edit fill:#87CEEB
    classDef context fill:#FFFFFF
Loading

Notes

  • Storage complexity: The Root Disk implementation handles 3 different formats: Crusoe (fixed size + count), AWS/GCP (min/max ranges), and fallback cases. This logic is complex and prone to edge cases.
  • Memory unit parsing: The parseMemoryToGB function handles various units (B, KB, MB, GB, TB, with/without 'i' suffix). Unit conversion bugs are common in this type of logic.
  • API dependency: Command relies on external Brev API which could change format or become unavailable. Error handling exists but may not cover all scenarios.
  • Price calculations: Converting from price-per-GB-per-hour to price-per-TB-per-hour involves floating point arithmetic that should be verified for accuracy.

Session details:

- Implement new CLI command 'brev find instance-type' with comprehensive filtering options
- Add support for filtering by GPU type, count, VRAM, provider, price, capabilities, RAM, and CPU
- Query public API at https://api.brev.dev/v1/instance/types for instance data
- Sort results by hourly price in ascending order
- Display results in formatted table with instance type, provider, GPUs, memory, VCPUs, price, and capabilities
- Add GetInstanceTypes method to NoAuthHTTPStore for API integration
- Support all requested flag combinations for flexible instance discovery

Co-Authored-By: Alec Fong <[email protected]>
@devin-ai-integration
Copy link
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@theFong
Copy link
Member

theFong commented Jul 22, 2025

Lets change --min-node-vram to mean the number of gpus * gpu vram. --min-gpu-vram is the per gpu vram. I think Node vram deserves its own column too.

devin-ai-integration bot and others added 2 commits July 22, 2025 02:15
…dd Node VRAM column

- Rename --min-total-vram flag to --min-node-vram for clarity
- Add Node VRAM column to table display showing total VRAM across all GPUs
- Update FilterOptions struct to use MinNodeVRAM field
- Rename hasMinTotalVRAM function to hasMinNodeVRAM
- Add formatNodeVRAM function to calculate total VRAM per instance
- Update command examples to use new flag name
- Maintain existing --min-gpu-vram functionality for per-GPU filtering

Co-Authored-By: Alec Fong <[email protected]>
- Change displayInstanceTypesTable parameter from 't' to '_' to indicate unused
- Break down matchesFilters function into smaller functions to reduce complexity:
  - matchesGPUFilters: handles GPU-related filtering
  - matchesResourceFilters: handles provider, price, RAM, CPU filtering
  - matchesCapabilityFilters: handles capability filtering

This addresses the CI lint failures while maintaining all existing functionality.

Co-Authored-By: Alec Fong <[email protected]>
@theFong
Copy link
Member

theFong commented Jul 22, 2025

Lets also add a column to the list to show the root disk. If it is static, then should be a scalar value but if it can be a range lets show the min and max it can be. You can choose the cheapest disk price. Lets also show the disk price per TB if available.

devin-ai-integration bot and others added 5 commits July 22, 2025 02:26
- Remove trailing whitespace
- Align struct field formatting for InstanceType
- Address CI lint failures for lines 224, 234, and 240

Co-Authored-By: Alec Fong <[email protected]>
- Add Count field to Storage struct for Crusoe compatibility
- Add Root Disk column to instance types table
- Implement formatRootDisk function to show disk size and cheapest price per TB
- Handle both fixed sizes (Crusoe) and ranges (AWS/GCP)
- Calculate and display price per TB from hourly GB pricing

Addresses GitHub comment feedback on PR #248

Co-Authored-By: Alec Fong <[email protected]>
The --min-disk flag was actually working correctly but had debug output
that needed to be removed. The implementation properly:

- Parses disk size strings (e.g., '1TB', '500GB') to GB values
- Checks all storage options for each instance type
- Handles both fixed sizes (Crusoe) and ranges (AWS/GCP)
- Uses MaxSize for range-based storage when Size is '0B'
- Returns true if any storage option meets the minimum requirement

Testing confirms the flag now filters instances correctly based on
minimum disk size requirements across all providers.

Addresses user feedback on --min-disk flag not working.

Co-Authored-By: Alec Fong <[email protected]>
Addresses gocritic ifElseChain rule violation in formatRootDisk function
by converting the conditional logic to use a switch statement with cases.
Maintains the same functionality while satisfying the linter requirements.

Co-Authored-By: Alec Fong <[email protected]>
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.

2 participants