When blocking expensive Loki queries per tenant is the right fix
A shared Loki cluster often slows for every tenant because one known query keeps running. In that case, per-tenant blocked_queries rules are the right containment step: they reject the offending query for the tenant it affects, and you apply them through runtime overrides without restarting Loki. The Loki documentation describes the rule as matching on an exact pattern, a regular expression, a query type such as metric, filter or limited, or a query hash. Because the rule is scoped to one tenant ID, a dashboard or script run by a single team can be stopped while other tenants keep querying normally.
The fit is narrow. Use this control when you can name the query or query family causing load, when the query is not something the tenant needs to run at that volume, and when you need relief before a permanent fix ships. Treat it as a containment tool, not a substitute for query limits, dashboard changes or capacity planning. Limits bound what every query can consume, dashboards are usually where the expensive query originates, and capacity planning addresses sustained growth. A blocked query also fails for the user, so confirm with the tenant owner first and record the rule and its reason so it does not outlive the incident unnoticed.
Before you rely on the feature, confirm three things in your own environment: that your Loki version supports blocked_queries in the runtime configuration you use, how your runtime overrides file is distributed and reloaded across the components that serve queries, and how the rule's matching behaves for the exact query text your dashboards generate, since small differences in whitespace or label order can change which queries match. Test each rule with a query you expect to be blocked and one you expect to pass. Review the Loki documentation on blocking unwanted queries for the current syntax before you write it.
Match types for blocked_queries and when each fits
This table compares the four match types Loki documents for blocked_queries: exact pattern, regex, query type and query hash. Read each row for what it matches, when it fits and the mistake most likely to block the wrong traffic or miss the costly query. Confirm the exact field syntax for your Loki version before you apply any rule.
| Match type | What it matches | When it fits | Main risk |
|---|---|---|---|
| Exact pattern | The query text as submitted, matched literally | A known dashboard or script query that runs the same way every time | Any change in whitespace, label order or time-based text lets the costly query slip through |
| Regex | Query text matched by a regular expression | One costly query family, such as a wildcard filter used across several panels | A broad expression can block legitimate queries that share part of the same text |
| Query type | Broad categories such as metric, filter or limited queries | Stopping a whole class of expensive work for one tenant while you investigate | Blocking a type can stop dashboards and alerts that a team depends on |
| Query hash | A hash computed from the query | Pinning one specific query without matching its text | The hash changes when the query text changes, so the rule stops working after an edit |
| Mixed rules | Several match types in one tenant's overrides | Narrow rules for known queries plus a type rule as a safety net | Overlapping rules are harder to review and can block more than intended |
How to add a blocked query rule through runtime overrides
This sequence takes a known costly query from identification to a verified block that applies to one tenant only, using per-tenant runtime overrides and no Loki restart. The result is a documented rule that operators can confirm, reverse and audit.
Identify the offending query in logs
Find the query that is destabilizing the cluster by reviewing Loki's query logs or the query statistics your Grafana or LogCLI sessions expose, and note the tenant ID from the X-Scope-OrgID header, the exact LogQL text and its query type. Record whether the query is a metric query, a filter query or a limited query, since that determines the match type you can use. Done when you have the tenant, the exact query text and a sample request that reproduces the problem in a non-production environment, if one exists.
Choose the match type for the rule
Decide between an exact pattern, a regex, a query type or a query hash, based on how much of the traffic you want to stop. An exact pattern blocks only that query text, a regex covers a family of similar queries, a query type such as metric or filter blocks broad classes, and a hash targets one specific query. Write the choice down with the tenant it applies to, because a broad match type can also block legitimate dashboards. Confirm the exact field names and accepted values for your Loki version in the official blocking documentation before editing any file.
Add the rule to the per-tenant runtime overrides
Add a blocked_queries entry under the affected tenant's section of the runtime overrides file, using the match type chosen in the previous step. The overrides file path and how it is mounted depend on your deployment, so confirm the runtime config location in your Helm values, systemd unit or container setup before editing. Keep the change in version control so the rule can be reviewed and reverted. Done when the file parses and the rule is saved under the correct tenant key and nowhere else.
Reload the runtime configuration without a restart
Let Loki pick up the updated runtime overrides without restarting components, using the reload mechanism your deployment provides, such as the runtime config reload interval Loki checks on its own or a configuration reload in your orchestration layer. Check the Loki logs or the runtime config endpoint to confirm the new file was loaded and no parse error was reported. Done when the loaded configuration shows the new blocked_queries rule for the tenant and the running pods or processes have not restarted.
Confirm the affected tenant receives the error
Send the blocked query from the affected tenant using its X-Scope-OrgID header through LogCLI or the Grafana data source configured for that tenant, and confirm Loki returns an error for the query rather than results. Record the status code and error message so support staff can match user reports to the rule. Done when a request that matches the rule fails for that tenant and a closely similar query that does not match still succeeds.
Verify other tenants are unaffected
Run the same blocked query under a different tenant ID and run normal dashboard queries from at least one other tenant, then compare results with the state before the change. The blocked_queries rule is scoped to the tenant in the overrides file, so other tenants should return results as before. Done when the other tenants return normal responses and the ingestion and query error rates in your monitoring show no new spike tied to this change.
Document the rule and its review date
Record the rule's tenant, match type, exact pattern or hash, the reason for it, the owner who approved it and the condition under which it should be removed, such as when the affected dashboard is rewritten. Store this alongside the overrides file change so auditors and on-call engineers can see why the block exists. Done when the change record is linked from the version-controlled overrides file and the affected tenant owner has been told how to rewrite the query.
How a blocked query is checked before it reaches the querier
The request starts at the client, which sends a LogQL query with an X-Scope-OrgID header. It passes through an authenticating reverse proxy, which is the only trust boundary Loki relies on for identity, and then reaches the query frontend. Loki compares the query against the tenant's blocked_queries rules from runtime overrides. A match is rejected with an error; a non-match continues to the queriers. Check that the proxy strips or overwrites client-supplied tenant headers.
Blocked queries are rejected at the query frontend before any querier work starts.
Security and operational risks of blocking queries
Blocking rules are a fast control, but they only protect Loki when the tenant identity behind them is correct, the rules are governed like code and their side effects are visible. The cards below cover the risks that tend to surface after a block is put in place.
Tenant identity comes from the proxy
Per-tenant blocking only works if the tenant ID that Loki sees is the one you intended. Loki identifies tenants from the X-Scope-OrgID header, and Loki has no authentication layer of its own, so the authenticating reverse proxy in front of it must set or overwrite that header for every request. If a client can send its own header, a rule aimed at one tenant may not match the traffic you meant to stop. Test this path with requests from each client type before you rely on a block.
Loki multi-tenancy docsRuntime overrides need access control
Blocking rules are written into the runtime overrides file, so anyone who can edit that file can silently block a team's queries or remove a protection that was in place. Restrict write access to the file to the people who run Loki, keep it in version control and record who changed what and when. Confirm how your deployment reloads the file and whether a failed or partial edit leaves the previous rules active.
Shared patterns block legitimate work
A pattern that matches an expensive ad hoc search can also match a dashboard panel or an alerting rule that runs the same query text on a schedule. Blocking that query can leave a dashboard empty or stop an alert from evaluating, and the failure may not appear until someone needs the data. Before adding a rule, search your dashboards and ruler configuration for the same query text, and decide whether a hash, regex or query type rule would be more precise for your case.
Rules drift as queries change
Exact patterns and hashes stop matching when a dashboard is edited, a Grafana version reformats a query or a team adds a label matcher, so a rule can quietly stop protecting the cluster. Regex rules can also become broader than intended over time. Schedule a periodic review of every blocked_queries entry against current dashboards, saved queries and recent query logs, and remove rules whose original reason no longer applies.
Blocked attempts need monitoring
A block that users never notice can hide a growing problem, and a block that users hit often may be a sign of a needed capacity or query change. Log rejected queries with their tenant and rule, and feed those events into the monitoring you already run for Loki. Confirm what your version records for blocked requests, including whether the query text is logged, and check that those logs do not expose sensitive data.
Questions teams ask before blocking Loki queries
Can I block expensive Loki queries without restarting the cluster?
Yes. Blocking rules are set per tenant as blocked_queries inside runtime overrides, so they are applied while Loki keeps running and do not require a restart of the cluster. Confirm the exact override file mechanism and reload behavior for your Loki version in the Loki block unwanted queries documentation before you rely on it in production. Test the rule in a non-production tenant first, because a rule that is too broad can reject legitimate dashboards.
How much effort does a blocking rule set take to build and maintain?
Effort depends on how many costly query patterns you need to handle and how stable those patterns are. Most of the work is collecting the queries that cause trouble, deciding which of them to block by exact pattern, regex, query type or hash, and checking that each rule does not reject normal use. Cost recurs when dashboards change, when teams add new tenants, or when Loki upgrades change how queries are classified. Ask any partner to price the investigation, rule design, testing and handover as separate line items.
Can our in-house team set up query blocking themselves?
Usually yes, if your platform team already operates Loki and has access to runtime configuration and query logs. The configuration itself is small. The harder parts are identifying the right patterns, understanding which tenant owns each dashboard, and writing rules that stop the expensive query without breaking the cheap ones next to it. Teams without that experience often benefit from a short review of their rules before rollout. Ask your team to confirm who approves changes to runtime overrides.
What do we need to provide for a blocking rule project?
You will need the tenant IDs (sent in the X-Scope-OrgID header on each request), query logs or a record of the queries that caused trouble, and access to the runtime overrides file used by your Loki deployment. You should also know which teams own each tenant and who can approve a change. Without query history, rules are guesses, so confirm that your query logging captures the query text, tenant and time range before the project starts.
How do blocked queries differ from query limits?
Query limits set general boundaries for every query in a tenant, such as how much data a query may read or how many series it may touch. Blocked queries target specific queries you already know are harmful, matching an exact pattern, a regex, a query type or a hash. Limits protect the cluster broadly, while blocking is a targeted control. Most teams use limits as the baseline and blocking for known problem queries. Confirm the limit names and their defaults for your version before setting either.
Could blocking queries hide a problem from our users?
It can, if a rule blocks a query without a clear error or without telling the owner. A blocked query returns an error to the person running it, so users need to know what happened and where to go next. Plan communication with tenant owners, document each rule with its reason and owner, and review rules when dashboards change. Blocking should slow a problem down while you fix the dashboard or query, not replace that fix.
When should we bring in a partner for query blocking?
Consider a partner when Loki serves several tenants with competing needs, when a few costly queries keep causing outages, or when your team has no time to analyze query logs and test rules. A partner can review your current limits, design the rule set, test it against real query patterns in your environment and hand over documentation. The scope, deliverables and timeline are agreed in writing before work starts, and DeployOpen provides a quote from that written scope.
How to roll out and review blocked queries safely
Start with the narrowest rule that stops the known problem. A tight rule is the safest first step: match the exact query text or its query hash, and apply it to one tenant that is causing the instability. Watch what the rule rejects before widening it. If you begin with a regex or a broad query type such as metric, you may block dashboards and alerts that nobody on the platform team knew depended on that query shape. Keep the rule in the tenant's runtime overrides so you can remove it in one change, without a restart.
Tell the tenant owners before the rule takes effect, and name the specific query, the reason it is costly and the alternative they should use, such as a narrower stream selector, a shorter time range or a recording rule. Ask them to confirm which dashboards or scripts issue the query. Then monitor rejected requests for the tenant after the rule goes live. Your monitoring should show whether clients retry in a loop, whether a second query shape appears to replace the blocked one, and whether anyone reports a broken panel. Confirm how your Loki version exposes rejected-request metrics and logs in your own environment before you rely on them.
Schedule a review date for every rule when you create it, and record the owner, the reason and the evidence behind it. Query shapes change as dashboards are rebuilt, Grafana panels are copied and teams adopt new tooling, so a rule that was precise last quarter may miss variants now or block legitimate work later. Treat the choice of match type as a trade-off: a tight rule is easy to justify but needs frequent updates, while a broad rule needs less upkeep but is more likely to block valid work. Retire rules that no longer match any traffic, and widen a rule only after the tenant owner has agreed to the change.
How DeployOpen works on this
DeployOpen starts by agreeing in writing which expensive query patterns, tenants and runtime override settings are in scope for Blocking expensive Loki queries per tenant. The work then moves through a tested build, a handover that your team can operate, and optional ongoing support under a retainer.
How we scope
- We inventory the query types, tenants and dashboards that have caused load problems in your cluster.
- We agree the blocking rules to write (exact pattern, regex, query type or hash) and the tenants each one applies to.
- The written scope fixes deliverables and timelines before any runtime override is changed in your environment.
How we build
- We write blocked_queries entries in the runtime overrides file and roll them out without restarting Loki.
- We test each rule against sample queries from your own tenants to confirm it matches only the intended traffic.
- We check that legitimate dashboards and alerts for other tenants keep working after each change.
How we hand over
- We document each blocking rule, its owner, the reason it exists and the steps to remove it.
- We walk your platform and on-call teams through the override process so they can add or retire rules themselves.
- We record a rollback procedure for the runtime overrides file so a bad rule can be reverted quickly.
How we support
- Ongoing support, rule reviews and upgrades are available as a retainer after the initial handover.
- We can review new query patterns as tenants and dashboards change, and propose rules for them.
- Confirm with DeployOpen during scoping which Loki version and override format your cluster runs.

