Important: This documentation is about an older version. It's relevant only to the release noted, many of the features and functions have been updated or replaced. Please view the current version.

Open source

Blocking Queries

In certain situations, you may not be able to control the queries being sent to your Loki installation. These queries may be intentionally or unintentionally expensive to run, and they may affect the overall stability or cost of running your service.

You can block queries using per-tenant overrides, like so:

      # block this query exactly
      - pattern: 'sum(rate({env="prod"}[1m]))'

      # block any query matching this regex pattern 
      - pattern: '.*prod.*'
        regex: true

      # block all metric queries
      - types: metric

      # block any filter or limited queries matching this regex pattern 
      - pattern: '.*prod.*'
        regex: true
        types: filter,limited

The available query types are:

  • metric: a query with an aggregation, e.g. sum(rate({env="prod"}[1m]))
  • filter: a query with a log filter, e.g. {env="prod"} |= "error"
  • limited: a query without a filter or a metric aggregation

Note: the order of patterns is preserved, so the first matching pattern will be used

Observing blocked queries

Blocked queries are logged, as well as counted in the loki_blocked_queries metric on a per-tenant basis.


Queries received via the API and executed as alerting/recording rules will be blocked.