Import log files from Google Cloud Storage (GCS) into Log Service for querying, analysis, and data processing.
This document is original content from Alibaba Cloud. As it describes how our services interact with third-party products, it may reference the names of other companies or their products.
A single GCS file cannot exceed 5 GB. For compressed files, this size limit applies to the file after compression.
Prerequisites
Create a data import configuration
-
Log on to the Log Service console.
-
In the right pane, click Import Data. On the Data Import tab, select GCS - data import.
-
Select the destination Project and Logstore, and then click Next.
-
In the data import configuration, configure the following parameters.
Parameter
Description
task name
The unique name of the Log Service task.
display name
The display name of the task.
task description
A description of the data import task.
GCS endpoint
The service endpoint for GCS. The global endpoint,
https://storage.googleapis.com, is used by default. Specify a different endpoint if needed.bucket
The name of the GCS bucket.
AccessKeyId
The AccessKeyId for your GCS account.
AccessKeySecret
The AccessKeySecret for your GCS account. For more information, see the GCS documentation.
file path prefix filter
Filters GCS files to import based on a file path prefix. For example, if your files are in the
test/directory, specify the prefix astest/. If this parameter is not set, the entire bucket is scanned.NoteRecommended. Scanning an entire bucket with many files reduces import efficiency.
file path regex filter
Imports only files with paths matching the specified regular expression. If empty, no regex filtering is applied. For example, for the file path
test1/test.txt, set the regular expression totes.*.file modification time filter
Imports only GCS files based on their last modified time.
-
All: Imports all files that meet the criteria.
-
From a specific time: Imports only files modified after a specified time.
-
Specific time range: Imports only files modified within a specified time range.
data format
The format used to parse the log files. Supported formats include:
-
CSV: Delimiter-separated text files. You can use the first row as field names or specify field names manually. Each subsequent row is parsed as field values.
-
single-line JSON: Each line is treated as a separate JSON object. The object's keys and values are mapped to log fields and their corresponding values.
-
single-line text log: Parses each line as a single log entry.
-
multiline text log: Combines multiple physical lines into a single log entry based on a regular expression that identifies the start or end of an entry.
-
JSON array: Parses the entire file as a JSON array, where each object in the array becomes a single log entry.
-
CloudTrail: Parses the entire file based on the standard CloudTrail data structure.
compression format
The compression format of the source files. Files are automatically decompressed before parsing.
encoding format
The encoding format of the GCS files. UTF-8 and GBK are supported.
new file check interval
The interval for checking new files. When set, the task runs continuously to import new files as they appear, processing each file only once. For a one-time import, select Never Check. The task stops after processing all existing files that match the filter criteria.
write processor
Preprocesses imported data, including data filtering, field extraction, field enrichment, and data masking. For more information, see Manage write processors.
Log time configuration
Parameter
Description
time field
The field in the source data that contains the log timestamp, used as the log time in Log Service. Available for CSV, single-line JSON, JSON array, and CloudTrail formats.
time extraction regex
A regular expression used to extract the time value from a log entry. For example, if a log entry is
127.0.0.1 - 2026-04-16 17:25:42 audit-log, you can set the regular expression to[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}.NoteAlso useful for extracting a specific time format from a time field that contains extraneous text.
time field format
The time format used to parse the value in the time field.
-
Supports time formats based on Java's SimpleDateFormat syntax, such as
yyyy-MM-dd HH:mm:ss. -
Supports epoch formats, including epoch, epochMillis, epochMicro, and epochNano.
time zone
The time zone of the timestamp in the source logs. This is not required for epoch formats. To account for Daylight Saving Time (DST), select a UTC-based time zone; otherwise, a GMT-based time zone is sufficient.
NoteThe default time zone is UTC+8.
When you select CSV or multiline text log as the data format, you must configure the following additional parameters.
CSV-specific parameters
Parameter
Description
delimiter
The character that separates fields in the CSV file. Default: comma (
,).quote character
The quote character for strings in the CSV file.
escape character
The escape character for the log. The default is a backslash (
\).maximum lines per log
The maximum number of lines that a single log entry can span. The default is 1.
NoteThe maximum value is 10,000 lines.
use first row as field names
When enabled, the first row of the CSV file is used as field names.
custom field list
If the first-row-as-field-names option is turned off, specify custom field names separated by commas (
,).lines to skip
The number of lines to skip from the beginning of the file. For example, if you set this to 1, data ingestion starts from the second line.
Multiline text log-specific parameters
Parameter
Description
regex matching position
The position where the regular expression is matched:
-
Start-of-line Regex: Uses a regular expression to match the first line of a log entry. Unmatched lines are considered part of the current log entry until the maximum line count is reached.
-
End-of-line Regex: Uses a regular expression to match the last line of a log entry. Unmatched lines are considered part of the next log entry until the maximum line count is reached.
regular expression
The regular expression for matching log entries.
maximum lines
The maximum number of lines for a single log entry.
NoteThe maximum value is 10,000 lines.
-
-
Click Preview to view the import results.
-
After you confirm the settings, click Next.
-
Click Query Logs to open the Query and Analysis page. It may take up to a minute for the imported data to appear. The import is successful when you see the GCS data in the query results.
View an import configuration
After creating a data import configuration, view its details and statistical reports.
-
In the Project list, click the target Project.
-
Under Log Storage, locate the target Logstore and select Data Collection > Data Import. Then, click the name of your import configuration.
-
View the basic information and statistical reports for the import configuration.
-
You can modify, start, stop, or delete the configuration.
WarningA deleted configuration cannot be recovered. Proceed with caution.
Billing
The data import feature is free in Log Service. However, Google Cloud charges for internet egress and API requests from GCS. Refer to your Google Cloud bill for details. The pricing model and relevant parameters are as follows:
|
Field |
Description |
|
T |
The total daily data import volume, in GB. |
|
p_read |
The internet egress price per GB of data. |
|
p_put |
The price per 10,000 PUT requests. |
|
p_get |
The price per 10,000 GET requests. |
|
M |
The new file check interval, in minutes. |
|
N |
The number of files in the bucket that can be listed by using the specified prefix. |
FAQ
|
Problem |
Possible cause |
Solution |
|
No data appears in the preview. |
There are no files in the GCS bucket, the files are empty, or no files match the filter criteria. |
Verify that the GCS bucket contains non-empty files. For CSV files, ensure they contain more than just a header row. After confirming the files contain data, adjust the file path or time filter settings. |
|
The imported data contains garbled characters. |
The configured data format, compression format, or encoding format does not match the actual file format. |
Confirm the actual format of the GCS files and adjust the data format, compression format, or encoding format settings accordingly. Garbled data that has already been imported cannot be fixed. You must create a new Logstore and a new data import configuration to re-import the data. |
|
The timestamp of the data in Log Service does not match the timestamp in the source data. |
The log time field was not specified, or the time format or time zone was configured incorrectly. |
Specify the correct time field, time field format, and time zone. |
|
After importing data, I cannot query or analyze it. |
The data is outside the selected query time range, an index is not configured, or the index has not taken effect. |
1. Ensure your query's time range includes the timestamps of the imported data. 2. Verify that indexing is enabled for the Logstore. If not, create an index. 3. If an index already exists, try rebuilding it. |
|
The number of imported log entries is less than expected. |
Log Service discards any single log entry that exceeds 3 MB. |
Ensure that each line of data in the GCS files does not exceed 3 MB. |
|
Some files were not imported. |
The filter criteria are incorrect, or a file size exceeds 5 GB. |
Check if the files meet the filter criteria and ensure that their sizes do not exceed 5 GB. |
|
Multiline text log parsing fails. |
The start-of-line or end-of-line regular expression is incorrect. |
Check and correct the start-of-line or end-of-line regular expression. |
|
New file imports are delayed. |
A large number of existing files match the file path prefix filter. |
For directories with over one million files, use a more specific prefix. You can also create multiple import tasks with different prefixes to process the files in parallel. |
Error handling
|
Error |
Description |
|
Failed to read a file |
The system retries reading a file on network issues or corruption. The file is skipped after three failed attempts. The retry interval matches the new file check interval. If this interval is set to Never Check, the retry interval defaults to 5 minutes. |
|
Failed to parse compression format |
If the compression format is invalid, the file is skipped. |
|
Failed to parse data format |
If parsing fails, the original raw text is stored in the |
|
GCS bucket does not exist |
The import task retries periodically. The task automatically resumes after the bucket is recreated. |
|
Permission error |
The task retries periodically on permission errors (when reading from GCS or writing to the Logstore) without skipping the file. Once permissions are corrected, the task resumes and processes any pending files. |