Skip to content

Commit 2b025d9

Browse files
committed
apply suggestions
1 parent 28bf785 commit 2b025d9

File tree

3 files changed

+21
-22
lines changed

3 files changed

+21
-22
lines changed

src/ngx_http_apisix_module.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ static ngx_command_t ngx_http_apisix_cmds[] = {
4141
offsetof(ngx_http_apisix_loc_conf_t, delay_client_max_body_check),
4242
NULL },
4343
{
44-
ngx_string("apisix_request_id_var"),
44+
ngx_string("lua_error_log_request_id"),
4545
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
4646
ngx_http_apisix_error_log_request_id,
4747
NGX_HTTP_LOC_CONF_OFFSET,
48-
offsetof(ngx_http_apisix_loc_conf_t, request_id_var_index),
48+
offsetof(ngx_http_apisix_loc_conf_t, apisix_request_id_var_index),
4949
NULL
5050
},
5151
ngx_null_command
@@ -112,7 +112,7 @@ ngx_http_apisix_create_loc_conf(ngx_conf_t *cf)
112112
}
113113

114114
conf->delay_client_max_body_check = NGX_CONF_UNSET;
115-
conf->request_id_var_index = NGX_CONF_UNSET;
115+
conf->apisix_request_id_var_index = NGX_CONF_UNSET;
116116
return conf;
117117
}
118118

@@ -123,7 +123,7 @@ ngx_http_apisix_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
123123
ngx_http_apisix_loc_conf_t *prev = parent;
124124
ngx_http_apisix_loc_conf_t *conf = child;
125125

126-
ngx_conf_merge_value(conf->request_id_var_index, prev->request_id_var_index, NGX_CONF_UNSET);
126+
ngx_conf_merge_value(conf->apisix_request_id_var_index, prev->apisix_request_id_var_index, NGX_CONF_UNSET);
127127
ngx_conf_merge_value(conf->delay_client_max_body_check,
128128
prev->delay_client_max_body_check, 0);
129129

