Skip to content

Commit

Permalink
feat: optional duplicate metrics to default tenant
Browse files Browse the repository at this point in the history
  • Loading branch information
thobianchi committed Sep 8, 2021
1 parent 865a6e8 commit 67657f8
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 12 deletions.
15 changes: 8 additions & 7 deletions config_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@ type config struct {
TimeoutShutdown time.Duration `yaml:"timeout_shutdown"`

Tenant struct {
Label string `yaml:"label,omitempty"`
LabelRemove bool `yaml:"label_remove,omitempty"`
NamespaceLabel string `yaml:"namespace_label,omitempty"`
BatchSize int `yaml:"batch_size,omitempty"`
QueryInterval int `yaml:"query_interval,omitempty"`
Header string
Default string
Label string `yaml:"label,omitempty"`
LabelRemove bool `yaml:"label_remove,omitempty"`
NamespaceLabel string `yaml:"namespace_label,omitempty"`
BatchSize int `yaml:"batch_size,omitempty"`
DuplicateToDefault bool `default:"false" yaml:"duplicate_to_default"`
QueryInterval int `yaml:"query_interval,omitempty"`
Header string
Default string
}

pipeIn *fhu.InmemoryListener
Expand Down
15 changes: 15 additions & 0 deletions config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package main

import (
"testing"

"github.com/stretchr/testify/assert"
)

func Test_DuplicateToDefault(t *testing.T) {
cfg, err := configLoad("config.yml")
if err != nil {
t.FailNow()
}
assert.Equal(t, cfg.Tenant.DuplicateToDefault, false)
}
3 changes: 3 additions & 0 deletions deploy/cortex-tenant.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,6 @@ tenant:
# will be rejected with HTTP code 400
default: example
batch_size: 500
# if true send all metrics to default tenant even the ones directed to different tenants
# the intended effect is to duplcate metrics
duplicate_to_default: false
3 changes: 3 additions & 0 deletions processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ func (p *processor) handle(ctx *fh.RequestCtx) {
if !ok {
log.Errorf("Not found chan for tenant: %s", tenant)
}
if p.cfg.Tenant.DuplicateToDefault && tenant != p.cfg.Tenant.Default {
p.disp.nstschan[p.cfg.Tenant.Default] <- ts
}
p.disp.nstschan[tenant] <- ts
}
ctx.SetStatusCode(fh.StatusOK)
Expand Down
5 changes: 0 additions & 5 deletions processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,6 @@ func sinkHandler(ctx *fh.RequestCtx) {
ctx.WriteString("Ok")
}

func Test_config(t *testing.T) {
_, err := configLoad("config.yml")
assert.Nil(t, err)
}

// func Test_handle(t *testing.T) {
// cfg, err := configParse([]byte(testConfig))
// assert.Nil(t, err)
Expand Down

0 comments on commit 67657f8

Please sign in to comment.