cloudcost.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. PluginConfigDirEnvVar = "PLUGIN_CONFIG_DIR"
  21. PluginExecutableDirEnvVar = "PLUGIN_EXECUTABLE_DIR"
  22. AzureDownloadBillingDataToDiskEnvVar = "AZURE_DOWNLOAD_BILLING_DATA_TO_DISK"
  23. )
  24. func IsCloudCostEnabled() bool {
  25. return env.GetBool(CloudCostEnabledEnvVar, false)
  26. }
  27. func IsCustomCostEnabled() bool {
  28. return env.GetBool(CustomCostEnabledEnvVar, false)
  29. }
  30. func GetCloudCostConfigPath() string {
  31. return env.GetPathFromConfig(CloudIntegrationConfigFile)
  32. }
  33. func GetCloudCostMonthToDateInterval() int {
  34. return env.GetInt(CloudCostMonthToDateIntervalVar, 6)
  35. }
  36. func GetCloudCostRefreshRateHours() int {
  37. return env.GetInt(CloudCostRefreshRateHoursEnvVar, 6)
  38. }
  39. func GetCloudCostQueryWindowDays() int {
  40. return env.GetInt(CloudCostQueryWindowDaysEnvVar, 7)
  41. }
  42. func GetCloudCostRunWindowDays() int {
  43. return env.GetInt(CloudCostRunWindowDaysEnvVar, 3)
  44. }
  45. func GetCloudCost1dRetention() int {
  46. return env.GetPrefixInt(CloudCostEnvVarPrefix, env.Resolution1dRetentionEnvVar, 30)
  47. }
  48. func GetCustomCostQueryWindowHours() int {
  49. return env.GetInt(CustomCostQueryWindowDaysEnvVar, 1)
  50. }
  51. func GetCustomCostQueryWindowDays() int {
  52. return env.GetInt(CustomCostQueryWindowDaysEnvVar, 7)
  53. }
  54. func GetCustomCost1dRetention() int {
  55. return env.GetPrefixInt(CustomCostEnvVarPrefix, env.Resolution1dRetentionEnvVar, 30)
  56. }
  57. func GetCustomCost1hRetention() int {
  58. return env.GetPrefixInt(CustomCostEnvVarPrefix, env.Resolution1hRetentionEnvVar, 49)
  59. }
  60. func GetPluginConfigDir() string {
  61. return env.Get(PluginConfigDirEnvVar, "/opt/opencost/plugin/config")
  62. }
  63. func GetPluginExecutableDir() string {
  64. return env.Get(PluginExecutableDirEnvVar, "/opt/opencost/plugin/bin")
  65. }
  66. func GetAzureDownloadBillingDataPath() string {
  67. return env.GetPathFromConfig(AzureBillingDataDownloadPath)
  68. }
  69. func GetCloudCostConfigControllerStateFile() string {
  70. return env.GetPathFromConfig(CloudCostConfigControllerStateFile)
  71. }