| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- package env
- import (
- "path"
- )
- const DefaultConfigPath = "/var/configs"
- const DefaultStorageFile = "federated-store.yaml"
- const (
- APIPortEnvVar = "API_PORT"
- ClusterIDEnvVar = "CLUSTER_ID"
- AppNameEnvVar = "APP_NAME"
- ConfigPathEnvVar = "CONFIG_PATH"
- PProfEnabledEnvVar = "PPROF_ENABLED"
- InstallNamespaceEnvVar = "INSTALL_NAMESPACE"
- Resolution1dRetentionEnvVar = "RESOLUTION_1D_RETENTION" // int: number of days
- Resolution1hRetentionEnvVar = "RESOLUTION_1H_RETENTION" // int: number of hours
- Resolution10mRetentionEnvVar = "RESOLUTION_10M_RETENTION" // int: number of 10m segments
- ExportLegacyDataModelEnvVar = "EXPORT_LEGACY_DATA_MODEL"
- ExportKubeModelEnvVar = "EXPORT_KUBEMODEL"
- ForceKubeModelV1EnvVar = "FORCE_KUBEMODEL_V1"
- )
- // GetAPIPort returns the environment variable value for APIPortEnvVar which
- // is the port number the API is available on.
- func GetAPIPortWithDefault(def int) int {
- return GetInt(APIPortEnvVar, def)
- }
- // GetClusterID returns the environment variable value for ClusterIDEnvVar which represents the
- // configurable identifier used for multi-cluster metric emission.
- func GetClusterID() string {
- return Get(ClusterIDEnvVar, "")
- }
- // GetAppName returns the name of the application name running the values
- func GetAppName() string {
- return Get(AppNameEnvVar, "Opencost")
- }
- // GetConfigPath returns the environment variable value for ConfigPathEnvVar which represents the cost
- // model configuration path
- func GetConfigPath() string {
- return Get(ConfigPathEnvVar, DefaultConfigPath)
- }
- func GetPathFromConfig(subPaths ...string) string {
- subPath := path.Join(subPaths...)
- return path.Join(GetConfigPath(), subPath)
- }
- func GetDefaultStorageConfigFilePath() string {
- return path.Join(GetConfigPath(), DefaultStorageFile)
- }
- func IsPProfEnabled() bool {
- return GetBool(PProfEnabledEnvVar, false)
- }
- func GetInstallNamespace(def string) string {
- return Get(InstallNamespaceEnvVar, def)
- }
- func IsLegacyDataModelExported() bool {
- return GetBool(ExportLegacyDataModelEnvVar, true)
- }
- func IsKubeModelExported() bool {
- return GetBool(ExportKubeModelEnvVar, false)
- }
- // IsKubeModelV1Forced returns true if the kubemodel pipeline should always
- // export the legacy v1 (cluster, namespaces, resource quotas only) shape,
- // regardless of whether the source reports a complete kubemodel.
- func IsKubeModelV1Forced() bool {
- return GetBool(ForceKubeModelV1EnvVar, true)
- }
|