Skip to content

Add helper recommendSpecOptions#2114

Merged
cb-github-robot merged 1 commit intocloud-barista:mainfrom
seokho-son:main
Aug 25, 2025
Merged

Add helper recommendSpecOptions#2114
cb-github-robot merged 1 commit intocloud-barista:mainfrom
seokho-son:main

Conversation

@seokho-son
Copy link
Copy Markdown
Member

Add feature for getting options for RecommendSpec API

  • Get available options for filtering and prioritizing specs in 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"]
}

Signed-off-by: Seokho Son <shsongist@gmail.com>
Copilot AI review requested due to automatic review settings August 25, 2025 07:50
@seokho-son seokho-son requested a review from yunkon-kim as a code owner August 25, 2025 07:50
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.

Comment on lines +66 to +70
u := &model.RecommendSpecReq{}
if err := c.Bind(u); err != nil {
return clientManager.EndRequestWithLog(c, err, nil)
}

Copy link

Copilot AI Aug 25, 2025

Choose a reason for hiding this comment

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

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.

Suggested change
u := &model.RecommendSpecReq{}
if err := c.Bind(u); err != nil {
return clientManager.EndRequestWithLog(c, err, nil)
}

Copilot uses AI. Check for mistakes.
Comment on lines +66 to +70
u := &model.RecommendSpecReq{}
if err := c.Bind(u); err != nil {
return clientManager.EndRequestWithLog(c, err, nil)
}

Copy link

Copilot AI Aug 25, 2025

Choose a reason for hiding this comment

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

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.

Suggested change
u := &model.RecommendSpecReq{}
if err := c.Bind(u); err != nil {
return clientManager.EndRequestWithLog(c, err, nil)
}

Copilot uses AI. Check for mistakes.
@seokho-son
Copy link
Copy Markdown
Member Author

/approve

@github-actions github-actions bot added the approved This PR is approved and will be merged soon. label Aug 25, 2025
@cb-github-robot cb-github-robot merged commit 5702b76 into cloud-barista:main Aug 25, 2025
5 checks passed
@seokho-son seokho-son review requested due to automatic review settings March 25, 2026 01:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved This PR is approved and will be merged soon.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants