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

out_http: Allow disabling http 2xx logs #9987

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
30 changes: 20 additions & 10 deletions plugins/out_http/http.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
}
Expand Down Expand Up @@ -591,6 +593,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) {
Expand All @@ -599,6 +603,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) {
Expand Down Expand Up @@ -649,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),
Expand Down
3 changes: 3 additions & 0 deletions plugins/out_http/http.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
4 changes: 4 additions & 0 deletions plugins/out_http/http_conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading