github.com/yankunsam/loki/v2@v2.6.3-0.20220817130409-389df5235c27/docs/sources/operations/multi-tenancy.md (about) 1 --- 2 title: Multi-tenancy 3 weight: 50 4 --- 5 # Grafana Loki Multi-Tenancy 6 7 Grafana Loki is a multi-tenant system; requests and data for tenant A are isolated from 8 tenant B. Requests to the Loki API should include an HTTP header 9 (`X-Scope-OrgID`) that identifies the tenant for the request. 10 11 Tenant IDs can be any alphanumeric string that fits within the Go HTTP header 12 limit (1MB). Operators are recommended to use a reasonable limit for uniquely 13 identifying tenants; 20 bytes is usually enough. 14 15 Loki defaults to running in multi-tenant mode. 16 Multi-tenant mode is set in the configuration with `auth_enabled: true`. 17 18 When configured with `auth_enabled: false`, Loki uses a single tenant. 19 The `X-Scope-OrgID` header is not required in Loki API requests. 20 The single tenant ID will be the string `fake`. 21 22 ## Multi-tenant Queries 23 24 In multi-tenant mode, queries may gather results from multiple tenants. 25 Set the querier configuration option `multi_tenant_queries_enabled: true` to enable queries across tenants. 26 The query API request defines the tenants. 27 Specify multiple tenants 28 in the query request HTTP header `X-Scope-OrgID` by separating the tenant IDs with the pipe character (`|`). 29 For example, a query for tenants `A` and `B` requires the header `X-Scope-OrgID: A|B`. 30 31 Only query endpoints support multi-tenant calls. 32 Calls to `GET /loki/api/v1/tail` and `POST /loki/api/v1/push` will return an HTTP 400 error if more than one tenant is defined in the HTTP header. 33 34 Instant and range queries support label filtering using tenant IDs. 35 For example, the query 36 37 ``` 38 {app="foo", __tenant_id__=~"a.+"} | logfmt 39 ``` 40 will return results for all tenants 41 that have a tenant ID that begins with the character `a`. 42 43 If the label `__tenant_id__` is already present in a log stream, it is prepended with the string `original_`. 44 45 Tenant ID filtering in stages is not supported. 46 An example of a query that will _not_ work: 47 48 ``` 49 {app="foo"} | __tenant_id__="1" | logfmt 50 ```