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

apisix中lua resty etcd出现的问题 #8138

Closed
yuqiquan opened this issue Oct 21, 2022 · 1 comment
Closed

apisix中lua resty etcd出现的问题 #8138

yuqiquan opened this issue Oct 21, 2022 · 1 comment

Comments

@yuqiquan
Copy link

yuqiquan commented Oct 21, 2022

Description

我写了个测试插件 testetcd.lua

local ngx = ngx
local core = require("apisix.core")
local schema = {
    type = "object",
    properties = {
        key = { type = "string" },
    }
}

local plugin_name = "testetcd"

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

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

function _M.init()
end

function _M.destroy()
end

function _M.rewrite(conf, ctx)
end


function _M.access(conf, ctx)
    local key = conf["key"]
    local etcd_cli, prefix, err = core.etcd.new()
    if not etcd_cli then
        core.log.warn("create etcd_cli failed, error --- > " , err)
        return
    end
    -- in etcd v2, get could implicitly turn into readdir
    -- while in v3, we need to do it explicitly
    local res, err = etcd_cli:readdir(key)
    if not res then
        core.log.warn("read etcd value failed, key --- > " , key)
        return
    end
    core.log.warn(core.json.encode(res.body))
end

function _M.body_filter(conf, ctx)

end

function _M.delayed_body_filter(conf, ctx)

end

return _M

然后在路由中配置该插件
image

作用就是访问该路由 ,会在日志中打印etcd中 key为 /testetcd 的value值,

先用命令行 etcdctl put /testetcd hahahah赋值

然后访问 打印出如下信息
image

使用etcdctl get /testetcd 可以获取到
image

Environment

  • APISIX version:2.15.0
@tzssangglass
Copy link
Member

I know the problem, let's fix it in the original issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants