×

If logs are produced faster than they can be collected, it can be difficult to predict or control the volume of logs being sent to an output. Not being able to predict or control the volume of logs being sent to an output can result in logs being lost. If there is a system outage and log buffers are accumulated without user control, this can also cause long recovery times and high latency when the connection is restored.

As an administrator, you can limit logging rates by configuring flow control mechanisms for your logging.

Benefits of flow control mechanisms

  • The cost and volume of logging can be predicted more accurately in advance.

  • Noisy containers cannot produce unbounded log traffic that drowns out other containers.

  • Ignoring low-value logs reduces the load on the logging infrastructure.

  • High-value logs can be preferred over low-value logs by assigning higher rate limits.

Configuring rate limits

Rate limits are configured per collector, which means that the maximum rate of log collection is the number of collector instances multiplied by the rate limit.

Because logs are collected from each node’s file system, a collector is deployed on each cluster node. For example, in a 3-node cluster, with a maximum rate limit of 10 records per second per collector, the maximum rate of log collection is 30 records per second.

Because the exact byte size of a record as written to an output can vary due to transformations, different encodings, or other factors, rate limits are set in number of records instead of bytes.

You can configure rate limits in the ClusterLogForwarder custom resource (CR) in two ways:

Output rate limit

Limit the rate of outbound logs to selected outputs, for example, to match the network or storage capacity of an output. The output rate limit controls the aggregated per-output rate.

Input rate limit

Limit the per-container rate of log collection for selected containers.

Configuring log forwarder output rate limits

You can limit the rate of outbound logs to a specified output by configuring the ClusterLogForwarder custom resource (CR).

Prerequisites
  • You have installed the Red Hat OpenShift Logging Operator.

  • You have administrator permissions.

Procedure
  1. Add a maxRecordsPerSecond limit value to the ClusterLogForwarder CR for a specified output.

    The following example shows how to configure a per collector output rate limit for a Kafka broker output named kafka-example:

    Example ClusterLogForwarder CR
    apiVersion: logging.openshift.io/v1
    kind: ClusterLogForwarder
    metadata:
    # ...
    spec:
    # ...
      outputs:
        - name: kafka-example (1)
          type: kafka (2)
          limit:
            maxRecordsPerSecond: 1000000 (3)
    # ...
    1 The output name.
    2 The type of output.
    3 The log output rate limit. This value sets the maximum Quantity of logs that can be sent to the Kafka broker per second. This value is not set by default. The default behavior is best effort, and records are dropped if the log forwarder cannot keep up. If this value is 0, no logs are forwarded.
  2. Apply the ClusterLogForwarder CR:

    Example command
    $ oc apply -f <filename>.yaml
Additional resources

Configuring log forwarder input rate limits

You can limit the rate of incoming logs that are collected by configuring the ClusterLogForwarder custom resource (CR). You can set input limits on a per-container or per-namespace basis.

Prerequisites
  • You have installed the Red Hat OpenShift Logging Operator.

  • You have administrator permissions.

Procedure
  1. Add a maxRecordsPerSecond limit value to the ClusterLogForwarder CR for a specified input.

    The following examples show how to configure input rate limits for different scenarios:

    Example ClusterLogForwarder CR that sets a per-container limit for containers with certain labels
    apiVersion: logging.openshift.io/v1
    kind: ClusterLogForwarder
    metadata:
    # ...
    spec:
    # ...
      inputs:
        - name: <input_name> (1)
          application:
            selector:
              matchLabels: { example: label } (2)
          containerLimit:
              maxRecordsPerSecond: 0 (3)
    # ...
    1 The input name.
    2 A list of labels. If these labels match labels that are applied to a pod, the per-container limit specified in the maxRecordsPerSecond field is applied to those containers.
    3 Configures the rate limit. Setting the maxRecordsPerSecond field to 0 means that no logs are collected for the container. Setting the maxRecordsPerSecond field to some other value means that a maximum of that number of records per second are collected for the container.
    Example ClusterLogForwarder CR that sets a per-container limit for containers in selected namespaces
    apiVersion: logging.openshift.io/v1
    kind: ClusterLogForwarder
    metadata:
    # ...
    spec:
    # ...
      inputs:
        - name: <input_name> (1)
          application:
            namespaces: [ example-ns-1, example-ns-2 ] (2)
          containerLimit:
            maxRecordsPerSecond: 10 (3)
        - name: <input_name>
          application:
            namespaces: [ test ]
          containerLimit:
              maxRecordsPerSecond: 1000
    # ...
    1 The input name.
    2 A list of namespaces. The per-container limit specified in the maxRecordsPerSecond field is applied to all containers in the namespaces listed.
    3 Configures the rate limit. Setting the maxRecordsPerSecond field to 10 means that a maximum of 10 records per second are collected for each container in the namespaces listed.
  2. Apply the ClusterLogForwarder CR:

    Example command
    $ oc apply -f <filename>.yaml