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: Pass tag dynamically in header #475

Merged
merged 1 commit into from
May 18, 2018
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
out_http: Pass tag dynamically in header
Signed-off-by: Vinh <[email protected]>
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.
  • Loading branch information
brava-vinh committed May 18, 2018
commit b4e099562ba96a1af33c57f537c840acca4672a9
16 changes: 16 additions & 0 deletions plugins/out_http/http.c
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,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 @@ -411,6 +419,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 @@ -477,6 +492,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 @@ -54,6 +54,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