Alibaba Cloud provides Tracing Analysis, a service that offers developers of distributed applications complete trace reconstruction, call volume statistics, and trace topology. Tracing Analysis helps you quickly analyze and diagnose performance bottlenecks in distributed application architectures to improve development and diagnostic efficiency for microservices. To view trace data, you must install the ALB Ingress Controller component for your cluster and enable the Xtrace feature.
Prerequisites
Install the ALB Ingress Controller component for your cluster. The component version must be 2.11.1 or later.
When you create a cluster, on the Component Configuration page, select ALB Ingress for the Ingress field. For more information, see Create an ACK managed cluster, Create an ACK dedicated cluster (new cluster creation is discontinued), or Create an ACK serverless cluster.
For existing clusters, for information about how to install and upgrade the ALB Ingress Controller component, see Manage components.
If you want to access a service in an ACK dedicated cluster using an ALB Ingress, you must grant permissions to the ALB Ingress Controller before you deploy the service. For more information, see Grant the ALB Ingress Controller access permissions to an ACK dedicated cluster.
You have activated ActivateManaged Service for OpenTelemetry.
Enable Tracing Analysis for AlbConfig
Step 1: Enable Simple Log Service for the cluster
After you enable Simple Log Service, the cluster automatically creates a Simple Log Service project. For more information, see Collect logs from ACK cluster containers.
Step 2: Get the ID of the Simple Log Service Project for later use
Log on to the ACK console. In the left navigation pane, click Clusters.
On the Clusters page, click the name of the target cluster. Then, in the navigation pane on the left, click Cluster Information.
On the Cluster Information page, click the Basic Information tab. Then, copy and save the ID from the Simple Log Service Project field.
Step 3: Create an AlbConfig
Use an AlbConfig to create an ALB instance and a listener. In the AlbConfig, enable Simple Log Service and access logs for the ALB instance. Then, configure the Xtrace settings in the listener to enable Xtrace and set the sampling algorithm and sample rate.
Create a file named `alb-test.yaml` and copy the following content into the file to create an AlbConfig.
NoteWhen you reuse an existing ALB instance and want to enable Simple Log Service through the AlbConfig, you must set the
forceOverridefield totrueto forcibly overwrite 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 vSwitch must be in a zone supported by ALB and in the same VPC as the cluster. For high availability, select at least two vSwitches in different zones. - vSwitchId: vsw-2vc82nndnoo********** # Set the ALB vSwitch ID as needed. - vSwitchId: vsw-2vc30f5mlhs********** accessLogConfig: logProject: "k8s-log-xz92lvykqj1siwvif****" # Use the actual Simple Log Service Project obtained. logStore: alb_xz92lvykqj1siwvif**** # The logStore name must start with "alb_" (using an underscore). If the specified logStore does not exist, the system automatically creates it. listeners: - port: 80 protocol: HTTP logConfig: accessLogRecordCustomizedHeadersEnabled: false accessLogTracingConfig: # Xtrace configuration parameters. tracingEnabled: true # Xtrace switch for the listener. The default value is false. To enable Xtrace, set this parameter to true. tracingSample: 9999 # Xtrace sample rate for the listener. Value range: 1 to 10000. This parameter takes effect only when tracingEnabled is true. tracingType: Zipkin # Xtrace sampling algorithm for the listener. Set to Zipkin. This parameter takes effect only when tracingEnabled is true.NoteFor information about how to create a vSwitch, see Create and manage vSwitches.
You can modify Xtrace configurations 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
Create a file named `alb.yaml` and copy the following content into the file to create an IngressClass.
apiVersion: networking.k8s.io/v1 kind: IngressClass metadata: name: alb spec: controller: ingress.k8s.alibabacloud/alb parameters: apiGroup: alibabacloud.com kind: AlbConfig name: alb-demoRun the following command to create the IngressClass.
kubectl apply -f alb.yamlExpected output:
ingressclass.networking.k8s.io/alb created
Step 5: Deploy Services and Configure Ingress Forwarding Rules
Create a file named `cafe-service.yaml` and copy the following content into the file to deploy 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: NodePortRun the following command to deploy the deployment and service.
kubectl apply -f cafe-service.yamlExpected output:
deployment.apps/coffee created service/coffee-svc createdCreate a file named `cafe-ingress.yaml` and copy the following content into the file to configure Ingress rules and expose services.
apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: cafe-ingress spec: ingressClassName: alb rules: - host: demo.domain.ingress.top http: paths: # Configure the context path - path: /coffee pathType: ImplementationSpecific backend: service: name: coffee-svc port: number: 80Run the following command to configure the domain name and path for exposing the `coffee` service.
kubectl apply -f cafe-ingress.yamlExpected output:
ingress.networking.k8s.io/cafe-ingress created
Step 6: Configure Domain Name Resolution
If you configured the spec.rules.host field with your custom domain name when you created an Ingress, you must add a CNAME record for your domain name that resolves to the ALB DNS name. Then, you can access the services using the custom domain name. For more information, see Create and use an ALB Ingress to expose Services to external traffic.
Step 7: Access the Service
Access the service to generate requests with Xtrace IDs.
Run the following command to obtain the ALB instance address (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 16mRun 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 Effect
Check the Simple Log Service access logs for the ALB instance to confirm that requests contain tagged Xtrace data.
Log on to the ACK console. In the left navigation pane, click Clusters.
On the Clusters page, click the name of the target cluster. Then, in the navigation pane on the left, click Cluster Information.
On the Cluster Information page, click the Basic Information tab. Then, click the link in the Simple Log Service Project field to go to the Simple Log Service console. In the navigation pane on the left, click the LogStore whose name starts with
alb_, such as `alb_xz92lvykqj1siwvif****`. On the current page, search forxtrace.
-
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.
On the application details page, in the navigation pane on the left, click API Calls. Then, click the Trace tab to view trace data.
On the Traces tab, you can view up to 100 traces that have the longest duration for the application. For more information about trace data, see Interface Calls.
References
For information about how to implement Tracing Analysis with Nginx Ingress, see Implement Tracing Analysis for the Nginx Ingress Controller Component.
If you encounter issues when you use ALB Ingress, see Troubleshoot ALB Ingress issues and ALB Ingress FAQ.