Skip to content

Cloud Native Custom Plugin Example: envoy-extproc-method-conv-demo-go

Envoy-extproc-method-conv-demo-go is an example based on envoy-extproc-sdk-go, demonstrating how to use the ext_proc feature provided by Envoy in Go.

Functionality

Its main function is to convert GET/POST requests initiated by the downstream into POST/GET requests before sending them to the upstream, thereby achieving the purpose of request method conversion.

Prerequisites

  • Install Envoy (Version >= v1.29)
  • Install Go (Version >= v1.21), this step can be skipped if you just want to run it
  • A target service supporting HTTP Method: GET/POST (hereinafter referred to as Upstream), assuming it supports the following routes:

    • /*
    • /no-extproc

Compilation

Navigate to the project root directory (this step can be skipped if you just want to run it).

go build . -o extproc

Running

  • Envoy:

    envoy -c ./envoy.yaml 
    
  • Caching:

    • Bare Metal:

      ./extproc method-conv --log-stream --log-phases
      
    • k8s:

      kubectl apply -f ./deployment.yaml 
      
  • Curl

    curl 127.0.0.1:8000/no-extproc  
    curl 127.0.0.1:8000/foo  
    curl -XPOST 127.0.0.1:8000/bar  
    

Parameter Description

  • log-stream: Whether to output logs about the request/response stream
  • log-phases: Whether to output logs for each processing phase
  • update-extproc-header: Whether to add the name of this plugin in the response header
  • update-duration-header: Add the total processing time in the response header when the stream ends

All of the above parameters default to false.

Notes

  1. This example only supports conversion between HTTP Methods: GET and POST.

  2. The allow_all_routing in mutation_rules must be set to true , as shown in the red box in the image below:

    Add Custom Attribute

Comments