Fair querying for many users within one Loki tenant

Loki's hierarchical scheduler queues, on by default since 2.9, stop one Grafana user or script from starving others in a shared tenant. This page covers how they work, what to configure and what to confirm.

On this page

Fair querying for many users within one Loki tenant: when you need it

When several teams or many Grafana users share one Loki tenant, a single heavy query can slow searches for everyone else. Loki's hierarchical scheduler queues provide fairness across actors within a tenant, and they have been enabled by default since 2.9, so the protection is already active on supported versions unless your configuration turns it off. An actor is the identity that submits a query: a person using Grafana, a person using the command line, or an application or script calling the Loki API. The scheduler uses the actor identity that Loki receives on each request, so the fairness is only as good as the identities your proxy and clients send.

You need to plan for this when one tenant serves more than one group of people or systems that query at different rates. Typical cases are a shared production tenant used by application teams, platform engineers and an automated report or alerting integration, or a tenant where a few analysts run wide time-range searches while others run dashboards. A single tenant is also the unit that per-tenant limits apply to, so fairness does not replace limits and does not separate data between teams. If one group must not see another group's logs, that is an access question for a separate tenant or label-based access control, not for the scheduler. Confirm your load profile with your own query logs before deciding, because no general threshold is documented that tells you when contention becomes a problem.

Decide now which identities will reach Loki and how they will be labeled. Grafana users, service accounts and scripts should reach Loki through paths where the actor can be told apart, and your reverse proxy should not collapse all traffic into one generic client. Check the Loki query fairness documentation for the actor headers your version expects and for how the queues are configured, and test with two competing actors before relying on the behavior. The Loki query fairness documentation is the natural next read for those details.

Configuration options and when each fits

This table compares the fairness mechanism and the related query scheduler, frontend and per-tenant limit settings, showing what each does by default and when to change it. Read it to decide whether the defaults are enough for your users or whether one of the tuning levers is worth a change. Confirm exact config keys against the query fairness page for your Loki version before editing any file.

OptionDefault behaviorWhen to keep itWhen to tune or change it
Hierarchical scheduler queues (query fairness)Enabled by default from Loki 2.9, spreading query work across actors such as Grafana users, CLI users and applications within a tenantMost shared tenants with a mix of dashboard users and scripts, where no single actor needs special treatmentRarely needed to disable; revisit only if a documented side effect appears in your version's release notes
Actor identification headersActors are identified from the request headers Loki receives, so the proxy and clients determine how fairly work is groupedWhen Grafana, CLI tools and automation each send consistent identifying headers through your reverse proxyWhen a proxy strips or rewrites headers, so all users appear as one actor and fairness has no effect
Max outstanding requests per tenant (queue depth)Limits how many queued requests a tenant can hold at once in the scheduler (confirm the key and default in your version)When queue wait stays short during normal peaks and no tenant is rejectedWhen one tenant floods the queue and others see timeouts, or when legitimate bursts are rejected too early
Query scheduler and querier concurrencyControls how many queries run in parallel per querier and how work is dispatched (confirm exact settings for your deployment mode)When query latency is steady and CPU or memory on queriers has headroomWhen queries queue behind a few heavy requests even with fairness active, and resources are available to add workers
Query frontend splitting and shardingSplits large range queries into smaller sub-queries that the scheduler can interleave with other workWhen typical queries are short and boundedWhen very long time ranges from one actor dominate workers; smaller splits let other actors' work run between them
Per-tenant query limits (runtime overrides)Apply per tenant, such as maximum query length, series and lookback, through the limits configurationWhen tenants have similar needs and the platform limits are acceptable to everyoneWhen a heavy tenant needs a stricter cap, since fairness balances actors but does not cap total tenant usage

How to set up query fairness in a shared tenant

