If your log data resides in a Simple Log Service Logstore and your structured data resides in an ApsaraDB RDS for MySQL database, use the data transformation feature to access the database through its internal endpoint and enrich your log data.
How it works
The following figure shows how the data transformation feature accesses an ApsaraDB RDS for MySQL database through its internal endpoint to enrich log data.
Solution overview
To enrich log data using the Simple Log Service data transformation feature and an ApsaraDB RDS for MySQL internal endpoint, complete the following three steps:
-
Query the advanced parameters required for a data transformation job: Log on to the ApsaraDB RDS console to retrieve the ApsaraDB RDS for MySQL instance information. Then, call an API operation in OpenAPI Explorer to obtain the advanced parameters.
-
Enable a data transformation job in the source Logstore: Configure a data transformation rule to enrich the log data.
-
Save the transformation results to the destination Logstore: Save the enriched data to the destination Logstore.
Prerequisites
-
You have raw log data.
-
Your ApsaraDB RDS for MySQL instance and your Simple Log Service project are located in the same region.
Step 1: Query the advanced parameters required for a data transformation job
-
Log on to the ApsaraDB RDS console.
-
In the left navigation pane, click Instances. On the Instances page, locate and click the target instance.

-
Configure an IP address whitelist. For more information, see Configure a whitelist.
-
In the left navigation pane, click . Enter a group name and the IP addresses in the group. Set the IP addresses to
100.104.0.0/16.
-
-
Retrieve the instance ID and internal port.
-
In the left navigation pane, click Basic Information. On the Basic Information page, locate and copy the Instance ID.

-
In the left navigation pane, click Database Connection. On the Database Connection page, view and copy the Internal Port.

-
-
Retrieve the
VpcIdandVpcCloudInstanceIdof the instance.-
Visit OpenAPI Explorer. In the section, locate the DBInstanceIdInstance ID text box and paste the copied instance ID. For more information about the API operation, see DescribeDBInstanceAttribute.

-
Click Call. On the Response tab, copy the values of
VpcIdandVpcCloudInstanceId.
-
Step 2: Enable a data transformation job in the source Logstore
-
Log on to the Simple Log Service console.
-
Go to the data transformation page.
-
In the Projects section, click the target project.

-
On the tab, click the target Logstore.

-
On the query and analysis page, click Data Transformation.

-
On the data transformation page, click Switch to Data Transformation (Legacy).

-
-
Add the advanced parameter configuration.
-
In the upper-right corner of the page, select Advanced. Then, click Preview Data.

-
On the Add Preview Settings page, click Advanced Options and add the following configuration.
ImportantYou can replace
your_namein all parameters with a custom value. Use the same value across all parameters. Also use this value to replaceyour_namein the transformation rule.Parameter
Value
Description
config.vpc.vpc_id.your_name
vpc-uf6mskb0b****n9yj
The VPC ID of the instance.
For more information, see Get the VPC ID of the instance.
config.vpc.instance_id.your_name
rm-uf6e61k****ahd7-2024091513
The instance ID.
For more information, see Get the VpcCloudInstanceId of the instance.
For a self-managed MySQL database in the same Alibaba Cloud region, use config.vpc.instance_ip.your_name to specify its VPC IP address.
config.vpc.instance_port.your_name
3306
The port number of the destination instance's private network address.
For more information, see Get the internal port of the instance.
The following figure shows a sample configuration.

-
After confirming the configuration, click OK in the lower-right corner.

-
-
Edit the transformation rule.
-
Add the following statement in the editor.
For syntax examples and details about enrichment functions and resource functions, see Enrich data by pulling from an ApsaraDB RDS for MySQL database and Resource functions.
/* e_table_map() The data enrichment function. res_rds_mysql() The pull function that retrieves table data or SQL execution results from an ApsaraDB RDS for MySQL database. str_format() The string formatting function. The value of your_name in res_local() must match the value of your_name in the advanced parameters. field The matching field. This field links log data in the Logstore to table data in the ApsaraDB RDS for MySQL database. A match succeeds only when the field value in the log matches the field value in the table. output_fields The output fields. When a match succeeds, the values of these fields are returned to generate a new log entry. */ e_table_map( res_rds_mysql( str_format("{}:{}", res_local("config.vpc.instance_id.your_name"), res_local("config.vpc.instance_port.your_name")), "Database account", "Database password", "Database name", table="Name of the required table in the database" ), "field", "output_fields" )The following figure shows the transformation statement.
This rule matches the
process_time_in_msfield in a Simple Log Service Logstore with theprocess_time_in_msfield in an RDS for MySQL table. A match is successful only if the values of theprocess_time_in_msfield are identical. If the match is successful, the rule returns themodelandpurchase_pricefields and their values from the RDS for MySQL table. This data is then concatenated with the data from the Logstore to generate new data.
-
-
In the upper-right corner of the data transformation page, click Preview Data to transform the data.

-
View the transformation results.
The following figure shows results when the rule fails to match.

The following figure shows results when the rule matches successfully.

Step 3: Save the transformation results to the destination Logstore
-
Click Save as Transformation Job (Legacy) in the lower-right corner. In the panel that appears, enter the required information and click OK.

-
On the Logstores tab, click the destination Logstore. In the upper-right corner of the page that appears, specify a query time range.
After selecting the time range, check whether the transformation results appear on the Raw Logs tab. The following figure confirms successful saving.

Appendix: Access an AnalyticDB for MySQL or PolarDB for MySQL database over an internal endpoint
Simple Log Service supports accessing ApsaraDB RDS for MySQL, AnalyticDB for MySQL, and PolarDB for MySQL databases over internal endpoints. The following list describes the settings:
-
AnalyticDB for MySQL databases
When configuring Advanced Parameter Settings, set config.vpc.instance_id.your_name to the AnalyticDB for MySQL instance ID followed by -controller, as shown in the following figure. Configure other parameters as described in this topic.

-
PolarDB for MySQL databases: Configure parameters as described in this topic.