Skip to content

Data Forwarding


For data that needs long-term retention but has low update frequency (such as logs), you can use Data Forwarding to automatically save it to object storage or forward it in real time to external systems such as Kafka. This feature filters the data you need according to rules, enabling low-cost long-term archiving and supporting subsequent secondary processing.

After a rule takes effect, set the query period and rule on the Data Forwarding page to search data that has been processed in destinations that support querying. The queryable time range depends on the data processing cycle of the destination.

Data Forwarding also supports Metrics data sources. When creating or editing a rule, you can select Metrics, configure filter conditions, and forward metric data that matches the rule to an external service. For details, see Define Forwarding Rules.

If you need to retain data locally or in your own cloud environment, you can choose LogBamboo as the destination and query historical records through the console.

How It Works

When using LogBamboo, see Forward Data to LogBamboo.

Taking forwarding to object storage in JSON format as an example, the workflow is as follows: User-reported data that matches the rule is first written line by line to a temporary file on the server's local disk. When the temporary file reaches a preset size (for example, 256 MB) or has been written to for longer than a set duration (for example, 1 hour), the system automatically closes the current file and creates a new temporary file to continue receiving data.

At the same time, a background service continuously scans these closed temporary files, compresses them in gzip format to reduce size, and then uploads them to the object storage location you specified according to predefined path rules. When you need to search the stored data, the system locates the relevant files in object storage according to the same path rules, downloads and decompresses them, and matches your search conditions line by line.

File Format

When JSON storage format is selected, regular archives are gzip-compressed. After decompression, the file content appears as multi-line text, each line corresponding to one original data record, with data fully stored in JSON format. Any blank lines in the file are automatically ignored by the system.

When Parquet storage format is selected, the file uses Parquet internal GZIP compression and cannot be decompressed as a regular gzip file. If the object storage rule has Encrypted Storage enabled, downloaded archives must first be decrypted.

A typical log-type data forwarding file looks like this:

Here, date is a required field that identifies the time of the data record, as a millisecond-level Unix timestamp, and the message field contains the specific log content.

{"__docid":"L_1750649205520_d1cciupkac7k1683bhq0","__namespace":"backup_log","date":1750649205520,"date_ns":168000,"df_metering_size":-9223372036854775808,"filepath":"/var/log/datakit/gin.log","host":"X.local","log_read_lines":2,"message":"[GIN] 2025/06/23 - 11:26:43 | 200 | 1.012923708s |       127.0.0.1 | GET     \"/metrics\"","message_length":87,"service":"default","source":"default","status":"unknown"}

{"__docid":"L_1750649205516_d1cciupkac7k1683bhqg","__namespace":"backup_log","date":1750649205516,"date_ns":897000,"df_metering_size":-9223372036854775808,"filepath":"/var/log/datakit/gin.log","host":"X.local","log_read_lines":1,"message":"[GIN] 2025/06/23 - 11:26:38 | 200 | 1.012696542s |       127.0.0.1 | GET     \"/metrics\"","message_length":87,"service":"default","source":"default","status":"unknown"}

{"__docid":"L_1750649206520_d1cciupkac7k1683bhr0","__namespace":"backup_log","date":1750649206520,"date_ns":948000,"df_metering_size":-9223372036854775808,"filepath":"/var/log/datakit/log","host":"X.local","log_read_lines":150,"message":"2025-06-23T11:26:46.520+0800\tWARN\thost_processes\tprocess/input.go:332\tprocess: {\"pid\":411}, proc.PageFaults(): not implemented yet","message_length":130,"service":"default","source":"default","status":"unknown"}

{"__docid":"L_1750649205520_d1cciupkac7k1683bhrg","__namespace":"backup_log","date":1750649205520,"date_ns":419000,"df_metering_size":-9223372036854775808,"filepath":"/var/log/datakit/log","host":"X.local","log_read_lines":9,"message":"2025-06-23T11:26:43.876+0800\tWARN\tcontainer\tcontainer/impl.go:254\tendpoint unix:///var/run/crio/crio.sock does not exist, maybe it is not running, skip","message_length":151,"service":"default","source":"default","status":"unknown"}

