Alibaba Cloud Service Mesh (ASM) can trace applications that are deployed inside an ASM instance. To trace applications that are deployed inside and outside an ASM instance at the same time, you must use Alibaba Cloud Tracing Analysis to generate call traces. This topic describes how to use Tracing Analysis to enable an external application to call an application inside an ASM instance. This way, Tracing Analysis generates a call trace between the two applications.

Prerequisites

  • An ASM instance is created. The ACK cluster is added to the ASM instance. For more information, see Create an ASM instance and Add a cluster to an ASM instance.
  • An ingress gateway is deployed for the ASM instance to allow external access to applications that are deployed inside the ASM instance. For more information, see Deploy an ingress gateway service.
  • Python 2.7 is installed in the runtime environment where you want to deploy an application outside the ASM instance.
  • Alibaba Cloud Tracing Analysis is enabled for the ASM instance. For more information, see Edit an ASM instance.

Background information

  • In this example, the ExternalProxy application that is compiled by using Python is deployed outside the ASM instance. ExternalProxy uses an HTTP server. When the root path of ExternalProxy is accessed, the HTTP server calls the Productpage microservice of the Bookinfo application that is deployed inside the ASM instance.
  • In this example, Tracing Analysis is used to trace applications. If you use a custom tracing system that is compatible with Zipkin, skip Step 2: Obtain the endpoint that is used to access Tracing Analysis and go to Step 3: Deploy the ExternalProxy application. Set the endpoint for external access to the custom tracing system as the endpoint to which tracing data is reported.

Step 1: Deploy the Bookinfo application inside an ASM instance

  1. Run the following command on the kubectl client to deploy Bookinfo in the ACK cluster that is added to the ASM instance.
    You can download the YAML file of Bookinfo from GitHub.
    kubectl --kubeconfig=${DATA_PLANE_KUBECONFIG} apply -f bookinfo.yaml
  2. Run the following command on the kubectl client to deploy virtual services for Bookinfo.
    You can download the YAML file of virtual services from GitHub.
    kubectl --kubeconfig=${ASM_KUBECONFIG} apply -f virtual-service-all-v1.yaml
  3. Run the following command on the kubectl client to deploy destination rules for Bookinfo.
    You can download the YAML file of destination rules from GitHub.
    kubectl --kubeconfig=${ASM_KUBECONFIG} apply -f destination-rule-all.yaml
  4. Run the following command on the kubectl client to deploy an Istio gateway for Bookinfo.
    You can download the YAML file of the Istio gateway from GitHub.
    kubectl --kubeconfig=${ASM_KUBECONFIG} apply -f bookinfo-gateway.yaml

Step 2: Obtain the endpoint that is used to access Tracing Analysis

  1. Log on to the Tracing Analysis console.
  2. In the left-side navigation pane, click Overview.
  3. On the Overview page, click View access point information.
  4. View the access endpoint.
    1. Select the region of the ACK cluster where Bookinfo is deployed. If you select another region, the tracing data of Bookinfo cannot be reported to Tracing Analysis.
    2. Turn on Show Token for the Cluster Information parameter. Select the public or private endpoint based on where you want to deploy the ExternalProxy application.
      In this example, the tracing data of ExternalProxy is reported by using the API of Zipkin V1. Therefore, you must use the public or private endpoint of Zipkin V1. Access point information

Step 3: Deploy the ExternalProxy application

  1. Create a file named ExternalProxy.py that contains the following content and save the file in the runtime environment of the ExternalProxy application:
    import requests
    from flask import Flask
    from py_zipkin.zipkin import zipkin_span,create_http_headers_for_new_span
    from py_zipkin.util import generate_random_64bit_string
    from py_zipkin.util import ZipkinAttrs
    import time
    
    app = Flask(__name__)
    
    def do_stuff(trace_id, span_id, parent_span_id):
        time.sleep(2)
        headers = create_http_headers_for_new_span()
        headers["X-B3-TraceId"] = trace_id
        headers["X-B3-SpanId"] = span_id
        headers["X-B3-ParentSpanId"] = parent_span_id
        print "SEND TO INGRESS HEADERS : {0}".format(headers)
        r = requests.get('http://${INGRESS_GATE_WAY_IP}/productpage', headers=headers)
        return 'OK'
    
    
    def http_transport(encoded_span):
        # encoding prefix explained in https://github.com/Yelp/py_zipkin#transport
        body=encoded_span
        zipkin_url="${XTRACE_ZIPKIN_V1_ENDPOINT}"
        headers = {"Content-Type": "application/x-thrift"}
    
        # You'd probably want to wrap this in a try/except in case POSTing fails
        r=requests.post(zipkin_url, data=body, headers=headers)
        print(body)
    
    
    @app.route('/')
    def index():
        with zipkin_span(
            service_name='external-proxy',
            span_name='external-proxy/inbound',
            transport_handler=http_transport,
            port=5000,
            sample_rate=100, 
        ) as inbound_span:
        do_stuff(inbound_span.zipkin_attrs.trace_id, inbound_span.zipkin_attrs.span_id, inbound_span.zipkin_attrs.parent_span_id)
    
        return 'OK', 200
    
    if __name__=='__main__':
        app.run(host="0.0.0.0",port=5000,debug=True)
  2. Replace the following variables in the ExternalProxy.py file:
    • Replace {XTRACE_ZIPKIN_V1_ENDPOINT} with the endpoint that you obtain in Step 2. If you need to report the tracing data to a custom tracing system, replace the variable with the access endpoint of the custom tracing system.
    • Replace {INGRESS_GATE_WAY_IP} with the endpoint of the ingress gateway that is deployed for the ACK cluster.
  3. Run the following command to start ExternalProxy:
    python ExternalProxy.py
     * Serving Flask app "main" (lazy loading)
     * Environment: production
       WARNING: This is a development server. Do not use it in a production deployment.
       Use a production WSGI server instead.
     * Debug mode: on
     * Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
     * Restarting with stat
     * Debugger is active!
     * Debugger PIN: 317-792-686
  4. Run the following command to call ExternalProxy:
    curl localhost:5000
    OK

Step 4: View tracing data

  1. Log on to the Tracing Analysis console.
  2. In the left-side navigation pane, click Applications. In the upper-left corner of the Applications page, select the region where the ACK cluster resides. Then, click ExternalProxy in the application list.
  3. On the page that appears, click Application Details in the left-side navigation pane. On the Application Details page, click the Traces tab. Then, click the trace ID of the call trace that you want to query.

Result

A call trace is generated between the ExternalProxy application that is deployed outside the ASM instance and the Bookinfo application that is deployed inside the ASM instance.