فهرست منبع

fix: rename header fields

Signed-off-by: ilya.melnikov <ilya.melnikov@idp.zyfra.com>
ilya.melnikov 3 سال پیش
والد
کامیت
6f411d6928
3فایلهای تغییر یافته به همراه30 افزوده شده و 30 حذف شده
  1. 3 3
      pkg/costmodel/router.go
  2. 4 4
      pkg/env/costmodelenv.go
  3. 23 23
      pkg/prom/prom.go

+ 3 - 3
pkg/costmodel/router.go

@@ -1533,9 +1533,9 @@ func Initialize(additionalConfigWatchers ...*watcher.ConfigMapWatcher) *Accesses
 			Password:    env.GetDBBasicAuthUserPassword(),
 			BearerToken: env.GetDBBearerToken(),
 		},
-		QueryConcurrency: queryConcurrency,
-		QueryLogFile:     "",
-		MimirHeaderOrgId: env.GetMimirHeaderOrgId(),
+		QueryConcurrency:  queryConcurrency,
+		QueryLogFile:      "",
+		HeaderXScopeOrgId: env.GetPrometheusHeaderXScopeOrgId(),
 	})
 	if err != nil {
 		log.Fatalf("Failed to create prometheus client, Error: %v", err)

+ 4 - 4
pkg/env/costmodelenv.go

@@ -92,7 +92,7 @@ const (
 	PrometheusRetryOnRateLimitMaxRetriesEnvVar  = "PROMETHEUS_RETRY_ON_RATE_LIMIT_MAX_RETRIES"
 	PrometheusRetryOnRateLimitDefaultWaitEnvVar = "PROMETHEUS_RETRY_ON_RATE_LIMIT_DEFAULT_WAIT"
 
-	MimirHeaderOrgIdEnvVar = "MIMIR_HEADER_ORG_ID"
+	PrometheusHeaderXScopeOrgIdEnvVar = "PROMETHEUS_HEADER_X_SCOPE_ORGID"
 
 	IngestPodUIDEnvVar = "INGEST_POD_UID"
 
@@ -164,9 +164,9 @@ func GetPrometheusRetryOnRateLimitDefaultWait() time.Duration {
 	return GetDuration(PrometheusRetryOnRateLimitDefaultWaitEnvVar, 100*time.Millisecond)
 }
 
-// GetMimirOrgIdHeader returns the default value for X-Scope-OrgID header used for requests in Mimir API.
-func GetMimirHeaderOrgId() string {
-	return Get(MimirHeaderOrgIdEnvVar, "")
+// GetPrometheusHeaderXScopeOrgId returns the default value for X-Scope-OrgID header used for requests in Mimir API.
+func GetPrometheusHeaderXScopeOrgId() string {
+	return Get(PrometheusHeaderXScopeOrgIdEnvVar, "")
 }
 
 // GetPrometheusQueryOffset returns the time.Duration to offset all prometheus queries by. NOTE: This env var is applied

+ 23 - 23
pkg/prom/prom.go

@@ -69,7 +69,7 @@ func (auth *ClientAuth) Apply(req *http.Request) {
 const MaxRetryAfterDuration = 10 * time.Second
 
 // Default header key for Mimir API requests
-const MimirHeader = "X-Scope-OrgID"
+const HeaderXScopeOrgId = "X-Scope-OrgID"
 
 // RateLimitRetryOpts contains retry options
 type RateLimitRetryOpts struct {
@@ -117,15 +117,15 @@ func (rlre *RateLimitedResponseError) Error() string {
 // RateLimitedPrometheusClient is a prometheus client which limits the total number of
 // concurrent outbound requests allowed at a given moment.
 type RateLimitedPrometheusClient struct {
-	id             string
-	client         prometheus.Client
-	auth           *ClientAuth
-	queue          collections.BlockingQueue[*workRequest]
-	decorator      QueryParamsDecorator
-	rateLimitRetry *RateLimitRetryOpts
-	outbound       atomic.Int32
-	fileLogger     *golog.Logger
-	mimirOrgId     string
+	id                string
+	client            prometheus.Client
+	auth              *ClientAuth
+	queue             collections.BlockingQueue[*workRequest]
+	decorator         QueryParamsDecorator
+	rateLimitRetry    *RateLimitRetryOpts
+	outbound          atomic.Int32
+	fileLogger        *golog.Logger
+	headerXScopeOrgId string
 }
 
 // requestCounter is used to determine if the prometheus client keeps track of
@@ -145,7 +145,7 @@ func NewRateLimitedClient(
 	decorator QueryParamsDecorator,
 	rateLimitRetryOpts *RateLimitRetryOpts,
 	queryLogFile string,
-	mimirHeaderOrgId string) (prometheus.Client, error) {
+	headerXScopeOrgId string) (prometheus.Client, error) {
 
 	queue := collections.NewBlockingQueue[*workRequest]()
 
@@ -174,14 +174,14 @@ func NewRateLimitedClient(
 	}
 
 	rlpc := &RateLimitedPrometheusClient{
-		id:             id,
-		client:         client,
-		queue:          queue,
-		decorator:      decorator,
-		rateLimitRetry: rateLimitRetryOpts,
-		auth:           auth,
-		fileLogger:     logger,
-		mimirOrgId:     mimirHeaderOrgId,
+		id:                id,
+		client:            client,
+		queue:             queue,
+		decorator:         decorator,
+		rateLimitRetry:    rateLimitRetryOpts,
+		auth:              auth,
+		fileLogger:        logger,
+		headerXScopeOrgId: headerXScopeOrgId,
 	}
 
 	// Start concurrent request processing
@@ -319,8 +319,8 @@ func (rlpc *RateLimitedPrometheusClient) worker() {
 
 // Rate limit and passthrough to prometheus client API
 func (rlpc *RateLimitedPrometheusClient) Do(ctx context.Context, req *http.Request) (*http.Response, []byte, error) {
-	if rlpc.mimirOrgId != "" {
-		req.Header.Set(MimirHeader, rlpc.mimirOrgId)
+	if rlpc.headerXScopeOrgId != "" {
+		req.Header.Set(HeaderXScopeOrgId, rlpc.headerXScopeOrgId)
 	}
 
 	rlpc.auth.Apply(req)
@@ -363,7 +363,7 @@ type PrometheusClientConfig struct {
 	Auth                  *ClientAuth
 	QueryConcurrency      int
 	QueryLogFile          string
-	MimirHeaderOrgId      string
+	HeaderXScopeOrgId     string
 }
 
 // NewPrometheusClient creates a new rate limited client which limits by outbound concurrent requests.
@@ -398,7 +398,7 @@ func NewPrometheusClient(address string, config *PrometheusClientConfig) (promet
 		nil,
 		config.RateLimitRetryOpts,
 		config.QueryLogFile,
-		config.MimirHeaderOrgId,
+		config.HeaderXScopeOrgId,
 	)
 }