apache / apisix-java-plugin-runner

APISIX Plugin Runner in Java
https://apisix.apache.org/
Apache License 2.0
128 stars 95 forks source link

request help: Custom filter performed twice? #205

Closed Cheol-Soon-Choi closed 1 year ago

Cheol-Soon-Choi commented 1 year ago

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

tzssangglass commented 1 year ago

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?

Cheol-Soon-Choi commented 1 year ago

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

tzssangglass commented 1 year ago

When you request APISIX once, output TWICE? twice?

Cheol-Soon-Choi commented 1 year ago

When you request APISIX once, output TWICE? twice?

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

tzssangglass commented 1 year ago

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?

Cheol-Soon-Choi commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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?

tzssangglass commented 1 year ago

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 commented 1 year ago

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.