Implement retry logic for all Lambda Labs API calls #20
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Implement retry logic for all Lambda Labs API calls
Summary
This PR extends the existing retry logic pattern from
GetInstanceTypesto all other Lambda Labs API calls. Previously, only theGetInstanceTypesmethod had retry logic implemented, leaving other critical operations like instance creation, termination, and management vulnerable to transient network issues or API rate limits.Changes made:
AddSSHKey,LaunchInstance,GetInstance,TerminateInstance,ListInstances, andRestartInstancegetInstanceTypescollections.RetryWithDataAndAttemptCount,getBackoff(), andhandleAPIError()collectionsimportFiles modified:
internal/lambdalabs/v1/instance.go- Main implementation with 6 new retry-wrapped functionsReview & Testing Checklist for Human
getInstanceTypesimplementation to ensure identical patternshandleAPIErrorusageAddSSHKeyretry logic works properlyRecommended test plan: Create a test instance, perform various operations (reboot, get status), then terminate it while monitoring for any unexpected errors or timeouts.
Diagram
%%{ init : { "theme" : "default" }}%% graph TD subgraph "Lambda Labs Provider" Instance["internal/lambdalabs/v1/<br/>instance.go"]:::major-edit InstanceType["internal/lambdalabs/v1/<br/>instancetype.go"]:::context Client["internal/lambdalabs/v1/<br/>client.go"]:::context Errors["internal/lambdalabs/v1/<br/>errors.go"]:::context end subgraph "Retry Infrastructure" Collections["internal/collections/<br/>RetryWithDataAndAttemptCount"]:::context Backoff["getBackoff()"]:::context ErrorHandler["handleAPIError()"]:::context end subgraph "API Operations" CreateOp["CreateInstance<br/>(LaunchInstance + AddSSHKey)"]:::major-edit GetOp["GetInstance"]:::major-edit ListOp["ListInstances"]:::major-edit TerminateOp["TerminateInstance"]:::major-edit RebootOp["RebootInstance<br/>(RestartInstance)"]:::major-edit GetTypesOp["GetInstanceTypes<br/>(existing pattern)"]:::context end Instance --> CreateOp Instance --> GetOp Instance --> ListOp Instance --> TerminateOp Instance --> RebootOp CreateOp --> Collections GetOp --> Collections ListOp --> Collections TerminateOp --> Collections RebootOp --> Collections GetTypesOp --> Collections Collections --> Backoff Collections --> ErrorHandler Client --> Backoff Errors --> ErrorHandler 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:#FFFFFFNotes
getInstanceTypesmethod