cloudcost.go 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 GetConfigPath() string {
  31. return env.GetConfigPath()
  32. }
  33. func GetCloudCostConfigPath() string {
  34. return env.GetPathFromConfig(CloudIntegrationConfigFile)
  35. }
  36. func GetCloudCostMonthToDateInterval() int {
  37. return env.GetInt(CloudCostMonthToDateIntervalVar, 6)
  38. }
  39. func GetCloudCostRefreshRateHours() int {
  40. return env.GetInt(CloudCostRefreshRateHoursEnvVar, 6)
  41. }
  42. func GetCloudCostQueryWindowDays() int {
  43. return env.GetInt(CloudCostQueryWindowDaysEnvVar, 7)
  44. }
  45. func GetCloudCostRunWindowDays() int {
  46. return env.GetInt(CloudCostRunWindowDaysEnvVar, 3)
  47. }
  48. func GetCloudCost1dRetention() int {
  49. return env.GetPrefixInt(CloudCostEnvVarPrefix, env.Resolution1dRetentionEnvVar, 30)
  50. }
  51. func GetCustomCostQueryWindowHours() int {
  52. return env.GetInt(CustomCostQueryWindowDaysEnvVar, 1)
  53. }
  54. func GetCustomCostQueryWindowDays() int {
  55. return env.GetInt(CustomCostQueryWindowDaysEnvVar, 7)
  56. }
  57. func GetCustomCost1dRetention() int {
  58. return env.GetPrefixInt(CustomCostEnvVarPrefix, env.Resolution1dRetentionEnvVar, 30)
  59. }
  60. func GetCustomCost1hRetention() int {
  61. return env.GetPrefixInt(CustomCostEnvVarPrefix, env.Resolution1hRetentionEnvVar, 49)
  62. }
  63. func GetPluginConfigDir() string {
  64. return env.Get(PluginConfigDirEnvVar, "/opt/opencost/plugin/config")
  65. }
  66. func GetPluginExecutableDir() string {
  67. return env.Get(PluginExecutableDirEnvVar, "/opt/opencost/plugin/bin")
  68. }
  69. func GetAzureDownloadBillingDataPath() string {
  70. return env.GetPathFromConfig(AzureBillingDataDownloadPath)
  71. }
  72. func GetCloudCostConfigControllerStateFile() string {
  73. return env.GetPathFromConfig(CloudCostConfigControllerStateFile)
  74. }