costmodelenv.go 7.6 KB

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