Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions internal/unleash/dataloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package unleash
import (
"context"
"fmt"
"net/http"
"strings"
"time"

Expand All @@ -19,13 +20,22 @@ import (

type ctxKey int

type mimirRoundTrip struct {
HeaderValue string
}

const (
prometheusURL = "https://nais-prometheus.%s.cloud.nais.io"
prometheusURL = "http://mimir-query-frontend:8080/prometheus"
loadersKey ctxKey = iota

FakeBifrostURL = "*fake*"
)

func (r mimirRoundTrip) RoundTrip(req *http.Request) (*http.Response, error) {
req.Header.Set("X-Scope-OrgID", r.HeaderValue)
return http.DefaultTransport.RoundTrip(req)
}

// NewLoaderContext creates a new context with a loaders value.
// If *fake* is provided as bifrostAPIURL, a fake client will be used.
func NewLoaderContext(ctx context.Context, tenantName string, appWatcher *watcher.Watcher[*UnleashInstance], bifrostAPIURL string, allowedClusters []string, log logrus.FieldLogger) context.Context {
Expand Down Expand Up @@ -58,9 +68,7 @@ func newLoaders(tenantName string, appWatcher *watcher.Watcher[*UnleashInstance]
prometheus = NewFakePrometheusClient()
} else {
client = NewBifrostClient(bifrostAPIURL, log)
promClient, err := promapi.NewClient(promapi.Config{
Address: fmt.Sprintf(prometheusURL, tenantName),
})
promClient, err := promapi.NewClient(promapi.Config{Address: prometheusURL, RoundTripper: mimirRoundTrip{HeaderValue: "nais"}})
if err != nil {
panic(fmt.Errorf("failed to create prometheus client: %w", err))
}
Expand Down