-
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.
test(opentelemetry): support variable resource attributes
- Loading branch information
1 parent
a2f613b
commit 7239a60
Showing
4 changed files
with
85 additions
and
7 deletions.
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
changelog/unreleased/kong/feat-variable-resource-attributes.yml
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,4 @@ | ||
message: | | ||
**Opentelemetry**: Support variable resource attributes | ||
type: feature | ||
scope: Plugin |
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
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
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,56 @@ | ||
local helpers = require "spec.helpers" | ||
local LOG_PHASE = require("kong.pdk.private.phases").phases.log | ||
|
||
describe("compile_resource_attributes()", function() | ||
local mock_request | ||
local old_ngx | ||
local old_kong | ||
local compile_resource_attributes | ||
|
||
setup(function() | ||
old_ngx = _G.ngx | ||
old_kong = _G.kong | ||
_G.ngx = { | ||
ctx = { | ||
KONG_PHASE = LOG_PHASE | ||
}, | ||
req = { | ||
get_headers = function() return mock_request.headers end, | ||
}, | ||
get_phase = function() return "log" end, | ||
} | ||
package.loaded["kong.pdk.request"] = nil | ||
package.loaded["kong.plugins.opentelemetry.utils"] = nil | ||
|
||
local pdk_request = require "kong.pdk.request" | ||
kong.request = pdk_request.new(kong) | ||
compile_resource_attributes = require "kong.plugins.opentelemetry.utils".compile_resource_attributes | ||
end) | ||
|
||
lazy_teardown(function() | ||
_G.ngx = old_ngx | ||
_G.kong = old_kong | ||
end) | ||
|
||
|
||
it("accepts valid template and valid string", function() | ||
mock_request = { | ||
headers = { | ||
host = "kong-test", | ||
}, | ||
} | ||
local resource_attributes = { | ||
["valid_variable"] = "$(headers.host)", | ||
["nonexist_variable"] = "$($@#)", | ||
["valid_string"] = "valid", | ||
} | ||
local rendered_resource_attributes, err = compile_resource_attributes(resource_attributes) | ||
|
||
assert.is_nil(err) | ||
assert.same(rendered_resource_attributes["valid_variable"], "kong-test") | ||
|
||
-- take as a normal string if variable does not exist | ||
assert.same(rendered_resource_attributes["nonexist_variable"], "$($@#)") | ||
assert.same(rendered_resource_attributes["valid_string"], "valid") | ||
end) | ||
end) |