Skip to content

Commit

Permalink
opentrace调研
Browse files Browse the repository at this point in the history
  • Loading branch information
xiyoo0812 committed Sep 27, 2023
1 parent f3c3f92 commit 1e7ede9
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 23 deletions.
2 changes: 1 addition & 1 deletion bin/share.conf
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ set_env("QUANTA_DB_CACHE_FLUSH", "10")
set_env("QUANTA_WEBHOOK_MODE", "log")
--set_env("QUANTA_LARK_URL", "https://open.feishu.cn/open-apis/bot/v2/hook/9a6565bf-51b4-48ab-80f0-64caf4d58ab8")
--set_env("QUANTA_DING_URL", "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=a4c64781-adad-4ddc-a615-6bc232ce71ef")
--set_env("QUANTA_WECHAT_URL", "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=ee6d97c5-477d-436f-83db-dd5361a5e8bd")
set_env("QUANTA_WECHAT_URL", "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=d7cd918c-f608-4762-87af-bb8c7fc51074")

--graylog配置
-----------------------------------------------------
Expand Down
8 changes: 4 additions & 4 deletions core/luabus/src/lua_socket_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ int lua_socket_node::forward_transfer(lua_State* L, uint32_t session_id, uint32_
return 1;
}

int lua_socket_node::forward_target(lua_State* L, uint32_t session_id, uint8_t flag, uint32_t target_id) {
int lua_socket_node::forward_target(lua_State* L, uint64_t session_id, uint8_t flag, uint32_t target_id) {
if (m_codec) {
size_t data_len = 0;
char* data = (char*)m_codec->encode(L, 4, &data_len);
Expand All @@ -142,7 +142,7 @@ int lua_socket_node::forward_target(lua_State* L, uint32_t session_id, uint8_t f
return 1;
}

int lua_socket_node::forward_hash(lua_State* L, uint32_t session_id, uint8_t flag, uint8_t service_id, uint16_t hash) {
int lua_socket_node::forward_hash(lua_State* L, uint64_t session_id, uint8_t flag, uint8_t service_id, uint16_t hash) {
if (m_codec) {
size_t data_len = 0;
char* data = (char*)m_codec->encode(L, 5, &data_len);
Expand All @@ -166,7 +166,7 @@ int lua_socket_node::forward_hash(lua_State* L, uint32_t session_id, uint8_t fla
return 1;
}

int lua_socket_node::transfer_call(lua_State* L, uint32_t session_id, uint32_t target_id) {
int lua_socket_node::transfer_call(lua_State* L, uint64_t session_id, uint32_t target_id) {
char* data;
size_t data_len = 0;
if (lua_type(L, 3) == LUA_TTABLE) {
Expand Down Expand Up @@ -194,7 +194,7 @@ int lua_socket_node::transfer_call(lua_State* L, uint32_t session_id, uint32_t t
return 0;
}

int lua_socket_node::transfer_hash(lua_State* L, uint32_t session_id, uint8_t service_id, uint16_t hash) {
int lua_socket_node::transfer_hash(lua_State* L, uint64_t session_id, uint8_t service_id, uint16_t hash) {
if (m_codec) {
size_t data_len = 0;
char* data = (char*)m_codec->encode(L, 4, &data_len);
Expand Down
26 changes: 12 additions & 14 deletions script/driver/webhook.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ local jencode = json.encode
local sformat = string.format

local WEBPATH = environ.get("QUANTA_WEBHOOK_PATH", "./webhooks/")
local log_dump = logfeature.dump("bilogs", WEBPATH, true)
local log_dump = logfeature.dump("webhooks", WEBPATH, true)

local event_mgr = quanta.get("event_mgr")
local thread_mgr = quanta.get("thread_mgr")
local http_client = quanta.get("http_client")

Expand All @@ -24,17 +23,16 @@ prop:reader("hooks", {}) --webhook通知接口
prop:reader("notify_limit", {}) --控制同样消息的发送频率

function Webhook:__init()
self.title = sformat("%s | %s", HOST_IP, quanta.service_name)
--初始化hooks
self.hooks.lark_log = environ.get("QUANTA_LARK_URL")
self.hooks.ding_log = environ.get("QUANTA_DING_URL")
self.hooks.wechat_log = environ.get("QUANTA_WECHAT_URL")
-- 注册事件
event_mgr:add_listener(self, "rpc_fire_webhook")
self.mode = environ.get("QUANTA_WEBHOOK_MODE")
if self.mode then
local mode = environ.get("QUANTA_WEBHOOK_MODE")
if mode then
--添加webhook功能
self.mode = mode
logger.add_monitor(self)
self.title = sformat("%s | %s", HOST_IP, quanta.service_name)
--初始化hooks
self.hooks.lark_log = environ.get("QUANTA_LARK_URL")
self.hooks.ding_log = environ.get("QUANTA_DING_URL")
self.hooks.wechat_log = environ.get("QUANTA_WECHAT_URL")
end
end

Expand Down Expand Up @@ -76,8 +74,8 @@ function Webhook:ding_log(url, context, at_mobiles, at_all)
end

--dispatch_log
function Webhook:dispatch_log(content, ...)
if next(self.hooks) then
function Webhook:dispatch_log(content)
if self.mode then
local now = quanta.now
local notify = self.notify_limit[content]
if not notify then
Expand All @@ -92,7 +90,7 @@ function Webhook:dispatch_log(content, ...)
end
notify.count = notify.count + 1
for hook_api, url in pairs(self.hooks) do
self[hook_api](self, url, content, ...)
self[hook_api](self, url, content)
end
end
end
Expand Down
11 changes: 7 additions & 4 deletions script/driver/zipkin.lua
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,13 @@ function Zipkin:sub_span(name, parent_id)
return self:general(name, trace_id, parent_id)
end

function Zipkin:set_tag(span, tag, value)
span.tags[tag] = tostring(value)
span.duration = quanta.now_ms * 1000 - span.timestamp
function Zipkin:set_tag(span, ...)
local tags = { ... }
local n = #tags // 2
for i = 1, n do
local tag = tags[i*2 - 1]
span.tags[tag] = tags[i*2]
end
end

function Zipkin:set_annotation(span, value)
Expand All @@ -88,7 +92,6 @@ function Zipkin:set_annotation(span, value)
}
local annotations = span.annotations
annotations[#annotations + 1] = annotation
span.duration = quanta.now_ms * 1000 - span.timestamp
end

function Zipkin:recovery_span(span)
Expand Down
1 change: 1 addition & 0 deletions script/feature/worker.lua
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ end
local function init_mainloop()
import("kernel/timer_mgr.lua")
import("kernel/update_mgr.lua")
import("driver/webhook.lua")
event_mgr = quanta.get("event_mgr")
thread_mgr = quanta.get("thread_mgr")
update_mgr = quanta.get("update_mgr")
Expand Down
1 change: 1 addition & 0 deletions script/kernel.lua
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ local function init_mainloop()
import("kernel/timer_mgr.lua")
import("kernel/update_mgr.lua")
import("feature/scheduler.lua")
import("driver/webhook.lua")
update_mgr = quanta.get("update_mgr")
scheduler = quanta.get("scheduler")
end
Expand Down

0 comments on commit 1e7ede9

Please sign in to comment.