Project: Grafana Loki (Observability and Analysis / Observability)
File: request-validation-rate-limits.md

title: Request Validation and Rate-Limit Errors menuTitle: description: Request Validation and Rate-Limit Errors weight: Loki will reject requests if they exceed a usage threshold (rate-limit error) or if they are invalid (validation error). All occurrences of these errors can be observed using the `lokidiscardedsamplestotal` and `lokidiscardedbytestotal` metrics. The sections below describe the various possible reasons specified in the `reason` label of these metrics. It is recommended that Loki operators set up alerts or dashboards with these metrics to detect when rate-limits or validation errors occur. sample: a log line stream: samples with a unique combination of labels active stream: streams that are present in the ingesters - these have recently received log lines within the `chunkidleperiod` period (default: 30m) Rate-limits are enforced when Loki cannot handle more requests from a tenant. This rate-limit is enforced when a tenant has exceeded their configured log ingestion rate-limit. One solution if you're seeing samples dropped due to `ratelimited` is simply to increase the rate limits on your Loki cluster. These limits can be modified globally in the block, or on a per-tenant basis in the file. The config options to use are `ingestionratemb` and `ingestionburstsizemb`. Note that you'll want to make sure your Loki cluster has sufficient resources provisioned to be able to accommodate these higher limits. Otherwise your cluster may experience performance degradation as it tries to handle this higher volume of log lines to ingest. Another option to address samples being dropped due to `rate_limits` is simply to decrease the rate of log lines being sent to your Loki cluster. Consider collecting logs from fewer targets or setting up `drop` stages in Promtail to filter out certain log lines. Promtail's also gives you the ability to control the volume of logs Promtail remote writes to your Loki cluster. | Property | Value | |-|-| | Enforced by | `distributor` | | Outcome | Request rejected | | Retryable | Yes | | Sample discarded | No | | Configurable per tenant | Yes | | HTTP status code | `429 Too Many Requests` | This limit is enforced when a single stream reaches its rate-limit. Each stream has a rate-limit applied to it to prevent individual streams from overwhelming the set of ingesters it is distributed to (the size of that set is equal to the `replication_factor` value). This value can be modified globally in the block, or on a per-tenant basis in the file. The config options to adjust are `perstreamratelimit` and `perstreamratelimit_burst`. Another option you could consider to decrease the rate of samples dropped due to `perstreamratelimit` is to split the stream that is getting rate limited into several smaller

A third option is to use Promtail's to limit the rate of samples sent to the stream hitting the `perstreamratelimit`. We typically recommend setting `perstreamratelimit` no higher than 5MB, and `perstreamratelimit_burst` no higher than 20MB. | Property | Value | |-|-| | Enforced by | `ingester` | | Outcome | Request rejected | | Retryable | Yes | | Sample discarded | No | | Configurable per tenant | Yes | | HTTP status code | `429 Too Many Requests` | This limit is enforced when a tenant reaches their maximum number of active streams. Active streams are held in memory buffers in the ingesters, and if this value becomes sufficiently large then it will cause the ingesters to run out of memory. This value can be modified globally in the block, or on a per-tenant basis in the file. To increase the allowable active streams, adjust `maxglobalstreamsperuser`. Alternatively, the number of active streams can be reduced by removing extraneous labels or removing excessive unique label values. | Property | Value | |-|-| | Enforced by | `ingester` | | Outcome | Request rejected | | Retryable | Yes | | Sample discarded | No | | Configurable per tenant | Yes | | HTTP status code | `429 Too Many Requests` | Validation errors occur when a request violates a validation rule defined by Loki. This error occurs when a log line exceeds the maximum allowable length in bytes. The HTTP response will include the stream to which the offending log line belongs as well as its size in bytes. This value can be modified globally in the block, or on a per-tenant basis in the file. To increase the maximum line size, adjust `maxlinesize`. We recommend that you do not increase this value above 256kb for performance reasons. Alternatively, Loki can be configured to ingest truncated versions of log lines over the length limit by using the `maxlinesize_truncate` option. | Property | Value | |-|| | Enforced by | `distributor` | | Retryable | No | | Sample discarded | Yes | | Configurable per tenant | Yes | This error occurs when one or more labels in the submitted streams fail validation. Loki uses the for validating labels. Label names may contain ASCII letters, numbers, as well as underscores. They must match the regex `*`. Label names beginning with are reserved for internal use. | Property | Value | |-|| | Enforced by | `distributor` | | Retryable | No | | Sample discarded | Yes | | Configurable per tenant | No | This validation error is returned when a stream is submitted without any

