HaoTien commented on code in PR #12765:
URL: https://github.com/apache/apisix/pull/12765#discussion_r2587237854
##########
apisix/plugins/api-breaker.lua:
##########
@@ -23,245 +23,643 @@ local error = error
local ipairs = ipairs
-local shared_buffer = ngx.shared["plugin-".. plugin_name]
+local shared_buffer = ngx.shared["plugin-" .. plugin_name]
if not shared_buffer then
- error("failed to get ngx.shared dict when load plugin " .. plugin_name)
+ error("failed to get ngx.shared dict when load plugin " .. plugin_name)
end
+-- Circuit breaker states (only for ratio policy)
+local CLOSED = 0
+local OPEN = 1
+local HALF_OPEN = 2
local schema = {
- type = "object",
+ type = "object",
+ properties = {
+ break_response_code = {
+ type = "integer",
+ minimum = 200,
+ maximum = 599,
+ },
+ break_response_body = {
+ type = "string"
+ },
+ break_response_headers = {
+ type = "array",
+ items = {
+ type = "object",
+ properties = {
+ key = {
+ type = "string",
+ minLength = 1
+ },
+ value = {
+ type = "string",
+ minLength = 1
+ }
+ },
+ required = { "key", "value" },
+ }
+ },
+ max_breaker_sec = {
+ type = "integer",
+ minimum = 3,
+ default = 300,
+ description = "Circuit breaker duration in seconds (applies to both
count and ratio policies)"
+ },
+ policy = {
+ type = "string",
+ enum = { "unhealthy-count", "unhealthy-ratio" },
+ default = "unhealthy-count",
+ }
+ },
+ required = { "break_response_code" },
+ ["if"] = {
+ properties = {
+ policy = {
+ enum = { "unhealthy-count" },
+ },
+ },
+ },
+ ["then"] = {
properties = {
- break_response_code = {
+ unhealthy = {
+ type = "object",
+ properties = {
+ http_statuses = {
+ type = "array",
+ minItems = 1,
+ items = {
+ type = "integer",
+ minimum = 500,
+ maximum = 599,
+ },
+ uniqueItems = true,
+ default = { 500 }
+ },
+ failures = {
type = "integer",
- minimum = 200,
- maximum = 599,
+ minimum = 1,
+ default = 3,
+ }
},
- break_response_body = {
- type = "string"
- },
- break_response_headers = {
+ default = { http_statuses = { 500 }, failures = 3 }
+ },
+ healthy = {
+ type = "object",
+ properties = {
+ http_statuses = {
type = "array",
+ minItems = 1,
items = {
- type = "object",
- properties = {
- key = {
- type = "string",
- minLength = 1
- },
- value = {
- type = "string",
- minLength = 1
- }
- },
- required = {"key", "value"},
- }
- },
- max_breaker_sec = {
+ type = "integer",
+ minimum = 200,
+ maximum = 499,
+ },
+ uniqueItems = true,
+ default = { 200 }
+ },
+ successes = {
type = "integer",
- minimum = 3,
- default = 300,
+ minimum = 1,
+ default = 3,
+ }
+ },
+ default = { http_statuses = { 200 }, successes = 3 }
+ }
+ }
+ },
+ ["else"] = {
+ ["if"] = {
+ properties = {
+ policy = {
+ enum = { "unhealthy-ratio" },
},
+ },
+ },
+ ["then"] = {
+ properties = {
unhealthy = {
- type = "object",
- properties = {
- http_statuses = {
- type = "array",
- minItems = 1,
- items = {
- type = "integer",
- minimum = 500,
- maximum = 599,
- },
- uniqueItems = true,
- default = {500}
- },
- failures = {
- type = "integer",
- minimum = 1,
- default = 3,
- }
+ type = "object",
+ properties = {
+ http_statuses = {
+ type = "array",
+ minItems = 1,
+ items = {
+ type = "integer",
+ minimum = 500,
+ maximum = 599,
+ },
+ uniqueItems = true,
+ default = { 500 }
+ },
+ error_ratio = {
+ type = "number",
+ minimum = 0,
+ maximum = 1,
+ default = 0.5,
+ description = "Failure rate threshold to trigger circuit breaker"
+ },
+ min_request_threshold = {
+ type = "integer",
+ minimum = 1,
+ default = 10,
+ description = "Minimum number of calls before circuit breaker
can be triggered"
+ },
+ sliding_window_size = {
+ type = "integer",
+ minimum = 10,
+ maximum = 3600,
+ default = 300,
+ description = "Size of the sliding window in seconds"
},
- default = {http_statuses = {500}, failures = 3}
+ permitted_number_of_calls_in_half_open_state = {
Review Comment:
I have optimized this variable name.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]