costmodelenv.go 20 KB

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