costmodelenv.go 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. package env
  2. const (
  3. AWSAccessKeyIDEnvVar = "AWS_ACCESS_KEY_ID"
  4. AWSAccessKeySecretEnvVar = "AWS_SECRET_ACCESS_KEY"
  5. AWSClusterIDEnvVar = "AWS_CLUSTER_ID"
  6. KubecostNamespaceEnvVar = "KUBECOST_NAMESPACE"
  7. ClusterIDEnvVar = "CLUSTER_ID"
  8. ClusterProfileEnvVar = "CLUSTER_PROFILE"
  9. PrometheusServerEndpointEnvVar = "PROMETHEUS_SERVER_ENDPOINT"
  10. MaxQueryConcurrencyEnvVar = "MAX_QUERY_CONCURRENCY"
  11. RemoteEnabledEnvVar = "REMOTE_WRITE_ENABLED"
  12. RemotePWEnvVar = "REMOTE_WRITE_PASSWORD"
  13. SQLAddressEnvVar = "SQL_ADDRESS"
  14. UseCSVProviderEnvVar = "USE_CSV_PROVIDER"
  15. CSVRegionEnvVar = "CSV_REGION"
  16. CSVPathEnvVar = "CSV_PATH"
  17. ConfigPathEnvVar = "CONFIG_PATH"
  18. CloudProviderAPIKeyEnvVar = "CLOUD_PROVIDER_API_KEY"
  19. ThanosEnabledEnvVar = "THANOS_ENABLED"
  20. ThanosQueryUrlEnvVar = "THANOS_QUERY_URL"
  21. ThanosOffsetEnvVar = "THANOS_QUERY_OFFSET"
  22. LogCollectionEnabledEnvVar = "LOG_COLLECTION_ENABLED"
  23. ProductAnalyticsEnabledEnvVar = "PRODUCT_ANALYTICS_ENABLED"
  24. ErrorReportingEnabledEnvVar = "ERROR_REPORTING_ENABLED"
  25. ValuesReportingEnabledEnvVar = "VALUES_REPORTING_ENABLED"
  26. MultiClusterBasicAuthUsername = "MC_BASIC_AUTH_USERNAME"
  27. MultiClusterBasicAuthPassword = "MC_BASIC_AUTH_PW"
  28. )
  29. // GetAWSAccessKeyID returns the environment variable value for AWSAccessKeyIDEnvVar which represents
  30. // the AWS access key for authentication
  31. func GetAWSAccessKeyID() string {
  32. return Get(AWSAccessKeyIDEnvVar, "")
  33. }
  34. // GetAWSAccessKeySecret returns the environment variable value for AWSAccessKeySecretEnvVar which represents
  35. // the AWS access key secret for authentication
  36. func GetAWSAccessKeySecret() string {
  37. return Get(AWSAccessKeySecretEnvVar, "")
  38. }
  39. // GetAWSClusterID returns the environment variable value for AWSClusterIDEnvVar which represents
  40. // an AWS specific cluster identifier.
  41. func GetAWSClusterID() string {
  42. return Get(AWSClusterIDEnvVar, "")
  43. }
  44. // GetKubecostNamespace returns the environment variable value for KubecostNamespaceEnvVar which
  45. // represents the namespace the cost model exists in.
  46. func GetKubecostNamespace() string {
  47. return Get(KubecostNamespaceEnvVar, "kubecost")
  48. }
  49. // GetClusterProfile returns the environment variable value for ClusterProfileEnvVar which
  50. // represents the cluster profile configured for
  51. func GetClusterProfile() string {
  52. return Get(ClusterProfileEnvVar, "development")
  53. }
  54. // GetClusterID returns the environment variable value for ClusterIDEnvVar which represents the
  55. // configurable identifier used for multi-cluster metric emission.
  56. func GetClusterID() string {
  57. return Get(ClusterIDEnvVar, "")
  58. }
  59. // GetPrometheusServerEndpoint returns the environment variable value for PrometheusServerEndpointEnvVar which
  60. // represents the prometheus server endpoint used to execute prometheus queries.
  61. func GetPrometheusServerEndpoint() string {
  62. return Get(PrometheusServerEndpointEnvVar, "")
  63. }
  64. // IsRemoteEnabled returns the environment variable value for RemoteEnabledEnvVar which represents whether
  65. // or not remote write is enabled for prometheus for use with SQL backed persistent storage.
  66. func IsRemoteEnabled() bool {
  67. return GetBool(RemoteEnabledEnvVar, false)
  68. }
  69. // GetRemotePW returns the environment variable value for RemotePWEnvVar which represents the remote
  70. // persistent storage password.
  71. func GetRemotePW() string {
  72. return Get(RemotePWEnvVar, "")
  73. }
  74. // GetSQLAddress returns the environment variable value for SQLAddressEnvVar which represents the SQL
  75. // database address used with remote persistent storage.
  76. func GetSQLAddress() string {
  77. return Get(SQLAddressEnvVar, "")
  78. }
  79. // IsUseCSVProvider returns the environment variable value for UseCSVProviderEnvVar which represents
  80. // whether or not the use of a CSV cost provider is enabled.
  81. func IsUseCSVProvider() bool {
  82. return GetBool(UseCSVProviderEnvVar, false)
  83. }
  84. // GetCSVRegion returns the environment variable value for CSVRegionEnvVar which represents the
  85. // region configured for a CSV provider.
  86. func GetCSVRegion() string {
  87. return Get(CSVRegionEnvVar, "")
  88. }
  89. // GetCSVPath returns the environment variable value for CSVPathEnvVar which represents the key path
  90. // configured for a CSV provider.
  91. func GetCSVPath() string {
  92. return Get(CSVPathEnvVar, "")
  93. }
  94. // GetConfigPath returns the environment variable value for ConfigPathEnvVar which represents the cost
  95. // model configuration path
  96. func GetConfigPath() string {
  97. return Get(ConfigPathEnvVar, "")
  98. }
  99. // GetConfigPath returns the environment variable value for ConfigPathEnvVar which represents the cost
  100. // model configuration path
  101. func GetConfigPathWithDefault(defaultValue string) string {
  102. return Get(ConfigPathEnvVar, defaultValue)
  103. }
  104. // GetCloudProviderAPI returns the environment variable value for CloudProviderAPIEnvVar which represents
  105. // the API key provided for the cloud provider.
  106. func GetCloudProviderAPIKey() string {
  107. return Get(CloudProviderAPIKeyEnvVar, "")
  108. }
  109. // IsThanosEnabled returns the environment variable value for ThanosEnabledEnvVar which represents whether
  110. // or not thanos is enabled.
  111. func IsThanosEnabled() bool {
  112. return GetBool(ThanosEnabledEnvVar, false)
  113. }
  114. // GetThanosQueryUrl returns the environment variable value for ThanosQueryUrlEnvVar which represents the
  115. // target query endpoint for hitting thanos.
  116. func GetThanosQueryUrl() string {
  117. return Get(ThanosQueryUrlEnvVar, "")
  118. }
  119. // GetThanosOffset returns the environment variable value for ThanosOffsetEnvVar which represents the total
  120. // amount of time to offset all queries made to thanos.
  121. func GetThanosOffset() string {
  122. return Get(ThanosOffsetEnvVar, "3h")
  123. }
  124. // IsLogCollectionEnabled returns the environment variable value for LogCollectionEnabledEnvVar which represents
  125. // whether or not log collection has been enabled for kubecost deployments.
  126. func IsLogCollectionEnabled() bool {
  127. return GetBool(LogCollectionEnabledEnvVar, true)
  128. }
  129. // IsProductAnalyticsEnabled returns the environment variable value for ProductAnalyticsEnabledEnvVar
  130. func IsProductAnalyticsEnabled() bool {
  131. return GetBool(ProductAnalyticsEnabledEnvVar, true)
  132. }
  133. // IsErrorReportingEnabled returns the environment variable value for ErrorReportingEnabledEnvVar
  134. func IsErrorReportingEnabled() bool {
  135. return GetBool(ErrorReportingEnabledEnvVar, true)
  136. }
  137. // IsValuesReportingEnabled returns the environment variable value for ValuesReportingEnabledEnvVar
  138. func IsValuesReportingEnabled() bool {
  139. return GetBool(ValuesReportingEnabledEnvVar, true)
  140. }
  141. // GetMaxQueryConcurrency returns the environment variable value for MaxQueryConcurrencyEnvVar
  142. func GetMaxQueryConcurrency() int {
  143. return GetInt(MaxQueryConcurrencyEnvVar, 5)
  144. }
  145. // GetMultiClusterBasicAuthUsername returns the environemnt variable value for MultiClusterBasicAuthUsername
  146. func GetMultiClusterBasicAuthUsername() string {
  147. return Get(MultiClusterBasicAuthUsername, "")
  148. }
  149. // GetMultiClusterBasicAuthPassword returns the environemnt variable value for MultiClusterBasicAuthPassword
  150. func GetMultiClusterBasicAuthPassword() string {
  151. return Get(MultiClusterBasicAuthPassword, "")
  152. }