diff --git a/kong/pluginsocket.proto b/kong/include/kong/pluginsocket.proto similarity index 100% rename from kong/pluginsocket.proto rename to kong/include/kong/pluginsocket.proto diff --git a/kong/plugins/opentelemetry/proto.lua b/kong/plugins/opentelemetry/proto.lua index 59a9b15868d9..484f0374716a 100644 --- a/kong/plugins/opentelemetry/proto.lua +++ b/kong/plugins/opentelemetry/proto.lua @@ -1,8 +1,4 @@ local grpc = require "kong.tools.grpc" -local pl_path = require "pl.path" - -local abspath = pl_path.abspath -local splitpath = pl_path.splitpath local proto_fpath = "opentelemetry/proto/collector/trace/v1/trace_service.proto" @@ -10,8 +6,6 @@ local function load_proto() local grpc_util = grpc.new() local protoc_instance = grpc_util.protoc_instance - local dir = splitpath(abspath(proto_fpath)) - protoc_instance:addpath(dir) protoc_instance:loadfile(proto_fpath) end diff --git a/kong/runloop/plugin_servers/pb_rpc.lua b/kong/runloop/plugin_servers/pb_rpc.lua index b41785beefe8..52859a9b8919 100644 --- a/kong/runloop/plugin_servers/pb_rpc.lua +++ b/kong/runloop/plugin_servers/pb_rpc.lua @@ -1,18 +1,18 @@ local kong_global = require "kong.global" local cjson = require "cjson.safe" -local protoc = require "protoc" +local grpc_tools = require "kong.tools.grpc" local pb = require "pb" local lpack = require "lua_pack" local ngx = ngx local kong = kong - - local cjson_encode = cjson.encode local t_unpack = table.unpack -- luacheck: ignore table local st_pack = lpack.pack local st_unpack = lpack.unpack +local proto_fname = "kong/pluginsocket.proto" + local Rpc = {} Rpc.__index = Rpc @@ -191,16 +191,11 @@ local function index_table(table, field) end local function load_service() - local p = protoc.new() - p:addpath("/usr/include") - p:addpath("/usr/local/opt/protobuf/include") - p:addpath("/usr/local/kong/lib") - p:addpath("kong") - p:addpath("spec/fixtures/grpc") - p.include_imports = true - - p:loadfile("pluginsocket.proto") - local parsed = p:parsefile("pluginsocket.proto") + local p = grpc_tools.new() + local protoc_instance = p.protoc_instance + + protoc_instance:loadfile(proto_fname) + local parsed = protoc_instance:parsefile(proto_fname) local service = {} for i, s in ipairs(parsed.service) do diff --git a/kong/tools/grpc.lua b/kong/tools/grpc.lua index 7b18e5a72d0a..7ed532a0766f 100644 --- a/kong/tools/grpc.lua +++ b/kong/tools/grpc.lua @@ -65,11 +65,11 @@ end function _M.new() local protoc_instance = protoc.new() + -- order by priority for _, v in ipairs { + "/usr/local/kong/include", + "/usr/local/opt/protobuf/include/", -- homebrew "/usr/include", - "/usr/local/opt/protobuf/include/", - "/usr/local/kong/lib/", - "kong", "kong/include", "spec/fixtures/grpc", } do diff --git a/kong/tools/wrpc/proto.lua b/kong/tools/wrpc/proto.lua index 64948ea9d667..d4d84acf57ff 100644 --- a/kong/tools/wrpc/proto.lua +++ b/kong/tools/wrpc/proto.lua @@ -11,8 +11,6 @@ local _MT = { __index = _M, } local wrpc_proto_name = "wrpc.wrpc" -local default_proto_path = { "kong/include/", "/usr/include/", } - local function parse_annotation(annotation) local parsed = {} for kv_pair in annotation:gmatch("[^;]+=[^;]+") do @@ -81,7 +79,6 @@ function _M.new() name_to_mthd = {}, }, _MT) - proto_instance:addpath(default_proto_path) proto_instance:import(wrpc_proto_name) return proto_instance end