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/24 01:55:36 UTC

[GitHub] [apisix] zlhgo opened a new issue #5596: request help: save upstream name to var

zlhgo opened a new issue #5596:
URL: https://github.com/apache/apisix/issues/5596


   ### Issue description
   
   for logging
   
   
   ### Environment
   
   - apisix version (cmd: `apisix version`):
   - OS (cmd: `uname -a`):
   - OpenResty / Nginx version (cmd: `nginx -V` or `openresty -V`):
   - etcd version, if have (cmd: run `curl http://127.0.0.1:9090/v1/server_info` to get the info from server-info API):
   - apisix-dashboard version, if have:
   - the plugin runner version, if the issue is about a plugin runner (cmd: depended on the kind of runner):
   - luarocks version, if the issue is about installation (cmd: `luarocks --version`):
   


-- 
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] zlhgo edited a comment on issue #5596: request help: save upstream name to var

Posted by GitBox <gi...@apache.org>.
zlhgo edited a comment on issue #5596:
URL: https://github.com/apache/apisix/issues/5596#issuecomment-979673859


   @tzssangglass thanks, is there any plan to merge to the apisix repo, i don't want to fork it.


-- 
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] zlhgo commented on issue #5596: request help: customize Nginx variable in the configuration

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


   i have written a plugin for this issue, but there is a problem that the `set $upstream_name  -;` directive must place in the location section, so maybe we are missing a http_server_location_configuration_snippet item.
   
   1. nginx config
   ```
   log_format main escape=default '$remote_addr - [$remote_addr] - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent" $request_length $request_time [$upstream_name] $upstream_addr $upstream_response_length $upstream_response_time $upstream_status $req_id $host [$scheme]';
   
   location / {
               set $upstream_name               -;
   }
   ```
   2.  code
   ```
   function _M.before_proxy(conf, ctx)
      -- maybe the ctx.matched_upstream can not access in the access phase
       ngx.var.upstream_name = ctx.matched_upstream.name
       core.log.warn("set $upstream_name=", ngx.var.upstream_name)
   end
   ```
   3. access log
   ```
   192.168.235.25 - [192.168.235.25] - - [07/Dec/2021:10:20:10 +0000] "GET /hostname HTTP/2.0" 200 33 "-" "curl/7.64.0" 48 0.003 [devops_flask-demo-online_8000] 172.16.214.127:8000 33 0.003 200 20d275ca0a73c2f141be75e22254b119 flask-demo.rd.kuaiyin123.net [https]
   ```


-- 
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] tzssangglass commented on issue #5596: request help: save upstream name to var

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


   ```diff
   diff --git a/apisix/cli/ngx_tpl.lua b/apisix/cli/ngx_tpl.lua
   index f5fa5d6e..90adf47d 100644
   --- a/apisix/cli/ngx_tpl.lua
   +++ b/apisix/cli/ngx_tpl.lua
   @@ -578,6 +578,7 @@ http {
                set $dubbo_service_version       '';
                set $dubbo_method                '';
                {% end %}
   +            set $upstream_name '';
    
                access_by_lua_block {
                    apisix.http_access_phase()
   diff --git a/apisix/init.lua b/apisix/init.lua
   index 801809f6..816352bf 100644
   --- a/apisix/init.lua
   +++ b/apisix/init.lua
   @@ -505,6 +505,9 @@ function _M.http_access_phase()
                                       or route_val.upstream
        end
    
   +    -- need to care of matched_upstream
   +    ngx.var.upstream_name = api_ctx.matched_upstream.parent.value.name
   +
        if enable_websocket then
            api_ctx.var.upstream_upgrade    = api_ctx.var.http_upgrade
            api_ctx.var.upstream_connection = api_ctx.var.http_connection
   diff --git a/conf/config.yaml b/conf/config.yaml
   index dd9bd565..c7871dae 100644
   --- a/conf/config.yaml
   +++ b/conf/config.yaml
   @@ -35,5 +35,6 @@ apisix:
        - name: admin
          key: edd1c9f034335f136f87ad84b625c8f1  # using fixed API token has security risk, please update it when you deploy to production environment
          role: admin
   -ext-plugin:
   -  path_for_test: /tmp/runner.sock
   +nginx_config:
   +  http:
   +    access_log_format: "$remote_addr - $remote_user [$time_local] $http_host \"$request\" $status $body_bytes_sent $request_time \"$http_referer\" \"$http_user_agent\" $upstream_name $upstream_addr $upstream_status $upstream_response_time \"$upstream_scheme://$upstream_host$upstream_uri\""
   ```
   try this, just an idea. you need to complate this by yourself.
   


