core.go 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. package env
  2. import (
  3. "path"
  4. )
  5. const DefaultConfigPath = "/var/configs"
  6. const DefaultStorageFile = "federated-store.yaml"
  7. const (
  8. APIPortEnvVar = "API_PORT"
  9. ClusterIDEnvVar = "CLUSTER_ID"
  10. AppNameEnvVar = "APP_NAME"
  11. ConfigPathEnvVar = "CONFIG_PATH"
  12. PProfEnabledEnvVar = "PPROF_ENABLED"
  13. InstallNamespaceEnvVar = "INSTALL_NAMESPACE"
  14. Resolution1dRetentionEnvVar = "RESOLUTION_1D_RETENTION" // int: number of days
  15. Resolution1hRetentionEnvVar = "RESOLUTION_1H_RETENTION" // int: number of hours
  16. Resolution10mRetentionEnvVar = "RESOLUTION_10M_RETENTION" // int: number of 10m segments
  17. ExportLegacyDataModelEnvVar = "EXPORT_LEGACY_DATA_MODEL"
  18. ExportKubeModelEnvVar = "EXPORT_KUBEMODEL"
  19. )
  20. // GetAPIPort returns the environment variable value for APIPortEnvVar which
  21. // is the port number the API is available on.
  22. func GetAPIPortWithDefault(def int) int {
  23. return GetInt(APIPortEnvVar, def)
  24. }
  25. // GetClusterID returns the environment variable value for ClusterIDEnvVar which represents the
  26. // configurable identifier used for multi-cluster metric emission.
  27. func GetClusterID() string {
  28. return Get(ClusterIDEnvVar, "")
  29. }
  30. // GetAppName returns the name of the application name running the values
  31. func GetAppName() string {
  32. return Get(AppNameEnvVar, "Opencost")
  33. }
  34. // GetConfigPath returns the environment variable value for ConfigPathEnvVar which represents the cost
  35. // model configuration path
  36. func GetConfigPath() string {
  37. return Get(ConfigPathEnvVar, DefaultConfigPath)
  38. }
  39. func GetPathFromConfig(subPaths ...string) string {
  40. subPath := path.Join(subPaths...)
  41. return path.Join(GetConfigPath(), subPath)
  42. }
  43. func GetDefaultStorageConfigFilePath() string {
  44. return path.Join(GetConfigPath(), DefaultStorageFile)
  45. }
  46. func IsPProfEnabled() bool {
  47. return GetBool(PProfEnabledEnvVar, false)
  48. }
  49. func GetInstallNamespace(def string) string {
  50. return Get(InstallNamespaceEnvVar, def)
  51. }
  52. func GetExportLegacyDataModel() bool {
  53. return GetBool(ExportLegacyDataModelEnvVar, true)
  54. }
  55. func GetExportKubeModel() bool {
  56. return GetBool(ExportKubeModelEnvVar, true)
  57. }