costmodelenv.go 19 KB

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