This sequence takes a shared Loki tenant from default scheduling to a tested state where one heavy user or script cannot starve the others. Each step closes with a check, so you confirm the fairness behavior in your own environment before you rely on it.

  1. Confirm the Loki version is 2.9 or newer

    Check the version of every read-path component, including the query frontend and any query scheduler, against the Loki releases page. Hierarchical scheduler queues were introduced in 2.9, so a single older component can silently change how requests are queued. Record the version of each component in your inventory. The step is done when every read component reports 2.9 or later and the inventory matches what is running, not what was planned.

  2. Confirm query scheduling is active

    Review the running configuration of the query frontend and scheduler, and confirm that no setting disables the hierarchical queues. Scheduling is enabled by default from 2.9, so the check is that your deployment has not overridden it in configuration files, Helm values or startup flags. Read the effective configuration from the running components, since a file on disk may differ from what is loaded. The step is done when the effective configuration shows scheduling active on every read component.

  3. Define the actors that send traffic

    Working with the platform owner and the teams that query Loki, list every actor that sends queries to the shared tenant. Typical actors are Grafana datasource users, command-line users, service accounts for dashboards and alert tools, and applications that call the query API. Note the owner, the approximate query pattern and whether the actor is interactive or automated for each one. The step is done when the list is agreed and every actor has a named owner, so later tests cover real traffic.

  4. Pass actor identification through clients and the proxy

    Loki's fairness depends on each request carrying an identity for the actor that sent it. Confirm the exact actor header name and how it is set in the Loki query fairness documentation. Configure your authenticating reverse proxy to set the header from the authenticated identity, and strip any value a client supplies, so users cannot claim another actor's queue. Confirm that Grafana datasources and scripts forward the identity they should. The step is done when a request from each actor type shows the expected identity in proxy or Loki logs.

  5. Run concurrent queries from two actors

    Using a test environment or a quiet window in production with the agreement of the owners, start a heavy query from one actor, such as a wide time range with a regular expression filter. While it runs, send a small, routine query from a second actor. Measure how long the second query takes to start and finish, and compare it with its normal latency when the first actor is idle. The step is done when the small query completes within the latency you set as acceptable for your users.

  6. Check queue behavior and metrics

    During the concurrent test, watch queue length and queue wait time for each actor on the query frontend and scheduler dashboards. Confirm the metric names in the Loki documentation and in your own Prometheus targets before building alerts on them. Look for the heavy actor's requests being held back while the light actor's requests are served. The step is done when the metrics show that the second actor was not blocked behind the first, and you have saved screenshots or exported values as the baseline.

  7. Record results and repeat the test after changes

    Write down the test scenario, the actors, the latency results, the metric values and the Loki version used. Store this record with your Loki operations runbook. Repeat the same test after each Loki upgrade, proxy change, new actor type or change to query limits, because any of these can alter queue behavior. The step is done when the baseline record exists, the owner of the runbook has accepted it, and a date for the next repeat is on the operations calendar.

How a query moves through the scheduler queues

A query starts in Grafana or a script, passes through the authenticating reverse proxy that sets the X-Scope-OrgID tenant header, then reaches the query frontend. There it is placed into a hierarchical scheduler queue keyed to the actor, and queriers pull work from those queues. Check that the proxy, not the client, sets the tenant header, and confirm which actor headers your clients send so that fairness applies to the users you expect.

Query path from client through the proxy to the scheduler queues and queriers.

Security and operational considerations

Fair querying only works when the actor each query is attributed to is trustworthy, and when operators can see whether the scheduler is doing its job. The cards below cover the identity source, the boundary that fairness does not provide, the signals to watch, and how scripts and service accounts stay visible in a shared tenant.

Take actor identity from the proxy

The actor a query is scheduled under comes from request headers, so a client that can set those headers itself could claim to be another user or a busy service. Your authenticating reverse proxy should be the only component that sets the actor header, overwriting anything the client sends. Check this with a test request that includes a forged value and confirm Loki schedules the query under the proxy's value. Confirm the exact header name and behavior for your Loki version in the query fairness docs before you rely on it.

Query fairness docs

Fairness is not tenant isolation

Hierarchical queues decide the order in which queries from different actors are run inside one tenant. They do not stop a user in tenant A from reading tenant B, and they do not restrict which streams a user can query within a tenant. Those boundaries come from the tenant ID set through X-Scope-OrgID and, where needed, from access controls at the proxy. Do not describe the queue as a security control in your review evidence.

