Enable Tracing Analysis with AlbConfig

更新时间:
复制 MD 格式

Tracing Analysis helps developers of distributed applications visualize complete traces, collect request statistics, and understand service topologies. It allows you to quickly diagnose performance bottlenecks and improve efficiency for microservice development and diagnostics. To view trace data, install the ALB Ingress controller in your cluster and enable the Xtrace feature.

Prerequisites

Enable Tracing Analysis for AlbConfig

Step 1: Enable Simple Log Service

After you enable Simple Log Service, a Simple Log Service project is automatically created for the cluster. For more information, see Collect log data from containers in an ACK cluster.

Step 2: Obtain the Log Service Project

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

  2. On the Clusters page, click the name of your cluster. In the left navigation pane, click Cluster Information.

  3. On the Cluster Information page, click the Basic Information tab, and then copy and save the ID next to Log Service Project.

Step 3: Create an AlbConfig

Create an AlbConfig to provision an Application Load Balancer (ALB) instance and its listeners. This configuration also enables access logging for the ALB instance through Simple Log Service. In the AlbConfig, you will also configure Xtrace-related settings for the listener to enable tracing and set the sampling algorithm and rate.

  1. To create the AlbConfig, copy the following content into a file named alb-test.yaml.

    Note

    When you reuse an existing ALB instance and enable Log Service by using AlbConfig, you must set the forceOverride field to true to force an override of the ALB instance properties. For more information, see Reuse an existing ALB instance.

    apiVersion: alibabacloud.com/v1
    kind: AlbConfig
    metadata:
      name: alb-demo
    spec:
      config:
        name: alb-test
        addressType: Intranet
        zoneMappings: # The specified vSwitches must be in zones supported by the ALB instance and in the same VPC as the cluster. To ensure high availability, select vSwitches in at least two different zones.
        - vSwitchId: vsw-2vc82nndnoo********** # Set the vSwitch ID based on your actual configuration.
        - vSwitchId: vsw-2vc30f5mlhs**********
        accessLogConfig:
          logProject: "k8s-log-xz92lvykqj1siwvif****" # Use the ID of the Simple Log Service project that you obtained.
          logStore: alb_xz92lvykqj1siwvif**** # The Logstore name must start with 'alb_'. If the specified Logstore does not exist, it is automatically created.
      listeners:
      - port: 80
        protocol: HTTP
        logConfig:
          accessLogRecordCustomizedHeadersEnabled: false
          accessLogTracingConfig: # Xtrace parameters.
            tracingEnabled: true  # Specifies whether to enable Xtrace for the listener. Default value: false. Set this to true to enable Xtrace.
            tracingSample: 9999   # The Xtrace sampling rate for the listener. Valid values: 1 to 10000. This parameter takes effect only when tracingEnabled is true.
            tracingType: Zipkin   # The Xtrace sampling algorithm for the listener. Set the value to Zipkin. This parameter takes effect only when tracingEnabled is true.
    Note
    • For more information about how to create a vSwitch, see Create and manage vSwitches.

    • You can modify the Xtrace configuration only after you enable Simple Log Service access logs for the instance.

  2. Run the following command to create the AlbConfig:

    kubectl apply -f alb-test.yaml

    Expected output:

    albconfig.alibabacloud.com/alb-demo created

Step 4: Create an IngressClass

  1. To create an IngressClass, create a file named alb.yaml and add the following content.

    apiVersion: networking.k8s.io/v1
    kind: IngressClass
    metadata:
      name: alb
    spec:
      controller: ingress.k8s.alibabacloud/alb
      parameters:
        apiGroup: alibabacloud.com
        kind: AlbConfig
        name: alb-demo
  2. Run the following command to create the IngressClass:

    kubectl apply -f alb.yaml

    Expected output:

    ingressclass.networking.k8s.io/alb created

Step 5: Deploy a service and configure Ingress rules

  1. Create a file named cafe-service.yaml with the following content. This deploys a Deployment named coffee and a Service named coffee-svc.

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: coffee
    spec:
      replicas: 2
      selector:
        matchLabels:
          app: coffee
      template:
        metadata:
          labels:
            app: coffee
        spec:
          containers:
          - name: coffee
            image: registry.cn-hangzhou.aliyuncs.com/acs-sample/nginxdemos:latest
            ports:
            - containerPort: 80
    ---
    apiVersion: v1
    kind: Service
    metadata:
      name: coffee-svc
    spec:
      ports:
      - port: 80
        targetPort: 80
        protocol: TCP
      selector:
        app: coffee
      type: NodePort
  2. Run the following command to deploy the Deployment and the Service:

    kubectl apply -f cafe-service.yaml

    Expected output:

    deployment.apps/coffee created
    service/coffee-svc created
  3. Create a file named cafe-ingress.yaml with the following content to configure Ingress rules that expose the service.

    apiVersion: networking.k8s.io/v1
    kind: Ingress
    metadata:
      name: cafe-ingress 
    spec:
      ingressClassName: alb
      rules:
       - host: demo.domain.ingress.top
         http:
          paths:
          # Configure a context path.
          - path: /coffee
            pathType: ImplementationSpecific
            backend:
              service:
                name: coffee-svc
                port: 
                  number: 80
  4. Run the following command to configure the domain name and path for accessing the coffee service:

    kubectl apply -f cafe-ingress.yaml

    Expected output:

    ingress.networking.k8s.io/cafe-ingress created

Step 6: Configure DNS resolution

If you specified your own domain in the spec.rules.host field of the Ingress, you must add a CNAME record that maps your domain to the DNS name of the ALB instance. This allows you to access the service using your domain name. For more information, see Create and use an ALB Ingress to expose a service.

Step 7: Access the service

Access the service to generate a request that includes an Xtrace ID.

  1. Run the following command to get the address of the ALB instance (ADDRESS):

    kubectl get ing

    Expected output:

    NAME           CLASS   HOSTS                     ADDRESS                                              PORTS   AGE
    cafe-ingress   alb     demo.domain.ingress.top   alb-u53i28ewt580*****.cn-<Region>.alb.aliyuncs.com   80      16m
  2. Run the following command to access the service:

    curl -H Host:demo.domain.ingress.top http://alb-u53i28ewt580*****.cn-<Region>.alb.aliyuncs.com/coffee

    The expected output is an HTML page with the title Hello World.

Verify Tracing Analysis

  1. Check the Simple Log Service access logs for the ALB instance to confirm that Xtrace data is tagged.

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

    2. On the Clusters page, click the name of your cluster. In the left navigation pane, click Cluster Information.

    3. On the Basic Information tab of the Cluster Information page, click the link to the right of Log Service Project to go to the Simple Log Service console. Then, in the left navigation bar, click the LogStore whose name starts with alb_ (for example, alb_xz92lvykqj1siwvif****), and then search for xtrace on the current page.

      In the search results, the xtrace keyword appears in two fields: slb_xtrace (the trace ID) and xtrace_type (with a value of zipkin). This confirms that the ALB access logs have successfully recorded the trace data.

  2. Log on to the Managed Service for OpenTelemetry console.

  3. On the Applications page, select a region in the top navigation bar and click the name of the application.

  4. In the left-side navigation pane of the application details page, click API Call, and then click the Traces tab to view the trace data.

    The Traces tab lists up to 100 of the longest traces for the application. For more information about trace data, see API Calls.

Related documentation