Log Service (SLS) supports shipping log data to MaxCompute (ODPS) for storage and analysis. Create a MaxCompute data shipping job (new version) to set up the data pipeline.
Prerequisites
-
You have created a project and a logstore in Log Service (SLS) and configured data collection. For more information, see Manage a project, Create a basic logstore, and Data collection overview.
-
You have created a MaxCompute (ODPS) partitioned table in the same region as the Log Service (SLS) project. For more information, see Create a table.
Usage notes
-
For information about the regions that support shipping data to MaxCompute (ODPS), see Supported regions.
-
If the value of a field of the
charorvarchartype exceeds the specified length, the excess part is truncated when shipped to MaxCompute (ODPS).For example, if the length limit is 3 and the field value is
012345, the value becomes012after being shipped to MaxCompute (ODPS). -
If the value of a field of the
string,char, orvarchartype is an empty string, its value becomes Null after being shipped to MaxCompute (ODPS). -
The value of a field of the
datetimetype must be in theYYYY-MM-DD HH:mm:ssformat. Multiple spaces are allowed betweenDDandHH. An invalid format does not cause a shipping error, but the value becomes Null after being shipped to MaxCompute (ODPS). -
If the value of a field of the
datetype is in an invalid format, the data shipping job does not report an error, but the value becomes Null after being shipped to MaxCompute (ODPS). -
For a decimal field, if its value exceeds the defined scale, the system rounds it. If the value exceeds the defined precision, the system discards the entire log as dirty data and increments the error count.
-
By default, the system discards dirty data during data shipping.
-
If a field specified in the shipping configuration does not exist in a log, its value in MaxCompute (ODPS) becomes the default value or Null.
-
If you specified a default value when you created the MaxCompute (ODPS) table, the field is assigned the default value.
-
If you did not specify a default value but the column allows Null values, the field value becomes Null.
-
-
Due to MaxCompute (ODPS) limitations, the maximum data shipping concurrency is 64 write operations. The maximum throughput for a single partition is 10 MB/s.
Procedure
Log on to the Simple Log Service console.
-
In the Projects section, click the project you want.
-
On the tab, click the > icon to the left of the target logstore, and then choose .
-
Hover the pointer over MaxCompute (ODPS) and click the + icon.
-
In the Data Shipping to MaxCompute panel, configure the following parameters and click OK.
After you create a data shipping job, log data is typically imported into MaxCompute (ODPS) within one hour of being written to the logstore. You can then query the data in MaxCompute (ODPS). For more information, see How do I check the integrity of data after it is shipped from Log Service to MaxCompute?
| log_source | log_time | log_topic | time | ip | thread | log_extract_others | log_partition_time | status | +------------+------------+-----------+-----------+-----------+-----------+------------------+--------------------+-----------+ | 10.10.*.* | 1642942213 | | 24/Jan/2022:20:50:13 +0800 | 10.10.*.* | 414579208 | {"url":"POST /PutData?Category=YunOsAccountOpLog&AccessKeyId=****************&Date=Fri%2C%2028%20Jun%202013%2006%3A53%3A30%20GMT&Topic=raw&Signature=******************************** HTTP/1.1","user-agent":"aliyun-sdk-java"} | 2022_01_23_20_50 | 200 | +------------+------------+-----------+-----------+-----------+-----------+------------------+--------------------+-----------+
Data model mapping
To ship logs from Log Service (SLS) to a MaxCompute (ODPS) table, you must map the data models of the two services. The following section describes the mapping rules and provides examples.
-
A MaxCompute (ODPS) table must contain at least one data column and one partition key column.
-
We recommend that you use the following Log Service (SLS) reserved fields: __partition_time__, __source__, and __topic__.
-
A MaxCompute (ODPS) table can have a maximum of 60,000 partitions. If this limit is exceeded, data cannot be written to the table.
-
The system reserved field __extract_others__ was previously named _extract_others_. The old name is still supported for compatibility.
-
The values of MaxCompute (ODPS) partition key columns cannot be MaxCompute (ODPS) reserved words or keywords. For more information, see Reserved words and keywords.
-
Partitions in a MaxCompute (ODPS) partitioned table cannot be empty. You must map a specific field, such as a system reserved field or a log field, to a partition key column. The value of the mapped field cannot be empty or null. If a log field is of the string type, it must be convertible to the data type of the partition key column. If the conversion fails and results in an empty partition key, the system discards the log during shipping.
-
In Log Service (SLS), a log field can be mapped to only one column in a MaxCompute (ODPS) table, either a data column or a partition key column. Field redundancy is not supported.
The following table shows an example of the mapping relationship between MaxCompute (ODPS) columns and Log Service (SLS) fields. For more information about Log Service (SLS) reserved fields, see Reserved fields.
|
MaxCompute column type |
Column name (MaxCompute) |
Data type (MaxCompute) |
Log field name (Log Service) |
Field type (Log Service) |
Description |
|
Data column |
log_source |
string |
__source__ |
Reserved field |
The source of the log. |
|
log_time |
bigint |
__time__ |
Reserved field |
The time of the log in Unix timestamp format. This corresponds to the time field in the data model. |
|
|
log_topic |
string |
__topic__ |
Reserved field |
The topic of the log. |
|
|
time |
string |
time |
Log field |
A field parsed from the log content, corresponding to a key-value pair in the data model. In many cases, the value of the |
|
|
ip |
string |
ip |
Log field |
A field parsed from the log content. |
|
|
thread |
string |
thread |
Log field |
A field parsed from the log content. |
|
|
log_extract_others |
string |
__extract_others__ |
Reserved field |
The system serializes other unmapped log fields into a flat key-value JSON object. Nested JSON objects are not supported. |
|
|
Partition key column |
log_partition_time |
string |
__partition_time__ |
Reserved field |
Log Service (SLS) calculates this value from the log's __time__ field and then aligns it. The partition granularity is configurable. |
|
status |
string |
status |
Log field |
A field parsed from the log content. The values of this field can be enumerated to ensure the number of partitions does not exceed the limit. |
Time partition format
MaxCompute data shipping (new version) supports two time partition formats: StrfTimeFormat and SimpleDateFormat. The time partition format takes effect only when the field in the MaxCompute partition key column is set to __partition_time__ or __receive_time__.
StrfTimeFormat
strftime is a standard UNIX C library function that formats dates and times. It uses format codes starting with a % character to convert a time partition into a string. For example, %Y_%m_%d represents the year, month, and day.
If you create a new MaxCompute (ODPS) data shipping job, you must use StrfTimeFormat.
|
Time partition format |
Table partition example |
|
%Y_%m_%d_%H_%M_00 |
2024_12_27_20_30_00 |
|
%Y_%m_%d_%H_%M |
2024_12_27_20_30 |
|
%Y_%m_%d_%H |
2024_12_27_20 |
|
%Y_%m_%d |
2024_12_27 |
|
%Y_%m |
2024_12 |
|
%Y |
2024 |
|
%Y%m%d%H%M |
202412272030 |
|
%Y%m%d%H |
2024122720 |
|
%Y%m%d |
20241227 |
|
%Y%m |
202412 |
SimpleDateFormat
The time format in Java SimpleDateFormat syntax, such as yyyy-MM-dd HH:mm. For more information, see Class SimpleDateFormat.
SimpleDateFormat is supported for backward compatibility when migrating from an older version. For new MaxCompute tasks, use StrfTimeFormat.
Legacy migration tasks support the following partition formats:
|
Partition time format |
Table partition example |
|
yyyy-MM-ddHH:mm |
2024-12-2720-30 |
|
yyyy_MM_dd_HH_mm |
2024_12_27_20_30 |
|
yyyy_MM_dd_HH |
2024_12_27_20 |
|
yyyy-MM-dd HH:mm |
2024-12-27 20:30 |
|
yyyyMMddHHmm |
202412272030 |
|
yyyyMMddHH |
2024122720 |
|
yyyyMMdd |
20241227 |
|
yyyy_MM-dd_HH_mm |
2024_12-27_20_30 |
|
yyyy-MM-dd |
2024-12-27 |
Reference information
-
The __partition_time__ field
A common way to filter data in MaxCompute is to use log time as a partition key column.
-
Format
The __partition_time__ field is derived from the __time__ field in Log Service (SLS). It generates a time string based on the time zone and partition time format. To avoid exceeding the partition limit for a single MaxCompute table, the date partition key value is aligned to 1800-second (half-hour) intervals.
For example, if the log time in Log Service is 27/Jan/2022 20:50:13 +0800, SLS calculates the reserved field __time__ as 1643287813 (Unix timestamp). The following table shows the values of the time partition key column for different configurations.
Partition time format
__partition_time__
%Y_%m_%d_%H_%M_00
2022_01_27_20_30_00
%Y_%m_%d_%H_%M
2022_01_27_20_30
%Y%m%d
20220127
-
Usage
Using __partition_time__ to filter data avoids a full-table scan. For example, to query log data for December 26, 2024:
select * from {ODPS_TABLE_NAME} where log_partition_time >= "2024_12_26" and log_partition_time < "2024_12_27";
-
-
The
__receive_time__fieldA common way to filter data in MaxCompute is to use the log arrival time as a partition key column.
-
Format
Partition time format
__receive_time__
%Y_%m_%d_%H_%M_00
2022_01_27_20_30_00
%Y_%m_%d_%H_%M
2022_01_27_20_30
%Y%m%d
20220127
-
-
The __extract_others__ and __extract_others_all__ fields
-
The __extract_others__ field contains all unmapped fields from the log fields, excluding __topic__, __tag__:*, and __source__.
-
The __extract_others_all__ field contains all unmapped fields from the log fields, including __topic__, __tag__:*, and __source__.
-
Shipping modes
MaxCompute data shipping (new version) supports two shipping modes: real-time shipping and batch shipping.
-
Real-time shipping: Instantly reads data from a Logstore and ships it to MaxCompute.
-
Batch shipping: Reads data from a Logstore that arrived 5 to 10 minutes ago and ships it to MaxCompute.
If you set the Shipping mode to Batch shipping, align the Start Time or End Time in the Start Time Range to 5-minute intervals. For example,
2022-05-24 16:35:00is a valid setting, but2022-05-24 16:36:00is an invalid setting.Batch shipping also supports shipping the __receive_time__ field. The __receive_time__ field indicates the time when a log is received by Log Service (SLS). Set its format using the time partition format. The maximum precision is half an hour. For more information about the time partition format, see Time partition format.
If you want to ship this field, add it to the MaxCompute partition key column.
icon to expand it, as shown in the following figure: