Logtail input configuration now supports the collection of container standard output. This topic introduces the new version of standard output collection configuration.
Features
Logtail can collect container stdout and stderr, uploading them along with container metadata to Simple Log Service. Logtail supports the following features:
Collects stdout and stderr logs.
Uses container label whitelist to specify containers for log collection.
Uses container label blacklist to exclude containers from log collection.
Uses environment variable whitelist to specify containers for log collection.
Uses environment variable blacklist to exclude containers from log collection.
Collects multi-line logs, such as Java stack traces.
Automatically associates metadata required for upload with the collected container logs, including container names, image names, pod names, namespaces, and environment variables.
For containers running in a Kubernetes cluster, Logtail also supports:
Using Kubernetes namespaces, pod names, and container names to specify containers for log collection.
Using Kubernetes label whitelist to specify containers for log collection.
Using Kubernetes label blacklist to exclude containers from log collection.
Automatically associating Kubernetes labels required for upload with the collected container logs.
Limitations
The new version of the standard output collection plugin currently only supports the Linux operating system and Logtail version 2.1.5 or later. It does not support collecting standard output logs through the host method. For information on checking and upgrading the version, see Install Logtail components (Alibaba Cloud Kubernetes cluster) and Install Logtail components (self-managed Kubernetes cluster).
Logtail collects data from containers using the Docker engine or containerd engine. The access paths are:
-
Docker: Logtail requires access to Docker via /run/docker.sock. Ensure this path is present and has the necessary access permissions.
-
Containerd: Logtail requires access to Containerd via /run/containerd/containerd.sock. Ensure this path is present and has the necessary access permissions.
-
The maximum size of each log read is 524288 bytes (512 KB) by default, with a maximum value of 8388608 bytes (8 MB). If your single log exceeds 524288 bytes, you can add the environment variable max_read_buffer_size to the Logtail container to modify it.
Collection stop policy: When a container stops, Logtail ceases to collect its standard output upon detecting the container's
die
event. In the event of collection latency, some stdout and stderr logs produced prior to the container's cessation may be lost.Docker engine limitation: The logging driver only collects stdout and stderr logs in JSON format from containers using the Docker engine.
Data processing: By default, the collected data is stored in the
content
field. Logtail facilitates data processing for standard output from containers. For more information, see how to use Logtail plug-ins for data processing. The latest version of the standard output collection plug-in allows for the integration of native processing plug-ins, which are high-performance and support multithreading, with extended plug-ins.The CRD method supports AliyunPipelineConfig.
The API method supports CreateLogtailPipelineConfig - Create Logtail pipeline configuration, UpdateLogtailPipelineConfig - Update Logtail pipeline configuration, and other pipeline configurations.
Advantages
The new version of standard output collection offers several advantages over the old version:
Type |
Advantages of the new standard output plugin (C++ version) |
Significant performance improvement |
Reconstructed with C++, performance improved by more than 100% compared to the old version of the standard output plugin. |
Supports native plugin data processing, multithreaded parallel processing, and fully utilizes system resources. |
|
Flexible combination of native plugins and Go plugins. |
|
Higher reliability |
Supports standard output log rotation queue. The log collection mechanism and file collection mechanism are unified, providing high reliability in scenarios where standard output logs rotate quickly. |
Lower resource consumption |
CPU utilization reduced by 20%. |
Memory usage reduced by 20%. |
|
Operational consistency |
The parameters of the new standard output collection plugin and the file collection plugin are unified. |
Container metadata field names and tag log storage locations are unified with the file collection scenario. Consumers only need to maintain the same processing logic. |
Configuration instructions
Form configuration (console configuration)
Parameter | Description |
Standard Output | After you enable Standard Output, Logtail collects container standard output. |
Standard Error | After you enable Standard Error, Logtail collects container standard error. |
Allow Multiple Collections Of Standard Output | By default, the standard output logs of a container can match only one Logtail new standard output collection configuration. If the standard output needs to be collected by multiple new standard output collection configurations, you need to enable the Allow Multiple Collections Of Standard Output switch. |
Enable Container Metadata Preview | After you enable Enable Container Metadata Preview, you can view container metadata, including matched container information and full container information, after creating a Logtail configuration. |
Container Filtering |
Important
|
Log Tag Enrichment | You can add environment variables and Kubernetes labels to logs as log tags. |
First Collection Size | The starting collection position of the standard output log file when the configuration takes effect for the first time. The default value of First Collection Size is 1024 KB.
You can modify the First Collection Size here. The value range is from 0 to 10485760. Unit: KB. |
Advanced Parameters | Some parameters of the Logtail configuration need to be manually entered. For more information, see Create Logtail pipeline configuration. |
Configuration example
CRD-AliyunPipelineConfig
If you use AliyunPipelineConfig, the image version of alibaba-log-controller must be no less than 0.5.1.
Parameter | Type | Required | Default value | Description |
Type | string | Yes | / | The type of the plug-in. Fixed to input_container_stdio. |
IgnoringStdout | Boolean | No | false | Whether to ignore stdout. |
IgnoringStderr | Boolean | No | false | Whether to ignore stderr. |
TailSizeKB | uint | No | 1024 | The starting collection position of the standard output file when the configuration takes effect for the first time. If the file size is less than this value, Logtail collects data from the beginning of the file. The value range is from 0 to 10485760 KB. |
Multiline | object | No | Empty | The multi-line aggregation options. For more information, see Table 1: Multi-line aggregation options. |
ContainerFilters | object | No | Empty | The container filter options. Multiple options are evaluated by using a logical AND. For more information, see Table 2: Container filter options. |
ExternalK8sLabelTag | map | No | Empty | For containers deployed in a Kubernetes environment, additional tags related to pod labels need to be added to logs. The key in the map is the pod label name, and the value is the corresponding tag name. For example, if you add |
ExternalEnvTag | map | No | Empty | For containers deployed in a Kubernetes environment, additional tags related to container environment variables need to be added to logs. The key in the map is the environment variable name, and the value is the corresponding tag name. For example, if you add |
FlushTimeoutSecs | uint | No | 5 | If no new complete logs appear in the file for a specified period of time, the content in the current read buffer is output as a log. |
AllowingIncludedByMultiConfigs | bool | No | false | Whether to allow the current configuration to collect the standard output logs of containers that are already matched by other configurations. |
Table 1: Multi-line aggregation options
Parameter
Type
Required
Default value
Description
Mode
string
No
custom
The multi-line aggregation mode. Only custom is supported.
StartPattern
string
Required when Multiline.Mode is set to custom
Empty
The regular expression for the start of a line.
UnmatchedContentTreatment
string
No
single_line
The processing method for unmatched log segments. The following options are available:
discard: Discard.
single_line: Store each line of the unmatched log segment in a separate event.
Table 2: Container filter options
Parameter
Type
Required
Default value
Description
K8sNamespaceRegex
string
No
Empty
For containers deployed in a Kubernetes environment, specify the namespace condition of the pod to which the container belongs. If this parameter is not added, logs are collected from all containers. Regular expression matching is supported.
K8sPodRegex
string
No
Empty
For containers deployed in a Kubernetes environment, specify the name condition of the pod to which the container belongs. If this parameter is not added, logs are collected from all containers. Regular expression matching is supported.
IncludeK8sLabel
map
No
Empty
For containers deployed in a Kubernetes environment, specify the label condition of the pod to which the container belongs. Multiple conditions are evaluated by using a logical OR. If this parameter is not added, logs are collected from all containers. Regular expression matching is supported. The key in the map is the pod label name, and the value is the pod label value. The following describes the conditions:
If the value in the map is empty, pods that contain the key as a label key are matched.
If the value in the map is not empty:
If the value starts with
^
and ends with$
, pods are matched when the pod label contains the key as a label name and the corresponding label value matches the value.In other cases, pods are matched when the pod label contains the key as a label name and the value as a label value.
ExcludeK8sLabel
map
No
Empty
For containers deployed in a Kubernetes environment, specify the label condition of the pod to which the container belongs that needs to be excluded from collection. Multiple conditions are evaluated by using a logical OR. If this parameter is not added, logs are collected from all containers. Regular expression matching is supported. The key in the map is the pod label name, and the value is the pod label value. The following describes the conditions:
If the value in the map is empty, pods that contain the key as a label key are matched.
If the value in the map is not empty:
If the value starts with
^
and ends with$
, pods are matched when the pod label contains the key as a label name and the corresponding label value matches the value.In other cases, pods are matched when the pod label contains the key as a label name and the value as a label value.
K8sContainerRegex
string
No
Empty
For containers deployed in a Kubernetes environment, specify the name condition of the container to be collected. If this parameter is not added, logs are collected from all containers. Regular expression matching is supported.
IncludeEnv
map
No
Empty
Specify the environment variable conditions of the container to be collected. Multiple conditions are evaluated by using a logical OR. If this parameter is not added, logs are collected from all containers. Regular expression matching is supported. The key in the map is the environment variable name, and the value is the environment variable value. The following describes the conditions:
If the value in the map is empty, containers that contain the key as an environment variable key are matched.
If the value in the map is not empty:
If the value starts with
^
and ends with$
, containers are matched when the container environment variable contains the key as an environment variable name and the corresponding environment variable value matches the value.In other cases, containers are matched when the container environment variable contains the key as an environment variable name and the value as an environment variable value.
ExcludeEnv
map
No
Empty
Specify the environment variable conditions of the container to be excluded from collection. Multiple conditions are evaluated by using a logical OR. If this parameter is not added, logs are collected from all containers. Regular expression matching is supported. The key in the map is the environment variable name, and the value is the environment variable value. The following describes the conditions:
If the value in the map is empty, containers that contain the key as an environment variable key are matched.
If the value in the map is not empty:
If the value starts with
^
and ends with$
, containers are matched when the container environment variable contains the key as an environment variable name and the corresponding environment variable value matches the value.In other cases, containers are matched when the container environment variable contains the key as an environment variable name and the value as an environment variable value.
IncludeContainerLabel
map
No
Empty
Specify the label conditions of the container to be collected. Multiple conditions are evaluated by using a logical OR. If this parameter is not added, logs are collected from all containers. Regular expression matching is supported. The key in the map is the container label name, and the value is the container label value. The following describes the conditions:
If the value in the map is empty, containers that contain the key as a label key are matched.
If the value in the map is not empty:
If the value starts with
^
and ends with$
, containers are matched when the container label contains the key as a label name and the corresponding label value matches the value.In other cases, containers are matched when the container label contains the key as a label name and the value as a label value.
ExcludeContainerLabel
map
No
Empty
Specify the label conditions of the container to be excluded from collection. Multiple conditions are evaluated by using a logical OR. If this parameter is not added, logs are collected from all containers. Regular expression matching is supported. The key in the map is the container label name, and the value is the container label value. The following describes the conditions:
If the value in the map is empty, containers that contain the key as a label key are matched.
If the value in the map is not empty:
If the value starts with
^
and ends with$
, containers are matched when the container label contains the key as a label name and the corresponding label value matches the value.In other cases, containers are matched when the container label contains the key as a label name and the value as a label value.
Configuration example
Manage collection configurations with AliyunPipelineConfig
apiVersion: telemetry.alibabacloud.com/v1alpha1 # Create a ClusterAliyunPipelineConfig kind: ClusterAliyunPipelineConfig metadata: # Specify the name of the resource. The name must be unique in the current Kubernetes cluster. The name is also the name of the iLogtail collection configuration that is created. name: example-k8s-stdout spec: # Specify the target project project: name: k8s-log-clusterid # Create a Logstore to store logs logstores: - name: k8s-stdout # Define the iLogtail collection configuration config: # Specify the sample log. You can leave this parameter empty. sample: | 2024-06-19 16:35:00 INFO test log line-1 line-2 end # Configure the Logtail input plug-ins inputs: # Use the input_container_stdio plug-in to collect container standard output - Type: input_container_stdio # Collect stdout logs IgnoringStdout: false # Do not collect stderr logs IgnoringStderr: true # Configure container information filter conditions. Multiple options are evaluated by using a logical AND. ContainerFilters: # Specify the namespace of the pod to which the container belongs. Regular expression matching is supported. K8sNamespaceRegex: "^(default)$" # Specify the name of the container to be collected. Regular expression matching is supported. K8sContainerRegex: "^(.*app.*)$" # Configure multi-line chunk configuration # Configure the regular expression for the start of a line Multiline: Mode: custom StartPattern: \d+-\d+-\d+.* UnmatchedContentTreatment: single_line # Configure the Logtail output plug-ins flushers: # Use the flusher_sls plug-in to send logs to a specific Logstore. - Type: flusher_sls Logstore: k8s-stdout Endpoint: cn-hangzhou.log.aliyuncs.com Region: cn-hangzhou TelemetryType: logs
Preview container metadata
After creating a Logtail configuration, you can view container metadata and reasons for non-matching filter conditions on the Logtail configuration page.
In the Project List, click the project where you created the Logtail configuration.
In the
tab, select the Logstore you used to create the Logtail configuration, then click > on the left side of the Logstore, and select .In the Logtail configuration list, click the desired Logtail configuration.
On the Logtail Configuration page, click Edit.
Turn on the Enable Container Metadata Preview switch.
Click Container Metadata Preview.
In the Container Preview dialog box, review the container metadata.
The Matched Containers tab shows metadata for containers that meet your filter conditions.
The All Containers tab displays metadata for all containers in the current Kubernetes cluster, including reasons why some containers did not match the filter conditions.
Log fields
The following fields are uploaded by default with each log in a Kubernetes cluster:
Field name | Description |
_time_ | The time when the log is collected. |
_source_ | The log source type, stdout or stderr. |
__tag__:_image_name_ | Image name |
__tag__:_container_name_ | Container name |
__tag__:_pod_name_ | Pod name |
__tag__:_namespace_ | The namespace where the pod resides |
__tag__:_pod_uid_ | The unique identifier of the pod |
Troubleshooting
If you encounter issues when using Logtail to collect logs from containers, including standard and Kubernetes containers, refer to the following topics for troubleshooting:
If standard error logs and access logs have different formats and cannot be parsed normally, consider adding an index to search for errors in the content. Simple Log Service does not support using plugins to extract fields for parsing. For more information, see Create an index.