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

support dgram unix socket #20

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ Available user configurations are listed as follows:

* `path`

If the log server uses a stream-typed unix domain socket, `path` is the socket file path. Note that host/port and path cannot both be empty. At least one must be supplied.
the unix socket file path. Note that host/port and path cannot both be empty. At least one must be supplied.

* `max_retry_times`

Expand Down
6 changes: 5 additions & 1 deletion lib/resty/logger/socket.lua
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,11 @@ local function _do_connect()
ok, err = sock:connect(host, port)
end
elseif path then
ok, err = sock:connect("unix:" .. path)
if (sock_type == 'udp') then
ok, err = sock:setpeername("unix:" .. path)
else
ok, err = sock:connect("unix:" .. path)
end
end

if not ok then
Expand Down
42 changes: 41 additions & 1 deletion t/sanity.t
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ foo



=== TEST 2: small flush_limit, instant flush, unix domain socket
=== TEST 2A: small flush_limit, instant flush, unix domain STREAM socket
--- http_config eval: $::HttpConfig
--- config
location /t {
Expand Down Expand Up @@ -103,6 +103,46 @@ foo



=== TEST 2B: small flush_limit, instant flush, unix domain DGRAM socket
--- http_config eval: $::HttpConfig
--- config
location /t {
content_by_lua 'ngx.say("foo")';
log_by_lua '
collectgarbage() -- to help leak testing

local logger = require "resty.logger.socket"
if not logger.initted() then
local ok, err = logger.init{
flush_limit = 1,
path = "$TEST_NGINX_HTML_DIR/logger_test.sock",
sock_type = "udp",
}
if not ok then
ngx.log(ngx.ERR, err)
return
end
end

local bytes, err = logger.log(ngx.var.request_uri)
if err then
ngx.log(ngx.ERR, err)
end
';
}
--- request
GET /t?a=1&b=2
--- wait: 0.1
--- udp_listen eval: "$ENV{TEST_NGINX_HTML_DIR}/logger_test.sock"
--- udp_reply:
--- no_error_log
[error]
--- udp_query: /t?a=1&b=2
--- response_body
foo



=== TEST 3: small flush_limit, instant flush, write a number to remote
--- http_config eval: $::HttpConfig
--- config
Expand Down