-
Notifications
You must be signed in to change notification settings - Fork 329
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
Add "if" option to the "match" object. #1204
Conversation
Couple of quick questions. What variables are we talking about here? Is the afore mentioned discussion available anywhere? |
Variable-related APIs, correspond to
I'm afraid no discussion was mentioned. |
njs variables?
I thought the below might have been discussed somewhere...
|
It means Unit variables, for example,
We did consider supporting certain variables, such as |
Perhaps that should be made clear in the commit message then... |
Added, thanks. |
I wonder if
and
should be combined? |
Good idea. |
nxt_int_t ret; | ||
nxt_router_conf_t *rtcf; | ||
nxt_http_action_t *action; | ||
nxt_http_status_t status; | ||
nxt_http_request_t *r; | ||
|
||
r = obj; | ||
action = data; | ||
nxt_int_t ret; | ||
nxt_router_conf_t *rtcf; | ||
nxt_http_status_t status; | ||
|
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.
Technically shouldn't nxt_router_conf_t *rtcf;
and nxt_http_status_t status;
be swapped around as when types are the same length we order by type alphabetically (yes it's the same order as before), not that I really care about this...
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.
Yep, it makes sense to consider the order. But I'd like to keep it the same as I touched it based on the existing order.
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.
All looks fairly reasonable to me...
HI @hongzhidao The only thing you might want to do to be consistent with recent commits is to lowercase the |
Good reminder, thanks. |
Status: The team needs to discuss if we merge this now or wait until variable updating is done. As I understand it:
Merging now avoids the risk of merge conflicts and burden of re-review, while waiting ensures that these patches are fully correct, necessary, and sufficient. |
The team's decision is to defer to @hongzhidao :) If you think we should merge it as-is, please do so. Otherwise, please convert it back to a draft until it's ready for re-review and merging. There's a button at the top right under Reviewers: |
Ah, while this is awaiting merging (or not), we should change the commit subjects to be in "imperative mood", e.g
|
Ok. And I'm going to merge the prepared patches after I test the "if" option, then I'll create a new PR for it. |
No need to make a new PR. You can un-draft this one! See the I've had a look at the latest patch, I'm assuming the rest didn't change and it was just rebased against master... You can always re-request a persons review if things changed enough to warrant re-reviewing... |
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.
This
http: Refactor out nxt_tstr_cond_t from access log
Still suffers from the problem that nxt_http_request_access_log()
was moved and changed in one step making the patch way bigger than it needs to be. If you change it without moving it, that'd be OK...
**EDIT: ** Well, it's not quite the same as before... I just don't understand why it's being done like this.
I think the best thing would be to just put it back like before but make
Look like I showed here. I would also change the subject to just |
OK, looking at it again, I don't think it's so bad. My problem now is the commit subject and message
Which doesn't really describe the change. Not only does it factor code out of I think there should be a commit before this one that adds the Then I'm not sure where this change belongs yet... diff --git ./src/nxt_router_access_log.c ./src/nxt_router_access_log.c
index cc8d5e4f..afecd0b1 100644
--- ./src/nxt_router_access_log.c
+++ ./src/nxt_router_access_log.c
@@ -143,15 +143,8 @@ nxt_router_access_log_create(nxt_task_t *task, nxt_router_conf_t *rtcf,
if (alcf.expr != NULL) {
nxt_conf_get_string(alcf.expr, &str);
- if (str.length > 0 && str.start[0] == '!') {
- rtcf->log_negate = 1;
-
- str.start++;
- str.length--;
- }
-
- rtcf->log_expr = nxt_tstr_compile(rtcf->tstr_state, &str, 0);
- if (nxt_slow_path(rtcf->log_expr == NULL)) {
+ ret = nxt_tstr_cond_compile(rtcf->tstr_state, &str, &rtcf->log_cond);
+ if (nxt_slow_path(ret != NXT_OK)) {
return NXT_ERROR;
}
} Does it directly depend on or is depended on by the change to |
“access log” in the subject means “access log module” but not “nxt_http_request_access_log()”, the later is one function in the access log module. In the commit, it touched the access log module but don’t need to mention specific details like which function “nxt_http_request_access_log()”. Then in the next commit, we get rid of “nxt_http_request_access_log()”.
Belongs to "the access log module". Btw, I change "access log" to "the access log module" in the subject. Hope it eliminates the confusion. |
I'm Looking at this again and by this, I'm talking about
I'm struggling to reconcile the commit message with the change itself. It really looks like to me this commit should be split into three
Let me show you what I mean. That commit now becomes the following in cronological order (1)
(2)
(3)
I think that is much clearer what is going on. The commits have become smaller, I've pushed this up to https://github.com/ac000/unit/commits/var-sync-rework/ |
Thanks a lot. It's a different way to think of it, I'd like to share my thoughts while I was implementing it.
They should be created at the same time, like "var_" stuff, "compile" and "query" are paired, one happens in configuration phase, and the other happens in the request runtime phase.
Is this design idea clear for you? |
I thik the difference is you're talking about committing the feature (i.e this commit) as a whole while, I'm talking about splitting it into logical components. But I don't think we're going to reach equilibrium on this, so I'll say OK to this and move onto looking at the rest of the commits... |
src/nxt_http_route.c
Outdated
if (ret <= 0) { | ||
action = (nxt_http_action_t *) (intptr_t) ret; | ||
return action; |
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.
Minor thing, feel free to ignore...
Do we need the action =
step rather than just returning the thing directly (casted of course).
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.
Makes sense.
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.
Tests: "if" option in http route match.
Should of course be written as
tests: "if" option in http route match
(The most important thing is to get rid of that trailing period!)
6349386
to
121eba5
Compare
src/nxt_http_route.c
Outdated
@@ -1594,8 +1626,15 @@ nxt_http_route_match(nxt_task_t *task, nxt_http_request_t *r, | |||
nxt_http_route_match_t *match) | |||
{ | |||
nxt_int_t ret; | |||
nxt_http_action_t *action; |
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.
Forgot to remove this now it's not needed!?
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.
Fixed.
OK, thanks I think this is good to go now... |
Initially, variable query was designed to accomodate both synchronous and asynchronous operations. However, upon consideration of actual requirements, we recognized that asynchronous support was not needed. The refactoring ensures that the success or failure of the variable query operation is now directly indicated by its return value. This change streamlines the function's usage and enhances code clarity, as it facilitates immediate error handling without the need for asynchronous callbacks or additional error checking functions. Note the patch only works for Unit native variables but not njs variables.
This nxt_tstr_cond_t will be reused for the feature of adding "if" option to the "match" object. The two "if" options have the same usage.
This feature allows users to specify conditions to check if one route is matched. It is used the same way as the "if" option in the access log. Example: { "match": { "if": "`${headers['User-Agent'].split('/')[0] == 'curl'}`" }, "action": { "return": 204 } }
Two things:
restrict variables to only support synchronous way.
Initially, variable query was designed to accomodate both synchronous and asynchronous operations. However, upon consideration of actual requirements, we recognized that asynchronous support was not needed.
This refactoring is intended to simplify the usage of variable queries and prepare for the subsequent feature of variable updating.
Add if option to match object to make matching scripting. For example: