Skip to content
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

fix(prometheus): add a toggle switch for wasm metrics export #13960

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions kong/clustering/compat/removed_fields.lua
Original file line number Diff line number Diff line change
Expand Up @@ -228,4 +228,11 @@ return {
"queue.concurrency_limit",
},
},

-- Any dataplane older than 3.9.0
[3009000000] = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
[3009000000] = {
[30010000000] = {

3.9.0 is in code freeze, should we target this to 3.10 or 3.9.1?
Note: I'm not sure that is how we target 3.10, is there a risk we target 3.1.0?

prometheus = {
"wasm_metrics",
},
},
}
14 changes: 13 additions & 1 deletion kong/plugins/prometheus/exporter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,19 @@ end


local function configure(configs)
IS_PROMETHEUS_ENABLED = configs ~= nil
IS_PROMETHEUS_ENABLED = false
wasm.set_enabled(false)

if configs ~= nil then
IS_PROMETHEUS_ENABLED = true

for i = 1, #configs do
if configs[i].wasm_metrics then
wasm.set_enabled(true)
break
end
end
end
end


Expand Down
1 change: 1 addition & 0 deletions kong/plugins/prometheus/schema.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ return {
{ latency_metrics = { description = "A boolean value that determines if latency metrics should be collected. If enabled, `kong_latency_ms`, `upstream_latency_ms` and `request_latency_ms` metrics will be exported.", type = "boolean", default = false }, },
{ bandwidth_metrics = { description = "A boolean value that determines if bandwidth metrics should be collected. If enabled, `bandwidth_bytes` and `stream_sessions_total` metrics will be exported.", type = "boolean", default = false }, },
{ upstream_health_metrics = { description = "A boolean value that determines if upstream metrics should be collected. If enabled, `upstream_target_health` metric will be exported.", type = "boolean", default = false }, },
{ wasm_metrics = { description = "A boolean value that determines if Wasm metrics should be collected.", type = "boolean", default = false }, },
},
custom_validator = validate_shared_dict,
}, },
Expand Down
7 changes: 6 additions & 1 deletion kong/plugins/prometheus/wasmx.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ local _M = {}
local FLUSH_EVERY = 100
local GET_METRIC_OPTS = { prefix = false }

local export_enabled = false

local metrics_data_buf = buf_new()
local labels_serialization_buf = buf_new()
Expand Down Expand Up @@ -181,7 +182,7 @@ end


_M.metrics_data = function()
if not wasm.enabled() then
if not export_enabled or not wasm.enabled() then
return
end

Expand Down Expand Up @@ -231,4 +232,8 @@ _M.metrics_data = function()
end


function _M.set_enabled(enabled)
export_enabled = enabled
end

return _M
28 changes: 26 additions & 2 deletions spec/02-integration/09-hybrid_mode/09-config-compat_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1013,13 +1013,37 @@ describe("CP/DP config compat transformations #" .. strategy, function()
}
-- ]]

finally(function()
admin.plugins:remove({ id = prometheus.id })
end)

local expected_prometheus_prior_38 = cycle_aware_deep_copy(prometheus)
expected_prometheus_prior_38.config.ai_metrics = nil
expected_prometheus_prior_38.config.wasm_metrics = nil

do_assert(uuid(), "3.7.0", expected_prometheus_prior_38)
end)

-- cleanup
admin.plugins:remove({ id = prometheus.id })
it("[prometheus] remove wasm_metrics property for versions below 3.9", function()
-- [[ 3.9.x ]] --
local prometheus = admin.plugins:insert {
name = "prometheus",
enabled = true,
config = {
wasm_metrics = true, -- becomes nil
},
}
-- ]]

finally(function()
admin.plugins:remove({ id = prometheus.id })
end)


local expected_prometheus_prior_39 = cycle_aware_deep_copy(prometheus)
expected_prometheus_prior_39.config.wasm_metrics = nil

do_assert(uuid(), "3.8.0", expected_prometheus_prior_39)
end)
end)

Expand Down
5 changes: 4 additions & 1 deletion spec/03-plugins/26-prometheus/09-wasmx_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,10 @@ for _, strategy in helpers.each_strategy() do
add_filter_to_service(bp, "tests", service)
add_filter_to_service(bp, "tests", service2)

bp.plugins:insert({ name = "prometheus" })
assert(bp.plugins:insert({
name = "prometheus",
config = { wasm_metrics = true },
}))

assert(helpers.start_kong({
nginx_conf = "spec/fixtures/custom_nginx.template",
Expand Down
Loading