| Property | Value | |-|| | Enforced by | `distributor` | | Retryable | No | | Sample discarded | Yes | | Configurable per tenant | No | The `toofarbehind` and `outoforder` reasons are identical. Loki clusters with `unorderedwrites=true` (the default value as of Loki v2.4) use `reason=toofarbehind`. Loki clusters with `unorderedwrites=false` use `reason=outoforder`. This validation error is returned when a stream is submitted out of order. More details can be found about Loki's ordering constraints. The `unorderedwrites` config value can be modified globally in the block, or on a per-tenant basis in the file, whereas `maxchunk_age` is a global configuration. This problem can be solved by ensuring that log delivery is configured correctly, or by increasing the `maxchunkage` value. It is recommended to resist modifying the default value of `maxchunkage` as this has other implications, and to instead try track down the cause for delayed logged delivery. It should also be noted that this a per-stream error, so by simply splitting streams (adding more labels) this problem can be circumvented, especially if multiple hosts are sending samples for a single stream. | Property | Value | |-|| | Enforced by | `ingester` | | Retryable | No | | Sample discarded | Yes | | Configurable per tenant | No | If the `rejectoldsamples` config option is set to `true` (it is by default), then samples will be rejected with `reason=greaterthanmaxsampleage` if they are older than the `rejectoldsamplesmaxage` value. You should not see samples rejected for `reason=greaterthanmaxsampleage` if `rejectoldsamples=false`. This value can be modified globally in the block, or on a per-tenant basis in the file. This error can be solved by increasing the `rejectoldsamplesmaxage` value, or investigating why log delivery is delayed for this particular stream. The stream in question will be returned in the body of the HTTP response. | Property | Value | |-|-| | Enforced by | `distributor` | | Outcome | Request rejected | | Retryable | No | | Sample discarded | Yes | | Configurable per tenant | Yes | | HTTP status code | `400 Bad Request` | If a sample's timestamp is greater than the current timestamp, Loki allows for a certain grace period during which samples will be accepted. If the grace period is exceeded, the error will occur. This value can be modified globally in the block, or on a per-tenant basis in the file. This error can be solved by increasing the `creationgraceperiod` value, or investigating why this particular stream has a timestamp too far into the future. The stream in question will be returned in the body of the HTTP

| Property | Value | |-|-| | Enforced by | `distributor` | | Outcome | Request rejected | | Retryable | No | | Sample discarded | Yes | | Configurable per tenant | Yes | | HTTP status code | `400 Bad Request` | If a sample is submitted with more labels than Loki has been configured to allow, it will be rejected with the `maxlabelnamesperseries` reason. Note that 'series' is the same thing as a 'stream' in Loki - the 'series' term is a legacy name. This value can be modified globally in the block, or on a per-tenant basis in the file. This error can be solved by increasing the `maxlabelnamesperseries` value. The stream to which the offending sample (i.e. the one with too many label names) belongs will be returned in the body of the HTTP response. | Property | Value | |-|-| | Enforced by | `distributor` | | Outcome | Request rejected | | Retryable | No | | Sample discarded | Yes | | Configurable per tenant | Yes | | HTTP status code | `400 Bad Request` | If a sample is sent with a label name that has a length in bytes greater than Loki has been configured to allow, it will be rejected with the `labelnametoo_long` reason. This value can be modified globally in the block, or on a per-tenant basis in the file. This error can be solved by increasing the `maxlabelname_length` value, though we do not recommend raising it significantly above the default value of `1024` for performance reasons. The offending stream will be returned in the body of the HTTP response. | Property | Value | |-|-| | Enforced by | `distributor` | | Outcome | Request rejected | | Retryable | No | | Sample discarded | Yes | | Configurable per tenant | Yes | | HTTP status code | `400 Bad Request` | If a sample has a label value with a length in bytes greater than Loki has been configured to allow, it will be rejected for the `labelvaluetoo_long` reason. This value can be modified globally in the block, or on a per-tenant basis in the file. This error can be solved by increasing the `maxlabelvalue_length` value. The offending stream will be returned in the body of the HTTP response. | Property | Value | |-|-| | Enforced by | `distributor` | | Outcome | Request rejected | | Retryable | No | | Sample discarded | Yes | | Configurable per tenant | Yes | | HTTP status code | `400 Bad Request` | If a sample is sent with two or more identical labels, it will be rejected for the `duplicatelabelnames` reason. The offending stream will be returned in the body of the HTTP response. | Property | Value | |-|-| | Enforced by | `distributor` | | Outcome | Request rejected | | Retryable | No | | Sample discarded | Yes | | Configurable per tenant | No | | HTTP status code | `400 Bad Request` |