costmodelenv.go 23 KB

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