costmodelenv.go 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657
  1. package env
  2. import (
  3. "fmt"
  4. "time"
  5. "github.com/opencost/opencost/core/pkg/env"
  6. "github.com/opencost/opencost/core/pkg/log"
  7. "github.com/opencost/opencost/core/pkg/util/timeutil"
  8. )
  9. const (
  10. APIPortEnvVar = "API_PORT"
  11. AWSAccessKeyIDEnvVar = "AWS_ACCESS_KEY_ID"
  12. AWSAccessKeySecretEnvVar = "AWS_SECRET_ACCESS_KEY"
  13. AWSClusterIDEnvVar = "AWS_CLUSTER_ID"
  14. AWSPricingURL = "AWS_PRICING_URL"
  15. AlibabaAccessKeyIDEnvVar = "ALIBABA_ACCESS_KEY_ID"
  16. AlibabaAccessKeySecretEnvVar = "ALIBABA_SECRET_ACCESS_KEY"
  17. AzureOfferIDEnvVar = "AZURE_OFFER_ID"
  18. AzureBillingAccountEnvVar = "AZURE_BILLING_ACCOUNT"
  19. KubecostNamespaceEnvVar = "KUBECOST_NAMESPACE"
  20. PodNameEnvVar = "POD_NAME"
  21. ClusterIDEnvVar = "CLUSTER_ID"
  22. ClusterProfileEnvVar = "CLUSTER_PROFILE"
  23. PrometheusServerEndpointEnvVar = "PROMETHEUS_SERVER_ENDPOINT"
  24. MaxQueryConcurrencyEnvVar = "MAX_QUERY_CONCURRENCY"
  25. QueryLoggingFileEnvVar = "QUERY_LOGGING_FILE"
  26. RemoteEnabledEnvVar = "REMOTE_WRITE_ENABLED"
  27. RemotePWEnvVar = "REMOTE_WRITE_PASSWORD"
  28. SQLAddressEnvVar = "SQL_ADDRESS"
  29. UseCSVProviderEnvVar = "USE_CSV_PROVIDER"
  30. CSVRegionEnvVar = "CSV_REGION"
  31. CSVEndpointEnvVar = "CSV_ENDPOINT"
  32. CSVPathEnvVar = "CSV_PATH"
  33. ConfigPathEnvVar = "CONFIG_PATH"
  34. CloudProviderAPIKeyEnvVar = "CLOUD_PROVIDER_API_KEY"
  35. DisableAggregateCostModelCache = "DISABLE_AGGREGATE_COST_MODEL_CACHE"
  36. EmitPodAnnotationsMetricEnvVar = "EMIT_POD_ANNOTATIONS_METRIC"
  37. EmitNamespaceAnnotationsMetricEnvVar = "EMIT_NAMESPACE_ANNOTATIONS_METRIC"
  38. EmitDeprecatedMetrics = "EMIT_DEPRECATED_METRICS"
  39. EmitKsmV1MetricsEnvVar = "EMIT_KSM_V1_METRICS"
  40. EmitKsmV1MetricsOnly = "EMIT_KSM_V1_METRICS_ONLY"
  41. ThanosEnabledEnvVar = "THANOS_ENABLED"
  42. ThanosQueryUrlEnvVar = "THANOS_QUERY_URL"
  43. ThanosOffsetEnvVar = "THANOS_QUERY_OFFSET"
  44. ThanosMaxSourceResEnvVar = "THANOS_MAX_SOURCE_RESOLUTION"
  45. PProfEnabledEnvVar = "PPROF_ENABLED"
  46. LogCollectionEnabledEnvVar = "LOG_COLLECTION_ENABLED"
  47. ProductAnalyticsEnabledEnvVar = "PRODUCT_ANALYTICS_ENABLED"
  48. ErrorReportingEnabledEnvVar = "ERROR_REPORTING_ENABLED"
  49. ValuesReportingEnabledEnvVar = "VALUES_REPORTING_ENABLED"
  50. DBBasicAuthUsername = "DB_BASIC_AUTH_USERNAME"
  51. DBBasicAuthPassword = "DB_BASIC_AUTH_PW"
  52. DBBearerToken = "DB_BEARER_TOKEN"
  53. MultiClusterBasicAuthUsername = "MC_BASIC_AUTH_USERNAME"
  54. MultiClusterBasicAuthPassword = "MC_BASIC_AUTH_PW"
  55. MultiClusterBearerToken = "MC_BEARER_TOKEN"
  56. InsecureSkipVerify = "INSECURE_SKIP_VERIFY"
  57. KubeConfigPathEnvVar = "KUBECONFIG_PATH"
  58. UTCOffsetEnvVar = "UTC_OFFSET"
  59. CurrentClusterIdFilterEnabledVar = "CURRENT_CLUSTER_ID_FILTER_ENABLED"
  60. CacheWarmingEnabledEnvVar = "CACHE_WARMING_ENABLED"
  61. ETLEnabledEnvVar = "ETL_ENABLED"
  62. ETLMaxPrometheusQueryDurationMinutes = "ETL_MAX_PROMETHEUS_QUERY_DURATION_MINUTES"
  63. ETLResolutionSeconds = "ETL_RESOLUTION_SECONDS"
  64. LegacyExternalAPIDisabledVar = "LEGACY_EXTERNAL_API_DISABLED"
  65. PromClusterIDLabelEnvVar = "PROM_CLUSTER_ID_LABEL"
  66. PricingConfigmapName = "PRICING_CONFIGMAP_NAME"
  67. MetricsConfigmapName = "METRICS_CONFIGMAP_NAME"
  68. KubecostJobNameEnvVar = "KUBECOST_JOB_NAME"
  69. KubecostConfigBucketEnvVar = "KUBECOST_CONFIG_BUCKET"
  70. ClusterInfoFileEnabledEnvVar = "CLUSTER_INFO_FILE_ENABLED"
  71. ClusterCacheFileEnabledEnvVar = "CLUSTER_CACHE_FILE_ENABLED"
  72. PrometheusQueryOffsetEnvVar = "PROMETHEUS_QUERY_OFFSET"
  73. PrometheusRetryOnRateLimitResponseEnvVar = "PROMETHEUS_RETRY_ON_RATE_LIMIT"
  74. PrometheusRetryOnRateLimitMaxRetriesEnvVar = "PROMETHEUS_RETRY_ON_RATE_LIMIT_MAX_RETRIES"
  75. PrometheusRetryOnRateLimitDefaultWaitEnvVar = "PROMETHEUS_RETRY_ON_RATE_LIMIT_DEFAULT_WAIT"
  76. PrometheusHeaderXScopeOrgIdEnvVar = "PROMETHEUS_HEADER_X_SCOPE_ORGID"
  77. IngestPodUIDEnvVar = "INGEST_POD_UID"
  78. ETLReadOnlyMode = "ETL_READ_ONLY"
  79. AllocationNodeLabelsEnabled = "ALLOCATION_NODE_LABELS_ENABLED"
  80. AllocationNodeLabelsIncludeList = "ALLOCATION_NODE_LABELS_INCLUDE_LIST"
  81. regionOverrideList = "REGION_OVERRIDE_LIST"
  82. ExportCSVFile = "EXPORT_CSV_FILE"
  83. ExportCSVLabelsList = "EXPORT_CSV_LABELS_LIST"
  84. ExportCSVLabelsAll = "EXPORT_CSV_LABELS_ALL"
  85. ExportCSVMaxDays = "EXPORT_CSV_MAX_DAYS"
  86. DataRetentionDailyResolutionDaysEnvVar = "DATA_RETENTION_DAILY_RESOLUTION_DAYS"
  87. // We assume that Kubernetes is enabled if there is a KUBERNETES_PORT environment variable present
  88. KubernetesEnabledEnvVar = "KUBERNETES_PORT"
  89. CloudCostEnabledEnvVar = "CLOUD_COST_ENABLED"
  90. CloudCostConfigPath = "CLOUD_COST_CONFIG_PATH"
  91. CloudCostMonthToDateIntervalVar = "CLOUD_COST_MONTH_TO_DATE_INTERVAL"
  92. CloudCostRefreshRateHoursEnvVar = "CLOUD_COST_REFRESH_RATE_HOURS"
  93. CloudCostQueryWindowDaysEnvVar = "CLOUD_COST_QUERY_WINDOW_DAYS"
  94. CloudCostRunWindowDaysEnvVar = "CLOUD_COST_RUN_WINDOW_DAYS"
  95. OCIPricingURL = "OCI_PRICING_URL"
  96. )
  97. const DefaultConfigMountPath = "/var/configs"
  98. func IsETLReadOnlyMode() bool {
  99. return env.GetBool(ETLReadOnlyMode, false)
  100. }
  101. func GetExportCSVFile() string {
  102. return env.Get(ExportCSVFile, "")
  103. }
  104. func GetExportCSVLabelsAll() bool {
  105. return env.GetBool(ExportCSVLabelsAll, false)
  106. }
  107. func GetExportCSVLabelsList() []string {
  108. return env.GetList(ExportCSVLabelsList, ",")
  109. }
  110. func IsPProfEnabled() bool {
  111. return env.GetBool(PProfEnabledEnvVar, false)
  112. }
  113. func GetExportCSVMaxDays() int {
  114. return env.GetInt(ExportCSVMaxDays, 90)
  115. }
  116. // GetAPIPort returns the environment variable value for APIPortEnvVar which
  117. // is the port number the API is available on.
  118. func GetAPIPort() int {
  119. return env.GetInt(APIPortEnvVar, 9003)
  120. }
  121. // GetKubecostConfigBucket returns a file location for a mounted bucket configuration which is used to store
  122. // a subset of kubecost configurations that require sharing via remote storage.
  123. func GetKubecostConfigBucket() string {
  124. return env.Get(KubecostConfigBucketEnvVar, "")
  125. }
  126. // IsClusterInfoFileEnabled returns true if the cluster info is read from a file or pulled from the local
  127. // cloud provider and kubernetes.
  128. func IsClusterInfoFileEnabled() bool {
  129. return env.GetBool(ClusterInfoFileEnabledEnvVar, false)
  130. }
  131. // IsClusterCacheFileEnabled returns true if the kubernetes cluster data is read from a file or pulled from the local
  132. // kubernetes API.
  133. func IsClusterCacheFileEnabled() bool {
  134. return env.GetBool(ClusterCacheFileEnabledEnvVar, false)
  135. }
  136. // IsPrometheusRetryOnRateLimitResponse will attempt to retry if a 429 response is received OR a 400 with a body containing
  137. // ThrottleException (common in AWS services like AMP)
  138. func IsPrometheusRetryOnRateLimitResponse() bool {
  139. return env.GetBool(PrometheusRetryOnRateLimitResponseEnvVar, true)
  140. }
  141. // GetPrometheusRetryOnRateLimitMaxRetries returns the maximum number of retries that should be attempted prior to failing.
  142. // Only used if IsPrometheusRetryOnRateLimitResponse() is true.
  143. func GetPrometheusRetryOnRateLimitMaxRetries() int {
  144. return env.GetInt(PrometheusRetryOnRateLimitMaxRetriesEnvVar, 5)
  145. }
  146. // GetPrometheusRetryOnRateLimitDefaultWait returns the default wait time for a retriable rate limit response without a
  147. // Retry-After header.
  148. func GetPrometheusRetryOnRateLimitDefaultWait() time.Duration {
  149. return env.GetDuration(PrometheusRetryOnRateLimitDefaultWaitEnvVar, 100*time.Millisecond)
  150. }
  151. // GetPrometheusHeaderXScopeOrgId returns the default value for X-Scope-OrgID header used for requests in Mimir/Cortex-Tenant API.
  152. // To use Mimir(or Cortex-Tenant) instead of Prometheus add variable from cluster settings:
  153. // "PROMETHEUS_HEADER_X_SCOPE_ORGID": "my-cluster-name"
  154. // Then set Prometheus URL to prometheus API endpoint:
  155. // "PROMETHEUS_SERVER_ENDPOINT": "http://mimir-url/prometheus/"
  156. func GetPrometheusHeaderXScopeOrgId() string {
  157. return env.Get(PrometheusHeaderXScopeOrgIdEnvVar, "")
  158. }
  159. // GetPrometheusQueryOffset returns the time.Duration to offset all prometheus queries by. NOTE: This env var is applied
  160. // to all non-range queries made via our query context. This should only be applied when there is a significant delay in
  161. // data arriving in the target prom db. For example, if supplying a thanos or cortex querier for the prometheus server, using
  162. // a 3h offset will ensure that current time = current time - 3h.
  163. //
  164. // This offset is NOT the same as the GetThanosOffset() option, as that is only applied to queries made specifically targeting
  165. // thanos. This offset is applied globally.
  166. func GetPrometheusQueryOffset() time.Duration {
  167. offset := env.Get(PrometheusQueryOffsetEnvVar, "")
  168. if offset == "" {
  169. return 0
  170. }
  171. dur, err := timeutil.ParseDuration(offset)
  172. if err != nil {
  173. return 0
  174. }
  175. return dur
  176. }
  177. func GetPricingConfigmapName() string {
  178. return env.Get(PricingConfigmapName, "pricing-configs")
  179. }
  180. func GetMetricsConfigmapName() string {
  181. return env.Get(MetricsConfigmapName, "metrics-config")
  182. }
  183. // IsEmitNamespaceAnnotationsMetric returns true if cost-model is configured to emit the kube_namespace_annotations metric
  184. // containing the namespace annotations
  185. func IsEmitNamespaceAnnotationsMetric() bool {
  186. return env.GetBool(EmitNamespaceAnnotationsMetricEnvVar, false)
  187. }
  188. // IsEmitPodAnnotationsMetric returns true if cost-model is configured to emit the kube_pod_annotations metric containing
  189. // pod annotations.
  190. func IsEmitPodAnnotationsMetric() bool {
  191. return env.GetBool(EmitPodAnnotationsMetricEnvVar, false)
  192. }
  193. // IsEmitKsmV1Metrics returns true if cost-model is configured to emit all necessary KSM v1
  194. // metrics that were removed in KSM v2
  195. func IsEmitKsmV1Metrics() bool {
  196. return env.GetBool(EmitKsmV1MetricsEnvVar, true)
  197. }
  198. func IsEmitKsmV1MetricsOnly() bool {
  199. return env.GetBool(EmitKsmV1MetricsOnly, false)
  200. }
  201. func IsEmitDeprecatedMetrics() bool {
  202. return env.GetBool(EmitDeprecatedMetrics, false)
  203. }
  204. // GetAWSAccessKeyID returns the environment variable value for AWSAccessKeyIDEnvVar which represents
  205. // the AWS access key for authentication
  206. func GetAWSAccessKeyID() string {
  207. awsAccessKeyID := env.Get(AWSAccessKeyIDEnvVar, "")
  208. // If the sample nil service key name is set, zero it out so that it is not
  209. // misinterpreted as a real service key.
  210. if awsAccessKeyID == "AKIXXX" {
  211. awsAccessKeyID = ""
  212. }
  213. return awsAccessKeyID
  214. }
  215. // GetAWSAccessKeySecret returns the environment variable value for AWSAccessKeySecretEnvVar which represents
  216. // the AWS access key secret for authentication
  217. func GetAWSAccessKeySecret() string {
  218. return env.Get(AWSAccessKeySecretEnvVar, "")
  219. }
  220. // GetAWSClusterID returns the environment variable value for AWSClusterIDEnvVar which represents
  221. // an AWS specific cluster identifier.
  222. func GetAWSClusterID() string {
  223. return env.Get(AWSClusterIDEnvVar, "")
  224. }
  225. // GetAWSPricingURL returns an optional alternative URL to fetch AWS pricing data from; for use in airgapped environments
  226. func GetAWSPricingURL() string {
  227. return env.Get(AWSPricingURL, "")
  228. }
  229. // GetAlibabaAccessKeyID returns the environment variable value for AlibabaAccessKeyIDEnvVar which represents
  230. // the Alibaba access key for authentication
  231. func GetAlibabaAccessKeyID() string {
  232. return env.Get(AlibabaAccessKeyIDEnvVar, "")
  233. }
  234. // GetAlibabaAccessKeySecret returns the environment variable value for AlibabaAccessKeySecretEnvVar which represents
  235. // the Alibaba access key secret for authentication
  236. func GetAlibabaAccessKeySecret() string {
  237. return env.Get(AlibabaAccessKeySecretEnvVar, "")
  238. }
  239. // GetAzureOfferID returns the environment variable value for AzureOfferIDEnvVar which represents
  240. // the Azure offer ID for determining prices.
  241. func GetAzureOfferID() string {
  242. return env.Get(AzureOfferIDEnvVar, "")
  243. }
  244. // GetAzureBillingAccount returns the environment variable value for
  245. // AzureBillingAccountEnvVar which represents the Azure billing
  246. // account for determining prices. If this is specified
  247. // customer-specific prices will be downloaded from the consumption
  248. // price sheet API.
  249. func GetAzureBillingAccount() string {
  250. return env.Get(AzureBillingAccountEnvVar, "")
  251. }
  252. // GetKubecostNamespace returns the environment variable value for KubecostNamespaceEnvVar which
  253. // represents the namespace the cost model exists in.
  254. func GetKubecostNamespace() string {
  255. return env.Get(KubecostNamespaceEnvVar, "kubecost")
  256. }
  257. // GetPodName returns the name of the current running pod. If this environment variable is not set,
  258. // empty string is returned.
  259. func GetPodName() string {
  260. return env.Get(PodNameEnvVar, "")
  261. }
  262. // GetClusterProfile returns the environment variable value for ClusterProfileEnvVar which
  263. // represents the cluster profile configured for
  264. func GetClusterProfile() string {
  265. return env.Get(ClusterProfileEnvVar, "development")
  266. }
  267. // GetClusterID returns the environment variable value for ClusterIDEnvVar which represents the
  268. // configurable identifier used for multi-cluster metric emission.
  269. func GetClusterID() string {
  270. return env.Get(ClusterIDEnvVar, "")
  271. }
  272. // GetPromClusterFilter returns environment variable value CurrentClusterIdFilterEnabledVar which
  273. // represents additional prometheus filter for all metrics for current cluster id
  274. func GetPromClusterFilter() string {
  275. if env.GetBool(CurrentClusterIdFilterEnabledVar, false) {
  276. return fmt.Sprintf("%s=\"%s\"", GetPromClusterLabel(), GetClusterID())
  277. }
  278. return ""
  279. }
  280. // GetPrometheusServerEndpoint returns the environment variable value for PrometheusServerEndpointEnvVar which
  281. // represents the prometheus server endpoint used to execute prometheus queries.
  282. func GetPrometheusServerEndpoint() string {
  283. return env.Get(PrometheusServerEndpointEnvVar, "")
  284. }
  285. func GetInsecureSkipVerify() bool {
  286. return env.GetBool(InsecureSkipVerify, false)
  287. }
  288. // IsAggregateCostModelCacheDisabled returns the environment variable value for DisableAggregateCostModelCache which
  289. // will inform the aggregator on whether to load cached data. Defaults to false
  290. func IsAggregateCostModelCacheDisabled() bool {
  291. return env.GetBool(DisableAggregateCostModelCache, false)
  292. }
  293. // IsRemoteEnabled returns the environment variable value for RemoteEnabledEnvVar which represents whether
  294. // or not remote write is enabled for prometheus for use with SQL backed persistent storage.
  295. func IsRemoteEnabled() bool {
  296. return env.GetBool(RemoteEnabledEnvVar, false)
  297. }
  298. // GetRemotePW returns the environment variable value for RemotePWEnvVar which represents the remote
  299. // persistent storage password.
  300. func GetRemotePW() string {
  301. return env.Get(RemotePWEnvVar, "")
  302. }
  303. // GetSQLAddress returns the environment variable value for SQLAddressEnvVar which represents the SQL
  304. // database address used with remote persistent storage.
  305. func GetSQLAddress() string {
  306. return env.Get(SQLAddressEnvVar, "")
  307. }
  308. // IsUseCSVProvider returns the environment variable value for UseCSVProviderEnvVar which represents
  309. // whether or not the use of a CSV cost provider is enabled.
  310. func IsUseCSVProvider() bool {
  311. return env.GetBool(UseCSVProviderEnvVar, false)
  312. }
  313. // GetCSVRegion returns the environment variable value for CSVRegionEnvVar which represents the
  314. // region configured for a CSV provider.
  315. func GetCSVRegion() string {
  316. return env.Get(CSVRegionEnvVar, "")
  317. }
  318. // GetCSVEndpoint returns the environment variable value for CSVEndpointEnvVar which represents the
  319. // endpoint configured for a S3 CSV provider another than AWS S3.
  320. func GetCSVEndpoint() string {
  321. return env.Get(CSVEndpointEnvVar, "")
  322. }
  323. // GetCSVPath returns the environment variable value for CSVPathEnvVar which represents the key path
  324. // configured for a CSV provider.
  325. func GetCSVPath() string {
  326. return env.Get(CSVPathEnvVar, "")
  327. }
  328. // GetCostAnalyzerVolumeMountPath is an alias of GetConfigPath, which returns the mount path for the
  329. // Cost Analyzer volume, which stores configs, persistent data, etc.
  330. func GetCostAnalyzerVolumeMountPath() string {
  331. return GetConfigPathWithDefault(DefaultConfigMountPath)
  332. }
  333. // GetConfigPath returns the environment variable value for ConfigPathEnvVar which represents the cost
  334. // model configuration path
  335. func GetConfigPathWithDefault(defaultValue string) string {
  336. return env.Get(ConfigPathEnvVar, defaultValue)
  337. }
  338. // GetCloudProviderAPI returns the environment variable value for CloudProviderAPIEnvVar which represents
  339. // the API key provided for the cloud provider.
  340. func GetCloudProviderAPIKey() string {
  341. return env.Get(CloudProviderAPIKeyEnvVar, "")
  342. }
  343. // IsThanosEnabled returns the environment variable value for ThanosEnabledEnvVar which represents whether
  344. // or not thanos is enabled.
  345. func IsThanosEnabled() bool {
  346. return env.GetBool(ThanosEnabledEnvVar, false)
  347. }
  348. // GetThanosQueryUrl returns the environment variable value for ThanosQueryUrlEnvVar which represents the
  349. // target query endpoint for hitting thanos.
  350. func GetThanosQueryUrl() string {
  351. return env.Get(ThanosQueryUrlEnvVar, "")
  352. }
  353. // GetThanosOffset returns the environment variable value for ThanosOffsetEnvVar which represents the total
  354. // amount of time to offset all queries made to thanos.
  355. func GetThanosOffset() string {
  356. return env.Get(ThanosOffsetEnvVar, "3h")
  357. }
  358. // GetThanosMaxSourceResolution returns the environment variable value for ThanosMaxSourceResEnvVar which represents
  359. // the max source resolution to use when querying thanos.
  360. func GetThanosMaxSourceResolution() string {
  361. res := env.Get(ThanosMaxSourceResEnvVar, "raw")
  362. switch res {
  363. case "raw":
  364. return "0s"
  365. case "0s":
  366. fallthrough
  367. case "5m":
  368. fallthrough
  369. case "1h":
  370. return res
  371. default:
  372. return "0s"
  373. }
  374. }
  375. // IsLogCollectionEnabled returns the environment variable value for LogCollectionEnabledEnvVar which represents
  376. // whether or not log collection has been enabled for kubecost deployments.
  377. func IsLogCollectionEnabled() bool {
  378. return env.GetBool(LogCollectionEnabledEnvVar, true)
  379. }
  380. // IsProductAnalyticsEnabled returns the environment variable value for ProductAnalyticsEnabledEnvVar
  381. func IsProductAnalyticsEnabled() bool {
  382. return env.GetBool(ProductAnalyticsEnabledEnvVar, true)
  383. }
  384. // IsErrorReportingEnabled returns the environment variable value for ErrorReportingEnabledEnvVar
  385. func IsErrorReportingEnabled() bool {
  386. return env.GetBool(ErrorReportingEnabledEnvVar, true)
  387. }
  388. // IsValuesReportingEnabled returns the environment variable value for ValuesReportingEnabledEnvVar
  389. func IsValuesReportingEnabled() bool {
  390. return env.GetBool(ValuesReportingEnabledEnvVar, true)
  391. }
  392. // GetMaxQueryConcurrency returns the environment variable value for MaxQueryConcurrencyEnvVar
  393. func GetMaxQueryConcurrency() int {
  394. return env.GetInt(MaxQueryConcurrencyEnvVar, 5)
  395. }
  396. // GetQueryLoggingFile returns a file location if query logging is enabled. Otherwise, empty string
  397. func GetQueryLoggingFile() string {
  398. return env.Get(QueryLoggingFileEnvVar, "")
  399. }
  400. func GetDBBasicAuthUsername() string {
  401. return env.Get(DBBasicAuthUsername, "")
  402. }
  403. func GetDBBasicAuthUserPassword() string {
  404. return env.Get(DBBasicAuthPassword, "")
  405. }
  406. func GetDBBearerToken() string {
  407. return env.Get(DBBearerToken, "")
  408. }
  409. // GetMultiClusterBasicAuthUsername returns the environment variable value for MultiClusterBasicAuthUsername
  410. func GetMultiClusterBasicAuthUsername() string {
  411. return env.Get(MultiClusterBasicAuthUsername, "")
  412. }
  413. // GetMultiClusterBasicAuthPassword returns the environment variable value for MultiClusterBasicAuthPassword
  414. func GetMultiClusterBasicAuthPassword() string {
  415. return env.Get(MultiClusterBasicAuthPassword, "")
  416. }
  417. func GetMultiClusterBearerToken() string {
  418. return env.Get(MultiClusterBearerToken, "")
  419. }
  420. // GetKubeConfigPath returns the environment variable value for KubeConfigPathEnvVar
  421. func GetKubeConfigPath() string {
  422. return env.Get(KubeConfigPathEnvVar, "")
  423. }
  424. // GetUTCOffset returns the environment variable value for UTCOffset
  425. func GetUTCOffset() string {
  426. return env.Get(UTCOffsetEnvVar, "")
  427. }
  428. // GetParsedUTCOffset returns the duration of the configured UTC offset
  429. func GetParsedUTCOffset() time.Duration {
  430. offset, err := timeutil.ParseUTCOffset(GetUTCOffset())
  431. if err != nil {
  432. log.Warnf("Failed to parse UTC offset: %s", err)
  433. return time.Duration(0)
  434. }
  435. return offset
  436. }
  437. // GetKubecostJobName returns the environment variable value for KubecostJobNameEnvVar
  438. func GetKubecostJobName() string {
  439. return env.Get(KubecostJobNameEnvVar, "kubecost")
  440. }
  441. func IsCacheWarmingEnabled() bool {
  442. return env.GetBool(CacheWarmingEnabledEnvVar, true)
  443. }
  444. func IsETLEnabled() bool {
  445. return env.GetBool(ETLEnabledEnvVar, true)
  446. }
  447. func GetETLMaxPrometheusQueryDuration() time.Duration {
  448. dayMins := 60 * 24
  449. mins := time.Duration(env.GetInt64(ETLMaxPrometheusQueryDurationMinutes, int64(dayMins)))
  450. return mins * time.Minute
  451. }
  452. // GetETLResolution determines the resolution of ETL queries. The smaller the
  453. // duration, the higher the resolution; the higher the resolution, the more
  454. // accurate the query results, but the more computationally expensive.
  455. func GetETLResolution() time.Duration {
  456. // Use the configured ETL resolution, or default to
  457. // 5m (i.e. 300s)
  458. secs := time.Duration(env.GetInt64(ETLResolutionSeconds, 300))
  459. return secs * time.Second
  460. }
  461. func LegacyExternalCostsAPIDisabled() bool {
  462. return env.GetBool(LegacyExternalAPIDisabledVar, false)
  463. }
  464. // GetPromClusterLabel returns the environment variable value for PromClusterIDLabel
  465. func GetPromClusterLabel() string {
  466. return env.Get(PromClusterIDLabelEnvVar, "cluster_id")
  467. }
  468. // IsIngestingPodUID returns the env variable from ingestPodUID, which alters the
  469. // contents of podKeys in Allocation
  470. func IsIngestingPodUID() bool {
  471. return env.GetBool(IngestPodUIDEnvVar, false)
  472. }
  473. func GetAllocationNodeLabelsEnabled() bool {
  474. return env.GetBool(AllocationNodeLabelsEnabled, true)
  475. }
  476. var defaultAllocationNodeLabelsIncludeList []string = []string{
  477. "cloud.google.com/gke-nodepool",
  478. "eks.amazonaws.com/nodegroup",
  479. "kubernetes.azure.com/agentpool",
  480. "node.kubernetes.io/instance-type",
  481. "topology.kubernetes.io/region",
  482. "topology.kubernetes.io/zone",
  483. }
  484. func GetAllocationNodeLabelsIncludeList() []string {
  485. // If node labels are not enabled, return an empty list.
  486. if !GetAllocationNodeLabelsEnabled() {
  487. return []string{}
  488. }
  489. list := env.GetList(AllocationNodeLabelsIncludeList, ",")
  490. // If node labels are enabled, but the white list is empty, use defaults.
  491. if len(list) == 0 {
  492. return defaultAllocationNodeLabelsIncludeList
  493. }
  494. return list
  495. }
  496. func GetRegionOverrideList() []string {
  497. regionList := env.GetList(regionOverrideList, ",")
  498. if regionList == nil {
  499. return []string{}
  500. }
  501. return regionList
  502. }
  503. func GetDataRetentionDailyResolutionDays() int64 {
  504. return env.GetInt64(DataRetentionDailyResolutionDaysEnvVar, 15)
  505. }
  506. func IsKubernetesEnabled() bool {
  507. return env.Get(KubernetesEnabledEnvVar, "") != ""
  508. }
  509. func IsCloudCostEnabled() bool {
  510. return env.GetBool(CloudCostEnabledEnvVar, false)
  511. }
  512. func GetCloudCostConfigPath() string {
  513. return env.Get(CloudCostConfigPath, "cloud-integration.json")
  514. }
  515. func GetCloudCostMonthToDateInterval() int {
  516. return env.GetInt(CloudCostMonthToDateIntervalVar, 6)
  517. }
  518. func GetCloudCostRefreshRateHours() int64 {
  519. return env.GetInt64(CloudCostRefreshRateHoursEnvVar, 6)
  520. }
  521. func GetCloudCostQueryWindowDays() int64 {
  522. return env.GetInt64(CloudCostQueryWindowDaysEnvVar, 7)
  523. }
  524. func GetCloudCostRunWindowDays() int64 {
  525. return env.GetInt64(CloudCostRunWindowDaysEnvVar, 3)
  526. }
  527. func GetOCIPricingURL() string {
  528. return env.Get(OCIPricingURL, "https://apexapps.oracle.com/pls/apex/cetools/api/v1/products")
  529. }