Skip to content
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

api: v2: reload: Prevent duplicated request via api v2 reload #8461

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/flb_reload.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
19 changes: 18 additions & 1 deletion src/http_server/api/v2/reload.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down
Loading