This topic explains how to configure the application log feature for a fully managed service in an ACK deployment scenario.
How it works
In an ACK scenario, Compute Nest uses the ACK log add-on to manage logs.
Your application runs as a Deployment or StatefulSet in the cluster. Compute Nest adds environment variables and pseudo-parameters to your application for dynamic tagging and unified collection of tenant application logs. The following diagram illustrates this process:

Create a service with application logs
Overview
-
The service provider prepares the necessary Simple Log Service (SLS) resources. This includes a Project, Logstores, and log collection configurations, which may vary depending on the deployment scenario.
-
You must configure delegated O&M permissions to allow users to view application logs for a service instance.
Procedure
This section provides detailed steps for each configuration scenario.
Step 1: Prepare SLS resources
Data transfer for Simple Log Service (SLS) between different regions can be costly. Therefore, you must configure a separate SLS Project, application-specific Logstores, and log collection settings for each region where your service is deployed. To simplify this process, Compute Nest provides a generic log resource preparation service that helps you initialize your SLS Projects and Logstores.
For example, assume your service needs to be deployed in the Beijing and Shanghai regions and the application needs to collect slow*.log and error*.log files. You must do the following:
For single-tenant or multi-tenant ACK scenarios:
-
Required resources: an ACK cluster, one SLS Project in the Beijing region, and one in the Shanghai region. For each Project, create two Logstores. For example, create a Logstore named
slowto collectslow*.logand another namederrorto collecterror*.log. -
Use the Compute Nest SLS resource quick preparation service to complete the configuration.
-
If you have an existing cluster:
-
Select the deployment region and set the deployment scenario to ACK. On the Create Service Instance page, for Select Template, select ack. Enter a Service Instance Name. The name must be up to 64 characters long, start with a letter, and contain only digits, letters, hyphens (-), and underscores (_). For Region, select China (Shanghai).
-
Configure the Project name and Logstore names. In the SLS Project Configuration section, set SLS Project Name to
log-service-shanghai. The name must be globally unique, 3 to 63 characters long and can contain only lowercase letters, digits, and hyphens (-). In the SLS Logstore Name Array field, add two Logstores:slowanderror. The name must be 3 to 63 characters long and can contain only lowercase letters, digits, hyphens (-), and underscores (_). You can click + Add to add more Logstores. -
Important
If the logtail-ds add-on is not installed on the cluster, you must install ACK Logtail. You can check the installation status in the ACK console under **Add-ons** > **Log and Monitoring**.
In the ACK Cluster Configuration section, enable the Create New ACK Cluster and Install ACK Logtail switches. From the Cluster ID drop-down list, select the target cluster. To create a new cluster, click Create Cluster.
-
-
If you do not have a cluster:
-
Configure the logging settings. For Select Template, select ack. Enter the Service Instance Name and select the Region. In the SLS Project Configuration section, set the SLS Project Name (for example,
app-log-demo) and the SLS Logstore Name Array (for example,slow-log). You can click + Add to add more Logstores. -
Select to create a new ACK cluster and configure the parameters. In the ACK Cluster Configuration section, enable the Create ACK Cluster switch. For Billing Method, select Pay-as-you-go. In the Basic Configurations section, select an availability zone such as Availability Zone J. Set VPC IPv4 CIDR Block to
192.168.0.0/16and VSwitch Subnet CIDR Block to192.168.1.0/24. Then, set the Instance Password. The password must be 8 to 30 characters in length and contain characters from at least three of the following types: uppercase letters, lowercase letters, numbers, and special symbols. -
Wait for the service instance to be created.
-
-
Step 2: Create a fully managed service
-
Log on to the Compute Nest console.
-
In the left-side navigation pane, choose My Services. On the My Services page, click the Services I Created tab and then click Create New Service.
-
On the Create New Service page, configure the service information.
This section describes only the O&M parameters that require special configuration. For information about other parameters, see Create a fully managed service.
-
Modify the service template.
-
For an ACK scenario, add environment variables to your Deployment or StatefulSet template.
-
The following is a sample template. In the environment variables, ${key} is a placeholder for the name of your Logstore, which corresponds to the Logstore Name that you configured earlier.
-
In the sample template, dynamically replace ${key} in the first three environment variables, and then copy them to your ROS template. Keep the other parts of the variables unchanged.
-
Add the fixed configuration section directly to the environment variables in your ROS template. This section requires no changes.
ImportantIn an ACK deployment scenario, the ${key} value in the environment variables must match the created Logstore name and must not contain underscores (_).
- | apiVersion: apps/v1 kind: StatefulSet metadata: name: '{{ serviceInstanceId }}' spec: serviceName: '{{ serviceInstanceId }}' replicas: ${Replicas} selector: matchLabels: app: mysql template: metadata: labels: app: mysql spec: containers: - name: mysql image: mysql:latest env: # Specify the Project to which the application logs are delivered. - name: 'aliyun_logs_{{ serviceSls.slow-log.Logstore }}_project' value: '{{ serviceSls.LogProject }}' # Set the log file path. - name: aliyun_logs_{{ serviceSls.slow-log.Logstore }} value: '{{ serviceSls.slow-log.LogPath }}{{ serviceSls.slow-log.LogFilePattern }}' # Specify the Logstore for storing logs. - name: 'aliyun_logs_{{ serviceSls.slow-log.Logstore }}_logstore' value: '{{ serviceSls.slow-log.Logstore }}' # Fixed configuration. Specifies the log delivery tag. - name: aliyun_logs_serviceinstanceid_tags value: _service_instance_id={{ serviceInstanceId }} # Fixed configuration. Specifies the tags to be attached to logs delivered to SLS, in key=value format. - name: aliyun_logs_tenantid_tags value: _ali_uid_={{ aliUid }} -
-
In the Service O&M (Optional) section, under Logs, configure the application log information.
-
Enable Application Log. Select the corresponding SLS Project for each supported deployment region, and then click Add Log Collection Region.
NoteWhen you enable the application log feature, the supported deployment regions are automatically synchronized with the regions where log collection is enabled.
-
In the Add Logstore dialog box, configure the application log settings.
Parameter
Description
Region
The region where application log collection is supported.
Project
Select the Project in the specified region.
Logstore Name
The name of the SLS Logstore where the application logs are saved.
Path
The storage path for application logs.
All files matching the specified pattern in the directory and its subdirectories are monitored.
File Name
The application log filename.
You can specify a full name or a wildcard pattern. Environment variables are supported.
-
You must configure the Logstore name, path, and file name. Compute Nest collects text logs in simple mode from the user's account based on these configurations.
-
-
-
Click Create Service, and then click OK in the confirmation dialog box.
Step 3 (Optional): Grant users permission to view logs
In the Service O&M section, select the checkbox to grant permissions to the user, and then select read-only or full permissions from the drop-down list.
In the policy tags, add the AliyunComputeNestPolicyForReadOnly read-only policy.
Create a service instance and view logs
-
Create a service instance.
For more information, see Create a fully managed service instance.
-
View the application logs after the service instance is created:
-
On the service instance details page, click Log Management > Application Log.
-
On the Application Log tab, view the application log information for the service instance.
-
You can select a Logstore to view its specific log content, or click View in SLS Console to open the Simple Log Service console for more details.
On the Log Management page of the service instance, click the Application Log tab. Select slow-log from the Logstore drop-down list to view the list of slow query logs. Each log entry includes information such as the time, User@Host, Query_time, Lock_time, Rows_sent, Rows_examined, and the actual SQL statement that was executed.