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
-
ALB Ingress controller 2.11.1 or later is installed in the cluster.
-
When you create a cluster, on the Component Configurations page, select ALB Ingress for the Ingress parameter. For more information, see Create an ACK managed cluster, Create an ACK dedicated cluster (discontinued), or Create an ACK Serverless cluster.
-
To install or update the ALB Ingress controller in an existing cluster, see Manage components.
-
-
If you use an ALB Ingress to access services in an ACK dedicated cluster, you must grant permissions to the ALB Ingress controller before you deploy the services. For more information, see Grant the ALB Ingress controller permissions to access an ACK dedicated cluster.
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
Log on to the ACK console. In the left navigation pane, click Clusters.
-
On the Clusters page, click the name of your cluster. In the left navigation pane, click Cluster Information.
-
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.
-
To create the AlbConfig, copy the following content into a file named alb-test.yaml.
NoteWhen you reuse an existing ALB instance and enable Log Service by using AlbConfig, you must set the
forceOverridefield totrueto 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.
-
-
Run the following command to create the AlbConfig:
kubectl apply -f alb-test.yamlExpected output:
albconfig.alibabacloud.com/alb-demo created
Step 4: Create an IngressClass
-
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 -
Run the following command to create the IngressClass:
kubectl apply -f alb.yamlExpected output:
ingressclass.networking.k8s.io/alb created
Step 5: Deploy a service and configure Ingress rules
-
Create a file named cafe-service.yaml with the following content. This deploys a Deployment named
coffeeand a Service namedcoffee-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 -
Run the following command to deploy the Deployment and the Service:
kubectl apply -f cafe-service.yamlExpected output:
deployment.apps/coffee created service/coffee-svc created -
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 -
Run the following command to configure the domain name and path for accessing the
coffeeservice:kubectl apply -f cafe-ingress.yamlExpected 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.
-
Run the following command to get the address of the ALB instance (ADDRESS):
kubectl get ingExpected output:
NAME CLASS HOSTS ADDRESS PORTS AGE cafe-ingress alb demo.domain.ingress.top alb-u53i28ewt580*****.cn-<Region>.alb.aliyuncs.com 80 16m -
Run the following command to access the service:
curl -H Host:demo.domain.ingress.top http://alb-u53i28ewt580*****.cn-<Region>.alb.aliyuncs.com/coffeeThe expected output is an HTML page with the title
Hello World.
Verify Tracing Analysis
-
Check the Simple Log Service access logs for the ALB instance to confirm that Xtrace data is tagged.
Log on to the ACK console. In the left navigation pane, click Clusters.
On the Clusters page, click the name of your cluster. In the left navigation pane, click Cluster Information.
-
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 forxtraceon the current page.In the search results, the xtrace keyword appears in two fields:
slb_xtrace(the trace ID) andxtrace_type(with a value ofzipkin). This confirms that the ALB access logs have successfully recorded the trace data.
-
Log on to the Managed Service for OpenTelemetry console.
-
On the Applications page, select a region in the top navigation bar and click the name of the application.
-
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
-
To enable tracing for the NGINX Ingress controller, see Enable Tracing Analysis for the NGINX Ingress controller.
-
If you encounter issues when using the ALB Ingress, see the following documentation: Troubleshoot ALB Ingress issues and ALB Ingress FAQ.