From 8303c4df14b32776546f9112446a683f5308f30c Mon Sep 17 00:00:00 2001 From: hippo-an Date: Wed, 4 Dec 2024 21:59:04 +0900 Subject: [PATCH] fix: change the product family value to Server to query the price information of the ncp provider --- internal/core/cost/price_collector.go | 12 +++++++++++- internal/infra/outbound/spider/price.go | 8 ++------ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/internal/core/cost/price_collector.go b/internal/core/cost/price_collector.go index 5547a9a..cc855ad 100644 --- a/internal/core/cost/price_collector.go +++ b/internal/core/cost/price_collector.go @@ -20,6 +20,11 @@ type PriceCollector interface { FetchPriceInfos(context.Context, RecommendSpecParam) (EstimateCostInfos, error) } +const ( + productFamily = "ComputeInstance" + ncpProductFamily = "Server" +) + var ( onDemandPricingPolicyMap = map[string]string{ "aws": "OnDemand", @@ -85,8 +90,13 @@ func (s *SpiderPriceCollector) FetchPriceInfos(ctx context.Context, param Recomm ConnectionName: connectionName, FilterList: s.generateFilter(param), } + pf := productFamily + + if strings.Contains(strings.ToLower(param.ProviderName), "ncp") { + pf = ncpProductFamily + } - result, err := s.sc.GetPriceInfoWithContext(ctx, param.RegionName, req) + result, err := s.sc.GetPriceInfoWithContext(ctx, pf, param.RegionName, req) if err != nil { diff --git a/internal/infra/outbound/spider/price.go b/internal/infra/outbound/spider/price.go index 6608917..6ba0ca2 100644 --- a/internal/infra/outbound/spider/price.go +++ b/internal/infra/outbound/spider/price.go @@ -10,15 +10,11 @@ import ( "github.com/rs/zerolog/log" ) -const ( - productFamily = "ComputeInstance" -) - -func (s *SpiderClient) GetPriceInfoWithContext(ctx context.Context, regionName string, body PriceInfoReq) (CloudPriceDataRes, error) { +func (s *SpiderClient) GetPriceInfoWithContext(ctx context.Context, pf, regionName string, body PriceInfoReq) (CloudPriceDataRes, error) { var cloudPriceData CloudPriceDataRes - url := s.withUrl(fmt.Sprintf("/priceinfo/%s/%s", productFamily, regionName)) + url := s.withUrl(fmt.Sprintf("/priceinfo/%s/%s", pf, regionName)) marshalledBody, err := json.Marshal(body) if err != nil {