-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
feat: Add real tests for splunk logger using vector #9526
Changes from all commits
01b4b85
227c9c4
34c250e
eb40d6e
58af4fd
4e64b0a
21920c2
9ad0e14
d2d6b10
71f8ce0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -145,7 +145,7 @@ GET /hello | |
--- response_body | ||
hello world | ||
--- error_log | ||
Batch Processor[splunk-hec-logging] failed to process entries: failed to send splunk, Invalid token | ||
Batch Processor[splunk-hec-logging] failed to process entries: failed to send splunk, Invalid authorization | ||
Batch Processor[splunk-hec-logging] exceeded the max_retry_count | ||
|
||
|
||
|
@@ -224,157 +224,139 @@ hello world | |
--- config | ||
location /t { | ||
content_by_lua_block { | ||
local config = { | ||
local t = require("lib.test_admin").test | ||
local code, body = t('/apisix/admin/plugin_metadata/splunk-hec-logging', | ||
ngx.HTTP_PUT, | ||
[[{ | ||
"log_format": { | ||
"host": "$host", | ||
"@timestamp": "$time_iso8601", | ||
"client_ip": "$remote_addr", | ||
"message_1":"test custom log format in plugin" | ||
} | ||
}]] | ||
) | ||
if code >= 300 then | ||
ngx.status = code | ||
ngx.say(body) | ||
return | ||
end | ||
|
||
local code, body = t('/apisix/admin/routes/1', ngx.HTTP_PUT, { | ||
uri = "/hello", | ||
upstream = { | ||
type = "roundrobin", | ||
nodes = { | ||
["127.0.0.1:1980"] = 1 | ||
["127.0.0.1:1982"] = 1 | ||
} | ||
}, | ||
plugins = { | ||
["splunk-hec-logging"] = { | ||
endpoint = { | ||
uri = "http://127.0.0.1:1980/splunk_hec_logging", | ||
uri = "http://127.0.0.1:18088/services/collector", | ||
token = "BD274822-96AA-4DA6-90EC-18940FB2414C" | ||
}, | ||
batch_max_size = 1, | ||
batch_max_size = 3, | ||
inactive_timeout = 1 | ||
} | ||
} | ||
} | ||
local t = require("lib.test_admin").test | ||
local code, body = t('/apisix/admin/routes/1', ngx.HTTP_PUT, config) | ||
|
||
}) | ||
if code >= 300 then | ||
ngx.status = code | ||
ngx.say(body) | ||
return | ||
end | ||
|
||
local code, body = t('/apisix/admin/plugin_metadata/splunk-hec-logging', | ||
ngx.HTTP_PUT, | ||
[[{ | ||
"log_format": { | ||
"host": "$host", | ||
"@timestamp": "$time_iso8601", | ||
"client_ip": "$remote_addr" | ||
} | ||
}]] | ||
) | ||
local code, _, body2 = t("/hello", "GET") | ||
if code >= 300 then | ||
ngx.status = code | ||
ngx.say(body) | ||
ngx.say("fail") | ||
return | ||
end | ||
ngx.say(body) | ||
} | ||
} | ||
--- response_body | ||
passed | ||
--- wait: 5 | ||
|
||
|
||
|
||
=== TEST 8: hit | ||
--- extra_init_by_lua | ||
local core = require("apisix.core") | ||
local decode = require("toolkit.json").decode | ||
local up = require("lib.server") | ||
up.splunk_hec_logging = function() | ||
ngx.log(ngx.WARN, "the mock backend is hit") | ||
|
||
ngx.req.read_body() | ||
local data = ngx.req.get_body_data() | ||
ngx.log(ngx.WARN, data) | ||
data = decode(data) | ||
assert(data.event.client_ip == "127.0.0.1") | ||
assert(data.source == "apache-apisix-splunk-hec-logging") | ||
assert(data.host == core.utils.gethostname()) | ||
ngx.say('{}') | ||
end | ||
--- request | ||
GET /hello | ||
--- wait: 2 | ||
--- response_body | ||
hello world | ||
--- error_log | ||
the mock backend is hit | ||
--- no_error_log | ||
[error] | ||
=== TEST 8: check splunk log | ||
--- exec | ||
tail -n 1 ci/pod/vector/splunk.log | ||
--- response_body eval | ||
qr/.*test custom log format in plugin.*/ | ||
|
||
|
||
|
||
=== TEST 9: set route to test custom log format in route | ||
--- config | ||
location /t { | ||
content_by_lua_block { | ||
local config = { | ||
local t = require("lib.test_admin").test | ||
local code, body = t('/apisix/admin/plugin_metadata/splunk-hec-logging', | ||
ngx.HTTP_PUT, | ||
[[{ | ||
"log_format": { | ||
"host": "$host", | ||
"@timestamp": "$time_iso8601", | ||
"vip": "$remote_addr", | ||
"message_2":"logger format in plugin" | ||
} | ||
}]] | ||
) | ||
if code >= 300 then | ||
ngx.status = code | ||
ngx.say(body) | ||
return | ||
end | ||
|
||
local code, body = t('/apisix/admin/routes/1', ngx.HTTP_PUT, { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. need a blank There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added newline at all suggested place @monkeyDluffy6017 |
||
uri = "/hello", | ||
upstream = { | ||
type = "roundrobin", | ||
nodes = { | ||
["127.0.0.1:1980"] = 1 | ||
["127.0.0.1:1982"] = 1 | ||
} | ||
}, | ||
plugins = { | ||
["splunk-hec-logging"] = { | ||
endpoint = { | ||
uri = "http://127.0.0.1:1980/splunk_hec_logging", | ||
uri = "http://127.0.0.1:18088/services/collector", | ||
token = "BD274822-96AA-4DA6-90EC-18940FB2414C" | ||
}, | ||
log_format = { | ||
host = "$host", | ||
["@timestamp"] = "$time_iso8601", | ||
vip = "$remote_addr" | ||
}, | ||
batch_max_size = 1, | ||
batch_max_size = 3, | ||
inactive_timeout = 1 | ||
} | ||
} | ||
} | ||
local t = require("lib.test_admin").test | ||
local code, body = t('/apisix/admin/routes/1', ngx.HTTP_PUT, config) | ||
|
||
}) | ||
if code >= 300 then | ||
ngx.status = code | ||
ngx.say(body) | ||
return | ||
end | ||
|
||
local code, _, body2 = t("/hello", "GET") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. need a blank |
||
if code >= 300 then | ||
ngx.status = code | ||
ngx.say("fail") | ||
return | ||
end | ||
ngx.say(body) | ||
} | ||
} | ||
--- response_body | ||
passed | ||
--- wait: 5 | ||
|
||
|
||
|
||
=== TEST 10: hit | ||
--- extra_init_by_lua | ||
local core = require("apisix.core") | ||
local decode = require("toolkit.json").decode | ||
local up = require("lib.server") | ||
up.splunk_hec_logging = function() | ||
ngx.log(ngx.WARN, "the mock backend is hit") | ||
|
||
ngx.req.read_body() | ||
local data = ngx.req.get_body_data() | ||
ngx.log(ngx.WARN, data) | ||
data = decode(data) | ||
assert(data.event.vip == "127.0.0.1") | ||
assert(data.source == "apache-apisix-splunk-hec-logging") | ||
assert(data.host == core.utils.gethostname()) | ||
ngx.say('{}') | ||
end | ||
--- request | ||
GET /hello | ||
--- wait: 2 | ||
--- response_body | ||
hello world | ||
--- error_log | ||
the mock backend is hit | ||
--- no_error_log | ||
[error] | ||
=== TEST 10: check splunk log | ||
--- exec | ||
tail -n 1 ci/pod/vector/splunk.log | ||
--- response_body eval | ||
qr/.*logger format in plugin.*/ | ||
|
||
|
||
|
||
|
@@ -383,12 +365,29 @@ the mock backend is hit | |
location /t { | ||
content_by_lua_block { | ||
local t = require("lib.test_admin").test | ||
local code, body = t('/apisix/admin/plugin_metadata/splunk-hec-logging', | ||
ngx.HTTP_PUT, | ||
[[{ | ||
"log_format": { | ||
"host": "$host", | ||
"@timestamp": "$time_iso8601", | ||
"vip": "$remote_addr", | ||
"message_3":"test batched data" | ||
} | ||
}]] | ||
) | ||
if code >= 300 then | ||
ngx.status = code | ||
ngx.say(body) | ||
return | ||
end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. need a blank |
||
|
||
local code, body = t('/apisix/admin/routes/1', ngx.HTTP_PUT, { | ||
uri = "/hello", | ||
upstream = { | ||
type = "roundrobin", | ||
nodes = { | ||
["127.0.0.1:1980"] = 1 | ||
["127.0.0.1:1982"] = 1 | ||
} | ||
}, | ||
plugins = { | ||
|
@@ -406,19 +405,24 @@ the mock backend is hit | |
if code >= 300 then | ||
ngx.status = code | ||
end | ||
|
||
local code, _, body2 = t("/hello", "GET") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. need a blank |
||
if code >= 300 then | ||
ngx.status = code | ||
ngx.say("fail") | ||
return | ||
end | ||
ngx.say(body) | ||
} | ||
} | ||
--- response_body | ||
passed | ||
--- wait: 5 | ||
|
||
|
||
|
||
=== TEST 12: hit | ||
--- pipelined_requests eval | ||
["GET /hello", "GET /hello", "GET /hello"] | ||
--- wait: 2 | ||
=== TEST 12: check splunk log | ||
--- exec | ||
tail -n 1 ci/pod/vector/splunk.log | ||
--- response_body eval | ||
["hello world\n", "hello world\n", "hello world\n"] | ||
--- no_error_log | ||
[error] | ||
qr/.*test batched data.*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why remove this component?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because we don't need a separate splunk server now. Vector does the job
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok