Chapter 3. Troubleshoot log forwarding
Resolve common log forwarding issues, including Loki rate limit errors, per-stream rate limit errors, and oversized log lines.
3.1. Troubleshoot Loki rate limit errors Copy linkLink copied to clipboard!
Resolve Loki ingestion rate limit errors when log volume persistently exceeds the configured limits for your LokiStack deployment.
If the Log Forwarder API forwards logs to Loki at a rate that exceeds the configured ingestion limit, Loki generates rate limit (429) errors. Vector retries requests that receive a 429 response. If the rate limit persists over time, Vector might lose log records.
Rate limit errors can occur during normal operation and might not require action. For example, when you first add logging to a cluster that already has logs, or after an incident where the collector was temporarily stopped, rate limit errors might occur while the collector processes the backlog. If the rate of new logs is lower than the rate limit, the system recovers without intervention.
If rate limit errors persist continuously, the log ingestion rate exceeds the LokiStack ingestion rate limit, and you must take action.
The LokiStack CR is not available on Grafana-hosted Loki. This procedure does not apply to Grafana-hosted Loki servers.
Prerequisites
- You have administrator permissions.
- You have configured the Log Forwarder API to forward logs to Loki.
The collector logs show
429 Too Many Requestserrors. For example:2023-08-25T16:08:49.301780Z WARN sink{component_kind="sink" component_id=default_loki_infra component_type=loki component_name=default_loki_infra}: vector::sinks::util::retries: Retrying after error. error=Server responded with an error: 429 Too Many Requests internal_log_rate_limit=true
Procedure
Run the following query in the OpenShift web console under Observe
Metrics to confirm that rate limiting is active and to discover the log tenants that the rate limit affects: sum by (tenant, reason) (rate(loki_discarded_samples_total[2m]))A nonzero result with
reason="RateLimit"confirms that rate limiting is active. Monitor the metric over time to check whether the situation resolves on its own. If the result returns to zero, no further action is necessary.If rate limiting persists, reduce the volume of logs sent to LokiStack before adjusting the ingestion limits:
- Apply input rate limits to containers that produce excessive logs.
- Use drop filters to discard log records that are not required.
For more information, see Fine-tune log forwarding and Configure filters.
If reducing log volume is not enough, update the
ingestionBurstSizeandingestionRatefields in theLokiStackCR:NoteIncreasing the ingestion rate limit increases resource usage in the LokiStack distributor pods. Before increasing these values, verify that the nodes where LokiStack pods run have enough CPU and memory available.
To find an appropriate value for
ingestionRate, run the following query in the OpenShift web console under ObserveMetrics to measure the actual ingestion rate per tenant: sum by (tenant) (rate(loki_distributor_bytes_received_total[5m]))Use the result, in bytes per second, as a baseline. Convert to MB and set
ingestionRateto at least that value.apiVersion: loki.grafana.com/v1 kind: LokiStack metadata: name: logging-loki namespace: openshift-logging spec: limits: global: ingestion: ingestionBurstSize: 16 ingestionRate: 8 # ...spec.limits.global.ingestion.ingestionBurstSize- The maximum local rate-limited sample size per distributor replica, in MB. This value is a hard limit. Set this value to at least the maximum size expected in a single push request. Loki rejects requests that exceed this value.
spec.limits.global.ingestion.ingestionRate- The maximum ingestion rate per second across all distributor replicas, in MB. This is a soft limit. When the log rate exceeds the limit, rate limit errors occur, but Vector retries the request. If the average rate is lower than the limit, the system recovers automatically.
3.2. Troubleshoot Loki per-stream rate limit errors Copy linkLink copied to clipboard!
Resolve per-stream rate limit errors when a single log stream exceeds the configured per-stream ingestion rate for your LokiStack deployment.
Loki organizes logs into streams, where each stream represents a unique set of labels such as namespace, pod name, container name, and log type. When one stream’s log volume exceeds the per-stream rate limit, Loki returns a per-stream rate limit error. Vector retries the request. If the rate limit persists, Vector might lose log records from the affected stream.
A common cause of per-stream rate limit errors is a single container producing an unusually high volume of logs, such as an application running in debug mode or an application in an error loop.
logging 5.9 and later enables automatic stream sharding by default, which dynamically adjusts the ingestion rate for each stream. In most cases, the default automatic stream sharding is enough and you do not need to configure perStreamRateLimit attributes manually.
The LokiStack CR is not available on Grafana-hosted Loki. This procedure does not apply to Grafana-hosted Loki servers.
Prerequisites
- You have administrator permissions.
- You have configured the Log Forwarder API to forward logs to Loki.
The LokiStack ingester pod logs show errors similar to the following:
level=warn ... err="rpc error: code = Code(429) desc = entry with timestamp ... ignored, reason: 'Per stream rate limit exceeded (limit: 3MB/sec) while attempting to ingest for stream '{kubernetes_container_name="<container_name>", kubernetes_namespace_name="<namespace>", ...}'"
Procedure
Run the following query in the OpenShift web console under Observe
Metrics to confirm per-stream rate limiting is active and to discover the tenants that the per-stream rate limit affects: sum by (tenant, reason) (rate(loki_discarded_samples_total[2m]))A nonzero result with
reason="StreamRateLimit"confirms that per-stream rate limiting is active.Find the container producing the high log volume by reviewing the ingester pod logs for the stream labels in the error message:
$ oc -n openshift-logging logs -l app.kubernetes.io/component=ingester | grep "Per stream rate limit exceeded"The error message includes labels such as
kubernetes_namespace_name,kubernetes_pod_name, andkubernetes_container_namethat identify the source container.Reduce the volume of logs produced by the affected container:
- Reduce the log verbosity of the application if it is running in debug or verbose mode.
- Use drop or prune filters to discard log records that are not required before they reach LokiStack.
For more information, see Configure filters.
If reducing log volume is not enough, update the
perStreamRateLimitandperStreamRateLimitBurstfields in theLokiStackCR. Do not exceed the recommended maximum values:apiVersion: loki.grafana.com/v1 kind: LokiStack metadata: name: logging-loki namespace: openshift-logging spec: limits: global: ingestion: perStreamRateLimit: 5 perStreamRateLimitBurst: 20 # ...NoteThe
ingestionRatevalue must be greater than theperStreamRateLimitvalue.spec.limits.global.ingestion.perStreamRateLimit-
The maximum ingestion rate per second for a single stream, in MB. The recommended maximum value is
5. spec.limits.global.ingestion.perStreamRateLimitBurst-
The maximum burst size for a single stream, in MB. The recommended maximum value is
20.
3.3. Troubleshoot log lines that exceed the Loki size limit Copy linkLink copied to clipboard!
Resolve errors that occur when individual log lines exceed the maximum size that LokiStack accepts.
LokiStack enforces a maximum size of 256 KB for individual log lines. The Loki distributor discards log lines that exceed this limit and does not retry them. Unlike rate limit errors, Vector does not retry these requests. The log lines are permanently lost.
The LokiStack CR is not available on Grafana-hosted Loki. This procedure does not apply to Grafana-hosted Loki servers.
Prerequisites
- You have administrator permissions.
- You have configured the Log Forwarder API to forward logs to Loki.
The LokiStack distributor pod logs show errors similar to the following:
level=error ... details="Max entry size '256000' bytes exceeded for stream '{kubernetes_container_name="<container_name>", kubernetes_namespace_name="<namespace>", ...}'"
Procedure
Run the following query in the OpenShift web console under Observe
Metrics to confirm that LokiStack is discarding oversized log lines and to discover the tenants that the size limit affects: sum by (tenant, reason) (irate(loki_discarded_samples_total[2m]))A nonzero result with
reason="LineTooLong"confirms that LokiStack is discarding log lines because they exceed the 256 KB limit.Confirm that the collector receives 400 errors from LokiStack by reviewing the collector logs:
$ oc -n openshift-logging logs -l app.kubernetes.io/component=collector | grep "400 Bad Request"Example output
2024-11-28T17:43:30.744862692Z ERROR sink{component_kind="sink" ...}: vector::sinks::util::retries: Non-retriable error; dropping the request. error=Server responded with an error: 400 Bad RequestThe
Non-retriable errormessage confirms that Vector is dropping the request and the log lines are permanently lost.Find the source of the oversized log lines by reviewing the distributor pod logs:
$ for pod in $(oc get pods -o name -l app.kubernetes.io/component=distributor -n openshift-logging); \ do oc logs $pod -n openshift-logging; \ done | grep "Max entry size '256000' bytes exceeded for stream"The error message includes stream labels such as
kubernetes_namespace_name,kubernetes_pod_name, andkubernetes_container_namethat identify the source container.Reduce the size of log lines produced by the affected container:
- Reduce the log verbosity of the application to prevent it from producing log lines over 256 KB.
- Change the application log format to produce shorter, structured log lines.
- Use a prune filter to remove large fields from log records before they reach LokiStack. For more information, see Configure filters.