I’m working with Cortex multi-tenancy where both write and read paths require X-Scope-OrgID
HTTP header in the request.
The write path is working fine. But I can’t figure out how to pass the chosen tenant name in my dashboard to the Cortex data source as X-Scope-OrgID
HTTP header.
My current Grafana data sources look like this:
apiVersion: 1
datasources:
- name: Prometheus
type: prometheus
url: "http://prom-kube-prometheus-stack-prometheus.observability:9090"
- name: Cortex
type: prometheus
url: "http://cortex-query-frontend-headless.cortex:8080/prometheus"
isDefault: true
jsonData:
httpHeaderName1: 'X-Scope-OrgID'
secureJsonData:
httpHeaderValue1: 'cust-3b74e7dd-808d-default'
As you can see, I just hard coded the X-Scope-OrgID
HTTP header value to a static tenant name (cust-3b74e7dd-808d-default
). This works fine and the dashboard is able to load and display metrics from that specific hard coded tenant just fine.
And it looks like this:
Notes:
- The dropdown/tenant names on left side is using Prometheus data source
- The
Foo
panel on right side is using Cortex data source; scoped/hardcoded tocust-3b74e7dd-808d-default
tenant
Question:
How do I pass the variable dropdown value to the Cortex data source as X-Scope-OrgID
HTTP header?
For example, when I choose cust-test-1234
tenant from the dropdown, the request to Cortex should has X-Scope-OrgID
HTTP header set to cust-test-1234
as well.
Is this something can be done? Do I need to use any plugins?
References (I’ve to put these links as code because new user is not allowed to put more than 2 links):
- https://cortexmetrics.io/docs/guides/auth/
- https://cortexmetrics.io/docs/guides/limitations/#tenant-id-naming
FWIW, this is my dashboard in JSON:
{
"annotations": {
"list": [
{
"builtIn": 1,
"datasource": {
"type": "grafana",
"uid": "-- Grafana --"
},
"enable": true,
"hide": true,
"iconColor": "rgba(0, 211, 255, 1)",
"name": "Annotations & Alerts",
"target": {
"limit": 100,
"matchAny": false,
"tags": [],
"type": "dashboard"
},
"type": "dashboard"
}
]
},
"editable": true,
"fiscalYearStartMonth": 0,
"graphTooltip": 0,
"id": 2,
"links": [],
"liveNow": false,
"panels": [
{
"datasource": {
"type": "prometheus",
"uid": "P6693426190CB2316"
},
"fieldConfig": {
"defaults": {
"color": {
"mode": "palette-classic"
},
"custom": {
"axisCenteredZero": false,
"axisColorMode": "text",
"axisLabel": "",
"axisPlacement": "auto",
"barAlignment": 0,
"drawStyle": "line",
"fillOpacity": 0,
"gradientMode": "none",
"hideFrom": {
"legend": false,
"tooltip": false,
"viz": false
},
"lineInterpolation": "linear",
"lineWidth": 1,
"pointSize": 5,
"scaleDistribution": {
"type": "linear"
},
"showPoints": "auto",
"spanNulls": false,
"stacking": {
"group": "A",
"mode": "none"
},
"thresholdsStyle": {
"mode": "off"
}
},
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
},
{
"color": "red",
"value": 80
}
]
}
},
"overrides": []
},
"gridPos": {
"h": 9,
"w": 12,
"x": 7,
"y": 0
},
"id": 2,
"options": {
"legend": {
"calcs": [],
"displayMode": "list",
"placement": "bottom",
"showLegend": true
},
"tooltip": {
"mode": "single",
"sort": "none"
}
},
"targets": [
{
"datasource": {
"type": "prometheus",
"uid": "P6693426190CB2316"
},
"editorMode": "code",
"expr": "sum by (id) (dummy_foo)",
"legendFormat": "__auto",
"range": true,
"refId": "A"
}
],
"title": "Foo",
"type": "timeseries"
}
],
"schemaVersion": 37,
"style": "dark",
"tags": [],
"templating": {
"list": [
{
"current": {
"selected": true,
"text": "cust-15276cac-808d-default",
"value": "cust-15276cac-808d-default"
},
"datasource": {
"type": "prometheus",
"uid": "PBFA97CFB590B2093"
},
"definition": "label_values(namespace)",
"hide": 0,
"includeAll": false,
"multi": false,
"name": "tenant",
"options": [],
"query": {
"query": "label_values(namespace)",
"refId": "StandardVariableQuery"
},
"refresh": 1,
"regex": "cust-.*",
"skipUrlSync": false,
"sort": 0,
"type": "query"
}
]
},
"time": {
"from": "now-5m",
"to": "now"
},
"timepicker": {},
"timezone": "",
"title": "My dashboard",
"uid": "nqdvuvK4z",
"version": 1,
"weekStart": ""
}