-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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(fault-injection): support conditional fault injection using nginx variables #3363
feat(fault-injection): support conditional fault injection using nginx variables #3363
Conversation
ci failed |
I need to adjust the code logic and I will solve the ci problem later. |
apisix/plugins/fault-injection.lua
Outdated
|
||
local plugin_name = "fault-injection" | ||
|
||
|
||
local vars_schema = { |
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.
I think we need to remove the vars_schema
.
- we can do the check better with
expr.new
when checking the schema. - when
not
/or
is supported directly in the expr, this schema is outdated. - this schema contains many incorrect hardcoded limitations, like the
maxLength
of operator is2
(not enough forhas
), and an expression may contain 4 elements if!
is used, etc.
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.
updated.
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.
No, you don't remove it.
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.
I think just keep:
local vars_schema = {
type = "array",
maxItems = 20
}
is enough. The remain can be validated via expr.new
.
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.
Okay, let me try it.
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.
updated.
apisix/plugins/fault-injection.lua
Outdated
for _, var in ipairs(vars) do | ||
local expr, err = expr.new(var) | ||
if err then | ||
core.log.error("vars expression does not match: ", err) |
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 be failed to create vars expression
, we haven't matched it yet.
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.
updated.
return match_result, nil | ||
end | ||
|
||
|
||
function _M.check_schema(conf) | ||
local ok, err = core.schema.check(schema, conf) |
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.
Better to check the expression here and add a test for it.
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.
updated.
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.
No, I mean checking the expression via:
local expr, err = expr.new(var)
if err then
core.log.error("failed to create vars expression: ", err)
return nil, err
end
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.
added.
What this PR does / why we need it:
We can add new features to the fault-injection plugin for the following reasons:
Currently, the
fault-injection
plugin does not support custom conditions to implement themock
function. I think we can add the request header as a conditional judgment in the request (there may be a better way) to realize the mock function.E.g:
If
vars
passes the verification, fault injection is performed on the request. Otherwise, no processing is done on the request. In order to maintain backward compatibility, the fault injection operation is still performed when the vars condition is not configured.close #2511
Pre-submission checklist: