From 00cd2e27352fd8bf24cb8e30ae6c47fb2547d96c Mon Sep 17 00:00:00 2001 From: Stewart Webb Date: Thu, 13 Feb 2025 13:44:47 +1100 Subject: [PATCH 1/2] out_http: add comments explaining two different output modes Signed-off-by: Stewart Webb --- plugins/out_http/http.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/plugins/out_http/http.c b/plugins/out_http/http.c index 4fa3d98615d..9620a1503b7 100644 --- a/plugins/out_http/http.c +++ b/plugins/out_http/http.c @@ -591,6 +591,8 @@ static void cb_http_flush(struct flb_event_chunk *event_chunk, (void) i_ins; if (ctx->body_key) { + /* If the HTTP body is pulled out of the record via a key, one POST + must be done per record */ ret = post_all_requests(ctx, event_chunk->data, event_chunk->size, ctx->body_key, ctx->headers_key, event_chunk); if (ret < 0) { @@ -599,6 +601,7 @@ static void cb_http_flush(struct flb_event_chunk *event_chunk, } } else { + /* Otherwise, the whole chunk can be POSTed */ ret = compose_payload(ctx, event_chunk->data, event_chunk->size, &out_body, &out_size); if (ret != FLB_OK) { From 28ec478ddfb240c10964ee9ebd364223373b20c9 Mon Sep 17 00:00:00 2001 From: Stewart Webb Date: Sat, 22 Feb 2025 12:15:00 +1100 Subject: [PATCH 2/2] out_http: add config option to allow disabling logging of HTTP 2xx successes In a busy system with lots of different tags/chunks being handled, this can get really noisy in usual operation Signed-off-by: Stewart Webb --- plugins/out_http/http.c | 27 +++++++++++++++++---------- plugins/out_http/http.h | 3 +++ plugins/out_http/http_conf.c | 4 ++++ 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/plugins/out_http/http.c b/plugins/out_http/http.c index 9620a1503b7..f5c60d7a71f 100644 --- a/plugins/out_http/http.c +++ b/plugins/out_http/http.c @@ -288,16 +288,18 @@ static int http_post(struct flb_out_http *ctx, } } else { - if (ctx->log_response_payload && - c->resp.payload && c->resp.payload_size > 0) { - flb_plg_info(ctx->ins, "%s:%i, HTTP status=%i\n%s", - ctx->host, ctx->port, - c->resp.status, c->resp.payload); - } - else { - flb_plg_info(ctx->ins, "%s:%i, HTTP status=%i", - ctx->host, ctx->port, - c->resp.status); + if (ctx->log_2xx_successes) { + if (ctx->log_response_payload && + c->resp.payload && c->resp.payload_size > 0) { + flb_plg_info(ctx->ins, "%s:%i, HTTP status=%i\n%s", + ctx->host, ctx->port, + c->resp.status, c->resp.payload); + } + else { + flb_plg_info(ctx->ins, "%s:%i, HTTP status=%i", + ctx->host, ctx->port, + c->resp.status); + } } } } @@ -652,6 +654,11 @@ static struct flb_config_map config_map[] = { 0, FLB_TRUE, offsetof(struct flb_out_http, log_response_payload), "Specify if the response paylod should be logged or not" }, + { + FLB_CONFIG_MAP_BOOL, "log_2xx_successes", "true", + 0, FLB_TRUE, offsetof(struct flb_out_http, log_2xx_successes), + "Specify if HTTP 2xx reponses should be logged or not" + }, { FLB_CONFIG_MAP_STR, "http_user", NULL, 0, FLB_TRUE, offsetof(struct flb_out_http, http_user), diff --git a/plugins/out_http/http.h b/plugins/out_http/http.h index ba588ac90ca..1f01a2c6120 100644 --- a/plugins/out_http/http.h +++ b/plugins/out_http/http.h @@ -92,6 +92,9 @@ struct flb_out_http { /* Log the response paylod */ int log_response_payload; + /* Whether 200 OK etc results should be logged or not */ + int log_2xx_successes; + /* Upstream connection to the backend server */ struct flb_upstream *u; diff --git a/plugins/out_http/http_conf.c b/plugins/out_http/http_conf.c index 906dd9301c7..778d1c421b0 100644 --- a/plugins/out_http/http_conf.c +++ b/plugins/out_http/http_conf.c @@ -88,6 +88,10 @@ struct flb_out_http *flb_http_conf_create(struct flb_output_instance *ins, } } + if (ctx->log_response_payload && !ctx->log_2xx_oks) { + flb_plg_warn(ctx->ins, "log_response_payload is enabled but log_2xx_oks is disabled - response payloads from 2xx reponses won't be logged"); + } + /* * Check if a Proxy have been set, if so the Upstream manager will use * the Proxy end-point and then we let the HTTP client know about it, so