Monitor queue wait time

Starvation shows up first as rising time spent waiting in the queue, before users complain about slow dashboards. Track queue duration and queue length per query frontend or querier and alert when waits grow for a sustained period. Compare waits for interactive Grafana traffic against scripted traffic so you can see which actor is creating the backlog. Confirm which queue metrics your Loki version exposes before you write alert rules.

Watch rejected and failed queries

When queues or per-tenant query limits are exceeded, Loki rejects requests, and those rejections are the clearest sign that a single actor is over its share. Count rejected queries by tenant and by actor where your metrics allow it, and review the logs of the proxy and Loki side by side during an incident. Ask your team to decide in advance who is paged for rejections and what the response is, such as contacting the owner of a runaway script.

Keep service accounts identifiable

Dashboards, alert queries, CLI sessions and automation all share one tenant, so a generic service identity makes it impossible to tell which workload is responsible for load. Give each script, scheduled job and integration its own proxy-issued identity, and document the owner and purpose of each one. Review the list periodically and retire identities that no longer have an owner. This keeps fairness decisions and capacity planning based on real actors instead of a single shared account.

Document the scheduling settings

Queue behavior depends on configuration that changes across Loki versions and deployment modes, so a change can alter fairness without anyone noticing. Record the Loki version, the scheduler and query frontend settings, and the proxy rules that set actor identity in your change management system. Require a review and a test query from a forged identity after any proxy or Loki upgrade. This gives auditors and operators one place to verify how fairness is configured.

Questions teams ask before fixing query fairness

Can our own team fix query fairness in Loki without a partner?

Yes, if your team already runs Loki and has someone comfortable with Grafana and reverse proxy configuration. Query fairness is enabled by default from Loki 2.9, so much of the mechanism is already in place. The work that usually takes time is deciding how actors are identified, making sure your proxy passes the actor headers consistently, and proving the result under realistic load. If nobody on the team has tested scheduler behavior under contention, a short external review can shorten that learning curve. Your team keeps ownership either way.

What drives the effort of a query fairness project?

Effort follows the number of actors and how they reach Loki. The main drivers are:

  • How many distinct Grafana users, CLI users and applications share one tenant, and whether they arrive through one proxy or several.
  • How Grafana is set up, including data source configuration, service accounts and any shared credentials that would make many people look like one actor.
  • How much testing is required, from a single noisy-script scenario to a repeatable load test that your operators can rerun after upgrades.

Smaller, single-proxy setups with clear identities take less time. Shared credentials and many automated clients add work, because identity has to be untangled before fairness can work as intended.

What do we need to provide before the work starts?

Expect to provide the Loki version you run, the identity provider that signs in your Grafana users, and read access to Loki and Grafana metrics so the team can see queue behavior before and after changes. You also need a description of how applications and scripts authenticate to Loki, and access to the reverse proxy configuration that sets the X-Scope-OrgID header. Confirm with your own environment owners which versions are approved for change, and whether a non-production Loki cluster is available for testing. Missing any of these items usually extends the discovery phase.

How long does a query fairness engagement take?

Duration depends on your environment, and it is set in the written scope rather than guessed from a general rule. The main variables are the number of actors, the state of your proxy and identity setup, the size of the test environment and how many change windows you can use. We agree on scope, deliverables and timelines in writing before work starts, and the quote follows from that scope. Ask for the scope to list each phase, the environment it runs in and what is handed over at the end.

Is query fairness a one-time change or ongoing tuning?

The initial setup is usually one-time work: identifying actors, configuring the proxy and Grafana, and verifying that queues behave as expected. Ongoing attention is still needed as users, applications and Loki versions change. New clients may arrive without actor information, and upgrades can change scheduler defaults or behavior, so a periodic check of queue metrics is sensible. Ask whether the engagement includes a retest after upgrades, or whether that should be handled by a retainer for ongoing support and continuous testing.

Does enabling query fairness alone stop a runaway query?

