Przeglądaj źródła

Merge branch 'develop' into cdp/uid-bug-fix

Alex Meijer 3 miesięcy temu
rodzic
commit
2ff0040711
2 zmienionych plików z 53 dodań i 1 usunięć
  1. 30 1
      pkg/cloud/azure/provider.go
  2. 23 0
      pkg/env/costmodel.go

+ 30 - 1
pkg/cloud/azure/provider.go

@@ -728,6 +728,14 @@ func createString(keys ...string) string {
 	return b.String()
 }
 
+// getConfigSource returns a human-readable string indicating the source of configuration
+func getConfigSource(envVarName, envValue, defaultSource string) string {
+	if envValue != "" {
+		return "env:" + envVarName
+	}
+	return defaultSource
+}
+
 func transformMachineType(subCategory string, mt []string) []string {
 	switch {
 	case strings.Contains(subCategory, "Basic"):
@@ -823,6 +831,27 @@ func (az *Azure) DownloadPricingData() error {
 		config.AzureOfferDurableID = envOfferID
 	}
 
+	// Check for Azure rate card filter environment variables with backward compatibility
+	locale := env.GetAzureLocale() // Defaults to "en-US"
+	
+	envCurrency := env.GetAzureCurrency()
+	currency := config.CurrencyCode // Use config default
+	if envCurrency != "" {
+		currency = envCurrency // Override with environment variable if provided
+	}
+	
+	envRegionInfo := env.GetAzureRegionInfo()
+	regionInfo := config.AzureBillingRegion // Use config default
+	if envRegionInfo != "" {
+		regionInfo = envRegionInfo // Override with environment variable if provided
+	}
+
+	// Debug logging for rate card configuration
+	log.Debugf("Azure rate card configuration: locale=%s (source: %s), currency=%s (source: %s), regionInfo=%s (source: %s)", 
+		locale, getConfigSource("AZURE_LOCALE", locale, "en-US"),
+		currency, getConfigSource("AZURE_CURRENCY", envCurrency, "config"),
+		regionInfo, getConfigSource("AZURE_REGION_INFO", envRegionInfo, "config"))
+
 	// Load the service provider keys
 	subscriptionID, clientID, clientSecret, tenantID := az.getAzureRateCardAuth(false, config)
 	config.AzureSubscriptionID = subscriptionID
@@ -866,7 +895,7 @@ func (az *Azure) DownloadPricingData() error {
 	providersClient := resources.NewProvidersClientWithBaseURI(azureEnv.ResourceManagerEndpoint, config.AzureSubscriptionID)
 	providersClient.Authorizer = authorizer
 
-	rateCardFilter := fmt.Sprintf("OfferDurableId eq '%s' and Currency eq '%s' and Locale eq 'en-US' and RegionInfo eq '%s'", config.AzureOfferDurableID, config.CurrencyCode, config.AzureBillingRegion)
+	rateCardFilter := fmt.Sprintf("OfferDurableId eq '%s' and Currency eq '%s' and Locale eq '%s' and RegionInfo eq '%s'", config.AzureOfferDurableID, currency, locale, regionInfo)
 
 	// create a preparer (the same way rcClient.Get() does) so that we can log the azureRateCard URL
 	log.Infof("Using azureRateCard query %s", rateCardFilter)

+ 23 - 0
pkg/env/costmodel.go

@@ -34,6 +34,11 @@ const (
 
 	AzureOfferIDEnvVar        = "AZURE_OFFER_ID"
 	AzureBillingAccountEnvVar = "AZURE_BILLING_ACCOUNT"
+	
+	// Azure rate card filter environment variables
+	AzureLocaleEnvVar     = "AZURE_LOCALE"
+	AzureCurrencyEnvVar   = "AZURE_CURRENCY"
+	AzureRegionInfoEnvVar = "AZURE_REGION_INFO"
 
 	// Currently being used for OCI and DigitalOcean
 	ProviderPricingURL = "PROVIDER_PRICING_URL"
@@ -221,6 +226,24 @@ func GetAzureBillingAccount() string {
 	return env.Get(AzureBillingAccountEnvVar, "")
 }
 
+// GetAzureLocale returns the environment variable value for AzureLocaleEnvVar which represents
+// the Azure rate card locale filter. Defaults to "en-US" if not specified.
+func GetAzureLocale() string {
+	return env.Get(AzureLocaleEnvVar, "en-US")
+}
+
+// GetAzureCurrency returns the environment variable value for AzureCurrencyEnvVar which represents
+// the Azure rate card currency filter. This overrides the default currency from config if specified.
+func GetAzureCurrency() string {
+	return env.Get(AzureCurrencyEnvVar, "")
+}
+
+// GetAzureRegionInfo returns the environment variable value for AzureRegionInfoEnvVar which represents
+// the Azure rate card region filter. This overrides the default region from config if specified.
+func GetAzureRegionInfo() string {
+	return env.Get(AzureRegionInfoEnvVar, "")
+}
+
 // IsAzureDownloadBillingDataToDisk returns the environment variable value for
 // AzureDownloadBillingDataToDiskEnvVar which indicates whether the Azure
 // Billing Data should be held in memory or written to disk.