Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

help request: how to mannually routing to another service base on some condition #12103

Open
darkSheep404 opened this issue Mar 31, 2025 · 0 comments
Labels
plugin question label for questions asked by users

Comments

@darkSheep404
Copy link
Contributor

darkSheep404 commented Mar 31, 2025

Description

Dear apisix team, i want to base on some condition to routing to different service
when i use ctx.upstream_id = conf.upstream_id it will routing to new upstream
but when i use ctx.service_id = conf.service_id , it still routing to old version
Cause we have plugins on service level , routing to new service will be better than routing to a new upstream
May I know how can we mannually change service to annother service in plugin code ?

local core       = require("apisix.core")
local upstream   = require("apisix.upstream")
local schema_def = require("apisix.schema_def")
local expr       = require("resty.expr.v1")

local plugin_name = "custom-traffic-split"
local schema = {
    type = "object",
    properties = {
        upstream_id = schema_def.id_schema,
        service_id = schema_def.id_schema
    }
}

local _M = {
    version = 0.1,
    priority = 966,
    name = plugin_name,
    schema = schema
}

function _M.check_schema(conf)
    return core.schema.check(schema, conf)
end

function _M.access(conf, ctx)
    if not conf then
        return
    end

    --  
    local gary_release = core.request.header(ctx, "gary_version")
    if not gary_release then
        return
    end

    -- 
    if conf.upstream_id then
        ctx.upstream_id = conf.upstream_id
        return
    end


    if conf.service_id then
        ctx.service_id = conf.service_id 
        return
    end


   
end

return _M

Environment

  • APISIX version (run apisix version):
  • Operating system (run uname -a):
  • OpenResty / Nginx version (run openresty -V or nginx -V):
  • etcd version, if relevant (run curl http://127.0.0.1:9090/v1/server_info):
  • APISIX Dashboard version, if relevant:
  • Plugin runner version, for issues related to plugin runners:
  • LuaRocks version, for installation issues (run luarocks --version):
@dosubot dosubot bot added plugin question label for questions asked by users labels Mar 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
plugin question label for questions asked by users
Projects
Status: 📋 Backlog
Development

No branches or pull requests

1 participant