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

request help: Custom filter performed twice?

Open Cheol-Soon-Choi opened this issue 2 years ago • 10 comments

Issue description

one request, but custom filter performed twice. my flow is : request > apisix + apisix runner(include custom filter) > my Backend Service A > my Backend Service B. and Service A redirect to service B. in this case, Is it normal for custom filters to work twice? (i guess that's right...)

I want the custom filter to work once regardless of the redirect(1 request -> custom filter work once -> 1 response) What should I do ??

Thank you in advance @tzssangglass

Environment

ubuntu

  • your apisix-java-plugin-runner version 0.3.0

Cheol-Soon-Choi avatar Oct 19 '22 09:10 Cheol-Soon-Choi

how did you config route? like: https://github.com/apache/apisix-java-plugin-runner/blob/d5421c292ef0d0ea93fb484afef668d7e2fc8767/tests/e2e/plugins/plugins_post_with_vars_test.go#L38-L64?

tzssangglass avatar Oct 20 '22 02:10 tzssangglass

my route is, { "uri": "/*", "name": "test", "methods": [ "GET" ], "plugins": { "ext-plugin-pre-req": { "conf": [ { "name": "HiFilter", "value": "{\"apiCode\":\"apiCode\",\"rejected_code\":\"403\"}" } ] } }, "upstream_id": "99", "status": 1 }

my backend, (serviceA = /test2, serviceB = /test) 스크린샷 2022-10-20 오후 2 35 26

my custom filter, 스크린샷 2022-10-20 오후 2 37 39

my error log, 스크린샷 2022-10-20 오후 2 39 05

Please refer to the above. thanks, @tzssangglass

Cheol-Soon-Choi avatar Oct 20 '22 05:10 Cheol-Soon-Choi

When you request APISIX once, output TWICE? twice?

tzssangglass avatar Oct 20 '22 06:10 tzssangglass

When you request APISIX once, output TWICE? twice?

yes.. Need more information? Redirect doesn't seem to matter.

Cheol-Soon-Choi avatar Oct 20 '22 11:10 Cheol-Soon-Choi

request > apisix + apisix runner(include custom filter) > my Backend Service A > my Backend Service B. and Service A redirect to service B.

can you provide more info about this?

tzssangglass avatar Oct 20 '22 13:10 tzssangglass

can you provide more info about this?

my demo project git: https://github.com/Cheol-Soon-Choi/demo_runner I think it's because of my project config or filter process?

my backend is 32

my route, upstream is 33 421

when i call (get) localhost:9080/test2 -> logged twice when i call (get) localhost:9080/test -> logged once

As you can see, this demo_runner project is also logged twice. 123

maybe @tzssangglass can reproduce twice logging like me. Thank you for your review.

Cheol-Soon-Choi avatar Oct 20 '22 14:10 Cheol-Soon-Choi

Since the url is /* in my router settings, the custom filter works once in the /test2 call, and the custom filter works once more in the redirected /test call, so is it logged twice in total??

Cheol-Soon-Choi avatar Oct 20 '22 15:10 Cheol-Soon-Choi

Solved the problem. It happened because the router was set to duplicate. I'm sorry I'm not used to it. @tzssangglass

Additionally, When I call apisix gw using resttemplate, the returned result is fine, but the custom filter doesn't seem to work. on the other way, When i call apisix gw directly, the custom filter works fine. Is there anything I missed in this process?

Cheol-Soon-Choi avatar Oct 21 '22 01:10 Cheol-Soon-Choi

Since the url is /* in my router settings, the custom filter works once in the /test2 call, and the custom filter works once more in the redirected /test call, so is it logged twice in total??

If you are saying that a redirect request occurred on the client side, then yes, APISIX processed the request twice and the java plugin runner will also process it twice.

tzssangglass avatar Oct 21 '22 01:10 tzssangglass

Additionally, When I call apisix gw using resttemplate, the returned result is fine, but the custom filter doesn't seem to work. on the other way, When i call apisix gw directly, the custom filter works fine.

It looks like the resttemplate sends a different request than the one sent by the direct call.

tzssangglass avatar Oct 21 '22 01:10 tzssangglass