From c604b74e0adc53c1f8497fccb57f1e0ef1fe2142 Mon Sep 17 00:00:00 2001 From: Hiroshi Hatake Date: Tue, 6 Feb 2024 13:42:10 +0900 Subject: [PATCH 1/2] reload: Mark hot reloading for the old context Signed-off-by: Hiroshi Hatake --- src/flb_reload.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/flb_reload.c b/src/flb_reload.c index 869a34a1801..2e6c4d6572c 100644 --- a/src/flb_reload.c +++ b/src/flb_reload.c @@ -446,6 +446,8 @@ int flb_reload(flb_ctx_t *ctx, struct flb_cf *cf_opts) ctx->config->shutdown_by_hot_reloading = FLB_TRUE; /* Mark hot reloading */ new_config->hot_reloading = FLB_TRUE; + /* Mark hot reloading for old ctx to prevent duplicated request via HTTP */ + old_config->hot_reloading = FLB_TRUE; #ifdef FLB_HAVE_STREAM_PROCESSOR /* Inherit stream processor definitions from command line */ From e4a572140c33f747fce72fbcac92dba78de59629 Mon Sep 17 00:00:00 2001 From: Hiroshi Hatake Date: Tue, 6 Feb 2024 13:42:51 +0900 Subject: [PATCH 2/2] api: v2: reload: Distinguish the status of hot reloading Signed-off-by: Hiroshi Hatake --- src/http_server/api/v2/reload.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/http_server/api/v2/reload.c b/src/http_server/api/v2/reload.c index d8ac42ff224..2f8c947cbd9 100644 --- a/src/http_server/api/v2/reload.c +++ b/src/http_server/api/v2/reload.c @@ -40,6 +40,7 @@ static void handle_reload_request(mk_request_t *request, struct flb_config *conf size_t out_size; msgpack_packer mp_pck; msgpack_sbuffer mp_sbuf; + int http_status = 200; /* initialize buffers */ msgpack_sbuffer_init(&mp_sbuf); @@ -57,6 +58,14 @@ static void handle_reload_request(mk_request_t *request, struct flb_config *conf msgpack_pack_str_body(&mp_pck, "status", 6); msgpack_pack_int64(&mp_pck, -1); } + else if (config->hot_reloading == FLB_TRUE) { + msgpack_pack_str(&mp_pck, 11); + msgpack_pack_str_body(&mp_pck, "in progress", 11); + msgpack_pack_str(&mp_pck, 6); + msgpack_pack_str_body(&mp_pck, "status", 6); + msgpack_pack_int64(&mp_pck, -2); + http_status = 400; + } else { ret = GenerateConsoleCtrlEvent(1 /* CTRL_BREAK_EVENT_1 */, 0); if (ret == 0) { @@ -79,6 +88,14 @@ static void handle_reload_request(mk_request_t *request, struct flb_config *conf msgpack_pack_str_body(&mp_pck, "status", 6); msgpack_pack_int64(&mp_pck, -1); } + else if (config->hot_reloading == FLB_TRUE) { + msgpack_pack_str(&mp_pck, 11); + msgpack_pack_str_body(&mp_pck, "in progress", 11); + msgpack_pack_str(&mp_pck, 6); + msgpack_pack_str_body(&mp_pck, "status", 6); + msgpack_pack_int64(&mp_pck, -2); + http_status = 400; + } else { ret = kill(getpid(), SIGHUP); if (ret != 0) { @@ -106,7 +123,7 @@ static void handle_reload_request(mk_request_t *request, struct flb_config *conf } out_size = flb_sds_len(out_buf); - mk_http_status(request, 200); + mk_http_status(request, http_status); flb_hs_add_content_type_to_req(request, FLB_HS_CONTENT_TYPE_JSON); mk_http_send(request, out_buf, out_size, NULL); mk_http_done(request);