Ajay Tripathy 5 anni fa
parent
commit
51550497be
2 ha cambiato i file con 22 aggiunte e 12 eliminazioni
  1. 10 7
      pkg/costmodel/router.go
  2. 12 5
      pkg/prom/prom.go

+ 10 - 7
pkg/costmodel/router.go

@@ -51,11 +51,13 @@ const (
 
 var (
 	// gitCommit is set by the build system
-	gitCommit               string
-	logCollectionEnabled    bool = strings.EqualFold(os.Getenv(logCollectionEnvVar), "true")
-	productAnalyticsEnabled bool = strings.EqualFold(os.Getenv(productAnalyticsEnvVar), "true")
-	errorReportingEnabled   bool = strings.EqualFold(os.Getenv(errorReportingEnvVar), "true")
-	valuesReportingEnabled  bool = strings.EqualFold(os.Getenv(valuesReportingEnvVar), "true")
+	gitCommit                       string
+	logCollectionEnabled            bool   = strings.EqualFold(os.Getenv(logCollectionEnvVar), "true")
+	productAnalyticsEnabled         bool   = strings.EqualFold(os.Getenv(productAnalyticsEnvVar), "true")
+	errorReportingEnabled           bool   = strings.EqualFold(os.Getenv(errorReportingEnvVar), "true")
+	valuesReportingEnabled          bool   = strings.EqualFold(os.Getenv(valuesReportingEnvVar), "true")
+	multiclusterDBBasicAuthUsername string = os.Getenv("MC_BASIC_AUTH_USERNAME")
+	multiclusterDBBasicAuthPW       string = os.Getenv("MC_BASIC_AUTH_PW")
 )
 
 var Router = httprouter.New()
@@ -972,7 +974,7 @@ func Initialize(additionalConfigWatchers ...ConfigWatchers) {
 		Address:      address,
 		RoundTripper: LongTimeoutRoundTripper,
 	}
-	promCli, _ := prom.NewRateLimitedClient(pc, queryConcurrency)
+	promCli, _ := prom.NewRateLimitedClient(pc, queryConcurrency, "", "")
 
 	m, err := ValidatePrometheus(promCli, false)
 	if err != nil || m.Running == false {
@@ -1186,7 +1188,8 @@ func Initialize(additionalConfigWatchers ...ConfigWatchers) {
 				Address:      thanosUrl,
 				RoundTripper: thanosRT,
 			}
-			thanosCli, _ := prom.NewRateLimitedClient(thanosConfig, queryConcurrency)
+
+			thanosCli, _ := prom.NewRateLimitedClient(thanosConfig, queryConcurrency, multiclusterDBBasicAuthUsername, multiclusterDBBasicAuthPW)
 
 			_, err = ValidatePrometheus(thanosCli, true)
 			if err != nil {

+ 12 - 5
pkg/prom/prom.go

@@ -11,7 +11,7 @@ import (
 
 // NewRateLimitedClient creates a prometheus client which limits the number of concurrent outbound
 // prometheus requests.
-func NewRateLimitedClient(config prometheus.Config, maxConcurrency int) (prometheus.Client, error) {
+func NewRateLimitedClient(config prometheus.Config, maxConcurrency int, username, password string) (prometheus.Client, error) {
 	c, err := prometheus.NewClient(config)
 	if err != nil {
 		return nil, err
@@ -20,16 +20,20 @@ func NewRateLimitedClient(config prometheus.Config, maxConcurrency int) (prometh
 	limiter := util.NewSemaphore(maxConcurrency)
 
 	return &RateLimitedPrometheusClient{
-		client:  c,
-		limiter: limiter,
+		client:   c,
+		limiter:  limiter,
+		username: username,
+		password: password,
 	}, nil
 }
 
 // Creates a new prometheus client which limits the total number of concurrent outbound requests
 // allowed at a given moment.
 type RateLimitedPrometheusClient struct {
-	client  prometheus.Client
-	limiter *util.Semaphore
+	client   prometheus.Client
+	limiter  *util.Semaphore
+	username string
+	password string
 }
 
 // Passthrough to the prometheus client API
@@ -39,6 +43,9 @@ func (rlpc *RateLimitedPrometheusClient) URL(ep string, args map[string]string)
 
 // Rate limit and passthrough to prometheus client API
 func (rlpc *RateLimitedPrometheusClient) Do(ctx context.Context, req *http.Request) (*http.Response, []byte, prometheus.Warnings, error) {
+	if rlpc.username != "" {
+		req.SetBasicAuth(rlpc.username, rlpc.password)
+	}
 	rlpc.limiter.Acquire()
 	defer rlpc.limiter.Return()