-- 
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] zlhgo edited a comment on issue #5596: request help: save upstream name to var

Posted by GitBox <gi...@apache.org>.
zlhgo edited a comment on issue #5596:
URL: https://github.com/apache/apisix/issues/5596#issuecomment-979673859


   @tzssangglass thanks, is there any plan to merge to apisix repo, i don't want to fork it.


-- 
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] tzssangglass commented on issue #5596: request help: save upstream name to var

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


   > @tzssangglass Do you mean something like:
   > 
   > https://github.com/apache/apisix/blob/942650037d77007a292b4f80d98975fe9d6a5a37/conf/config-default.yaml#L173-L174
   > 
   > But for variable?
   
   Yes, it looks like it's a good way to go.
   Maybe we can add this to the pending discussion. If there are some similar proposals within the community, then we can consider supporting it. what's your option?


-- 
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] spacewander commented on issue #5596: request help: customize Nginx variable in the configuration

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


   Just do it.


-- 
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] spacewander edited a comment on issue #5596: request help: save upstream name to var

Posted by GitBox <gi...@apache.org>.
spacewander edited a comment on issue #5596:
URL: https://github.com/apache/apisix/issues/5596#issuecomment-980841554


   @tzssangglass 
   Do you mean something like:
   https://github.com/apache/apisix/blob/942650037d77007a292b4f80d98975fe9d6a5a37/conf/config-default.yaml#L173-L174
   
   But for variable?


-- 
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] spacewander commented on issue #5596: request help: customize Nginx variable in the configuration

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


   Yes, @zlhgo  can write a plugin and do it in the `access` method.


-- 
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] zlhgo commented on issue #5596: request help: save upstream name to var

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


   1. etcd data
   ```
   /apisix/upstreams/d430db86
   {"create_time":1637547549,"pass_host":"pass","nodes":[{"host":"172.16.213.197","port":8000,"weight":100,"priority":0}],"desc":"Created by apisix-ingress-controller, DO NOT modify it manually","hash_on":"vars","id":"d430db86","update_time":1637547549,"labels":{"managed-by":"apisix-ingress-controller"},"name":"devops_flask-demo_8000","type":"roundrobin","scheme":"http"}
   ```
   2. nginx.conf
   ```
   log_format main '[$upstream_name]';
   ```
   
   3. access.log
   127.0.0.1 - - [10/Sep/2021:10:41:10 +0800] [devops_flask-demo_8000]
   
   


-- 
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] zlhgo commented on issue #5596: request help: save upstream name to var

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


   @tzssangglass thanks, is there any plan to merge to apisix repo, i don't want to fork apisix.


-- 
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] spacewander commented on issue #5596: request help: save upstream name to var

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


   @tzssangglass 
   Do you mean something like:
   https://github.com/apache/apisix/blob/942650037d77007a292b4f80d98975fe9d6a5a37/conf/config-default.yaml#L173-L174


-- 
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] zlhgo commented on issue #5596: request help: save upstream name to var

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


   @tzssangglass What do you think of this issue?


-- 
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] spacewander commented on issue #5596: request help: customize Nginx variable in the configuration

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


   BTW, look like this part has to be maintained in the fork...
   ```
   diff --git a/apisix/init.lua b/apisix/init.lua
   index 801809f6..816352bf 100644
   --- a/apisix/init.lua
   +++ b/apisix/init.lua
   @@ -505,6 +505,9 @@ function _M.http_access_phase()
                                       or route_val.upstream
        end
    
   +    -- need to care of matched_upstream
   +    ngx.var.upstream_name = api_ctx.matched_upstream.parent.value.name
   +
        if enable_websocket then
            api_ctx.var.upstream_upgrade    = api_ctx.var.http_upgrade
            api_ctx.var.upstream_connection = api_ctx.var.http_connection
   ```


-- 
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] zlhgo edited a comment on issue #5596: request help: customize Nginx variable in the configuration

