costmodelenv.go 8.0 KB

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