costmodelenv.go 8.3 KB

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