Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,15 @@ tenant:
# https://grafana.com/docs/mimir/latest/configure/about-tenant-ids/
# env: CT_TENANT_PREFIX
prefix: foobar-

# If true will use the tenant ID of the inbound request as the prefix of the new tenant id.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need a bit more detailed description, maybe with a example etc. I didn't get it at first :) Maybe clarify that it takes X-Org-Id header from incoming request, concatenates etc

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added an example inline. Do you think that's sufficient? If not I can add a more detailed example further down in the README.

# Will be automatically suffixed with a `-` character.
# Example:
# Prometheus forwards metrics with `X-Scope-OrgID: Prom-A` set in the inbound request.
# This would result in the tenant prefix being set to `Prom-A-`.
# https://grafana.com/docs/mimir/latest/configure/about-tenant-ids/
# env: CT_TENANT_PREFIX_PREFER_SOURCE
prefix_prefer_source: false
```

### Prometheus configuration example
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.12.4
1.12.5
15 changes: 8 additions & 7 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,14 @@ type config struct {
}

Tenant struct {
Label string `env:"CT_TENANT_LABEL"`
LabelList []string `yaml:"label_list" env:"CT_TENANT_LABEL_LIST" envSeparator:","`
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" env:"CT_TENANT_LABEL_LIST" envSeparator:","`
Prefix string `yaml:"prefix" env:"CT_TENANT_PREFIX"`
PrefixPreferSource bool `yaml:"prefix_prefer_source" env:"CT_TENANT_PREFIX_PREFER_SOURCE`
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
Expand Down
1 change: 1 addition & 0 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ tenant:
- tenant
- other_tenant
prefix: ""
prefix_prefer_source: false
label_remove: true
header: X-Scope-OrgID
default: ""
Expand Down
4 changes: 2 additions & 2 deletions deploy/k8s/chart/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
apiVersion: v2
description: A Helm Chart for cortex-tenant
name: cortex-tenant
version: 0.4.1 # This is the chart version
appVersion: 1.12.4 # version number of the application being deployed.
version: 0.4.2 # This is the chart version
appVersion: 1.12.5 # version number of the application being deployed.
type: application
sources:
- https://github.com/blind-oracle/cortex-tenant
1 change: 1 addition & 0 deletions deploy/k8s/chart/templates/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ data:
{{- . | toYaml | nindent 8 }}
{{- end }}
prefix: {{ .Values.config.tenant.prefix }}
prefix_prefer_source: {{ .Values.config.tenant.prefix_prefer_source }}
label_remove: {{ .Values.config.tenant.label_remove }}
header: {{ .Values.config.tenant.header }}
default: {{ .Values.config.tenant.default }}
Expand Down
6 changes: 6 additions & 0 deletions deploy/k8s/chart/values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,12 @@
"title": "Prefix",
"description": "Optional hard-coded prefix with delimeter for all tenant values"
},
"prefix_prefer_source": {
"type": "boolean",
"title": "Prefix Prefer Source",
"description": "If true will use the tenant ID of the inbound request as the prefix of the new tenant id.",
"default": false
},
"label_remove": {
"type": "boolean",
"title": "Label Remove",
Expand Down
8 changes: 8 additions & 0 deletions deploy/k8s/chart/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,20 @@ config:
# (env: `CT_TENANT_LABEL`)
label: tenant
# -- List of labels examined for tenant information. If set takes precedent over `label`
# (env: `CT_TENANT_LABEL_LIST`)
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/
# (env: `CT_TENANT_PREFIX`)
prefix: ""
# -- If true will use the tenant ID of the inbound request as the prefix of the new tenant id.
# Will be automatically suffixed with a `-` character.
# Example:
# Prometheus forwards metrics with `X-Scope-OrgID: Prom-A` set in the inbound request.
# This would result in the tenant prefix being set to `Prom-A-`.
# (env: `CT_TENANT_PREFIX_PREFER_SOURCE`)
prefix_prefer_source: false
# -- Whether to remove the tenant label from the request
# (env: `CT_TENANT_LABEL_REMOVE`)
label_remove: false
Expand Down
7 changes: 7 additions & 0 deletions deploy/k8s/manifests/config-file-configmap.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ data:
# Delimeters allowed for use:
# https://grafana.com/docs/mimir/latest/configure/about-tenant-ids/
prefix: ""
# If true will use the tenant ID of the inbound request as the prefix of the new tenant id.
# Will be automatically suffixed with a `-` character.
# Example:
# Prometheus forwards metrics with `X-Scope-OrgID: Prom-A` set in the inbound request.
# This would result in the tenant prefix being set to `Prom-A-`.
# https://grafana.com/docs/mimir/latest/configure/about-tenant-ids/
prefix_prefer_source: false
# Whether to remove the tenant label from the request
label_remove: false
# To which header to add the tenant ID
Expand Down
7 changes: 7 additions & 0 deletions processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,13 @@ func (p *processor) handle(ctx *fh.RequestCtx) {
return
}

if p.cfg.Tenant.PrefixPreferSource {
sourceTenantPrefix := string(ctx.Request.Header.Peek(p.cfg.Tenant.Header))
if sourceTenantPrefix != "" {
p.cfg.Tenant.Prefix = sourceTenantPrefix + "-"
}
}

clientIP := ctx.RemoteAddr()
reqID, _ := uuid.NewRandom()

Expand Down