-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests(opentelemetry): OTel formatted logs
This commit adds unit and integration tests for the OTel-formatted logs feature.
- Loading branch information
Showing
5 changed files
with
388 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
-- This software is copyright Kong Inc. and its licensors. | ||
-- Use of the software is subject to the agreement between your organization | ||
-- and Kong Inc. If there is no such agreement, use is governed by and | ||
-- subject to the terms of the Kong Master Software License Agreement found | ||
-- at https://konghq.com/enterprisesoftwarelicense/. | ||
-- [ END OF LICENSE 0867164ffc95e54f04670b5169c09574bdbd9bba ] | ||
|
||
require "kong.tools.utils" | ||
|
||
|
||
describe("Observability/Logs unit tests", function() | ||
describe("maybe_push()", function() | ||
local o11y_logs, maybe_push, get_request_logs, get_worker_logs | ||
local old_ngx, old_kong | ||
|
||
lazy_setup(function() | ||
old_ngx = _G.ngx | ||
old_kong = _G.kong | ||
|
||
_G.ngx = { | ||
config = { subsystem = "http" }, | ||
ctx = {}, | ||
DEBUG = ngx.DEBUG, | ||
INFO = ngx.INFO, | ||
WARN = ngx.WARN, | ||
} | ||
|
||
_G.kong = { | ||
configuration = { | ||
log_level = "info", | ||
}, | ||
} | ||
|
||
o11y_logs = require "kong.observability.logs" | ||
maybe_push = o11y_logs.maybe_push | ||
get_request_logs = o11y_logs.get_request_logs | ||
get_worker_logs = o11y_logs.get_worker_logs | ||
end) | ||
|
||
before_each(function() | ||
_G.ngx.ctx = {} | ||
end) | ||
|
||
lazy_teardown(function() | ||
_G.ngx = old_ngx | ||
_G.kong = old_kong | ||
end) | ||
|
||
it("has no effect when no log line is provided", function() | ||
maybe_push(ngx.INFO) | ||
local worker_logs = get_worker_logs() | ||
assert.same({}, worker_logs) | ||
local request_logs = get_request_logs() | ||
assert.same({}, request_logs) | ||
end) | ||
|
||
it("has no effect when log line is empty", function() | ||
maybe_push(ngx.INFO, "") | ||
local worker_logs = get_worker_logs() | ||
assert.same({}, worker_logs) | ||
local request_logs = get_request_logs() | ||
assert.same({}, request_logs) | ||
end) | ||
|
||
it("has no effect when log level is lower than the configured value", function() | ||
maybe_push(ngx.DEBUG, "Don't mind me, I'm just a debug log") | ||
local worker_logs = get_worker_logs() | ||
assert.same({}, worker_logs) | ||
local request_logs = get_request_logs() | ||
assert.same({}, request_logs) | ||
end) | ||
|
||
it("generates request-scoped log entries", function() | ||
local log_level = ngx.WARN | ||
local body = "Careful! I'm a warning!" | ||
|
||
maybe_push(log_level, body) | ||
local worker_logs = get_worker_logs() | ||
assert.same({}, worker_logs) | ||
|
||
local request_logs = get_request_logs() | ||
assert.same(1, #request_logs) | ||
|
||
local logged_entry = request_logs[1] | ||
assert.same(log_level, logged_entry.log_level) | ||
assert.same(body, logged_entry.body) | ||
assert.is_table(logged_entry.attributes) | ||
assert.is_number(logged_entry.attributes.introspection_current_line) | ||
assert.is_string(logged_entry.attributes.introspection_name) | ||
assert.is_string(logged_entry.attributes.introspection_namewhat) | ||
assert.is_string(logged_entry.attributes.introspection_source) | ||
assert.is_string(logged_entry.attributes.introspection_what) | ||
assert.is_number(logged_entry.observed_time_unix_nano) | ||
assert.is_number(logged_entry.time_unix_nano) | ||
end) | ||
end) | ||
end) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.