costmodelenv.go 9.4 KB

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