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

feat(schema): add deprecation field attribute #12686

Merged
merged 2 commits into from
Mar 13, 2024
Merged
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
message: "**Schema**: Added a deprecation field attribute to identify deprecated fields"
type: feature
scope: Configuration
12 changes: 12 additions & 0 deletions kong/db/schema/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ local nkeys = require "table.nkeys"
local is_reference = require "kong.pdk.vault".is_reference
local json = require "kong.db.schema.json"
local cjson_safe = require "cjson.safe"
local deprecation = require "kong.deprecation"
local deepcompare = require "pl.tablex".deepcompare


local setmetatable = setmetatable
Expand Down Expand Up @@ -882,6 +884,16 @@ function Schema:validate_field(field, value)
return nil, validation_errors.SUBSCHEMA_ABSTRACT_FIELD
end

if field.deprecation then
local old_default = field.deprecation.old_default
local should_warn = old_default == nil
Copy link
Contributor

Choose a reason for hiding this comment

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

This line seems conflict with the doc in metaschema.lua "If old_default is set, logging is conditional to the field's value being different from the value of old_default.". Should it be old_default ~= nil or update the document like:
"If old_default is not set, logging is conditional to the field's value being different from the value of old_default."
?

Copy link
Member Author

@samugi samugi Mar 12, 2024

Choose a reason for hiding this comment

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

I realize the comment (in the code) wasn't very clear, I reworded it, could you check again? Thanks!

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks! My previous comment also does not correctly catch the meaning of the code. But your last version makes it more clear. And sorry for the confusion comment.

or not deepcompare(value, old_default)
if should_warn then
deprecation(field.deprecation.message,
{ after = field.deprecation.removal_in_version, })
end
end

if field.type == "array" then
if not is_sequence(value) then
return nil, validation_errors.ARRAY
Expand Down
14 changes: 14 additions & 0 deletions kong/db/schema/metaschema.lua
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,20 @@ local field_schema = {
{ encrypted = { type = "boolean" }, },
{ referenceable = { type = "boolean" }, },
{ json_schema = json_metaschema },
-- Deprecation attribute: used to mark a field as deprecated
-- Results in `message` and `removal_in_version` to be printed in a warning
-- (via kong.deprecation) when the field is used.
-- If `old_default` is not set, the warning message is always printed.
-- If `old_default` is set, the warning message is only printed when the
-- field's value is different from the value of `old_default`.
{ deprecation = {
type = "record",
fields = {
{ message = { type = "string", required = true } },
{ removal_in_version = { type = "string", required = true } },
{ old_default = { type = "any", required = false } },
},
} },
}


Expand Down
21 changes: 12 additions & 9 deletions kong/plugins/acme/schema.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
local typedefs = require "kong.db.schema.typedefs"
local reserved_words = require "kong.plugins.acme.reserved_words"
local redis_schema = require "kong.tools.redis.schema"
local deprecation = require("kong.deprecation")

local tablex = require "pl.tablex"

Expand Down Expand Up @@ -43,37 +42,41 @@ local LEGACY_SCHEMA_TRANSLATIONS = {
type = "string",
len_min = 0,
translate_backwards = {'password'},
deprecation = {
message = "acme: config.storage_config.redis.auth is deprecated, please use config.storage_config.redis.password instead",
removal_in_version = "4.0", },
func = function(value)
deprecation("acme: config.storage_config.redis.auth is deprecated, please use config.storage_config.redis.password instead",
{ after = "4.0", })
return { password = value }
end
}},
{ ssl_server_name = {
type = "string",
translate_backwards = {'server_name'},
deprecation = {
message = "acme: config.storage_config.redis.ssl_server_name is deprecated, please use config.storage_config.redis.server_name instead",
removal_in_version = "4.0", },
func = function(value)
deprecation("acme: config.storage_config.redis.ssl_server_name is deprecated, please use config.storage_config.redis.server_name instead",
{ after = "4.0", })
return { server_name = value }
end
}},
{ namespace = {
type = "string",
len_min = 0,
translate_backwards = {'extra_options', 'namespace'},
deprecation = {
message = "acme: config.storage_config.redis.namespace is deprecated, please use config.storage_config.redis.extra_options.namespace instead",
removal_in_version = "4.0", },
func = function(value)
deprecation("acme: config.storage_config.redis.namespace is deprecated, please use config.storage_config.redis.extra_options.namespace instead",
{ after = "4.0", })
return { extra_options = { namespace = value } }
end
}},
{ scan_count = {
type = "integer",
translate_backwards = {'extra_options', 'scan_count'},
deprecation = {
message = "acme: config.storage_config.redis.scan_count is deprecated, please use config.storage_config.redis.extra_options.scan_count instead",
removal_in_version = "4.0", },
func = function(value)
deprecation("acme: config.storage_config.redis.scan_count is deprecated, please use config.storage_config.redis.extra_options.scan_count instead",
{ after = "4.0", })
return { extra_options = { scan_count = value } }
end
}},
Expand Down
51 changes: 20 additions & 31 deletions kong/plugins/datadog/schema.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
local typedefs = require "kong.db.schema.typedefs"
local deprecation = require("kong.deprecation")

