Skip to content

Commit c9a3435

Browse files
committed
feat(log): add action and proxy response time to log
1 parent 93e0804 commit c9a3435

File tree

4 files changed

+14
-1
lines changed

4 files changed

+14
-1
lines changed

src/ngx_http_redirectionio_module.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,8 @@ static ngx_int_t ngx_http_redirectionio_create_ctx_handler(ngx_http_request_t *r
223223
ctx->response_headers = NULL;
224224
ctx->body_filter = NULL;
225225
ctx->action_string = NULL;
226+
ctx->action_match_time = 0;
227+
ctx->proxy_response_time = 0;
226228
ctx->action_string_len = 0;
227229
ctx->action_string_readed = 0;
228230
ctx->connection_error = 0;
@@ -716,6 +718,7 @@ static void ngx_http_redirectionio_read_match_action_handler(ngx_event_t *rev, c
716718
ngx_http_redirectionio_ctx_t *ctx;
717719
ngx_http_request_t *r;
718720
ngx_connection_t *c;
721+
ngx_time_t *tp;
719722

720723
c = rev->data;
721724
r = c->data;
@@ -733,6 +736,9 @@ static void ngx_http_redirectionio_read_match_action_handler(ngx_event_t *rev, c
733736

734737
ctx->action = (struct REDIRECTIONIO_Action *)redirectionio_action_json_deserialize((char *)action_serialized);
735738

739+
tp = ngx_timeofday();
740+
ctx->action_match_time = (tp->sec * 1000 + tp->msec);
741+
736742
ngx_http_core_run_phases(r);
737743
}
738744

src/ngx_http_redirectionio_module.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ typedef struct {
8282
struct REDIRECTIONIO_Action *action;
8383
struct REDIRECTIONIO_HeaderMap *response_headers;
8484
struct REDIRECTIONIO_FilterBodyAction *body_filter;
85+
ngx_uint_t action_match_time;
86+
ngx_uint_t proxy_response_time;
8587
ngx_uint_t backend_response_status_code;
8688

8789
ngx_uint_t connection_error;

src/ngx_http_redirectionio_module_filter.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ ngx_int_t ngx_http_redirectionio_headers_filter(ngx_http_request_t *r) {
194194

195195
static ngx_int_t ngx_http_redirectionio_create_filter_body(ngx_http_request_t *r) {
196196
ngx_http_redirectionio_ctx_t *ctx;
197+
ngx_time_t *tp;
197198

198199
ctx = ngx_http_get_module_ctx(r, ngx_http_redirectionio_module);
199200

@@ -213,6 +214,10 @@ static ngx_int_t ngx_http_redirectionio_create_filter_body(ngx_http_request_t *r
213214
r->headers_out.content_length_n = -1;
214215
}
215216

217+
// Save proxy response time
218+
tp = ngx_timeofday();
219+
ctx->proxy_response_time = (tp->sec * 1000 + tp->msec);
220+
216221
return ngx_http_next_header_filter(r);
217222
}
218223

src/ngx_http_redirectionio_protocol.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ ngx_http_redirectionio_log_t* ngx_http_redirectionio_protocol_create_log(ngx_htt
186186
ngx_http_redirectionio_log_t *log;
187187

188188
client_ip = ngx_http_redirectionio_str_to_char(&r->connection->addr_text, r->pool);
189-
log_serialized = redirectionio_api_create_log_in_json(ctx->request, r->headers_out.status, ctx->response_headers, ctx->action, PROXY_VERSION_STR(PROXY_VERSION), time, client_ip);
189+
log_serialized = redirectionio_api_create_log_in_json(ctx->request, r->headers_out.status, ctx->response_headers, ctx->action, PROXY_VERSION_STR(PROXY_VERSION), time, ctx->action_match_time, ctx->proxy_response_time, client_ip);
190190

191191
if (log_serialized == NULL) {
192192
return NULL;

0 commit comments

Comments
 (0)