undying opened a new pull request, #12187:
URL: https://github.com/apache/apisix/pull/12187

   ### Description
   
   Added support for Nginx variables in the `service_name` parameter for 
service discovery. This allows dynamic service name resolution based on Nginx 
variables such as `$host`, `$http_host`, and others, working with all service 
discovery implementations (Consul, Eureka, Nacos, etc.).
   
   ### Detailed Description
   
   #### Problem
   
   The current implementation of service discovery in APISIX does not support 
using Nginx variables in the `service_name` parameter. This limits 
configuration flexibility as the service name must be hardcoded in the 
configuration, regardless of which service discovery implementation is used.
   
   #### Solution
   
   Added support for Nginx variables in the `service_name` parameter at the 
upstream level. This change enables dynamic service name resolution across all 
service discovery implementations. For example:
   
   #### Usage Example
   
   1. Define a variable in Nginx configuration:
   ```nginx
   map $http_host $backend {
     default echo;
     "~([^.]+).domain.local" $1;
   }
   ```
   
   2. Define routes
   ```yaml
   routes:
     -
       uri: "/*"
       host: "*.domain.local"
       upstream:
         service_name: $backend  # Nginx variable
         type: "roundrobin"
         discovery_type: "consul"  # or any other discovery type
   ```
   
   2. Use the variable in route configuration with any service discovery:
   ```yaml
   routes:
     -
       uri: "/*"
       host: "*.domain.local"
       upstream:
         service_name: $backend
         type: "roundrobin"
         discovery_type: "consul"  # or "eureka", "nacos", etc.
   ```
   
   In this example, if a request comes to `service1.domain.local`, the 
`$backend` variable will be set to `service1`, and APISIX will look for a 
service with this name in the configured service discovery system.
   
   #### Backward Compatibility
   
   The change is fully backward compatible because:
   1. Existing configurations will continue to work without changes
   2. The new functionality is only activated when using Nginx variables in 
`service_name`
   3. The change is implemented at the upstream level, making it available to 
all service discovery implementations
   
   ---
   
   ### Checklist
   
   - [ ] I have explained the need for this PR and the problem it solves
   - [ ] I have explained the changes or the new features added to this PR
   - [ ] I have added tests corresponding to this change
   - [ ] I have updated the documentation to reflect this change
   - [ ] I have verified that this change is backward compatible (If not, 
please discuss on the [APISIX mailing 
list](https://github.com/apache/apisix/tree/master#community) first)
   
   <!--
   
   Note
   
   1. Mark the PR as draft until it's ready to be reviewed.
   2. Always add/update tests for any changes unless you have a good reason.
   3. Always update the documentation to reflect the changes made in the PR.
   4. Make a new commit to resolve conversations instead of `push -f`.
   5. To resolve merge conflicts, merge master instead of rebasing.
   6. Use "request review" to notify the reviewer after making changes.
   7. Only a reviewer can mark a conversation as resolved.
   
   -->


-- 
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-unsubscr...@apisix.apache.org

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

Reply via email to