Skip to content

Commit

Permalink
out_http: Pass tag dynamically in header (#475)
Browse files Browse the repository at this point in the history
The http plugin currently not sending the message's tag. The in_http
plugin of Fluentd use the URI as tag. If we want to keep the original
tag then we have to define multipe output section per tag to map it to
URI. This change send the tag in a header(the headername can define in
config file), and it's up to the receiver to parse the header and
replace the tag.

Signed-off-by: Vinh <[email protected]>
  • Loading branch information
brava-vinh authored and edsiper committed May 21, 2018
1 parent 2ef7a8f commit 1238067
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
16 changes: 16 additions & 0 deletions plugins/out_http/http.c
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,14 @@ int cb_http_init(struct flb_output_instance *ins, struct flb_config *config,
}
}

/* Tag in header */
tmp = flb_output_get_property("header_tag", ins);
if (tmp) {
ctx->header_tag = flb_strdup(tmp);
ctx->headertag_len = strlen(ctx->header_tag);
flb_info("[out_http] configure to pass tag in header: %s", ctx->header_tag);
}

/* Output format */
ctx->out_format = FLB_HTTP_OUT_MSGPACK;
tmp = flb_output_get_property("format", ins);
Expand Down Expand Up @@ -425,6 +433,13 @@ void cb_http_flush(void *data, size_t bytes,
sizeof(FLB_HTTP_MIME_MSGPACK) - 1);
}

if (ctx->header_tag) {
flb_http_add_header(c,
ctx->header_tag,
ctx->headertag_len,
tag, tag_len);
}

if (ctx->http_user && ctx->http_passwd) {
flb_http_basic_auth(c, ctx->http_user, ctx->http_passwd);
}
Expand Down Expand Up @@ -493,6 +508,7 @@ int cb_http_exit(void *data, struct flb_config *config)
flb_free(ctx->proxy_host);
flb_free(ctx->uri);
flb_free(ctx->json_date_key);
flb_free(ctx->header_tag);
flb_free(ctx);

return 0;
Expand Down
4 changes: 4 additions & 0 deletions plugins/out_http/http.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ struct flb_out_http_config {
char *host;
int port;

/* Include tag in header */
char *header_tag;
size_t headertag_len;

/* Upstream connection to the backend server */
struct flb_upstream *u;
};
Expand Down

0 comments on commit 1238067

Please sign in to comment.