local STAT_NAMES = {
"kong_latency",
Expand Down Expand Up @@ -89,17 +88,30 @@ return {
consumer_tag = { description = "String to be attached as tag of the consumer.", type = "string",
default = "consumer" }, },
{
retry_count = { description = "Number of times to retry when sending data to the upstream server.",
type = "integer" }, },
retry_count = {
description = "Number of times to retry when sending data to the upstream server.",
type = "integer",
deprecation = {
message = "datadog: config.retry_count no longer works, please use config.queue.max_retry_time instead",
removal_in_version = "4.0",
old_default = 10 }, }, },
{
queue_size = {
description = "Maximum number of log entries to be sent on each message to the upstream server.",
type = "integer" }, },
description = "Maximum number of log entries to be sent on each message to the upstream server.",
type = "integer",
deprecation = {
message = "datadog: config.queue_size is deprecated, please use config.queue.max_batch_size instead",
removal_in_version = "4.0",
old_default = 1 }, }, },
{
flush_timeout = {
description =
"Optional time in seconds. If `queue_size` > 1, this is the max idle time before sending a log with less than `queue_size` records.",
type = "number" }, },
description =
"Optional time in seconds. If `queue_size` > 1, this is the max idle time before sending a log with less than `queue_size` records.",
type = "number",
deprecation = {
message = "datadog: config.flush_timeout is deprecated, please use config.queue.max_coalescing_delay instead",
removal_in_version = "4.0",
old_default = 2 }, }, },
{ queue = typedefs.queue },
{
metrics = {
Expand Down Expand Up @@ -135,29 +147,6 @@ return {
},
},
},

entity_checks = {
{
custom_entity_check = {
field_sources = { "retry_count", "queue_size", "flush_timeout" },
fn = function(entity)
if (entity.retry_count or ngx.null) ~= ngx.null and entity.retry_count ~= 10 then
deprecation("datadog: config.retry_count no longer works, please use config.queue.max_retry_time instead",
{ after = "4.0", })
end
if (entity.queue_size or ngx.null) ~= ngx.null and entity.queue_size ~= 1 then
deprecation("datadog: config.queue_size is deprecated, please use config.queue.max_batch_size instead",
{ after = "4.0", })
end
if (entity.flush_timeout or ngx.null) ~= ngx.null and entity.flush_timeout ~= 2 then
deprecation("datadog: config.flush_timeout is deprecated, please use config.queue.max_coalescing_delay instead",
{ after = "4.0", })
end
return true
end
}
},
},
},
},
},
Expand Down
46 changes: 21 additions & 25 deletions kong/plugins/http-log/schema.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
local typedefs = require "kong.db.schema.typedefs"
local url = require "socket.url"
local deprecation = require("kong.deprecation")