{"__docid":"L_1750649205517_d1cciupkac7k1683bhs0","__namespace":"backup_log","date":1750649205517,"date_ns":79000,"df_metering_size":-9223372036854775808,"filepath":"/var/log/datakit/log","host":"X.local","log_read_lines":1,"message":"2025-06-23T11:26:38.365+0800\tWARN\thttp\thttpapi/http.go:494\tlistener.Close failed: close tcp [::]:9529: use of closed network connection","message_length":135,"service":"default","source":"default","status":"unknown"}
{"__docid":"L_1750649205517_d1cciupkac7k1683bhsg","__namespace":"backup_log","date":1750649205517,"date_ns":80000,"df_metering_size":-9223372036854775808,"filepath":"/var/log/datakit/log","host":"X.local","log_read_lines":2,"message":"2025-06-23T11:26:38.365+0800\tWARN\thttp\thttpapi/http.go:494\tlistener.Close failed: close tcp [::]:9529: use of closed network connection","message_length":135,"service":"default","source":"default","status":"unknown"}

File Naming and Storage Path

[{$path_prefix}/]{$workspace_uuid}/[{$data_type}/]

{$rule_name}/{$year}/{$month}/{$day}/{$hour}/{$time}-{$hostname}.gz

Parts enclosed in [] are optional. See the descriptions below for details:

Variable
Description
Example Notes
$path_prefix Path prefix path/to/backup Optional. Corresponds to the storage path option when creating a backup rule.
Object storage does not support keys starting with /, so do not start with /
$workspace_uuid Workspace ID wksp_d9a1851859e040469d290409bc17cceb
$data_type Backup data type. Valid values:

  • logging: Logs
  • rum: Real User Monitoring (RUM)
  • tracing: Traces
  • event: Events
  • audit_event: Audit Events
  • tracing Because logs are the default data type, for log data, the {$data_type}/ part (that is, logging/) must be omitted
    $rule_name Rule name backup_logging_for_test Corresponds to the rule name option when creating a rule.
    English is recommended
    $year Year of the log occurrence time, 4 digits 2025 UTC
    $month Month of the log occurrence time, 2 digits 03 UTC
    $day Day of the log occurrence time, 2 digits 01 UTC
    $hour Hour of the log occurrence time, 2 digits 22 UTC
    $time Occurrence time of the last log in the file
    Format: HHMMSS + 3-digit milliseconds
    220607889 UTC
    $hostname First 16 characters of the hostname after MD5 calculation c6a92aafa992599c When constructing a file manually, you can use the crc64 of the current file.
    Or randomly generate a 64-bit random number and convert it to hexadecimal

    Path examples:

    wksp_d9a1851859e040469d290409bc17cceb/backup_logging_for_test/2025/05/06/17/175950000-c6a92aafa992599c.gz

    path/to/backup/wksp_d9a1851859e040469d290409bc17cceb/tracing/test-minio/2025/05/06/17/175950000-c6a92aafa992599c.gz

    File Splitting Rules
    • Time boundary: A single file contains only logs within the same hour and never spans hours.
    • Size boundary: The uncompressed original file is kept between 256 MB and 512 MB. After gzip compression, it is usually tens of MB to hundreds of MB. Files that are too large or too small reduce search efficiency.

    You can upload external files to object storage in the format and path rules generated by data forwarding rules, and the console will search and display them in the same way.

    Get Started

    Create a Forwarding Rule

    Create data forwarding rules that meet your business needs based on different types of forwarding destinations:

    Type Forwarding Destination
    Built-in Storage Guance
    Object Storage AWS S3, Huawei Cloud OBS, Alibaba Cloud OSS, Volcengine TOS, GCP GCS
    Analytics Platform Apache Doris, TiDB Cloud Lake, LogBamboo
    Message Queues Kafka

    Manage Forwarding Rules

    In the data forwarding rule list, you can manage rules through a series of operations.

    Data View Permissions

    When creating a data forwarding rule, you can choose to allow all members in the workspace to view the data or specify member roles that can view the data. For specific configuration, see Define Data View Permissions.

    Decrypt Files

    Applies to archive files forwarded to AWS S3, Huawei Cloud OBS, Alibaba Cloud OSS, Volcengine TOS, GCP GCS with storage format JSON or Parquet and Encrypted Storage enabled. The Apache Iceberg format on AWS S3 does not apply.

    File Extension Processing Method Output File
    .lock.gz Use the decryption tool to decrypt and perform gzip decompression JSON lines file, such as .jsonl
    .parquet.lock.gz Use the decryption tool to decrypt; do not perform gzip decompression .parquet
    .gz Not encrypted; perform gzip decompression directly JSON lines file, such as .jsonl
    .parquet.gz Not encrypted; open directly with a Parquet reader Parquet file

    Prerequisites

    1. Download the complete archive from object storage and keep the original copy.
    2. Obtain the Workspace ID (UUID). You can copy it from Manage > Workspace Settings > Basic Information in the workspace to which the file belongs, using the complete value starting with wksp_.
    3. Prepare a working Go environment and download the decryption tool decrypt.go. The tool depends only on the Go standard library, processes files locally, and does not require object storage access keys.

    Steps

    The following commands apply to Bash and Zsh on macOS or Linux. Place the tool and the archive in the same directory, and open a terminal in that directory. Modify -in and -out according to the actual file names, and replace the value of -workspace with the complete workspace ID copied during preparation. For -out, use an output path that does not yet exist.

    1. Verify the Go Environment

    go version
    

    2. Use Default Decryption Parameters

    The tool has a built-in default IV (initialization vector, a parameter used during encryption). When the archive uses the default encryption configuration, you do not need to separately obtain or enter the IV. Run the following command to ensure that the tool uses the built-in default value:

    unset KODO_BACKUP_IV
    
    When the deployment environment uses custom encryption parameters

    If backup_log.iv has been modified on the server, contact the personnel responsible for maintaining that deployment environment to obtain the configuration value used when the file was generated. Then use the following command instead of the unset command above:

    export KODO_BACKUP_IV='IV used when the file was generated'
    

    KODO_BACKUP_IV only passes this value to the local decryption tool. Do not set it to an empty string to indicate that the default value is used; if the configuration has changed, old files still need the value used when they were generated.

    3. Run Decryption

    go run decrypt.go \
      -in "./archive.lock.gz" \
      -out "./archive.jsonl" \
      -workspace "wksp_your_workspace_uuid"
    

    The tool automatically completes decryption and gzip decompression. The generated .jsonl can be read as JSON line by line, and no further decompression is required.

    go run decrypt.go \
      -in "./archive.parquet.lock.gz" \
      -out "./archive.parquet" \
      -workspace "wksp_your_workspace_uuid"
    

    After decryption, the tool generates a Parquet file. Use a Parquet reader directly to check the schema and data. The decryption tool does not perform full Parquet structure validation.

    The tool identifies the format based on the decrypted file header and does not rely on the file name. The input file remains unchanged. If the output path already exists, it will not be overwritten. If processing fails, the tool attempts to delete the incomplete output file generated in this run.

    4. Check the Decryption Result

    After the command completes successfully, the terminal outputs the corresponding message based on the file format:

    Restored decompressed JSON/NDJSON: ./archive.jsonl
    

    Or:

    Restored Parquet: ./archive.parquet
    
    • JSON lines file: Check whether each line can be parsed as JSON, and spot-check fields such as time and data content.
    • Parquet file: Open it with a Parquet reader, check the schema and data content, and do not run gunzip again.

    Optional: Build and Use

    go build -o backup-decrypt decrypt.go
    ./backup-decrypt -in "./archive.lock.gz" -out "./archive.jsonl" -workspace "wksp_your_workspace_uuid"
    

    The compiled tool still reads a custom IV through KODO_BACKUP_IV. You can copy it to a machine with the same operating system and architecture and run it there; the target machine does not need Go installed.

    Unencrypted Files

    Regular .gz files can be decompressed directly. Choose an output file name that does not yet exist:

    (set -C; gzip -dc "./archive.gz" > "./archive.jsonl")
    

    This command preserves the original archive; if the output file already exists, it reports an error and stops, so change the file name. .parquet.gz uses Parquet internal GZIP compression and should be passed directly to a Parquet reader; do not use this command for it.

    FAQ

    Symptom Checks and Actions
    unrecognized decrypted header Verify the complete workspace ID starting with wksp_, the IV used when the file was generated, and file integrity. Unencrypted files should not be processed with the decryption tool.
    invalid gzip header or gzip verification failure Verify the decryption parameters and re-download the original archive to rule out corruption or truncation.
    Error when running gunzip on Parquet Open the decrypted file directly with a Parquet reader.
    file exists Use a different output file name that does not yet exist.
    go: command not found Install Go, or compile on another machine and copy a compatible executable file.
    permission denied Confirm that the input file is readable and the output directory is writable.
    no space left on device Reserve disk space based on the amount of decompressed data.
    no such file or directory Verify the tool and archive paths, and create the output directory in advance.

    Feedback

    Is this page helpful?