costmodelenv.go 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. package env
  2. const (
  3. AppVersionEnvVar = "APP_VERSION"
  4. AWSAccessKeyIDEnvVar = "AWS_ACCESS_KEY_ID"
  5. AWSAccessKeySecretEnvVar = "AWS_SECRET_ACCESS_KEY"
  6. AWSClusterIDEnvVar = "AWS_CLUSTER_ID"
  7. KubecostNamespaceEnvVar = "KUBECOST_NAMESPACE"
  8. ClusterIDEnvVar = "CLUSTER_ID"
  9. ClusterProfileEnvVar = "CLUSTER_PROFILE"
  10. PrometheusServerEndpointEnvVar = "PROMETHEUS_SERVER_ENDPOINT"
  11. MaxQueryConcurrencyEnvVar = "MAX_QUERY_CONCURRENCY"
  12. QueryLoggingFileEnvVar = "QUERY_LOGGING_FILE"
  13. RemoteEnabledEnvVar = "REMOTE_WRITE_ENABLED"
  14. RemotePWEnvVar = "REMOTE_WRITE_PASSWORD"
  15. SQLAddressEnvVar = "SQL_ADDRESS"
  16. UseCSVProviderEnvVar = "USE_CSV_PROVIDER"
  17. CSVRegionEnvVar = "CSV_REGION"
  18. CSVPathEnvVar = "CSV_PATH"
  19. ConfigPathEnvVar = "CONFIG_PATH"
  20. CloudProviderAPIKeyEnvVar = "CLOUD_PROVIDER_API_KEY"
  21. ThanosEnabledEnvVar = "THANOS_ENABLED"
  22. ThanosQueryUrlEnvVar = "THANOS_QUERY_URL"
  23. ThanosOffsetEnvVar = "THANOS_QUERY_OFFSET"
  24. ThanosMaxSourceResEnvVar = "THANOS_MAX_SOURCE_RESOLUTION"
  25. LogCollectionEnabledEnvVar = "LOG_COLLECTION_ENABLED"
  26. ProductAnalyticsEnabledEnvVar = "PRODUCT_ANALYTICS_ENABLED"
  27. ErrorReportingEnabledEnvVar = "ERROR_REPORTING_ENABLED"
  28. ValuesReportingEnabledEnvVar = "VALUES_REPORTING_ENABLED"
  29. DBBasicAuthUsername = "DB_BASIC_AUTH_USERNAME"
  30. DBBasicAuthPassword = "DB_BASIC_AUTH_PW"
  31. DBBearerToken = "DB_BEARER_TOKEN"
  32. MultiClusterBasicAuthUsername = "MC_BASIC_AUTH_USERNAME"
  33. MultiClusterBasicAuthPassword = "MC_BASIC_AUTH_PW"
  34. MultiClusterBearerToken = "MC_BEARER_TOKEN"
  35. InsecureSkipVerify = "INSECURE_SKIP_VERIFY"
  36. KubeConfigPathEnvVar = "KUBECONFIG_PATH"
  37. )
  38. // GetAWSAccessKeyID returns the environment variable value for AWSAccessKeyIDEnvVar which represents
  39. // the AWS access key for authentication
  40. func GetAppVersion() string {
  41. return Get(AppVersionEnvVar, "1.70.0")
  42. }
  43. // GetAWSAccessKeyID returns the environment variable value for AWSAccessKeyIDEnvVar which represents
  44. // the AWS access key for authentication
  45. func GetAWSAccessKeyID() string {
  46. return Get(AWSAccessKeyIDEnvVar, "")
  47. }
  48. // GetAWSAccessKeySecret returns the environment variable value for AWSAccessKeySecretEnvVar which represents
  49. // the AWS access key secret for authentication
  50. func GetAWSAccessKeySecret() string {
  51. return Get(AWSAccessKeySecretEnvVar, "")
  52. }
  53. // GetAWSClusterID returns the environment variable value for AWSClusterIDEnvVar which represents
  54. // an AWS specific cluster identifier.
  55. func GetAWSClusterID() string {
  56. return Get(AWSClusterIDEnvVar, "")
  57. }
  58. // GetKubecostNamespace returns the environment variable value for KubecostNamespaceEnvVar which
  59. // represents the namespace the cost model exists in.
  60. func GetKubecostNamespace() string {
  61. return Get(KubecostNamespaceEnvVar, "kubecost")
  62. }
  63. // GetClusterProfile returns the environment variable value for ClusterProfileEnvVar which
  64. // represents the cluster profile configured for
  65. func GetClusterProfile() string {
  66. return Get(ClusterProfileEnvVar, "development")
  67. }
  68. // GetClusterID returns the environment variable value for ClusterIDEnvVar which represents the
  69. // configurable identifier used for multi-cluster metric emission.
  70. func GetClusterID() string {
  71. return Get(ClusterIDEnvVar, "")
  72. }
  73. // GetPrometheusServerEndpoint returns the environment variable value for PrometheusServerEndpointEnvVar which
  74. // represents the prometheus server endpoint used to execute prometheus queries.
  75. func GetPrometheusServerEndpoint() string {
  76. return Get(PrometheusServerEndpointEnvVar, "")
  77. }
  78. func GetInsecureSkipVerify() bool {
  79. return GetBool(InsecureSkipVerify, false)
  80. }
  81. // IsRemoteEnabled returns the environment variable value for RemoteEnabledEnvVar which represents whether
  82. // or not remote write is enabled for prometheus for use with SQL backed persistent storage.
  83. func IsRemoteEnabled() bool {
  84. return GetBool(RemoteEnabledEnvVar, false)
  85. }
  86. // GetRemotePW returns the environment variable value for RemotePWEnvVar which represents the remote
  87. // persistent storage password.
  88. func GetRemotePW() string {
  89. return Get(RemotePWEnvVar, "")
  90. }
  91. // GetSQLAddress returns the environment variable value for SQLAddressEnvVar which represents the SQL
  92. // database address used with remote persistent storage.
  93. func GetSQLAddress() string {
  94. return Get(SQLAddressEnvVar, "")
  95. }
  96. // IsUseCSVProvider returns the environment variable value for UseCSVProviderEnvVar which represents
  97. // whether or not the use of a CSV cost provider is enabled.
  98. func IsUseCSVProvider() bool {
  99. return GetBool(UseCSVProviderEnvVar, false)
  100. }
  101. // GetCSVRegion returns the environment variable value for CSVRegionEnvVar which represents the
  102. // region configured for a CSV provider.
  103. func GetCSVRegion() string {
  104. return Get(CSVRegionEnvVar, "")
  105. }
  106. // GetCSVPath returns the environment variable value for CSVPathEnvVar which represents the key path
  107. // configured for a CSV provider.
  108. func GetCSVPath() string {
  109. return Get(CSVPathEnvVar, "")
  110. }
  111. // GetConfigPath returns the environment variable value for ConfigPathEnvVar which represents the cost
  112. // model configuration path
  113. func GetConfigPath() string {
  114. return Get(ConfigPathEnvVar, "")
  115. }
  116. // GetConfigPath returns the environment variable value for ConfigPathEnvVar which represents the cost
  117. // model configuration path
  118. func GetConfigPathWithDefault(defaultValue string) string {
  119. return Get(ConfigPathEnvVar, defaultValue)
  120. }
  121. // GetCloudProviderAPI returns the environment variable value for CloudProviderAPIEnvVar which represents
  122. // the API key provided for the cloud provider.
  123. func GetCloudProviderAPIKey() string {
  124. return Get(CloudProviderAPIKeyEnvVar, "")
  125. }
  126. // IsThanosEnabled returns the environment variable value for ThanosEnabledEnvVar which represents whether
  127. // or not thanos is enabled.
  128. func IsThanosEnabled() bool {
  129. return GetBool(ThanosEnabledEnvVar, false)
  130. }
  131. // GetThanosQueryUrl returns the environment variable value for ThanosQueryUrlEnvVar which represents the
  132. // target query endpoint for hitting thanos.
  133. func GetThanosQueryUrl() string {
  134. return Get(ThanosQueryUrlEnvVar, "")
  135. }
  136. // GetThanosOffset returns the environment variable value for ThanosOffsetEnvVar which represents the total
  137. // amount of time to offset all queries made to thanos.
  138. func GetThanosOffset() string {
  139. return Get(ThanosOffsetEnvVar, "3h")
  140. }
  141. // GetThanosMaxSourceResolution returns the environment variable value for ThanosMaxSourceResEnvVar which represents
  142. // the max source resolution to use when querying thanos.
  143. func GetThanosMaxSourceResolution() string {
  144. res := Get(ThanosMaxSourceResEnvVar, "raw")
  145. switch res {
  146. case "raw":
  147. return "0s"
  148. case "0s":
  149. fallthrough
  150. case "5m":
  151. fallthrough
  152. case "1h":
  153. return res
  154. default:
  155. return "0s"
  156. }
  157. }
  158. // IsLogCollectionEnabled returns the environment variable value for LogCollectionEnabledEnvVar which represents
  159. // whether or not log collection has been enabled for kubecost deployments.
  160. func IsLogCollectionEnabled() bool {
  161. return GetBool(LogCollectionEnabledEnvVar, true)
  162. }
  163. // IsProductAnalyticsEnabled returns the environment variable value for ProductAnalyticsEnabledEnvVar
  164. func IsProductAnalyticsEnabled() bool {
  165. return GetBool(ProductAnalyticsEnabledEnvVar, true)
  166. }
  167. // IsErrorReportingEnabled returns the environment variable value for ErrorReportingEnabledEnvVar
  168. func IsErrorReportingEnabled() bool {
  169. return GetBool(ErrorReportingEnabledEnvVar, true)
  170. }
  171. // IsValuesReportingEnabled returns the environment variable value for ValuesReportingEnabledEnvVar
  172. func IsValuesReportingEnabled() bool {
  173. return GetBool(ValuesReportingEnabledEnvVar, true)
  174. }
  175. // GetMaxQueryConcurrency returns the environment variable value for MaxQueryConcurrencyEnvVar
  176. func GetMaxQueryConcurrency() int {
  177. return GetInt(MaxQueryConcurrencyEnvVar, 5)
  178. }
  179. // GetQueryLoggingFile returns a file location if query logging is enabled. Otherwise, empty string
  180. func GetQueryLoggingFile() string {
  181. return Get(QueryLoggingFileEnvVar, "")
  182. }
  183. func GetDBBasicAuthUsername() string {
  184. return Get(DBBasicAuthUsername, "")
  185. }
  186. func GetDBBasicAuthUserPassword() string {
  187. return Get(DBBasicAuthPassword, "")
  188. }
  189. func GetDBBearerToken() string {
  190. return Get(DBBearerToken, "")
  191. }
  192. // GetMultiClusterBasicAuthUsername returns the environemnt variable value for MultiClusterBasicAuthUsername
  193. func GetMultiClusterBasicAuthUsername() string {
  194. return Get(MultiClusterBasicAuthUsername, "")
  195. }
  196. // GetMultiClusterBasicAuthPassword returns the environemnt variable value for MultiClusterBasicAuthPassword
  197. func GetMultiClusterBasicAuthPassword() string {
  198. return Get(MultiClusterBasicAuthPassword, "")
  199. }
  200. func GetMultiClusterBearerToken() string {
  201. return Get(MultiClusterBearerToken, "")
  202. }
  203. // GetKubeConfigPath returns the environment variable value for KubeConfigPathEnvVar
  204. func GetKubeConfigPath() string {
  205. return Get(KubeConfigPathEnvVar, "")
  206. }