Simple Log Service is an all-in-one logging service developed by Alibaba Cloud. Simple Log Service allows you to collect, consume, ship, query, and analyze log data without development work. After Simple Log Service is enabled on Knative, you can manage and maintain serverless applications with higher efficiency. This topic describes how to enable Simple Log Service on Knative. This way, you can collect container logs of serverless applications in a production environment and analyze log data to meet O&M requirements.
Prerequisites
Simple Log Service is activated. For more information, see Use Simple Log Service to collect container logs.
Knative is deployed in the cluster. For more information, see Deploy Knative.
Step 1: Deploy a Service
In this example, a Knative Service named helloworld-go
is deployed. For more information, see Use Knative to deploy serverless applications.
Step 2: Enable log collection for the Service
Log on to the ACK console. In the left-side navigation pane, click Clusters.
On the Clusters page, click the name of the cluster that you want to manage and click Cluster Information in the left-side navigation pane.
On the Cluster Information page, click the Cluster Resources tab, and then click the link next to Log Service Project.
In the lower-left corner of the helloworld-go project page, click Import Data to enable log collection for the helloworld-go Service.
For more information, see Use the Simple Log Service console to collect container stdout and stderr in DaemonSet mode.
In the Quick Data Import dialog box, click Integrate Now in the Docker Stdout and Stderr - Container card. Then, click Continue to open the Docker Stdout and Stderr wizard.
In the Specify Logstore step, confirm the project and click Next.
Configure Create Machine Group.
The ogtail-ds component is installed as a prerequisite. Therefore, click Use Existing Machine Groups.
You can select Kubernetes Cluster (Recommended) or Standard Docker Container. For more information, see Collect log data from containers by using Simple Log Service and Collect logs from standard Docker containers.
Configure Machine Group Settings and click Next.
In the Specify Data Source step, click Switch to Editor Configuration and configure Plug-in Configuration.
In this example, the environment variable is set to
"K_SERVICE": "helloworld-go"
. Use processors to process log data. Example:"Keys": [ "time","level", "msg" ]
. The following code block is an example:{ "inputs": [ { "detail": { "IncludeEnv": { "K_SERVICE": "helloworld-go" }, "IncludeLabel": {}, "ExcludeLabel": {} }, "type": "service_docker_stdout" } ], "processors": [ { "detail": { "KeepSource": false, "NoMatchError": true, "Keys": [ "time", "level", "msg" ], "NoKeyError": true, "Regex": "(\\d+-\\d+-\\d+\\s+\\d+:\\d+:\\d+)\\s+(\\w+)\\s+(.*)", "SourceKey": "content" }, "type": "processor_regex" } ] }
After you configure the data source, click Next.
In the Query and Analysis Configurations step, turn on Full Text Index and configure indexes for query fields.
Click Next to go to the End step.
Run the following command to access the helloworld-go Service:
The following log data is generated:
curl -H "Host: helloworld-go.default.example.com" http:<Gateway IP address> # The actual IP address and domain name of the gateway are displayed.
Expected output:
Hello Knative!
In the Logstores section, move the pointer over the icon and select to view the log data.
Configure statements to query and analyze logs.
For more information about how to query and analyze logs, see Query and analyze logs.