No. Hierarchical scheduler queues share query capacity fairly across actors within a tenant, so one user or script is less able to starve others. They do not limit how expensive a single query is, and they do not stop a query from consuming resources while it runs. Protection from heavy queries also depends on per-tenant query limits, sensible LogQL design, time range restrictions and monitoring. Treat fairness as one control in a set, and confirm the other limits in your own configuration before relying on it.

Can we rely on actor headers to identify every user?

Only if every request reaching Loki carries a correct actor identity. Actor information is set by the client or the proxy in front of Loki, so a misconfigured proxy or a shared service account can merge many people into one actor. This is why the identity design, the proxy header handling and the Grafana data source setup should be reviewed together. Verify with test requests from several users that each one appears as a separate actor in your queue metrics before you treat fairness as enforced.

Does fairness also need access control to be safe?

Fairness and access control solve different problems. Fairness manages how shared capacity is used within a tenant, while access control decides which data a user may read. Within one tenant, every authorized user can see the same streams, so fairness does not restrict what anyone reads. If teams must not see each other's logs, separate tenants or label-based access control are the relevant choices, and those belong in a different design decision. Confirm your data separation requirements before scoping this work.

What a fixed-scope query fairness engagement covers

DeployOpen agrees scope, deliverables and timelines in writing before any work starts, and a quote follows from that written scope. For query fairness, the scope usually turns on how many actors share one tenant, which of them reach Loki through Grafana, through scripts or through the command line, and whether a reverse proxy already sits in front of the cluster. Those facts shape the work more than the Loki configuration itself, so they are the first items to pin down before anyone agrees a quote.

A written scope for this topic typically lists a configuration review of the query frontend and querier settings that govern the hierarchical scheduler queues, a proxy design for the actor headers that identify Grafana users, CLI users and applications, a test plan that shows one actor cannot starve the others, and a runbook for operators who will watch queue behavior later. Ask the vendor or your own platform team to confirm which of these your Loki version and deployment mode support, and which header names your proxy can set. Because the scheduler is enabled by default from Loki 2.9, the review should confirm whether any existing settings override that default.

Ask for each deliverable to name its acceptance check, the environment where tests run and who signs off. Recurring items, such as re-running the fairness tests after a Loki upgrade or reviewing queue metrics after new teams join, should be listed separately from the one-time build so they can be priced and scheduled as a retainer if needed. A quote that cannot be traced line by line to the written scope is a sign that the scope needs more detail before you sign.

How DeployOpen scopes, delivers and supports Loki query fairness

DeployOpen treats query fairness as part of the wider Loki tenant design, so the scheduler settings, reverse proxy headers and Grafana data source configuration are agreed together before anything is changed. Each engagement is fixed-scope, with the work, deliverables and timeline agreed in writing before it starts.

How we scope

  • Confirm which Loki version and deployment mode you run, and whether the scheduler queues are already enabled for your cluster.
  • List the actors that query each tenant, such as Grafana users, CLI users, dashboards and automated scripts, and how each one identifies itself.
  • Agree in writing which query paths are in scope, the acceptance tests for fairness, and the retainer terms if ongoing support is wanted.

How we build

  • Set and document the actor header values that Grafana, CLI tools and applications send, so each actor appears as its own queue participant.
  • Configure the query frontend and querier settings that control queue behavior, and review them against your tenant limits and query load.
  • Test fairness with concurrent heavy and light queries from separate actors, recording what each user experiences before and after the change.

How we hand over

  • Deliver a written configuration record covering the scheduler settings, header conventions, reverse proxy rules and the test results.
  • Document the runbook for adding a new script or integration, including which actor header it should send and how to verify it.
  • Walk your platform and observability teams through the configuration and the retest so they can run the checks without DeployOpen.

How we support

  • Review queue and query latency signals after changes and report anything that suggests a single actor is still crowding out others.
  • Revisit actor headers and scheduler settings when Loki versions, Grafana versions or query patterns change in your environment.
  • Offer ongoing support, upgrades and continuous testing as a retainer, with the scope of that retainer agreed in writing.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.