core.go 1.9 KB

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