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

metrics-generator: don't inject X-Scope-OrgID header for single-tenant setups #1417

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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## main / unreleased

* [BUGFIX] metrics-generator: don't inject X-Scope-OrgID header for single-tenant setups [1417](https://github.com/grafana/tempo/pull/1417) (@kvrhdn)

## v1.4.0 / 2022-04-28

* [CHANGE] Vulture now exercises search at any point during the block retention to test full backend search.
Expand Down
6 changes: 5 additions & 1 deletion modules/generator/storage/config_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"github.com/go-kit/log/level"
prometheus_config "github.com/prometheus/prometheus/config"
"github.com/weaveworks/common/user"

"github.com/grafana/tempo/pkg/util"
)

// generateTenantRemoteWriteConfigs creates a copy of the remote write configurations with the
Expand All @@ -31,7 +33,9 @@ func generateTenantRemoteWriteConfigs(originalCfgs []prometheus_config.RemoteWri
}

// inject the X-Scope-OrgId header for multi-tenant metrics backends
cloneCfg.Headers[user.OrgIDHeaderName] = tenant
if tenant != util.FakeTenantID {
cloneCfg.Headers[user.OrgIDHeaderName] = tenant
}

cloneCfgs = append(cloneCfgs, cloneCfg)
}
Expand Down
19 changes: 19 additions & 0 deletions modules/generator/storage/config_util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
prometheus_common_config "github.com/prometheus/common/config"
prometheus_config "github.com/prometheus/prometheus/config"
"github.com/stretchr/testify/assert"

"github.com/grafana/tempo/pkg/util"
)

func Test_generateTenantRemoteWriteConfigs(t *testing.T) {
Expand Down Expand Up @@ -39,6 +41,23 @@ func Test_generateTenantRemoteWriteConfigs(t *testing.T) {
assert.Equal(t, map[string]string{"foo": "bar", "X-Scope-OrgID": "my-tenant"}, result[1].Headers)
}

func Test_generateTenantRemoteWriteConfigs_singleTenant(t *testing.T) {
logger := log.NewLogfmtLogger(log.NewSyncWriter(os.Stdout))

original := []prometheus_config.RemoteWriteConfig{
{
URL: &prometheus_common_config.URL{URL: urlMustParse("http://prometheus-1/api/prom/push")},
Headers: map[string]string{},
},
}

result := generateTenantRemoteWriteConfigs(original, util.FakeTenantID, logger)

assert.Equal(t, original[0].URL, result[0].URL)
// X-Scope-OrgID has not been injected
assert.Empty(t, result[0].Headers)
}

func Test_copyMap(t *testing.T) {
original := map[string]string{
"k1": "v1",
Expand Down