costmodelenv.go 20 KB

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