@@ -843,7 +843,7 @@ ngx_http_apisix_is_ntls_enabled(ngx_http_conf_ctx_t *conf_ctx)
843843
/*
844844
* This function contains the logic to append the Request ID to
845845
* the error log line when being called.
846-
* Get the location configuration from helper function. Find indexed variable with the loc_conf->request_id_var_index. and add that to buffer.
846+
* Get the location configuration from helper function. Find indexed variable with the loc_conf->apisix_request_id_var_index. and add that to buffer.
847847
*/
848848
static u_char*
849849
ngx_http_apisix_error_log_handler(ngx_http_request_t *r, u_char *buf, size_t len)
@@ -852,11 +852,11 @@ ngx_http_apisix_error_log_handler(ngx_http_request_t *r, u_char *buf, size_t len
852852
ngx_http_apisix_loc_conf_t *loc_conf;
853853

854854
loc_conf = ngx_http_get_module_loc_conf(r, ngx_http_apisix_module);
855-
if (loc_conf->request_id_var_index == NGX_CONF_UNSET) {
855+
if (loc_conf->apisix_request_id_var_index == NGX_CONF_UNSET) {
856856
return buf;
857857
}
858858

859-
request_id_var = ngx_http_get_indexed_variable(r, loc_conf->request_id_var_index);
859+
request_id_var = ngx_http_get_indexed_variable(r, loc_conf->apisix_request_id_var_index);
860860
if (request_id_var == NULL || request_id_var->not_found) {
861861
return buf;
862862
}
@@ -959,8 +959,8 @@ ngx_http_apisix_error_log_request_id(ngx_conf_t *cf, ngx_command_t *cmd, void *c
959959
value[1].len--;
960960
value[1].data++;
961961

962-
loc_conf->request_id_var_index = ngx_http_get_variable_index(cf, &value[1]);
963-
if (loc_conf->request_id_var_index == NGX_ERROR) {
962+
loc_conf->apisix_request_id_var_index = ngx_http_get_variable_index(cf, &value[1]);
963+
if (loc_conf->apisix_request_id_var_index == NGX_ERROR) {
964964
return NGX_CONF_ERROR;
965965
}
966966

src/ngx_http_apisix_module.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
typedef struct {
88
ngx_flag_t delay_client_max_body_check;
9-
ngx_int_t request_id_var_index;
9+
ngx_int_t apisix_request_id_var_index;
1010

1111
} ngx_http_apisix_loc_conf_t;
1212

t/request-id-err-log.t

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ __DATA__
77
=== TEST 1: request_id in error log set
88
--- config
99
location /t {
10-
set $request_id_new 1234;
11-
apisix_request_id_var $request_id_new;
10+
set $request_id_new 1234;
11+
lua_error_log_request_id $request_id_new;
1212
content_by_lua_block {
1313
ngx.log(ngx.INFO, "log_msg")
1414
ngx.exit(200)
@@ -28,8 +28,8 @@ qr/log_msg.*request_id: "1234"$/
2828
=== TEST 2: request_id in error log set when a runtime error occurs
2929
--- config
3030
location /t {
31-
set $request_id_new 1234;
32-
apisix_request_id_var $request_id_new;
31+
set $request_id_new 1234;
32+
lua_error_log_request_id $request_id_new;
3333
content_by_lua_block {
3434
error("error_message")
3535
}
@@ -46,16 +46,15 @@ qr/.*request_id: "1234".*$/
4646
--- config
4747
location = /append_method {
4848
set $req_id_b 654321;
49-
apisix_request_id_var $req_id_b;
50-
49+
lua_error_log_request_id $req_id_b;
5150
content_by_lua_block {
5251
ngx.log(ngx.INFO, "log_msg")
5352
ngx.exit(200)
5453
}
5554
}
5655
location = /append_req_id {
5756
set $req_id_a 123456;
58-
apisix_request_id_var $req_id_a;
57+
lua_error_log_request_id $req_id_a;
5958
content_by_lua_block {
6059
ngx.log(ngx.INFO, "log_msg")
6160
ngx.exit(200)
@@ -88,7 +87,7 @@ qr/log_msg.*request_id: "123456"$/
8887
--- config
8988
location /append {
9089
set $req_id 123456;
91-
apisix_request_id_var $req_id;
90+
lua_error_log_request_id $req_id;
9291
content_by_lua_block {
9392
ngx.log(ngx.ERR, "log_msg")
9493
ngx.exit(200)
@@ -110,7 +109,7 @@ qr/log_msg.*request_id/
110109

111110
=== TEST 6: scoping: value is appended correctly to error logs when the directive is in the main configuration
112111
--- http_config
113-
apisix_request_id_var $req_id;
112+
lua_error_log_request_id $req_id;
114113
--- config
115114
set $req_id 123456;
116115
location = /test {
@@ -133,13 +132,13 @@ qr/log_msg.*request_id: "123456"$/
133132

134133
=== TEST 7: scoping: value is appended correctly to error logs and the local directive overrides the global one
135134
--- http_config
136-
apisix_request_id_var $req_id_global;
135+
lua_error_log_request_id $req_id_global;
137136
--- config
138137
set $req_id_global global;
139138
set $req_id_local local;
140139

141140
location = /test {
142-
apisix_request_id_var $req_id_local;
141+
lua_error_log_request_id $req_id_local;
143142
content_by_lua_block {
144143
ngx.log(ngx.INFO, "log_msg")
145144
ngx.exit(200)
@@ -159,7 +158,7 @@ qr/log_msg.*request_id: "global"$/
159158
--- config
160159
location = /test {
161160
set $my_var "";
162-
apisix_request_id_var $my_var;
161+
lua_error_log_request_id $my_var;
163162
rewrite_by_lua_block {
164163
ngx.log(ngx.INFO, "rewrite_0")
165164
ngx.var.my_var = "changed_in_rewrite"

0 commit comments

Comments
 (0)