Posted by GitBox <gi...@apache.org>.
zlhgo edited a comment on issue #5596:
URL: https://github.com/apache/apisix/issues/5596#issuecomment-987792571


   i have written a plugin for this issue, but there is a problem that the `set $upstream_name  -;` directive must be placed in the location block, so maybe we are missing a http_server_location_configuration_snippet item.
   
   1. nginx config
   ```
   log_format main escape=default '$remote_addr - [$remote_addr] - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent" $request_length $request_time [$upstream_name] $upstream_addr $upstream_response_length $upstream_response_time $upstream_status $req_id $host [$scheme]';
   
   location / {
               set $upstream_name               -;
   }
   ```
   2.  code
   ```
   function _M.before_proxy(conf, ctx)
       -- maybe the ctx.matched_upstream can not access in the access phase
       ngx.var.upstream_name = ctx.matched_upstream.name
       core.log.warn("set $upstream_name=", ngx.var.upstream_name)
   end
   ```
   3. access log
   ```
   192.168.235.25 - [192.168.235.25] - - [07/Dec/2021:10:20:10 +0000] "GET /hostname HTTP/2.0" 200 33 "-" "curl/7.64.0" 48 0.003 [devops_flask-demo-online_8000] 172.16.214.127:8000 33 0.003 200 20d275ca0a73c2f141be75e22254b119 flask-demo.apisix.net [https]
   ```


-- 
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] zlhgo edited a comment on issue #5596: request help: customize Nginx variable in the configuration

Posted by GitBox <gi...@apache.org>.
zlhgo edited a comment on issue #5596:
URL: https://github.com/apache/apisix/issues/5596#issuecomment-987792571


   i have written a plugin for this issue, but there is a problem that the `set $upstream_name  -;` directive must place in the location section, so maybe we are missing a http_server_location_configuration_snippet item.
   
   1. nginx config
   ```
   log_format main escape=default '$remote_addr - [$remote_addr] - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent" $request_length $request_time [$upstream_name] $upstream_addr $upstream_response_length $upstream_response_time $upstream_status $req_id $host [$scheme]';
   
   location / {
               set $upstream_name               -;
   }
   ```
   2.  code
   ```
   function _M.before_proxy(conf, ctx)
      -- maybe the ctx.matched_upstream can not access in the access phase
       ngx.var.upstream_name = ctx.matched_upstream.name
       core.log.warn("set $upstream_name=", ngx.var.upstream_name)
   end
   ```
   3. access log
   ```
   192.168.235.25 - [192.168.235.25] - - [07/Dec/2021:10:20:10 +0000] "GET /hostname HTTP/2.0" 200 33 "-" "curl/7.64.0" 48 0.003 [devops_flask-demo-online_8000] 172.16.214.127:8000 33 0.003 200 20d275ca0a73c2f141be75e22254b119 flask-demo.apisix.net [https]
   ```


-- 
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] tzssangglass commented on issue #5596: request help: customize Nginx variable in the configuration

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


   Although this can be done. I'd like @spacewander 's way, do it with a special directive in `config-default.yaml`.


-- 
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] tzssangglass commented on issue #5596: request help: save upstream name to var

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


   `ngx.var.upstream_name = api_ctx.matched_upstream.parent.value.name` is wrong, which got the routes' name, not the upstream' name.


-- 
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] tzssangglass commented on issue #5596: request help: save upstream name to var

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


   pls describe your problem clearly, I can't get it.


-- 
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] zlhgo edited a comment on issue #5596: request help: save upstream name to var

Posted by GitBox <gi...@apache.org>.
zlhgo edited a comment on issue #5596:
URL: https://github.com/apache/apisix/issues/5596#issuecomment-977519041


   1. etcd data
   ```
   /apisix/upstreams/d430db86
   {"create_time":1637547549,"pass_host":"pass","nodes":[{"host":"172.16.213.197","port":8000,"weight":100,"priority":0}],"desc":"Created by apisix-ingress-controller, DO NOT modify it manually","hash_on":"vars","id":"d430db86","update_time":1637547549,"labels":{"managed-by":"apisix-ingress-controller"},"name":"devops_flask-demo_8000","type":"roundrobin","scheme":"http"}
   ```
   2. nginx.conf
   ```
   log_format main '[$upstream_name]';
   ```
   
   3. access.log
   ```
   127.0.0.1 - - [10/Sep/2021:10:41:10 +0800] [devops_flask-demo_8000]
   ```
   


-- 
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] tzssangglass commented on issue #5596: request help: customize Nginx variable in the configuration

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


   > BTW, look like this part has to be maintained in the fork...
   > 
   > ```
   > diff --git a/apisix/init.lua b/apisix/init.lua
   > index 801809f6..816352bf 100644
   > --- a/apisix/init.lua
   > +++ b/apisix/init.lua
   > @@ -505,6 +505,9 @@ function _M.http_access_phase()
   >                                     or route_val.upstream
   >      end
   >  
   > +    -- need to care of matched_upstream
   > +    ngx.var.upstream_name = api_ctx.matched_upstream.parent.value.name
   > +
   >      if enable_websocket then
   >          api_ctx.var.upstream_upgrade    = api_ctx.var.http_upgrade
   >          api_ctx.var.upstream_connection = api_ctx.var.http_connection
   > ```
   
   I think this part is more suitable for users to develop their own plugins to do so.
   
   


-- 
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] zlhgo edited a comment on issue #5596: request help: customize Nginx variable in the configuration

Posted by GitBox <gi...@apache.org>.
zlhgo edited a comment on issue #5596:
URL: https://github.com/apache/apisix/issues/5596#issuecomment-987792571


   i have written a plugin for this issue, but there is a problem that the `set $upstream_name  -;` directive must be placed in the location section, so maybe we are missing a http_server_location_configuration_snippet item.
   
   1. nginx config
   ```
   log_format main escape=default '$remote_addr - [$remote_addr] - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent" $request_length $request_time [$upstream_name] $upstream_addr $upstream_response_length $upstream_response_time $upstream_status $req_id $host [$scheme]';
   
   location / {
               set $upstream_name               -;
   }
   ```
   2.  code
   ```
   function _M.before_proxy(conf, ctx)
       -- maybe the ctx.matched_upstream can not access in the access phase
       ngx.var.upstream_name = ctx.matched_upstream.name
       core.log.warn("set $upstream_name=", ngx.var.upstream_name)
   end
   ```
   3. access log
   ```
   192.168.235.25 - [192.168.235.25] - - [07/Dec/2021:10:20:10 +0000] "GET /hostname HTTP/2.0" 200 33 "-" "curl/7.64.0" 48 0.003 [devops_flask-demo-online_8000] 172.16.214.127:8000 33 0.003 200 20d275ca0a73c2f141be75e22254b119 flask-demo.apisix.net [https]
   ```


-- 
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] tzssangglass commented on issue #5596: request help: save upstream name to var

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


   @spacewander maybe we can allow user to declare variables, then they can use custom variables in access_log_format or others.


-- 
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] spacewander closed issue #5596: request help: customize Nginx variable in the configuration

Posted by GitBox <gi...@apache.org>.
spacewander closed issue #5596:
URL: https://github.com/apache/apisix/issues/5596


   


-- 
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] zlhgo closed issue #5596: request help: save upstream name to var

Posted by GitBox <gi...@apache.org>.
zlhgo closed issue #5596:
URL: https://github.com/apache/apisix/issues/5596


   


-- 
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] tzssangglass commented on issue #5596: request help: customize Nginx variable in the configuration

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


   > so maybe we are missing an http_server_location_configuration_snippet item.
   
   Yes, that's what I mean about our lack of provision for users to set custom variables. Would you like to try it?


-- 
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] zlhgo edited a comment on issue #5596: request help: customize Nginx variable in the configuration

