diff --git a/CHANGELOG.md b/CHANGELOG.md index 6e24fe0d12f..62f9dab15cb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/modules/generator/storage/config_util.go b/modules/generator/storage/config_util.go index 2393a1948ac..a8ff03930eb 100644 --- a/modules/generator/storage/config_util.go +++ b/modules/generator/storage/config_util.go @@ -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 @@ -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) } diff --git a/modules/generator/storage/config_util_test.go b/modules/generator/storage/config_util_test.go index acaaeb95e7a..c14cd379dc8 100644 --- a/modules/generator/storage/config_util_test.go +++ b/modules/generator/storage/config_util_test.go @@ -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) { @@ -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",