Skip to content

Commit

Permalink
metrics-generator: don't inject X-Scope-OrgID header for single-tenan…
Browse files Browse the repository at this point in the history
…t setups (#1417)

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

* Update CHANGELOG.md
  • Loading branch information
Koenraad Verheyden authored May 2, 2022
1 parent de9d9a4 commit 046319f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
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

0 comments on commit 046319f

Please sign in to comment.