You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2021/11/19 11:40:07 UTC

[GitHub] [apisix] Rdebu opened a new issue #5561: request help: I want to add a new parameter B to the request based on parameter A, and then customize the distribution based on parameter B

Rdebu opened a new issue #5561:
URL: https://github.com/apache/apisix/issues/5561


   ### Issue description
   
   I want to add a new parameter SID to the request based on the RID parameter, and then customize the publication based on the SID parameter.  I wanted to use Vars and custom plug-ins to do this, but after testing, I found that custom plug-ins have a lower priority than Vars. Now I created a new intermediate route and asked it to create sid parameters directly, upstream from Apisix itself.  The other route receives the intermediate URI and streams the SID parameter.  I feel that this way is a bit troublesome, may I ask if Apisix provides a solution that can be completed with only one route  
   【我想要在请求中根据rid参数添加一个新参数sid,再根据sid参数进行自定义发布。我本来想使用vars和自定义插件完成,但是经过测试发现自定义插件的优先级没有vars高,现在的解决方案是我又新建了个过渡的路由,让它直接接收请求创建sid参数,他的上游是apisix自己;另一个路由接收的是那个中间过渡的uri,再对sid参数进行分流。我感觉我这种方式有点麻烦,请问apisix有没有提供一个可以只用一个路由就能完成的方案呢】
   
   Here is my configuration
   【以下是我的配置】
   
   My plug-in for sid generation
   【我的用于生成sid的插件:】
   @Component
   public class RidGetSidFilter implements PluginFilter {
       @Override
       public String name() {
           return "RidGetSidFilter";
       }
   
       @Override
       public Mono<Void> filter(HttpRequest request, HttpResponse response, PluginFilterChain chain) {
           String ridStr = request.getArg("rid");
           Long ridLong = Long.parseLong(ridStr);
           //根据rid生成sid
           RID rid = RID.parse(ridLong);
           int sid = rid.getSid();
           request.setArg("sid", String.valueOf(sid));
           return chain.filter(request, response);
       }
   }
   
   The first route I configured(Access the Java plug-in to generate the SID parameter  ):
   【我配置的第一个路由(访问java插件生成sid参数):】
   {
     "uri": "/rid",
     "name": "rid",
     "desc": "RidGetSidFilter",
     "methods": [
       "GET",
       "POST",
       "PUT",
       "DELETE",
       "PATCH",
       "HEAD",
       "OPTIONS",
       "CONNECT",
       "TRACE"
     ],
     "plugins": {
       "ext-plugin-pre-req": {
         "conf": [
           {
             "name": "RidGetSidFilter",
             "value": ""
           }
         ]
       },
       "proxy-rewrite": {
         "uri": "/sid"
       }
     },
     "upstream": {
       "nodes": [
         {
           "host": "127.0.0.1",
           "port": 9080,
           "weight": 1
         }
       ],
       "type": "roundrobin",
       "scheme": "http",
       "pass_host": "pass"
     },
     "status": 1
   }
   
   The second route I configured (custom advertise based on sid 0)  
   【我配置的第二个路由(根据sid是否为0进行自定义发布)】
   {
     "uri": "/sid",
     "name": "sid",
     "methods": [
       "GET",
       "POST",
       "PUT",
       "DELETE",
       "PATCH",
       "HEAD",
       "OPTIONS",
       "CONNECT",
       "TRACE"
     ],
     "vars": [
       [
         "arg_sid",
         "==",
         "0"
       ]
     ],
     "plugins": {
       "proxy-rewrite": {
         "uri": "/rid"
       }
     },
     "upstream": {
       "nodes": [
         {
           "host": "172.20.23.125",
           "port": 8002,
           "weight": 1
         }
       ],
       "type": "roundrobin",
       "scheme": "http",
       "pass_host": "pass"
     },
     "status": 1
   }
   
   
   例外附上我最开始的路由,但是vars的优先级高于自定义插件
   {
       "uri":"/rid",
       "name":"sid",
       "methods":[
           "GET",
           "POST",
           "PUT",
           "DELETE",
           "PATCH",
           "HEAD",
           "OPTIONS",
           "CONNECT",
           "TRACE"
       ],
       "vars":[
           [
               "arg_sid",
               "==",
               "0"
           ]
       ],
       "plugins":{
           "ext-plugin-pre-req":{
               "conf":[
                   {
                       "name":"RidGetSidFilter",
                       "value":""
                   }
               ]
           }
       },
       "upstream":{
           "nodes":[
               {
                   "host":"172.20.23.125",
                   "port":8002,
                   "weight":1
               }
           ],
           "type":"roundrobin",
           "scheme":"http",
           "pass_host":"pass"
       },
       "status":1
   }
   
   
   ### Environment
   
   - apisix version (cmd: `apisix version`): 2.7
   - OS (cmd: `uname -a`): centos7
   - OpenResty / Nginx version (cmd: `nginx -V` or `openresty -V`): openresty/1.19.9.1
   - etcd version, if have (cmd: run `curl http://127.0.0.1:9090/v1/server_info` to get the info from server-info API): 3.4.0
   - apisix-dashboard version, if have: 2.8
   - the plugin runner version, if the issue is about a plugin runner (cmd: depended on the kind of runner): java8 + apisix-java-plugin-runner 0.1
   - luarocks version, if the issue is about installation (cmd: `luarocks --version`): 3.4.0
   


-- 
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: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] shuaijinchao commented on issue #5561: request help: I want to add a new parameter B to the request based on parameter A, and then customize the distribution based on parameter B

Posted by GitBox <gi...@apache.org>.
shuaijinchao commented on issue #5561:
URL: https://github.com/apache/apisix/issues/5561#issuecomment-975327641


   Why not complete the generation and judgment actions at the same time in a custom plugin?


-- 
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: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] Rdebu commented on issue #5561: request help: I want to add a new parameter B to the request based on parameter A, and then customize the distribution based on parameter B

Posted by GitBox <gi...@apache.org>.
Rdebu commented on issue #5561:
URL: https://github.com/apache/apisix/issues/5561#issuecomment-975335929


   Because I have to use vars to do custom publishing if I don't use vars and use the traffic-split plugin wouldn't that only be greyscale publishing?  Is there any way you can stream streams into specific upstreams in a Java plug-in  
   
   【因为我进行自定义发布得要借助vars才能实现  假如不借助vars使用traffic-split插件 那不是只能进行灰度发布吗?大佬有什么办法能够在java插件中进行分流到具体的upstream中呢】


-- 
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: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] shuaijinchao commented on issue #5561: request help: I want to add a new parameter B to the request based on parameter A, and then customize the distribution based on parameter B

Posted by GitBox <gi...@apache.org>.
shuaijinchao commented on issue #5561:
URL: https://github.com/apache/apisix/issues/5561#issuecomment-975392924


   You set your `sid` through java, and then use the `rules.match.vars` in the `traffic` plugin to match the strategy set by the java plugin. Can this solve your problem?


-- 
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: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org