From 67657f83943a35b2b04486810b3529c11de294e8 Mon Sep 17 00:00:00 2001 From: Thomas Bianchi Date: Tue, 7 Sep 2021 17:47:22 +0200 Subject: [PATCH] feat: optional duplicate metrics to default tenant --- config_schema.go | 15 ++++++++------- config_test.go | 15 +++++++++++++++ deploy/cortex-tenant.yml | 3 +++ processor.go | 3 +++ processor_test.go | 5 ----- 5 files changed, 29 insertions(+), 12 deletions(-) create mode 100644 config_test.go diff --git a/config_schema.go b/config_schema.go index a6f585b..c237d3a 100644 --- a/config_schema.go +++ b/config_schema.go @@ -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 diff --git a/config_test.go b/config_test.go new file mode 100644 index 0000000..d17fa39 --- /dev/null +++ b/config_test.go @@ -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) +} diff --git a/deploy/cortex-tenant.yml b/deploy/cortex-tenant.yml index 20204b6..6bd0c38 100644 --- a/deploy/cortex-tenant.yml +++ b/deploy/cortex-tenant.yml @@ -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 diff --git a/processor.go b/processor.go index a20b352..905a6c7 100644 --- a/processor.go +++ b/processor.go @@ -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) diff --git a/processor_test.go b/processor_test.go index 7187755..c157eaa 100644 --- a/processor_test.go +++ b/processor_test.go @@ -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)