Posted by GitBox <gi...@apache.org>.
zlhgo edited a comment on issue #5596:
URL: https://github.com/apache/apisix/issues/5596#issuecomment-987792571


   i have written a plugin for this issue, but there is a problem that the `set $upstream_name  -;` directive must be placed in the location block, so maybe we are missing an http_server_location_configuration_snippet item.
   
   1. nginx config
   ```
   log_format main escape=default '$remote_addr - [$remote_addr] - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent" $request_length $request_time [$upstream_name] $upstream_addr $upstream_response_length $upstream_response_time $upstream_status $req_id $host [$scheme]';
   
   location / {
               set $upstream_name               -;
   }
   ```
   2.  code
   ```
   function _M.before_proxy(conf, ctx)
       -- maybe the ctx.matched_upstream can not access in the access phase
       ngx.var.upstream_name = ctx.matched_upstream.name
       core.log.warn("set $upstream_name=", ngx.var.upstream_name)
   end
   ```
   3. access log
   ```
   192.168.235.25 - [192.168.235.25] - - [07/Dec/2021:10:20:10 +0000] "GET /hostname HTTP/2.0" 200 33 "-" "curl/7.64.0" 48 0.003 [devops_flask-demo-online_8000] 172.16.214.127:8000 33 0.003 200 20d275ca0a73c2f141be75e22254b119 flask-demo.apisix.net [https]
   ```


-- 
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] zlhgo commented on issue #5596: request help: customize Nginx variable in the configuration

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


   ```
   diff --git a/apisix/cli/ngx_tpl.lua b/apisix/cli/ngx_tpl.lua
   index f5fa5d6e..523ae4d7 100644
   --- a/apisix/cli/ngx_tpl.lua
   +++ b/apisix/cli/ngx_tpl.lua
   @@ -573,6 +573,12 @@ http {
                set $ctx_ref                     '';
                set $from_error_page             '';
    
   +            # http server location configuration snippet starts
   +            {% if http_server_location_configuration_snippet then %}
   +            {* http_server_location_configuration_snippet *}
   +            {% end %}
   +            # http server location configuration snippet ends
   +
                {% if enabled_plugins["dubbo-proxy"] then %}
                set $dubbo_service_name          '';
                set $dubbo_service_version       '';
   diff --git a/conf/config-default.yaml b/conf/config-default.yaml
   index 7be15f92..3d089bdb 100644
   --- a/conf/config-default.yaml
   +++ b/conf/config-default.yaml
   @@ -191,6 +191,9 @@ nginx_config:                     # config for render the template to generate n
      http_server_configuration_snippet: |
        # Add custom Nginx http server configuration to nginx.conf.
        # The configuration should be well indented!
   +  http_server_location_configuration_snippet: |
   +    # Add custom Nginx http server location configuration to nginx.conf.
   +    # The configuration should be well indented!
      http_admin_configuration_snippet: |
        # Add custom Nginx admin server configuration to nginx.conf.
        # The configuration should be well indented!
   ```
   
   So simple?


-- 
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] tzssangglass commented on issue #5596: request help: save upstream name to var

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


   > @tzssangglass thanks, is there any plan to merge to the apisix repo, i don't want to fork it.
   
   no, this function is not universal, you can implement similar functions through write custom plugins


-- 
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] spacewander commented on issue #5596: request help: save upstream name to var

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


   @zlhgo 
   Would you give it a try?


-- 
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] zlhgo edited a comment on issue #5596: request help: customize Nginx variable in the configuration

Posted by GitBox <gi...@apache.org>.
zlhgo edited a comment on issue #5596:
URL: https://github.com/apache/apisix/issues/5596#issuecomment-987792571


   i have written a plugin for this issue, but there is a problem that the `set $upstream_name  -;` directive must place in the location section, so maybe we are missing a http_server_location_configuration_snippet item.
   
   1. nginx config
   ```
   log_format main escape=default '$remote_addr - [$remote_addr] - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent" $request_length $request_time [$upstream_name] $upstream_addr $upstream_response_length $upstream_response_time $upstream_status $req_id $host [$scheme]';
   
   location / {
               set $upstream_name               -;
   }
   ```
   2.  code
   ```
   function _M.before_proxy(conf, ctx)
       -- maybe the ctx.matched_upstream can not access in the access phase
       ngx.var.upstream_name = ctx.matched_upstream.name
       core.log.warn("set $upstream_name=", ngx.var.upstream_name)
   end
   ```
   3. access log
   ```
   192.168.235.25 - [192.168.235.25] - - [07/Dec/2021:10:20:10 +0000] "GET /hostname HTTP/2.0" 200 33 "-" "curl/7.64.0" 48 0.003 [devops_flask-demo-online_8000] 172.16.214.127:8000 33 0.003 200 20d275ca0a73c2f141be75e22254b119 flask-demo.apisix.net [https]
   ```


-- 
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