2
0

core.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. )
  18. // GetAPIPort returns the environment variable value for APIPortEnvVar which
  19. // is the port number the API is available on.
  20. func GetAPIPortWithDefault(def int) int {
  21. return GetInt(APIPortEnvVar, def)
  22. }
  23. // GetClusterID returns the environment variable value for ClusterIDEnvVar which represents the
  24. // configurable identifier used for multi-cluster metric emission.
  25. func GetClusterID() string {
  26. return Get(ClusterIDEnvVar, "")
  27. }
  28. // GetAppName returns the name of the application name running the values
  29. func GetAppName() string {
  30. return Get(AppNameEnvVar, "Opencost")
  31. }
  32. // GetConfigPath returns the environment variable value for ConfigPathEnvVar which represents the cost
  33. // model configuration path
  34. func GetConfigPath() string {
  35. return Get(ConfigPathEnvVar, DefaultConfigPath)
  36. }
  37. func GetPathFromConfig(subPaths ...string) string {
  38. subPath := path.Join(subPaths...)
  39. return path.Join(GetConfigPath(), subPath)
  40. }
  41. func GetDefaultStorageConfigFilePath() string {
  42. return path.Join(GetConfigPath(), DefaultStorageFile)
  43. }
  44. func IsPProfEnabled() bool {
  45. return GetBool(PProfEnabledEnvVar, false)
  46. }
  47. func GetInstallNamespace(def string) string {
  48. return Get(InstallNamespaceEnvVar, def)
  49. }