Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wangdayong228 opened this issue Aug 4, 2023 · 5 comments

Comments

@wangdayong228
Copy link

wangdayong228 commented Aug 4, 2023

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 ci: enable #1 SMP Thu Mar 17 17:08:06 UTC 2022 x86_64 GNU/Linux
@zxyao145
Copy link

zxyao145 commented Aug 7, 2023

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

// ResponseFilter is the method to handle response.
// This filter is currently only pre-defined and has not been implemented.
ResponseFilter(conf interface{}, w pkgHTTP.Response)

@wangdayong228
Copy link
Author

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

// ResponseFilter is the method to handle response.
// This filter is currently only pre-defined and has not been implemented.
ResponseFilter(conf interface{}, w pkgHTTP.Response)

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
}

@zxyao145
Copy link

zxyao145 commented Aug 7, 2023

收到,谢谢你的说明!

@YogSothoth-mxc
Copy link

请问这个问题有解决吗?

@wangdayong228
Copy link
Author

请问这个问题有解决吗?

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants