All Products
Search
Document Center

Alibaba Cloud Service Mesh:Use the Wasm plug-in to add the dimensions of ASM monitoring metrics

Last Updated:Dec 10, 2024

Service Mesh (ASM) comes with multiple built-in monitoring metrics and multiple dimensions to help you better understand the real-time running of your applications. With powerful extension mechanism, ASM allows you to specify processing logics based on request or response content and add the processing results to the dimensions of monitoring metrics. This topic describes how to use the Wasm plug-in to add custom dimensions to the existing monitoring metrics in ASM.

Background information

ASM provides multiple monitoring metrics including istio_requests_total and istio_request_duration_milliseconds. By default, these metrics are configured with some dimensions, such as source_workload, destination_workload, and response_code. You can configure the monitoring metrics generated by the mesh proxy based on these dimensions. For more information, see Configure observability settings. In this way, you can create various dashboards and alert rules.

Prerequisites

Step 1: Write a Wasm plug-in and apply it to an HTTPBin application

This section describes how to develop a Wasm plug-in in Rust, decode the user-name in a request header using Base64, and then add the user-name to the istio_requests_total metric as a dimension.

The API for other languages is similar to that of Rust plug-ins. If you write Wasm plug-ins in other languages, please refer to the corresponding SDK documentation.
  1. Get the plug-in source code.

  2. Compile and deploy a Wasm plug-in. For more information, see Write a Wasm plug-in in Rust for an Envoy proxy in ASM.

    The plug-in is designed to call the SetProperty function to specify the parsing result as a filter_state. The sample YAML file for WasmPlugin is as follows.

    apiVersion: extensions.istio.io/v1alpha1
    kind: WasmPlugin
    metadata:
      name: add-metrics-log
      namespace: default
    spec:
      imagePullPolicy: IfNotPresent
      selector:
        matchLabels:
          app: httpbin
      url: oci://registry-cn-hangzhou.ack.aliyuncs.com/ack-demo/asm-wasm-rust-add-metrics-tag:v1.22.6.7-g1926b20-aliyun
      phase: AUTHN
    The image in this example is stored in a public repository. Therefore, you do not need to configure wasm-secrets. If the ACR you are using is a private repository, you need to make adjustments according to the sample YAML file in Write a Wasm plug-in in Rust for an Envoy proxy in ASM.

Step 2: Modify the observability settings to add custom dimensions

  1. Log on to the ASM console. In the left-side navigation pane, choose Service Mesh > Mesh Management.

  2. On the Mesh Management page, click the name of the ASM instance. In the left-side navigation pane, choose Observability Management Center > Observability Settings.

  3. In the Monitoring Metrics Configuration list, enable the Client-side Metrics and Server-side Metrics for REQUEST_COUNT, and add the custom dimension user_name with the value filter_state["wasm.user-name"] respectively.

    image

  4. Click Submit to add the filter_state to the custom dimension.

Step 3: Access an HTTPBin service

  1. Run the following command to access an HTTPBin service.

    curl ${IP address of ASM gateway}:80/status/418 --header "user-name:YXNtLXRlc3QtdXNlcgo="
    YXNtLXRlc3QtdXNlcgo= the result of asm-test-user encoded in Base64.

    Expected output:

        -=[ teapot ]=-
    
           _...._
         .'  _ _ `.
        | ."` ^ `". _,
        \_;`"---"`|//
          |       ;/
          \_     _/
            `"""`
  2. Run the following command by using the kubeconfig file of the ASM cluster on the data plane to view the Prometheus metrics for the HTTPBin pod.

    kubectl exec deploy/httpbin -it -c istio-proxy -- curl localhost:15000/stats/prometheus | grep istio_requests_total

    Expected output:

    # TYPE istio_requests_total counter
    istio_requests_total{reporter="destination",source_workload="istio-ingressgateway",...,user_name="asm-test-user"} 3

    In this case, you can specify statistics information for specific users in Prometheus based in this dimension.