Add helper recommendSpecOptions#2114
Conversation
Signed-off-by: Seokho Son <shsongist@gmail.com>
There was a problem hiding this comment.
Pull Request Overview
This PR adds a new helper endpoint /recommendSpecOptions that provides available options for filtering and prioritizing specs in the RecommendSpec API.
- Introduces a GET endpoint to retrieve filtering and prioritization options
- Adds comprehensive model structures for request options and examples
- Updates Swagger documentation for the new endpoint
Reviewed Changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/interface/rest/server/server.go | Adds new GET route for RecommendSpecOptions endpoint |
| src/interface/rest/server/infra/recommendation.go | Implements RestRecommendSpecOptions handler function |
| src/interface/rest/docs/swagger.yaml | Updates Swagger documentation with new endpoint and model definitions |
| src/interface/rest/docs/swagger.json | Updates JSON Swagger documentation with new schemas |
| src/interface/rest/docs/docs.go | Updates Go documentation templates |
| src/interface/mcp/tb-mcp.py | Removes old get_specs and get_images functions, adds new get_recommend_spec_options tool |
| src/core/model/spec.go | Defines new model structures for RecommendSpecRequestOptions |
| src/core/infra/recommendation.go | Implements RecommendSpecOptions business logic with database queries |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| u := &model.RecommendSpecReq{} | ||
| if err := c.Bind(u); err != nil { | ||
| return clientManager.EndRequestWithLog(c, err, nil) | ||
| } | ||
|
|
There was a problem hiding this comment.
The variable u is created and bound but never used. This GET endpoint doesn't require a request body, so this binding is unnecessary and could potentially cause errors if clients send invalid JSON.
| u := &model.RecommendSpecReq{} | |
| if err := c.Bind(u); err != nil { | |
| return clientManager.EndRequestWithLog(c, err, nil) | |
| } |
| u := &model.RecommendSpecReq{} | ||
| if err := c.Bind(u); err != nil { | ||
| return clientManager.EndRequestWithLog(c, err, nil) | ||
| } | ||
|
|
There was a problem hiding this comment.
This binding logic is inappropriate for a GET endpoint that should not require a request body. Remove the binding code since this endpoint only needs to return static options.
| u := &model.RecommendSpecReq{} | |
| if err := c.Bind(u); err != nil { | |
| return clientManager.EndRequestWithLog(c, err, nil) | |
| } |
|
/approve |
Add feature for getting options for RecommendSpec API
Request URL
http://localhost:1323/tumblebug/recommendSpecOptions
Response body
{ "filter": { "availableMetrics": [ "id", "providerName", "regionName", "cspSpecName", "architecture", "acceleratorModel", "acceleratorType", "description", "vCPU", "memoryGiB", "acceleratorCount", "acceleratorMemoryGB", "costPerHour", "evaluationScore01" ], "examplePolicies": [ { "metric": "vCPU", "description": "Filter specs with 2-8 vCPUs", "condition": [ { "operator": ">=", "operand": "2" }, { "operator": "<=", "operand": "8" } ] }, { "metric": "memoryGiB", "description": "Filter specs with at least 4GB memory", "condition": [ { "operator": ">=", "operand": "4" } ] }, { "metric": "costPerHour", "description": "Filter specs with cost under $0.50/hour", "condition": [ { "operator": "<=", "operand": "0.50" } ] }, { "metric": "providerName", "description": "Filter specs from specific provider", "condition": [ { "operator": "=", "operand": "aws" } ] }, { "metric": "architecture", "description": "Filter specs by architecture", "condition": [ { "operator": "=", "operand": "x86_64" } ] }, { "metric": "infraType", "description": "Filter specs by infrastructure type", "condition": [ { "operator": "=", "operand": "vm" } ] }, { "metric": "acceleratorType", "description": "Filter specs with GPU accelerator", "condition": [ { "operator": "=", "operand": "GPU" } ] }, { "metric": "diskSizeGB", "description": "Filter specs with disk size between 100-500GB", "condition": [ { "operator": ">=", "operand": "100" }, { "operator": "<=", "operand": "500" } ] } ], "availableValues": { "providerName": [ "alibaba", "aws", "azure", "gcp", "ibm", "kt", "ncp", "nhn", "tencent" ], "regionName": [ "af-south-1", "africa-south1", "ap-bangkok", "ap-beijing", "ap-chengdu", "ap-chongqing", "ap-east-1", "ap-guangzhou", "ap-hongkong", "ap-jakarta", "... (중략: 전체 regionName 리스트)" ], "cspSpecName": [ "a1.2xlarge", "Standard_A1_v2", "bx2-128x512", "ecs.c1.large", "... (중략: 전체 cspSpecName 리스트)" ], "infraType": null, "architecture": ["arm64", "arm64_mac", "s390x", "x86_64", "x86_64_mac"], "acceleratorModel": [ "A910E", "AMD Instinct MI300X", "NVIDIA A100", "NVIDIA H100", "... (중략: 전체 acceleratorModel 리스트)" ], "acceleratorType": ["gpu"] } }, "priority": { "availableMetrics": ["cost", "performance", "location", "latency", "random"], "examplePolicies": [ { "metric": "cost", "description": "Prioritize by lowest cost", "weight": "1.0" }, { "metric": "performance", "description": "Prioritize by highest performance", "weight": "1.0" }, { "metric": "location", "description": "Prioritize by proximity to coordinates", "weight": "1.0", "parameter": [ { "key": "coordinateClose", "description": "Find specs closest to given coordinate", "val": ["37.5665/126.9780"] } ] }, { "metric": "latency", "description": "Prioritize by minimal network latency", "weight": "1.0", "parameter": [ { "key": "latencyMinimal", "description": "Find specs with minimal latency to target", "val": ["aws+us-east-1"] } ] }, { "metric": "random", "description": "Random prioritization for testing", "weight": "1.0" } ], "parameterOptions": { "locationParameters": [ { "key": "coordinateClose", "description": "Find specs closest to given coordinate (latitude/longitude)", "format": "latitude/longitude", "example": ["37.5665/126.9780", "35.6762/139.6503", "40.7128/-74.0060"] }, { "key": "coordinateWithin", "description": "Find specs within radius of coordinate (latitude/longitude/radius_km)", "format": "latitude/longitude/radius_km", "example": ["37.5665/126.9780/100", "35.6762/139.6503/50"] }, { "key": "coordinateFair", "description": "Fair distribution around coordinate with radius (latitude/longitude/radius_km)", "format": "latitude/longitude/radius_km", "example": ["37.5665/126.9780/200", "35.6762/139.6503/150"] } ], "latencyParameters": [ { "key": "latencyMinimal", "description": "Find specs with minimal network latency to target region", "format": "provider+region", "example": ["aws+us-east-1", "azure+eastus", "gcp+us-central1-a"] } ] } }, "limit": ["5", "10", "20", "50"] }