-
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
5ab8c15
commit 5b0da6d
Showing
4 changed files
with
82 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,53 @@ | ||
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 compile_resource_attributes | ||
|
||
setup(function() | ||
old_ngx = _G.ngx | ||
_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 | ||
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) |
5b0da6d
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.
Bazel Build
Docker image available
kong/kong:5b0da6df3601eedca37054ca87a39290d645212c
Artifacts available https://github.com/Kong/kong/actions/runs/12468830217