Skip to content

Commit

Permalink
fix: failing redis price calculation
Browse files Browse the repository at this point in the history
Signed-off-by: Azanul <[email protected]>
  • Loading branch information
Azanul committed Jul 27, 2024
1 parent 2bad51c commit c2329a4
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions providers/gcp/redis/pricing.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"math"
"net/http"
"strings"
"time"

"cloud.google.com/go/redis/apiv1/redispb"
Expand Down Expand Up @@ -66,17 +67,18 @@ func calculateRedisCost(redis *redispb.Instance, pricing *GcpDatabasePricing) fl

if redis.Tier == redispb.Instance_BASIC {
priceMap = pricing.Gcp.Databases.CloudMemorystore.Redis.Basic
priceKey = fmt.Sprintf("Rediscapacitybasicm%ddefault", capacityTier)
priceKey = fmt.Sprintf("rediscapacitybasicm%ddefault", capacityTier)
} else if redis.Tier == redispb.Instance_STANDARD_HA {
priceMap = pricing.Gcp.Databases.CloudMemorystore.Redis.Standard
if redis.ReadReplicasMode == redispb.Instance_READ_REPLICAS_DISABLED {
priceKey = fmt.Sprintf("Rediscapacitystandardm%ddefault", capacityTier)
priceKey = fmt.Sprintf("rediscapacitystandardm%ddefault", capacityTier)
} else {
priceKey = fmt.Sprintf("Rediscapacitystandardnodem%d", capacityTier)
priceKey = fmt.Sprintf("rediscapacitystandardnodem%d", capacityTier)
}
}

pricePerHrPerGbInNanos := priceMap[priceKey].Regions[redis.LocationId].Price[0].Nanos
location := strings.Join(strings.Split(redis.LocationId, "-")[:2], "-")
pricePerHrPerGbInNanos := priceMap[priceKey].Regions[location].Price[0].Nanos
pricePerHrPerGbInDollars := pricePerHrPerGbInNanos / math.Pow(10, 9)

now := time.Now().UTC()
Expand Down

0 comments on commit c2329a4

Please sign in to comment.