Skip to content

Commit

Permalink
out_datadog: custom added ability ot set custom HTTP headers
Browse files Browse the repository at this point in the history
Signed-off-by: Andrii Chubatiuk <[email protected]>
  • Loading branch information
AndrewChubatiuk committed Sep 28, 2024
1 parent 41b90b7 commit a8e2f63
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
19 changes: 18 additions & 1 deletion plugins/out_datadog/datadog.c
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,10 @@ static void cb_datadog_flush(struct flb_event_chunk *event_chunk,
size_t b_sent;
int ret = FLB_ERROR;
int compressed = FLB_FALSE;
struct mk_list *head;
struct flb_config_map_val *mv;
struct flb_slist_entry *key = NULL;
struct flb_slist_entry *val = NULL;

/* Get upstream connection */
upstream_conn = flb_upstream_conn_get(ctx->upstream);
Expand Down Expand Up @@ -427,7 +431,15 @@ static void cb_datadog_flush(struct flb_event_chunk *event_chunk,
if (compressed == FLB_TRUE) {
flb_http_set_content_encoding_gzip(client);
}
/* TODO: Append other headers if needed*/

flb_config_map_foreach(head, mv, ctx->headers) {
key = mk_list_entry_first(mv->val.list, struct flb_slist_entry, _head);
val = mk_list_entry_last(mv->val.list, struct flb_slist_entry, _head);

flb_http_add_header(client,
key->str, flb_sds_len(key->str),
val->str, flb_sds_len(val->str));
}

/* finaly send the query */
ret = flb_http_do(client, &b_sent);
Expand Down Expand Up @@ -493,6 +505,11 @@ static struct flb_config_map config_map[] = {
"compresses the payload in GZIP format, "
"Datadog supports and recommends setting this to 'gzip'."
},
{
FLB_CONFIG_MAP_SLIST_1, "header", NULL,
FLB_CONFIG_MAP_MULT, FLB_TRUE, offsetof(struct flb_out_datadog, headers),
"Add a HTTP header key/value pair. Multiple headers can be set"
},
{
FLB_CONFIG_MAP_STR, "apikey", NULL,
0, FLB_TRUE, offsetof(struct flb_out_datadog, api_key),
Expand Down
1 change: 1 addition & 0 deletions plugins/out_datadog/datadog.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ struct flb_out_datadog {
flb_sds_t api_key;
int include_tag_key;
flb_sds_t tag_key;
struct mk_list *headers;
bool remap;

/* final result */
Expand Down

0 comments on commit a8e2f63

Please sign in to comment.