diff --git a/README.md b/README.md index e12300f..9817159 100644 --- a/README.md +++ b/README.md @@ -124,6 +124,11 @@ tenant: # env: CT_TENANT_LABEL label: tenant + # List of labels examined for tenant information. If set takes precedent over `label` + label_list: + - tenant + - other_tenant + # Whether to remove the tenant label from the request # env: CT_TENANT_LABEL_REMOVE label_remove: true diff --git a/VERSION b/VERSION index 81f3632..89c881b 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.12.3 +1.12.4 diff --git a/config.go b/config.go index 9b02490..bc0ca91 100644 --- a/config.go +++ b/config.go @@ -37,12 +37,13 @@ type config struct { } Tenant struct { - Label string `env:"CT_TENANT_LABEL"` - Prefix string `yaml:"prefix" env:"CT_TENANT_PREFIX"` - LabelRemove bool `yaml:"label_remove" env:"CT_TENANT_LABEL_REMOVE"` - Header string `env:"CT_TENANT_HEADER"` - Default string `env:"CT_TENANT_DEFAULT"` - AcceptAll bool `yaml:"accept_all" env:"CT_TENANT_ACCEPT_ALL"` + Label string `env:"CT_TENANT_LABEL"` + LabelList []string `yaml:"label_list"` + Prefix string `yaml:"prefix" env:"CT_TENANT_PREFIX"` + LabelRemove bool `yaml:"label_remove" env:"CT_TENANT_LABEL_REMOVE"` + Header string `env:"CT_TENANT_HEADER"` + Default string `env:"CT_TENANT_DEFAULT"` + AcceptAll bool `yaml:"accept_all" env:"CT_TENANT_ACCEPT_ALL"` } pipeIn *fhu.InmemoryListener diff --git a/config.yml b/config.yml index c74e0f7..da92f32 100644 --- a/config.yml +++ b/config.yml @@ -21,6 +21,9 @@ log_response_errors: true tenant: label: tenant + label_list: + - tenat + - other_tenant prefix: "" label_remove: true header: X-Scope-OrgID diff --git a/deploy/k8s/chart/Chart.yaml b/deploy/k8s/chart/Chart.yaml index 38ac7e4..14f0927 100644 --- a/deploy/k8s/chart/Chart.yaml +++ b/deploy/k8s/chart/Chart.yaml @@ -1,8 +1,8 @@ apiVersion: v2 description: A Helm Chart for cortex-tenant name: cortex-tenant -version: 0.4.0 # This is the chart version -appVersion: 1.11.0 # version number of the application being deployed. +version: 0.4.1 # This is the chart version +appVersion: 1.12.4 # version number of the application being deployed. type: application sources: - https://github.com/blind-oracle/cortex-tenant diff --git a/deploy/k8s/chart/templates/configmap.yaml b/deploy/k8s/chart/templates/configmap.yaml index 4d518cd..46dfd55 100644 --- a/deploy/k8s/chart/templates/configmap.yaml +++ b/deploy/k8s/chart/templates/configmap.yaml @@ -25,6 +25,10 @@ data: {{- end }} tenant: label: {{ .Values.config.tenant.label }} + {{- with .Values.config.tenant.label_list }} + label_list: + {{- . | toYaml | nindent 8 }} + {{- end }} prefix: {{ .Values.config.tenant.prefix }} label_remove: {{ .Values.config.tenant.label_remove }} header: {{ .Values.config.tenant.header }} diff --git a/deploy/k8s/chart/values.schema.json b/deploy/k8s/chart/values.schema.json index 9b1458d..4ef4388 100644 --- a/deploy/k8s/chart/values.schema.json +++ b/deploy/k8s/chart/values.schema.json @@ -260,6 +260,16 @@ "description": "Which label to look for the tenant information", "default": "tenant" }, + "label_list": { + "type": "array", + "title": "LabelList", + "description": "List of labels examined for tenant information. If set takes precedent over `label`", + "items": { + "type": "string", + "title": "LabelListItems", + "default": "" + } + }, "prefix": { "type": "string", "title": "Prefix", diff --git a/deploy/k8s/chart/values.yaml b/deploy/k8s/chart/values.yaml index 3a9326a..32cbe22 100644 --- a/deploy/k8s/chart/values.yaml +++ b/deploy/k8s/chart/values.yaml @@ -100,6 +100,8 @@ config: # -- Which label to look for the tenant information # (env: `CT_TENANT_LABEL`) label: tenant + # -- List of labels examined for tenant information. If set takes precedent over `label` + label_list: [] # -- Optional hard-coded prefix with delimeter for all tenant values. # Delimeters allowed for use: # https://grafana.com/docs/mimir/latest/configure/about-tenant-ids/ diff --git a/processor.go b/processor.go index 591b516..819ecbc 100644 --- a/processor.go +++ b/processor.go @@ -6,6 +6,7 @@ import ( "fmt" "net" "strconv" + "strings" "sync" "sync/atomic" "time" @@ -331,16 +332,25 @@ func removeOrdered(slice []prompb.Label, s int) []prompb.Label { func (p *processor) processTimeseries(ts *prompb.TimeSeries) (tenant string, err error) { idx := 0 + + configuredLabels := p.cfg.Tenant.LabelList + + if len(configuredLabels) == 0 { + configuredLabels = append(configuredLabels, p.cfg.Tenant.Label) + } + for i, l := range ts.Labels { - if l.Name == p.cfg.Tenant.Label { - tenant, idx = l.Value, i - break + for _, configuredLabel := range configuredLabels { + if l.Name == configuredLabel { + tenant, idx = l.Value, i + break + } } } if tenant == "" { if p.cfg.Tenant.Default == "" { - return "", fmt.Errorf("label '%s' not found", p.cfg.Tenant.Label) + return "", fmt.Errorf("label(s): {'%s'} not found", strings.Join(configuredLabels, "','")) } return p.cfg.Tenant.Default, nil diff --git a/processor_test.go b/processor_test.go index 7da5418..7aa134b 100644 --- a/processor_test.go +++ b/processor_test.go @@ -32,6 +32,10 @@ max_conns_per_host: 64 tenant: label_remove: false default: default + label_list: + - "__tenant__" + - "__foo__" + - "__bar__" ` testConfigWithValues = `listen: 0.0.0.0:8080 listen_pprof: 0.0.0.0:7008 @@ -45,6 +49,9 @@ tenant: prefix: foobar- label_remove: false default: default + label_list: + - "__foo__" + - "__bar__" ` )