All Products
Search
Document Center

Container Service for Kubernetes:Enable Simple Log Service on Knative

Last Updated:Mar 04, 2024

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

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

  1. Log on to the ACK console. In the left-side navigation pane, click Clusters.

  2. 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.

  3. On the Cluster Information page, click the Cluster Resources tab, and then click the link next to Log Service Project.

  4. 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.

    1. 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.

      指定采集模式

    2. In the Specify Logstore step, confirm the project and click Next.

    3. 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.

    4. Configure Machine Group Settings and click Next.

    5. 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"
          }
        ]
      }
    6. After you configure the data source, click Next.

    7. In the Query and Analysis Configurations step, turn on Full Text Index and configure indexes for query fields.

    8. Click Next to go to the End step.

  5. 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!
  6. In the Logstores section, move the pointer over the 日志库图标 icon and select 日志库图标 > Search & Analysis to view the log data.

    image.png

  7. Configure statements to query and analyze logs.

    For more information about how to query and analyze logs, see Query and analyze logs.