thinkdb1 opened a new issue, #9505:
URL: https://github.com/apache/apisix/issues/9505

   ### Description
   
   The log was only:
   ```shell
   2023/05/18 08:30:59 [emerg] 53#53: *231837 3######OnHttpRequestHeaders guo 
#####, client: 1.1.1.1, server: _, request: "POST 
/watch/api/health/health/Check?abc=123&test=3334 HTTP/1.1", host: ""
   2023/05/18 08:30:59 [emerg] 53#53: *231837 2######OnHttpResponseHeaders guo 
##### while reading response header from upstream, client: 1.1.1.1, server: _, 
request: "POST /watch/api/health/health/Check?abc=123&test=3334 HTTP/1.1", 
upstream: 
"http://10.99.73.11:80/watch-alert/api/health/health/Check?abc=123&test=3334";, 
host: ""
   ``` 
   OnHttpRequestBody and OnHttpRequestTrailers was not be executed
   
   ### Environment
   
   
   env is this docker: 
https://github.com/apache/apisix-docker/blob/master/example/docker-compose.yml
   - APISIX version (run `apisix version`):3.3.0
   - Operating system (run `uname -a`):
   ```shell
   Linux esf-B85-HD3 5.4.0-47-generic #51~18.04.1-Ubuntu SMP Sat Sep 5 14:35:50 
UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
   ``` 
   - OpenResty / Nginx version (run `openresty -V` or `nginx -V`):
   - etcd version, if relevant (run `curl 
http://127.0.0.1:9090/v1/server_info`):bitnami/etcd:3.4.15
   - APISIX Dashboard version, if relevant:apache/apisix-dashboard:3.0.1-alpine
   - code
   ```go
   // Copyright 2020-2021 Tetrate
   //
   // Licensed under the Apache License, Version 2.0 (the "License");
   // you may not use this file except in compliance with the License.
   // You may obtain a copy of the License at
   //
   // http://www.apache.org/licenses/LICENSE-2.0
   //
   // Unless required by applicable law or agreed to in writing, software
   // distributed under the License is distributed on an "AS IS" BASIS,
   // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   // See the License for the specific language governing permissions and
   // limitations under the License.
   
   package main
   
   import (
        "github.com/tetratelabs/proxy-wasm-go-sdk/proxywasm"
        "github.com/tetratelabs/proxy-wasm-go-sdk/proxywasm/types"
   )
   
   func main() {
        proxywasm.SetVMContext(&vmContext{})
   }
   
   type vmContext struct {
        // Embed the default VM context here,
        // so that we don't need to reimplement all the methods.
        types.DefaultVMContext
   }
   
   // Override types.DefaultVMContext.
   func (*vmContext) NewPluginContext(contextID uint32) types.PluginContext {
        return &pluginContext{}
   }
   
   type pluginContext struct {
        // Embed the default plugin context here,
        // so that we don't need to reimplement all the methods.
        types.DefaultPluginContext
   
        // headerName and headerValue are the header to be added to response. 
They are configured via
        // plugin configuration during OnPluginStart.
   }
   
   // Override types.DefaultPluginContext.
   func (p *pluginContext) NewHttpContext(contextID uint32) types.HttpContext {
        return &httpHeaders{
                contextID: contextID,
        }
   }
   
   func (p *pluginContext) OnPluginStart(pluginConfigurationSize int) 
types.OnPluginStartStatus {
        proxywasm.LogDebug("loading plugin config")
   
        return types.OnPluginStartStatusOK
   }
   
   type httpHeaders struct {
        // Embed the default http context here,
        // so that we don't need to reimplement all the methods.
        types.DefaultHttpContext
        contextID            uint32
        totalRequestBodySize int
   }
   
   // Override types.DefaultHttpContext.
   func (ctx *httpHeaders) OnHttpRequestHeaders(numHeaders int, endOfStream 
bool) types.Action {
        proxywasm.LogCritical("3######OnHttpRequestHeaders guo #####")
        hs, err := proxywasm.GetHttpRequestHeaders()
        if err != nil {
                proxywasm.LogCriticalf("$$$$$failed to get request headers: 
%v", err)
        }
   
        for _, h := range hs {
                proxywasm.LogInfof("request header --> %s: %s", h[0], h[1])
        }
        return types.ActionContinue
   }
   func (ctx *httpHeaders) OnHttpRequestBody(bodySize int, endOfStream bool) 
types.Action {
        proxywasm.LogCritical("1######OnHttpRequestBody guo #####")
        ctx.totalRequestBodySize += bodySize
        if !endOfStream {
                // Wait until we see the entire body to replace.
                return types.ActionPause
        }
   
        originalBody, err := proxywasm.GetHttpRequestBody(0, 
ctx.totalRequestBodySize)
        if err != nil {
                proxywasm.LogCriticalf("err@#@#@#failed to get request body: 
%v", err)
                return types.ActionContinue
        }
        proxywasm.LogCriticalf("guo@#@#@#original request body: %s", 
string(originalBody))
   
        return types.ActionContinue
   }
   func (ctx *httpHeaders) OnHttpRequestTrailers(numTrailers int) types.Action {
        proxywasm.LogCritical("4######OnHttpRequestTrailers guo #####")
        return types.ActionContinue
   }
   
   // Override types.DefaultHttpContext.
   func (ctx *httpHeaders) OnHttpResponseHeaders(_ int, _ bool) types.Action {
        proxywasm.LogCritical("2######OnHttpResponseHeaders guo #####")
        return types.ActionContinue
   }
   
   // Override types.DefaultHttpContext.
   func (ctx *httpHeaders) OnHttpStreamDone() {
        proxywasm.LogInfof("&&&&&&##%d finished", ctx.contextID)
   }
   
   ``` 
   - Plugin runner version, for issues related to plugin runners: 
    https://github.com/apache/apisix/blob/master/t/wasm/log/main.go use 
   ```shell
     tinygo build -o otherlog.wasm -scheduler=none -target=wasi main.go 
   ``` 
   to otherlog.wasm
   and
    
   ```shell
   docker cp otherlog.wasm dockerapisix_apisix_1:/usr/local/apisix/t/
   ``` 
   - config.yaml  :
   ```shell
   apisix:
     node_listen: 9080              # APISIX listening port
     enable_ipv6: false
   
     enable_control: true
     control:
       ip: "0.0.0.0"
       port: 9092
   
   deployment:
     admin:
       allow_admin:               # 
https://nginx.org/en/docs/http/ngx_http_access_module.html#allow
         - 0.0.0.0/0              # We need to restrict ip access rules for 
security. 0.0.0.0/0 is for test.
   
       admin_key:
         - name: "admin"
           key: edd1c9f034335f136f87ad84b625c8f1
           role: admin                 # admin: manage all configuration data
   
         - name: "viewer"
           key: 4054f7cf07e344346cd3f287985e76a2
           role: viewer
   
     etcd:
       host:                           # it's possible to define multiple etcd 
hosts addresses of the same etcd cluster.
         - "http://etcd:2379";          # multiple etcd address
       prefix: "/apisix"               # apisix configurations prefix
       timeout: 30                     # 30 seconds
   
   plugin_attr:
     prometheus:
       export_addr:
         ip: "0.0.0.0"
         port: 9091
   
   wasm:
     plugins:
       - name: wasm_log # the name of the plugin
         priority: 7999 # priority
         file: /usr/local/apisix/t/wasm.wasm # the path of `.wasm` file
         http_request_phase: access # default to "access", can be one of 
["access", "rewrite"]
       - name: other_wasm_log # the name of the plugin
         priority: 7999 # priority
         file: /usr/local/apisix/t/otherlog.wasm # the path of `.wasm` file
         http_request_phase: access # default to "access", can be one of 
["access", "rewrite"]
   ``` 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to