apisix-go-plugin-runner icon indicating copy to clipboard operation
apisix-go-plugin-runner copied to clipboard

request help: request id 和 通过 response 取的 request id 不一样 ,是否有什么规则?

Open wangdayong228 opened this issue 2 years ago • 5 comments

Issue description

request id 和 通过 response 取的 request id 不一样, 请问有什么规则? 除了通过ID的方式,是否还有其他方式可以根据response 获取到对应的 request?

插件代码如下

package plugins

import (
	"net/http"

	pkgHTTP "github.com/apache/apisix-go-plugin-runner/pkg/http"
	"github.com/apache/apisix-go-plugin-runner/pkg/log"
	"github.com/apache/apisix-go-plugin-runner/pkg/plugin"
)

func init() {
	err := plugin.RegisterPlugin(&CheckId{})
	if err != nil {
		log.Fatalf("failed to register plugin check_id: %s", err)
	}
}

// Say is a demo to show how to return data directly instead of proxying
// it to the upstream.
type CheckId struct {
	// Embed the default plugin here,
	// so that we don't need to reimplement all the methods.
	plugin.DefaultPlugin
}

type CheckIdConf struct {
}

func (p *CheckId) Name() string {
	return "check_id"
}

func (p *CheckId) ParseConf(in []byte) (interface{}, error) {
	return CheckIdConf{}, nil
}

func (p *CheckId) RequestFilter(conf interface{}, w http.ResponseWriter, r pkgHTTP.Request) {
	log.Infof("run request filter, r.ID() %d", r.ID())
}

func (p *CheckId) ResponseFilter(conf interface{}, w pkgHTTP.Response) {
	log.Infof("run response filter, w.ID() %d", w.ID())
}

当发送请求时控制台输出

apisix_1            | 2023/08/04 10:33:48 [warn] 60#60: *120 [lua] init.lua:953: 2023-08-04T10:33:48.456Z       INFO    server/server.go:115    Client connected (unix)
apisix_1            | 2023-08-04T10:33:48.456Z  INFO    server/server.go:115    Client connected (unix)
apisix_1            | , context: ngx.timer
apisix_1            | 2023/08/04 10:33:48 [warn] 60#60: *120 [lua] init.lua:953: 2023-08-04T10:33:48.458Z       INFO    server/server.go:131    receive rpc type: 2 data length: 216
apisix_1            | 2023-08-04T10:33:48.458Z  INFO    plugin/plugin.go:120    run plugin check_id
apisix_1            | 2023-08-04T10:33:48.458Z  INFO    plugins/check_req_res_id.go:38  run request filter, r.ID() 4194308
apisix_1            | , context: ngx.timer
apisix_1            | 2023/08/04 10:33:48 [warn] 60#60: *120 [lua] init.lua:953: 2023-08-04T10:33:48.463Z       INFO    server/server.go:131    receive rpc type: 4 data length: 388
apisix_1            | , context: ngx.timer
apisix_1            | 2023/08/04 10:33:48 [warn] 60#60: *120 [lua] init.lua:953: 2023-08-04T10:33:48.463Z       INFO    plugin/plugin.go:185    run plugin check_id
apisix_1            | 2023-08-04T10:33:48.463Z  INFO    plugins/check_req_res_id.go:42  run response filter, w.ID() 4194309

request filter 中获取的 request id 跟 responsor filter中获取的request id 不一致,分别是 4194308 和 4194309

Environment

  • APISIX Go Plugin Runner's version: master 主分支
  • APISIX version: docker 3.4.0-debian
  • Go version: 1.18
  • OS (cmd: uname -a): Linux 49dc336f1aee 5.10.104-linuxkit #1 SMP Thu Mar 17 17:08:06 UTC 2022 x86_64 GNU/Linux

wangdayong228 avatar Aug 04 '23 10:08 wangdayong228

@wangdayong228 hi,我这边 ResponseFilter 方法不会执行,看代码注释这个方法似乎没有被使用到,请问你是有什么配置吗?

https://github.com/apache/apisix-go-plugin-runner/blob/f04930485b11ec29121585b2864157c957602be8/pkg/plugin/plugin.go#L45-L47

zxyao145 avatar Aug 07 '23 07:08 zxyao145

@wangdayong228 hi,我这边 ResponseFilter 方法不会执行,看代码注释这个方法似乎没有被使用到,请问你是有什么配置吗?

https://github.com/apache/apisix-go-plugin-runner/blob/f04930485b11ec29121585b2864157c957602be8/pkg/plugin/plugin.go#L45-L47

hi, 通过配置 ext-plugin-post-resp 就可以在response后执行插件了,我的配置如下

{
  "uri": "/",
  "name": "check-id",
  "plugins": {
    "ext-plugin-post-resp": {
      "allow_degradation": false,
      "conf": [
        {
          "name": "check_id",
          "value": ""
        }
      ]
    },
    "ext-plugin-pre-req": {
      "allow_degradation": false,
      "conf": [
        {
          "name": "check_id",
          "value": ""
        }
      ]
    }
  },
  "upstream": {
    "nodes": [
      {
        "host": "172.16.100.253",
        "port": 8086,
        "weight": 1
      }
    ]
  },
  "status": 1
}

wangdayong228 avatar Aug 07 '23 08:08 wangdayong228

收到,谢谢你的说明!

zxyao145 avatar Aug 07 '23 10:08 zxyao145

请问这个问题有解决吗?

YogSothoth-mxc avatar Aug 18 '23 11:08 YogSothoth-mxc

请问这个问题有解决吗?

自己写了个代理服务处理了,go 插件官方好像不维护了,坑有点多

wangdayong228 avatar Sep 28 '23 02:09 wangdayong228