Log forwarding
Understand how OpsChain's log aggregator works and, if required, configure it to forward build, change and workflow run logs to external log storage. After following this guide you should know how to:
- add plugins to the OpsChain log aggregator
- configure build, change and workflow run logs to be sent to external log storage
Introduction
OpsChain uses Fluentd as its log aggregator. Fluentd provides an extensive framework that allows for custom developed and pre-built plugins to be used to forward logs to external log storage solutions. This guide describes the capabilities of OpsChain's log aggregator and provides the steps on how to configure OpsChain to forward build, change and workflow run logs to a Splunk HTTPS Event Collector.
The log aggregator does not store MintPress's logs. Every log line is stored in MintPress's database first, as described in the log ingestion guide, and the log aggregator receives a copy of each stored line to send to the additional outputs you configure. Without any additional outputs, it only writes the lines it receives to its own output.
A Kubernetes network policy, opschain-log-aggregator, accepts connections to the log aggregator only from the opschain-api and opschain-api-worker pods.
Capabilities
MintPress's log aggregator is provided with a 1GB PVC, mounted at /data, for buffering logs. MintPress does not use any of it itself, so the whole volume is available to buffer logs for your additional outputs. Refer to Fluentd's buffer configuration guide on how to configure the buffer for your outputs, and keep the buffer path under /data so the buffered logs survive a restart of the log aggregator.
If you need to increase the PVC size, you can do so by modifying your values.yaml file and setting the logAggregator.volume.size value to the desired size and (re)deploying MintPress.
logAggregator:
volume:
size: 2Gi
For example, to configure the buffer for the Splunk output plugin, dropping oldest chunks on an overflow and compressing the chunks using zstd, use a configuration similar to the example below:
<store>
@type splunk_hec
host splunk.myco.com
port 8088
token <Splunk HEC token>
use_ssl false
<buffer>
@type file
path /data/my-company/splunk
retry_forever true
total_limit_size 100MB
overflow_action drop_oldest_chunk
compress zstd
</buffer>
</store>
It's up to you to ensure your configuration is valid. Please refer to Fluentd's config file syntax guide for more information.
You can check the log aggregator's logs for errors by running the following command:
kubectl logs -n ${KUBERNETES_NAMESPACE} deployment/opschain-log-aggregator -f
Automated restarts
OpsChain will automatically restart the log aggregator deployment if it's stuck or unresponsive.
While the log aggregator is down, MintPress carries on as normal: agents, builds, changes and workflow runs still start, and their logs are still stored and visible in MintPress. Only forwarding to your additional outputs is delayed. See when the log aggregator is unavailable.
If Fluentd never recovers, you can check its logs and events to investigate the issue.
How stored log lines reach the log aggregator
When a log line is stored, MintPress also queues a copy of it in the database to be forwarded. A background job on each site sends the queued lines to that site's log aggregator in batches, and removes them from the queue once the log aggregator has acknowledged them. In a high availability deployment, the sites share one queue, so a line may be forwarded by any site's log aggregator — configure the same additional outputs on every site (the settings method does this for you).
Lines are forwarded at least once. If the log aggregator receives a batch but MintPress does not receive its acknowledgement, the batch is sent again, so an additional output can occasionally receive the same line twice.
When the log aggregator is unavailable
While lines cannot be sent to the log aggregator, MintPress keeps them queued and retries, waiting up to a minute between attempts. Once the log aggregator is reachable again, the queued lines are forwarded, oldest first. While forwarding is failing, MintPress raises an error:log_forwarding:failed event, at most once an hour for each site.
The number of lines that can wait in the queue is limited by the log_forwarding.max_queued_lines setting, 2,000,000 by default. When more lines than that are waiting, the oldest are removed from the queue and will not be forwarded, and MintPress raises a warning:log_forwarding:dropped event recording how many. The lines themselves remain stored in MintPress — they are only missing from your additional outputs.
Configure additional outputs
MintPress provides multiple options to configure additional outputs for Fluentd, choose the one that best suits your needs.
However you decide to configure the additional outputs, the configuration will be stored in a Kubernetes ConfigMap and mounted into the log-aggregator pod at runtime. You'll need to supply the entire <store></store> string of your configuration to this setting.
The configuration you provide to these settings will be read by Fluentd in the context of the copy output plugin which MintPress takes advantage of to send the MintPress logs to multiple outputs.
Under the copy configuration, each <store> directive added instructs Fluentd to send the log entry to an additional target.
The specific configuration to include in additionalOutputConfig will depend on the plugin @type used. Please see Fluentd's config file syntax guide, and the relevant plugin manual for further information.
Via settings - post-installation
You can configure MintPress settings pre-installation via Helm chart or post-installation via the UI configuration page.
Using the UI configuration page - post-installation
The simplest way to manage additional outputs is via MintPress's UI configuration page. For example, to enable sending the logs to Splunk, just paste the entire <store></store> section into the setting and save.
<store>
@type splunk_hec
host splunk.myco.com
port 8088
token <Splunk HEC token>
use_ssl false
</store>
The log aggregator picks the change up on its own, without restarting: it watches its configuration and asks Fluentd to reload, so log forwarding continues uninterrupted while the new outputs take effect. When in a high availability deployment, the configuration is applied to every site.
Via Helm chart - pre-installation
The MintPress Helm chart allows you to provide the additional configuration via the logAggregator.additionalOutputConfig value before installing MintPress. An example configuration is provided below:
logAggregator:
additionalOutputConfig: |-
<store>
@type splunk_hec
host splunk.myco.com
port 8088
token <Splunk HEC token>
use_ssl false
</store>
When this method is used, the configuration will not appear in MintPress's UI configuration page. You can check the ConfigMap to verify the configuration that is being applied.
kubectl get configmap opschain-log-aggregator-additional-output-config -n ${KUBERNETES_NAMESPACE} -o jsonpath='{.data.output\.conf}'