core.go 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. ForceKubeModelV1EnvVar = "FORCE_KUBEMODEL_V1"
  20. )
  21. // GetAPIPort returns the environment variable value for APIPortEnvVar which
  22. // is the port number the API is available on.
  23. func GetAPIPortWithDefault(def int) int {
  24. return GetInt(APIPortEnvVar, def)
  25. }
  26. // GetClusterID returns the environment variable value for ClusterIDEnvVar which represents the
  27. // configurable identifier used for multi-cluster metric emission.
  28. func GetClusterID() string {
  29. return Get(ClusterIDEnvVar, "")
  30. }
  31. // GetAppName returns the name of the application name running the values
  32. func GetAppName() string {
  33. return Get(AppNameEnvVar, "Opencost")
  34. }
  35. // GetConfigPath returns the environment variable value for ConfigPathEnvVar which represents the cost
  36. // model configuration path
  37. func GetConfigPath() string {
  38. return Get(ConfigPathEnvVar, DefaultConfigPath)
  39. }
  40. func GetPathFromConfig(subPaths ...string) string {
  41. subPath := path.Join(subPaths...)
  42. return path.Join(GetConfigPath(), subPath)
  43. }
  44. func GetDefaultStorageConfigFilePath() string {
  45. return path.Join(GetConfigPath(), DefaultStorageFile)
  46. }
  47. func IsPProfEnabled() bool {
  48. return GetBool(PProfEnabledEnvVar, false)
  49. }
  50. func GetInstallNamespace(def string) string {
  51. return Get(InstallNamespaceEnvVar, def)
  52. }
  53. func IsLegacyDataModelExported() bool {
  54. return GetBool(ExportLegacyDataModelEnvVar, true)
  55. }
  56. func IsKubeModelExported() bool {
  57. return GetBool(ExportKubeModelEnvVar, false)
  58. }
  59. // IsKubeModelV1Forced returns true if the kubemodel pipeline should always
  60. // export the legacy v1 (cluster, namespaces, resource quotas only) shape,
  61. // regardless of whether the source reports a complete kubemodel.
  62. func IsKubeModelV1Forced() bool {
  63. return GetBool(ForceKubeModelV1EnvVar, true)
  64. }