Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Remove tenant_header_key from config (#2414)" #2795

Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* [BUGFIX] Only search ingester blocks that fall within the request time range. [#2783](https://github.com/grafana/tempo/pull/2783) (@joe-elliott)
* [BUGFIX] Fix incorrect metrics for index failures [#2781](https://github.com/grafana/tempo/pull/2781) (@zalegrala)
* [BUGFIX] Fix panic in the metrics-generator when using multiple tenants with default overrides [#2786](https://github.com/grafana/tempo/pull/2786) (@kvrhdn)
* [BUGFIX] Restore `tenant_header_key` removed in #2414. [#2786](https://github.com/grafana/tempo/pull/2795) (@joe-elliott)

## v2.2.0 / 2023-07-31

Expand Down
14 changes: 11 additions & 3 deletions cmd/tempo-query/tempo/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@ package tempo

import (
"github.com/grafana/dskit/crypto/tls"
"github.com/jaegertracing/jaeger/plugin/storage/grpc/shared"
"github.com/spf13/viper"
)

// Config holds the configuration for redbull.
type Config struct {
Backend string `yaml:"backend"`
TLSEnabled bool `yaml:"tls_enabled" category:"advanced"`
TLS tls.ClientConfig `yaml:",inline"`
Backend string `yaml:"backend"`
TLSEnabled bool `yaml:"tls_enabled" category:"advanced"`
TLS tls.ClientConfig `yaml:",inline"`
TenantHeaderKey string `yaml:"tenant_header_key"`
}

// InitFromViper initializes the options struct with values from Viper
Expand All @@ -23,4 +25,10 @@ func (c *Config) InitFromViper(v *viper.Viper) {
c.TLS.InsecureSkipVerify = v.GetBool("tls_insecure_skip_verify")
c.TLS.CipherSuites = v.GetString("tls_cipher_suites")
c.TLS.MinVersion = v.GetString("tls_min_version")

tenantHeader := v.GetString("tenant_header_key")
if tenantHeader == "" {
tenantHeader = shared.BearerTokenKey
}
c.TenantHeaderKey = tenantHeader
}
25 changes: 13 additions & 12 deletions cmd/tempo-query/tempo/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"google.golang.org/grpc/metadata"

jaeger "github.com/jaegertracing/jaeger/model"
"github.com/jaegertracing/jaeger/plugin/storage/grpc/shared"
jaeger_spanstore "github.com/jaegertracing/jaeger/storage/spanstore"

ot_jaeger "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/jaeger"
Expand Down Expand Up @@ -54,10 +53,11 @@ var tlsVersions = map[string]uint16{
}

type Backend struct {
tempoBackend string
tlsEnabled bool
tls tlsCfg.ClientConfig
httpClient *http.Client
tempoBackend string
tlsEnabled bool
tls tlsCfg.ClientConfig
httpClient *http.Client
tenantHeaderKey string
}

func New(cfg *Config) (*Backend, error) {
Expand All @@ -66,10 +66,11 @@ func New(cfg *Config) (*Backend, error) {
return nil, err
}
return &Backend{
tempoBackend: cfg.Backend,
tlsEnabled: cfg.TLSEnabled,
tls: cfg.TLS,
httpClient: httpClient,
tempoBackend: cfg.Backend,
tlsEnabled: cfg.TLSEnabled,
tls: cfg.TLS,
httpClient: httpClient,
tenantHeaderKey: cfg.TenantHeaderKey,
}, nil
}

Expand Down Expand Up @@ -434,17 +435,17 @@ func (b *Backend) newGetRequest(ctx context.Context, url string, span opentracin

// currently Jaeger Query will only propagate bearer token to the grpc backend and no other headers
// so we are going to extract the tenant id from the header, if it exists and use it
tenantID, found := extractBearerToken(ctx)
tenantID, found := extractBearerToken(ctx, b.tenantHeaderKey)
if found {
req.Header.Set(user.OrgIDHeaderName, tenantID)
}

return req, nil
}

func extractBearerToken(ctx context.Context) (string, bool) {
func extractBearerToken(ctx context.Context, tenantHeader string) (string, bool) {
if md, ok := metadata.FromIncomingContext(ctx); ok {
values := md.Get(shared.BearerTokenKey)
values := md.Get(tenantHeader)
if len(values) > 0 {
return values[0], true
}
Expand Down