cloudcost.go 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. package env
  2. import (
  3. "github.com/opencost/opencost/core/pkg/env"
  4. )
  5. const (
  6. CloudCostConfigControllerStateFile = "cloud-configurations.json"
  7. CloudIntegrationConfigFile = "cloud-integration.json"
  8. AzureBillingDataDownloadPath = "db/cloudcost"
  9. )
  10. const (
  11. CloudCostEnvVarPrefix = "CLOUD_COST_"
  12. CloudCostEnabledEnvVar = "CLOUD_COST_ENABLED"
  13. CloudCostMonthToDateIntervalVar = "CLOUD_COST_MONTH_TO_DATE_INTERVAL"
  14. CloudCostRefreshRateHoursEnvVar = "CLOUD_COST_REFRESH_RATE_HOURS"
  15. CloudCostQueryWindowDaysEnvVar = "CLOUD_COST_QUERY_WINDOW_DAYS"
  16. CloudCostRunWindowDaysEnvVar = "CLOUD_COST_RUN_WINDOW_DAYS"
  17. CustomCostEnvVarPrefix = "CUSTOM_COST_"
  18. CustomCostEnabledEnvVar = "CUSTOM_COST_ENABLED"
  19. CustomCostQueryWindowDaysEnvVar = "CUSTOM_COST_QUERY_WINDOW_DAYS"
  20. PricingModelEnabledEnvVar = "PRICING_MODEL_ENABLED"
  21. PluginConfigDirEnvVar = "PLUGIN_CONFIG_DIR"
  22. PluginExecutableDirEnvVar = "PLUGIN_EXECUTABLE_DIR"
  23. AzureDownloadBillingDataToDiskEnvVar = "AZURE_DOWNLOAD_BILLING_DATA_TO_DISK"
  24. )
  25. func IsCloudCostEnabled() bool {
  26. return env.GetBool(CloudCostEnabledEnvVar, false)
  27. }
  28. func IsCustomCostEnabled() bool {
  29. return env.GetBool(CustomCostEnabledEnvVar, false)
  30. }
  31. func GetCloudCostConfigPath() string {
  32. return env.GetPathFromConfig(CloudIntegrationConfigFile)
  33. }
  34. func GetCloudCostMonthToDateInterval() int {
  35. return env.GetInt(CloudCostMonthToDateIntervalVar, 6)
  36. }
  37. func GetCloudCostRefreshRateHours() int {
  38. return env.GetInt(CloudCostRefreshRateHoursEnvVar, 6)
  39. }
  40. func GetCloudCostQueryWindowDays() int {
  41. return env.GetInt(CloudCostQueryWindowDaysEnvVar, 7)
  42. }
  43. func GetCloudCostRunWindowDays() int {
  44. return env.GetInt(CloudCostRunWindowDaysEnvVar, 3)
  45. }
  46. func GetCloudCost1dRetention() int {
  47. return env.GetPrefixInt(CloudCostEnvVarPrefix, env.Resolution1dRetentionEnvVar, 30)
  48. }
  49. func GetCustomCostQueryWindowHours() int {
  50. return env.GetInt(CustomCostQueryWindowDaysEnvVar, 1)
  51. }
  52. func GetCustomCostQueryWindowDays() int {
  53. return env.GetInt(CustomCostQueryWindowDaysEnvVar, 7)
  54. }
  55. func GetCustomCost1dRetention() int {
  56. return env.GetPrefixInt(CustomCostEnvVarPrefix, env.Resolution1dRetentionEnvVar, 30)
  57. }
  58. func GetCustomCost1hRetention() int {
  59. return env.GetPrefixInt(CustomCostEnvVarPrefix, env.Resolution1hRetentionEnvVar, 49)
  60. }
  61. func GetPluginConfigDir() string {
  62. return env.Get(PluginConfigDirEnvVar, "/opt/opencost/plugin/config")
  63. }
  64. func GetPluginExecutableDir() string {
  65. return env.Get(PluginExecutableDirEnvVar, "/opt/opencost/plugin/bin")
  66. }
  67. func GetAzureDownloadBillingDataPath() string {
  68. return env.GetPathFromConfig(AzureBillingDataDownloadPath)
  69. }
  70. func GetCloudCostConfigControllerStateFile() string {
  71. return env.GetPathFromConfig(CloudCostConfigControllerStateFile)
  72. }