When collecting container text logs via DaemonSet mode, you can configure reserved field placeholders in the collection path to avoid mismatches between the log content collected by LogCollector and container metadata fields caused by configuring path wildcards. This topic describes use cases and configuration methods for container log collection path placeholders.
Use cases
When collecting container text logs using DaemonSet, path placeholders mainly used to solve mismatches between log content and container metadata fields. For example, provides that the application is deployed in containers and its logs are persisted to nodes using HostPath mount. When the application runs rolling upgrade, the node paths of the log files for the old and new pods differ only in pod name or other container metadata, while the rest of the path remains the same. If you use wildcards (*) in the collection path of LogCollector to dynamically match pod names or other container metadata, LogCollector may continue to collect logs from old pods after the rolling upgrade.
Another example, provides that the node path of the application's log file is /data00/basic_log/mnt_logs/tls_api_autotest-tls/POD_api-autotest-tls-6df9c76bf4-pxxxx/tlsapi/access.log, where POD_api-autotest-tls-6df9c76bf4-pxxxx is the pod name. If you use a wildcard (*) for this section of the collection path, the wildcard (*) will still match and collect old pod log files after a rolling upgrade. However, the reserved field __pod_name__ will automatically update to the new pod name, causing a mismatch between reserved fields and log contents.
Configuration methods
After you install LogCollector in the Kubernetes cluster using DaemonSet and create a host group, you can go to console or use API to add log collection configurations or fill in the collection path that includes placeholders for reserved container fields.
When collecting container text logs via DaemonSet, you can use reserved container field placeholders in the collection path. The placeholder format is {reserved container field}, which enables dynamic matching of container metadata automatically written by LogCollector. For supported reserved container fields, see Background information. For example, if the reserved container fields include __pod_name__, the collection path can be set to /var/log/basic_log/POD_{__pod_name__}/tlsapi/access.log, where {__pod_name__} is a placeholder. LogCollector will automatically use the actual pod name to replace the placeholder during log collection.