return {
Expand All @@ -15,9 +14,27 @@ return {
{ content_type = { description = "Indicates the type of data sent. The only available option is `application/json`.", type = "string", default = "application/json", one_of = { "application/json", "application/json; charset=utf-8" }, }, },
{ timeout = { description = "An optional timeout in milliseconds when sending data to the upstream server.", type = "number", default = 10000 }, },
{ keepalive = { description = "An optional value in milliseconds that defines how long an idle connection will live before being closed.", type = "number", default = 60000 }, },
{ retry_count = { description = "Number of times to retry when sending data to the upstream server.", type = "integer" }, },
{ queue_size = { description = "Maximum number of log entries to be sent on each message to the upstream server.", type = "integer" }, },
{ flush_timeout = { description = "Optional time in seconds. If `queue_size` > 1, this is the max idle time before sending a log with less than `queue_size` records.", type = "number" }, },
{ retry_count = {
description = "Number of times to retry when sending data to the upstream server.",
type = "integer",
deprecation = {
message = "http-log: config.retry_count no longer works, please use config.queue.max_retry_time instead",
removal_in_version = "4.0",
old_default = 10 }, }, },
{ queue_size = {
description = "Maximum number of log entries to be sent on each message to the upstream server.",
type = "integer",
deprecation = {
message = "http-log: config.queue_size is deprecated, please use config.queue.max_batch_size instead",
removal_in_version = "4.0",
old_default = 1 }, }, },
{ flush_timeout = {
description = "Optional time in seconds. If `queue_size` > 1, this is the max idle time before sending a log with less than `queue_size` records.",
type = "number",
deprecation = {
message = "http-log: config.flush_timeout is deprecated, please use config.queue.max_coalescing_delay instead",
removal_in_version = "4.0",
old_default = 2 }, }, },
{ headers = { description = "An optional table of headers included in the HTTP message to the upstream server. Values are indexed by header name, and each header name accepts a single string.", type = "map",
keys = typedefs.header_name {
match_none = {
Expand All @@ -43,27 +60,6 @@ return {
{ queue = typedefs.queue },
{ custom_fields_by_lua = typedefs.lua_code },
},

entity_checks = {
{ custom_entity_check = {
field_sources = { "retry_count", "queue_size", "flush_timeout" },
fn = function(entity)
if (entity.retry_count or ngx.null) ~= ngx.null and entity.retry_count ~= 10 then
deprecation("http-log: config.retry_count no longer works, please use config.queue.max_retry_time instead",
{ after = "4.0", })
end
if (entity.queue_size or ngx.null) ~= ngx.null and entity.queue_size ~= 1 then
deprecation("http-log: config.queue_size is deprecated, please use config.queue.max_batch_size instead",
{ after = "4.0", })
end
if (entity.flush_timeout or ngx.null) ~= ngx.null and entity.flush_timeout ~= 2 then
deprecation("http-log: config.flush_timeout is deprecated, please use config.queue.max_coalescing_delay instead",
{ after = "4.0", })
end
return true
end
} },
},
custom_validator = function(config)
-- check no double userinfo + authorization header
local parsed_url = url.parse(config.http_endpoint)
Expand Down
33 changes: 14 additions & 19 deletions kong/plugins/opentelemetry/schema.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
local typedefs = require "kong.db.schema.typedefs"
local Schema = require "kong.db.schema"
local deprecation = require("kong.deprecation")

local function custom_validator(attributes)
for _, v in pairs(attributes) do
Expand Down Expand Up @@ -50,8 +49,20 @@ return {
max_batch_size = 200,
},
} },
{ batch_span_count = { description = "The number of spans to be sent in a single batch.", type = "integer" } },
{ batch_flush_delay = { description = "The delay, in seconds, between two consecutive batches.", type = "integer" } },
{ batch_span_count = {
description = "The number of spans to be sent in a single batch.",
type = "integer",
deprecation = {
message = "opentelemetry: config.batch_span_count is deprecated, please use config.queue.max_batch_size instead",
removal_in_version = "4.0",
old_default = 200 }, }, },
{ batch_flush_delay = {
description = "The delay, in seconds, between two consecutive batches.",
type = "integer",
deprecation = {
message = "opentelemetry: config.batch_flush_delay is deprecated, please use config.queue.max_coalescing_delay instead",
removal_in_version = "4.0",
old_default = 3, }, }, },
{ connect_timeout = typedefs.timeout { default = 1000 } },
{ send_timeout = typedefs.timeout { default = 5000 } },
{ read_timeout = typedefs.timeout { default = 5000 } },
Expand All @@ -71,22 +82,6 @@ return {
default = nil,
} },
},
entity_checks = {
{ custom_entity_check = {
field_sources = { "batch_span_count", "batch_flush_delay" },
fn = function(entity)
if (entity.batch_span_count or ngx.null) ~= ngx.null and entity.batch_span_count ~= 200 then
deprecation("opentelemetry: config.batch_span_count is deprecated, please use config.queue.max_batch_size instead",
{ after = "4.0", })
end
if (entity.batch_flush_delay or ngx.null) ~= ngx.null and entity.batch_flush_delay ~= 3 then
deprecation("opentelemetry: config.batch_flush_delay is deprecated, please use config.queue.max_coalescing_delay instead",
{ after = "4.0", })
end
return true
end
} },
},
}, },
},
}
Loading
Loading