-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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(opentelemetry): support variable resource attributes #13839
base: master
Are you sure you want to change the base?
feat(opentelemetry): support variable resource attributes #13839
Conversation
failing test is expected, let's rebase after #13877 is merged |
6dc12b9
to
eaf8f25
Compare
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.
Thank you so much for your contribution, this is great! I left a few comments for things that I feel could be improved a bit. There's some code duplication with request-transformer
that we may want to take care of, but that refactor can be done later.
eaf8f25
to
8a185af
Compare
0581567
to
4cfc804
Compare
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.
thanks for the quick action! I left a couple more suggestions, then I think it's good to go.
4cfc804
to
aba7105
Compare
aba7105
to
48c4be0
Compare
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.
Looks good to me, thank you!!
Could you just update the documentation line for this configuration field in the plugin's schema? This is used to auto-generate docs.
f9e3afb
to
4e2c7ab
Compare
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.
great job and thanks again!
Edit: sorry about the failing CI, it's because the new schema description exceeded the length limit, if you undo that change I'll take care of updating the plugin's docs as required.
4e2c7ab
to
d5a0c23
Compare
Do we need a second reviewer to get this in? |
yes @SuzyWangIBMer I'm trying to get the second approval, thank you for your patience |
kong/plugins/opentelemetry/utils.lua
Outdated
return { | ||
http_export_request = http_export_request, | ||
get_headers = get_headers, | ||
_log_prefix = _log_prefix, | ||
read_resource_attributes = read_resource_attributes, |
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.
should we have a unit test for this function?
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.
We now have a test for possible resource attributes sent and received. I can also work on one if you think it does not cover everything.
kong/spec/03-plugins/37-opentelemetry/04-exporter_spec.lua
Lines 566 to 572 in 982f2a3
setup_instrumentations("all", { | |
resource_attributes = { | |
["service.name"] = "kong_oss", | |
["os.version"] = "debian", | |
["host.name"] = "$(headers.host)", | |
["validstr"] = "$($@#)", | |
} |
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.
@SuzyWangIBMer I think @fffonion is referring to the fact we could have a dedicated unit test for this function, in addition to the integration test you've mentioned, for example in a spec/03-plugins/37-opentelemetry/06-utils_spec.lua
file.
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.
Sure, I will work on one.
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.
PR updated, let me know what do you guys think.
d5a0c23
to
982f2a3
Compare
982f2a3
to
7239a60
Compare
7239a60
to
f56f481
Compare
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.
That looks great! Thank you @SuzyWangIBMer for your contribution! 🚀
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.
@SuzyWangIBMer please address these, then CI should become green and we should be ready.
@@ -1,9 +1,17 @@ | |||
local http = require "resty.http" | |||
local clone = require "table.clone" | |||
|
|||
local sandbox = require "kong.tools.sandbox" | |||
local deep_copy = require("kong.tools.table").deep_copy |
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.
local deep_copy = require("kong.tools.table").deep_copy | |
local cycle_aware_deep_copy = require("kong.tools.table").cycle_aware_deep_copy |
sorry, I noticed this last-minute
local template_env = {} | ||
if lua_enabled and sandbox_enabled then | ||
-- load the sandbox environment to be used to render the template | ||
template_env = deep_copy(sandbox.configuration.environment) |
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.
template_env = deep_copy(sandbox.configuration.environment) | |
template_env = cycle_aware_deep_copy(sandbox.configuration.environment) |
@@ -0,0 +1,52 @@ | |||
local LOG_PHASE = require("kong.pdk.private.phases").phases.log | |||
|
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.
require "spec.helpers" | |
we still need to require helpers because it does some needed setup on the environment, but don't assign it to a local variable, or else the linter will complain because it's unused.
Summary
This change allows render resource attributes as lua code.
For example,
host.id
is0.0.0.0:9000
or depends onheaders.host
value.Checklist
changelog/unreleased/kong
orskip-changelog
label added on PR if changelog is unnecessary. README.mdIssue reference
Fix #12538