Chapter 5. Fine-tune log forwarding
Adjust rate limits, delivery behavior, collector log levels, and resource limits to optimize log forwarding performance for your workload.
5.1. Configure rate limits Copy linkLink copied to clipboard!
You can configure rate limits on inputs and outputs to control log forwarding volume and prevent resource exhaustion. Rate limits specify the maximum number of log records per second that the collector can process. When the rate limit is exceeded, the collector drops excess log records.
Prerequisites
-
You have a working
ClusterLogForwardercustom resource (CR). -
You have
cluster-adminpermissions.
Procedure
Configure rate limits on inputs, outputs, or both.
apiVersion: observability.openshift.io/v1 kind: ClusterLogForwarder metadata: name: instance namespace: openshift-logging spec: serviceAccount: name: collector inputs: - name: limited-app-logs type: application application: tuning: rateLimitPerContainer: maxRecordsPerSecond: 100 outputs: - name: limited-splunk type: splunk splunk: url: https://splunk.example.com:8088 authentication: token: key: token secretName: splunk-secret rateLimit: maxRecordsPerSecond: 1000 pipelines: - name: app-to-splunk inputRefs: - limited-app-logs outputRefs: - limited-splunk- Input rate limit (
inputs[].application.tuning.rateLimitPerContainer) Limits the number of log records per second from each container that matches this input. This is a per-container limit. For example, if you set
maxRecordsPerSecond: 100and 10 containers match the input selector, the total input rate could be up to 1000 records per second (100 per container × 10 containers).Use case: Site reliability engineers can use input rate limits to prevent noisy applications from overwhelming the log collector and consuming excessive cluster resources.
- Output rate limit (
outputs[].rateLimit) Limits the total number of log records per second that the collector forwards to this output from a single collector pod. This is an aggregate limit across all pipelines that reference this output. Generally, one collector pod runs per cluster node.
Use case: Developers can use output rate limits to stay within the ingestion quotas imposed by third-party log aggregation services, preventing overage charges or throttling.
ImportantWhen rate limits are exceeded, the collector drops log records. The collector increments the
observability_log_forwarder_output_rate_limited_totalmetric for each dropped record. Monitor this metric to determine if your rate limits are too restrictive.Rate limit only on output
spec: outputs: - name: rate-limited-kafka type: kafka kafka: brokers: - kafka.example.com:9092 topic: logs rateLimit: maxRecordsPerSecond: 5000 pipelines: - name: all-logs-to-kafka inputRefs: - application - infrastructure outputRefs: - rate-limited-kafkaRate limit only on input
spec: inputs: - name: high-volume-namespace type: application application: includes: - namespace: "production" tuning: rateLimitPerContainer: maxRecordsPerSecond: 500 pipelines: - name: production-to-loki inputRefs: - high-volume-namespace outputRefs: - default-lokistackDifferent rate limits for different outputs
spec: outputs: - name: expensive-splunk type: splunk splunk: url: https://splunk.example.com:8088 authentication: token: key: token secretName: splunk-secret rateLimit: maxRecordsPerSecond: 500 - name: cheap-s3 type: s3 s3: url: https://s3.us-east-1.amazonaws.com bucket: log-archive rateLimit: maxRecordsPerSecond: 10000 pipelines: - name: critical-to-splunk inputRefs: - audit outputRefs: - expensive-splunk - name: bulk-to-s3 inputRefs: - application - infrastructure outputRefs: - cheap-s3
- Input rate limit (
Apply the updated
ClusterLogForwarderCR by running the following command:$ oc apply -f <filename>.yaml
Verification
Verify that the collector pods restarted by running the following command:
$ oc get pods -n openshift-logging -l app.kubernetes.io/component=collector
5.2. Tune log payloads and delivery Copy linkLink copied to clipboard!
The tuning spec in the ClusterLogForwarder custom resource (CR) provides a means of configuring your deployment to prioritize either throughput or durability of logs.
For example, if you need to reduce the possibility of log loss when the collector restarts, or you require collected log messages to survive a collector restart to support regulatory mandates, you can tune your deployment to prioritize log durability. If you use outputs that have hard limitations on the size of batches they can receive, you might want to tune your deployment to prioritize log throughput.
You can tune both inputs and outputs in the ClusterLogForwarder CR.
5.2.1. Tune inputs Copy linkLink copied to clipboard!
You can tune application and infrastructure inputs to control message size limits and rate limiting. These settings apply to container log collection and help prevent resource exhaustion from high-volume logging workloads.
The following example shows the ClusterLogForwarder CR options that you can change to tune log forwarder inputs:
Example ClusterLogForwarder CR input tuning options
apiVersion: observability.openshift.io/v1
kind: ClusterLogForwarder
metadata:
# ...
spec:
# ...
inputs:
- name: application
type: application
application:
tuning:
container:
maxMessageSize: 16Ki
rateLimitPerContainer:
maxRecordsPerSecond: 1000
- name: infrastructure
type: infrastructure
infrastructure:
tuning:
container:
maxMessageSize: 16Ki
rateLimitPerContainer:
maxRecordsPerSecond: 1000
maxMessageSize-
Specifies the maximum message length in bytes that a single log event can be when all partial log lines merge. Messages exceeding this limit are dropped. You can specify this value as an integer or as a string with units such as
KiorMi. rateLimitPerContainer.maxRecordsPerSecond- Specifies the maximum number of log records allowed per second for each container. This limit is applied per collector deployment. When a container exceeds this rate, the collector drops excess log records until the rate falls below the limit.
5.2.2. Tune outputs Copy linkLink copied to clipboard!
The following example shows the ClusterLogForwarder CR options that you can change to tune log forwarder outputs:
Example ClusterLogForwarder CR tuning options
apiVersion: observability.openshift.io/v1
kind: ClusterLogForwarder
metadata:
# ...
spec:
# ...
outputs:
- name: default-lokistack
type: lokiStack
lokiStack:
tuning:
deliveryMode: AtLeastOnce
compression: gzip
maxWrite: 3Mi
minRetryDuration: 2
maxRetryDuration: 300
deliveryModeSpecify the delivery mode for log forwarding. When left unset, the system defaults to using an in-memory buffer, which offers the highest performance due to low latency but does not provide durability. Buffered data is lost on process termination or failure.
-
AtLeastOncedelivery means that if the log forwarder crashes or restarts, the collector re-sends any logs it read before the crash but did not send to their destination. The collector might duplicate some logs after a crash. -
AtMostOncedelivery means that the log forwarder makes no effort to recover logs lost during a crash. This mode gives better throughput, but might result in greater log loss.
-
compression-
Specifying a
compressionconfiguration causes the collector to compress data before sending it over the network. Note that not all output types support compression, and if the specified compression type is not supported by the output, this results in an error. For more information, see "Supported compression types for tuning outputs". When left unset, the collector does not apply compression. maxWrite-
Specifies a limit for the maximum payload in bytes of a single send operation to the output. You can specify this value as an integer or as a string with units such as
Ki(kibibyte),Mi(mebibyte), orGi(gibibyte). For example:1048576,"1Mi", or"3Mi". ForLokiStackoutputs, the default value is3Miwhen not specified. minRetryDuration-
Specifies a minimum duration in seconds to wait between attempts before retrying delivery after a failure. This value is an integer representing seconds. For example,
2means 2 seconds. maxRetryDuration-
Specifies a maximum duration in seconds to wait between attempts before retrying delivery after a failure. This value is an integer representing seconds. For example,
300means 300 seconds (5 minutes).
| Compression algorithm | Splunk | Amazon CloudWatch | Elasticsearch 8 | LokiStack | Apache Kafka | HTTP | Syslog | Google Cloud | Microsoft Azure Monitoring | Amazon S3 |
|---|---|---|---|---|---|---|---|---|---|---|
|
| X | X | X | X | X | X | ||||
|
| X | X | X | X | ||||||
|
| X | X | X | |||||||
|
| X | X | X | |||||||
|
| X |
5.3. Set the collector log level Copy linkLink copied to clipboard!
Set the collector log level by adding the observability.openshift.io/log-level annotation to the ClusterLogForwarder custom resource (CR).
Prerequisites
-
You have a working
ClusterLogForwarderCR. -
You have
cluster-adminpermissions.
Procedure
Set the log level by running the following command:
$ oc annotate clusterlogforwarder instance -n openshift-logging \ observability.openshift.io/log-level=debug --overwriteThe supported log levels are
trace,debug,info,warn,error, andoff. The default level isinfo.Verify that the collector pod restarted with the new log level by running the following command:
$ oc logs -n openshift-logging -l app.kubernetes.io/component=collector --tail=5At the
debuglevel, entries begin withDEBUG.NoteUse
debugortraceonly for troubleshooting. These levels increase log volume significantly and can affect collector performance. Reset the level toinfoafter troubleshooting.
5.4. Set the collector resource limits Copy linkLink copied to clipboard!
Set CPU and memory resource limits by modifying the spec.collector.resources stanza in the ClusterLogForwarder custom resource (CR).
Prerequisites
-
You have a working
ClusterLogForwarderCR. -
You have
cluster-adminpermissions.
Procedure
Patch the
ClusterLogForwarderCR by running the following command:$ oc patch clusterlogforwarder instance -n openshift-logging \ --type=merge \ -p '{"spec":{"collector":{"resources":{"requests":{"cpu":"100m","memory":"256Mi"},"limits":{"cpu":"500m","memory":"512Mi"}}}}}'Verify that the collector pod restarted with the updated resources by running the following command:
$ oc get pods -n openshift-logging -l app.kubernetes.io/component=collectorThe pod age should show a recent restart.
NoteIf you do not set resource limits explicitly, the collector applies default limits: 500m CPU and 64Mi memory for requests, and 6000m CPU and 2048Mi memory for limits. Setting explicit limits prevents the collector from consuming more resources than expected on nodes with high log volume.
5.5. Create the log file metric exporter Copy linkLink copied to clipboard!
Create a LogFileMetricExporter custom resource (CR) to generate metrics about the logs produced by running containers. The Operator does not deploy the exporter by default, so you must create it manually.
If you do not create the LogFileMetricExporter CR, the Produced Logs field in the OpenShift Container Platform web console dashboard shows No datapoints found.
Prerequisites
- You have administrator permissions.
- Ensure that you installed the Red Hat OpenShift Logging Operator.
-
You have installed the OpenShift CLI (
oc).
Procedure
Create a
LogFileMetricExporterCR as a YAML file:apiVersion: logging.openshift.io/v1alpha1 kind: LogFileMetricExporter metadata: name: instance namespace: openshift-logging spec: nodeSelector: {} resources: limits: cpu: 500m memory: 256Mi requests: cpu: 200m memory: 128Mi tolerations: []spec.nodeSelector- Optional: Define the nodes that the exporter pods run on.
spec.resources- Optional: Define CPU and memory resource limits and requests for the exporter.
spec.tolerationsOptional: Define tolerations that the exporter pods accept.
NoteThe
LogFileMetricExporteris a singleton. The Operator only honorsopenshift-logging/instancefor the namespace and name.
Run the following command to apply the
LogFileMetricExporterCR:$ oc apply -f <filename>.yaml
Verification
Run the following command to verify that the
logfilesmetricexporterpods are running:$ oc get pods -l app.kubernetes.io/component=logfilesmetricexporter \ -n openshift-loggingExample output
NAME READY STATUS RESTARTS AGE logfilesmetricexporter-9qbjj 1/1 Running 0 2m46s logfilesmetricexporter-cbc4v 1/1 Running 0 2m46sA
logfilesmetricexporterpod runs concurrently with acollectorpod on each node.