Use AnalyticDB Pipeline Service (APS) to stream log data from Simple Log Service (SLS) to an AnalyticDB for MySQL cluster for real-time analysis, starting from a specified time.
Prerequisites
-
The AnalyticDB for MySQL cluster must be in the same region as the SLS project and Logstore. For more information, see Create a cluster and Create a project and a Logstore.
A database account is created for the AnalyticDB for MySQL cluster.
If you use an Alibaba Cloud account, you need to only create a privileged account.
If you use a Resource Access Management (RAM) user, you must create a privileged account and a standard account and associate the standard account with the RAM user.
-
A destination database and table are required in the AnalyticDB for MySQL cluster.
-
A job-specific resource group is required in the AnalyticDB for MySQL cluster (for Enterprise Edition, Basic Edition, or Data Lakehouse Edition only).
Limitations
Currently, a table in an AnalyticDB for MySQL cluster can be synchronized with only one Logstore. If you need to synchronize multiple Logstores, create multiple data tables.
Billing
Elastic resources are billed pay-as-you-go based on the ACUs used by the data link. For details, see Pricing.
Steps
You can create sync tasks in the Log Service console or the AnalyticDB for MySQL console. The differences are as follows:
-
Create a sync task on the Log Service console: This method allows you to import SLS data from the same Alibaba Cloud account only. Simply create a data synchronization link, and the system automatically creates an SLS data source based on the
SLS ProjectandSLS logstoreparameters you specify. -
Create a sync task on the AnalyticDB for MySQL console: This method allows you to import SLS data across Alibaba Cloud accounts. You must first create an SLS data source and then create a data synchronization link based on it.
Create a sync task
Step 1: Create a data source and data link
Log on to the Simple Log Service console.
-
In the Project list, click the target Project. In the left-side navigation pane, click the
icon, go to the Logstores tab, and then expand the target Logstore. -
Click , and then click the + icon next to AnalyticDB.
-
In the Shipping Note dialog box, select Create in AnalyticDB for MySQL Console.
This dialog box indicates that direct shipping sends all newly written data to the destination. If you need to process data, such as by filtering, converting formats, or enriching data, or if you need to ship historical data, you can use the Data Transformation feature. This requires staging the data in a temporary Logstore and then creating a direct shipping task from it.
-
On the AnalyticDB for MySQL Log Synchronization page, configure the parameters in the Source and Destination Settings, Destination Database and Table Settings, and Synchronization Settings sections.
-
The following table describes the parameters for Source and Destination Settings.
Parameter
Description
Job Name
The name of the synchronization job. The system generates a name based on the data source type and the creation time. You can modify the name as needed.
Simple Log Service Project
The source SLS Project.
Simple Log Service Logstore
The source SLS Logstore.
Destination AnalyticDB for MySQL Cluster
Select the destination AnalyticDB for MySQL cluster.
AnalyticDB for MySQL Account
The database account for the AnalyticDB for MySQL cluster.
AnalyticDB for MySQL Password
The password for the AnalyticDB for MySQL database account.
-
Destination Database and Table Settings
Parameter
Description
Database Name
The name of the database in the AnalyticDB for MySQL cluster.
Table Name
The name of the destination table in the AnalyticDB for MySQL cluster.
Source Data Preview
Click View Latest 10 Logstore Data Entries to preview the 10 most recent entries from the source SLS logstore.
Schema Field Mapping
The AnalyticDB for MySQL cluster table fields automatically populate the Destination Field and Source Field. If the mapping between the Destination Field and Source Field is incorrect, modify it manually.
For example, if a field in a data table of an AnalyticDB for MySQL cluster is named
nameand the source data field in SLS is nameduser_name, the system automatically populates the Source Field and Destination Field withname. In this case, you must manually change the Source Field touser_name. -
The following table describes the parameters for Synchronization Settings.
Parameter
Description
Start Offset
Specifies the point in time from which the synchronization job starts consuming SLS data.
For example, if you set the Start Offset to 2024-04-09 13:10, the system starts consuming data from the first record created after 13:10 on April 9, 2024.
Dirty Data Processing Mode
Synchronization can fail if a source field's data type is incompatible with the corresponding destination field's type. For example, if the source data is
abcand the destination field type isint, a conversion error occurs, causing synchronization to fail.The following modes are available for handling dirty data:
-
Stop Synchronization (Default): The synchronization job stops. You must modify the destination field type or select a different dirty data processing mode, and then restart the job.
-
Treat as Null: Dirty data is converted to NULL and written to the destination table. The original dirty data is discarded.
For example, if a row in SLS has three fields (col1, col2, and col3) and the data in col2 is dirty, the value of col2 is set to NULL, while the data in col1 and col3 is written as usual.
Convert UNIX Timestamp into Datetime
If the source SLS field is a Unix timestamp (for example, 1710604800) and the destination field type is DATETIME or TIMESTAMP, enable this feature to convert the value. After you enable this option, select the precision of the source timestamp: Timestamp Accurate to Seconds, Timestamp Accurate to Milliseconds, or Timestamp Accurate to Microseconds.
Job Resource Group
Select the job-specific resource group to run the incremental sync task.
ImportantThis parameter applies only to AnalyticDB for MySQL clusters of the Enterprise Edition, Basic Edition, or Data Lakehouse Edition.
ACUs for Incremental Synchronization
-
The initial number of ACUs for the incremental sync task is fixed at 1.
-
After the data link is created, AnalyticDB for MySQL automatically scales the number of ACUs for the task based on the workload, from a minimum of 1 ACU to a maximum of 64 ACUs.
ImportantThis parameter applies only to AnalyticDB for MySQL clusters of the Enterprise Edition, Basic Edition, or Data Lakehouse Edition.
-
-
-
After you configure the parameters, click Submit.
The system automatically creates a Simple Log Service data source and a data link in AnalyticDB for MySQL and redirects you to the Simple Log Service/Kafka Data Synchronization page in the AnalyticDB for MySQL console.
Step 2: Start the sync task
-
In the Actions column for the target data link, click Start.
-
After starting the task, click Search in the upper-right corner. The sync task has started successfully when its status changes to Running.
Step 3: Manage the sync task
In the Actions column, you can perform the following operations:
|
Actions |
Description |
|
Start |
Starts the sync task. |
|
View Details |
View details of the sync task, including source and destination settings, run logs, and monitoring metrics. |
|
Edit |
Edit the task settings, such as the Start Offset and field mappings. |
|
Pause |
Pauses the sync task. To resume the task, click Start. Synchronization resumes from the offset where it was paused. |
|
Delete |
Deletes the sync task. This operation cannot be undone. Proceed with caution. |
Create a synchronization job in the AnalyticDB for MySQL console
Step 1: Configure RAM authorization (optional)
If you are synchronizing Simple Log Service (SLS) data within the same Alibaba Cloud account, you can skip this step and proceed to Step 2: Create a data source.
For cross-account synchronization of Simple Log Service (SLS) data to AnalyticDB for MySQL, you must create a RAM role in the source account, grant the role fine-grained authorization, and modify its trust policy.
-
Create a RAM role. For more information, see Create a RAM role for a trusted Alibaba Cloud account.
NoteWhen you configure the Select Trusted Alibaba Cloud Account parameter, select Other Alibaba Cloud Account and enter the account ID of the Alibaba Cloud account that contains the AnalyticDB for MySQL cluster. You can find the account ID on the Overview page in the Account Center.
-
Use fine-grained authorization to grant the AliyunAnalyticDBAccessingLogRolePolicy permission to the RAM role.
-
Modify the trust policy of the RAM role to allow the AnalyticDB for MySQL cluster in the specified Alibaba Cloud account to assume this role.
{ "Statement": [ { "Action": "sts:AssumeRole", "Effect": "Allow", "Principal": { "RAM": [ "acs:ram::<Alibaba Cloud account ID>:root" ], "Service": [ "<Alibaba Cloud account ID>@ads.aliyuncs.com" ] } } ], "Version": "1" }NoteReplace
<Alibaba Cloud account ID>with the account ID of the Alibaba Cloud account that contains the AnalyticDB for MySQL cluster, as specified in Step 1. Do not include the angle brackets (<>).
Step 2: Create a data source
If you have already added an SLS data source, you can skip this step and proceed to Step 3: Create a synchronization job.
Log on to the AnalyticDB for MySQL console. In the upper-left corner of the console, select a region. In the left-side navigation pane, click Clusters. Find the cluster that you want to manage and click the cluster ID.
-
In the left-side navigation pane, choose .
-
In the upper-right corner, click Create Data Source.
-
On the Create Data Source page, configure the parameters as described in the following table.
Parameter
Description
Data Source Type
Select SLS.
Data Source Name
The system generates a name based on the data source type and the creation time. You can modify the name as needed.
Data Source Description
An optional description of the data source, such as its use case or business-related constraints.
Deployment Mode
Only Alibaba Cloud Instance is supported.
Region of Simple Log Service Project
The region where the SLS project is located.
NoteYou can only select the region where your AnalyticDB for MySQL cluster is located.
Across Alibaba Cloud Accounts
AnalyticDB for MySQL clusters can synchronize SLS data from the same Alibaba Cloud account or a different one (cross-account).
-
No: Synchronize SLS data from the current Alibaba Cloud account to the AnalyticDB for MySQL cluster.
-
Yes: Synchronize SLS data from a different Alibaba Cloud account to the AnalyticDB for MySQL cluster. If you select Yes, you must configure RAM authorization and specify the Alibaba Cloud Account and RAM Role. For more information about RAM authorization, see Step 1: Configure RAM authorization (optional).
Note-
Alibaba Cloud Account: The account ID of the Alibaba Cloud account that contains the SLS project.
-
RAM Role: The RAM role in the Alibaba Cloud account that contains the SLS project. This is the RAM role that you created in Step 1.
-
Simple Log Service Project
The source SLS project.
Simple Log Service Logstore
The source SLS logstore.
-
-
After you configure the parameters, click Create.
Step 3: Create a synchronization job
-
In the left-side navigation pane, choose .
-
In the upper-right corner, click Create Synchronization Job.
-
On the Create Synchronization Job page, configure the Source and Destination Settings, Destination Database and Table Settings, and Synchronization Settings sections. The parameters are described in the following tables.
-
Source and Destination Settings
Parameter
Description
Job Name
The name of the synchronization job. The system generates a name based on the data source type and the creation time. You can modify the name as needed.
Data Source
Select an existing SLS data source, or create a new one.
Destination Type
-
For Enterprise Edition, Basic Edition, and Data Lakehouse Edition clusters, select Data Warehouse - ADB Storage.
-
This parameter does not apply to Data Warehouse Edition clusters.
AnalyticDB for MySQL Account
The database account for the AnalyticDB for MySQL cluster.
AnalyticDB for MySQL Password
The password for the AnalyticDB for MySQL database account.
-
-
Destination Database and Table Settings
Parameter
Description
Database Name
The name of the database in the AnalyticDB for MySQL cluster.
Table Name
The name of the destination table in the AnalyticDB for MySQL cluster.
Source Data Preview
Click View Latest 10 Logstore Data Entries to preview the 10 most recent entries from the source SLS logstore.
Schema Field Mapping
The AnalyticDB for MySQL cluster table fields automatically populate the Destination Field and Source Field. If the mapping between the Destination Field and Source Field is incorrect, modify it manually.
For example, if a field in a data table of an AnalyticDB for MySQL cluster is named
nameand the source data field in SLS is nameduser_name, the system automatically populates the Source Field and Destination Field withname. In this case, you must manually change the Source Field touser_name. -
Synchronization Settings
Parameter
Description
Start Offset
Specifies the point in time from which the synchronization job starts consuming SLS data.
For example, if you set the Start Offset to 2024-04-09 13:10, the system starts consuming data from the first record created after 13:10 on April 9, 2024.
Dirty Data Processing Mode
Synchronization can fail if a source field's data type is incompatible with the corresponding destination field's type. For example, if the source data is
abcand the destination field type isint, a conversion error occurs, causing synchronization to fail.The following modes are available for handling dirty data:
-
Stop Synchronization (Default): The synchronization job stops. You must modify the destination field type or select a different dirty data processing mode, and then restart the job.
-
Treat as Null: Dirty data is converted to NULL and written to the destination table. The original dirty data is discarded.
For example, if a row in SLS has three fields (col1, col2, and col3) and the data in col2 is dirty, the value of col2 is set to NULL, while the data in col1 and col3 is written as usual.
Convert UNIX Timestamp into Datetime
If the source SLS field is a Unix timestamp (for example, 1710604800) and the destination field type is DATETIME or TIMESTAMP, enable this feature to convert the value. After you enable this option, select the precision of the source timestamp: Timestamp Accurate to Seconds, Timestamp Accurate to Milliseconds, or Timestamp Accurate to Microseconds.
-
-
-
After you configure all the parameters, click Submit.
Step 4: Start the data synchronization job
-
On the Data Synchronization page, find the synchronization job you created. In the Actions column, click Start.
-
In the upper-right corner, click Search. The job starts successfully when its status changes to Running.
Step 5: Manage the synchronization job
On the Data Synchronization page, you can perform the following operations in the Actions column.
|
Actions |
Description |
|
Start |
Starts the data synchronization job. |
|
View Details |
Displays the details of the synchronization job, including source and destination configurations, run logs, and monitoring metrics. |
|
Edit |
Edit job settings, such as the start offset and field mappings. |
|
Pause |
Pauses the synchronization job. To resume synchronization, click Start. The job automatically resumes from the offset where it was paused. |
|
Delete |
Deletes the synchronization job. This action cannot be undone. Proceed with caution. |