Skip to content

Commit db8487d

Browse files
authored
out_loki: add ability to add arbitrary http headers and adjust the URI path (#7979)
Following the pattern from prometheus_remote_write, this adds the option to add arbitrary HTTP headers. Tested against a Loki endpoint and logging reverse proxy. Signed-off-by: Alan Richards <alarobric@gmail.com>
1 parent cf4db83 commit db8487d

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

plugins/out_loki/loki.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1515,6 +1515,10 @@ static void cb_loki_flush(struct flb_event_chunk *event_chunk,
15151515
struct flb_connection *u_conn;
15161516
struct flb_http_client *c;
15171517
struct flb_loki_dynamic_tenant_id_entry *dynamic_tenant_id;
1518+
struct mk_list *head;
1519+
struct flb_config_map_val *mv;
1520+
struct flb_slist_entry *key = NULL;
1521+
struct flb_slist_entry *val = NULL;
15181522

15191523
dynamic_tenant_id = FLB_TLS_GET(thread_local_tenant_id);
15201524

@@ -1604,6 +1608,16 @@ static void cb_loki_flush(struct flb_event_chunk *event_chunk,
16041608
flb_http_bearer_auth(c, ctx->bearer_token);
16051609
}
16061610

1611+
/* Arbitrary additional headers */
1612+
flb_config_map_foreach(head, mv, ctx->headers) {
1613+
key = mk_list_entry_first(mv->val.list, struct flb_slist_entry, _head);
1614+
val = mk_list_entry_last(mv->val.list, struct flb_slist_entry, _head);
1615+
1616+
flb_http_add_header(c,
1617+
key->str, flb_sds_len(key->str),
1618+
val->str, flb_sds_len(val->str));
1619+
}
1620+
16071621
/* Add Content-Type header */
16081622
flb_http_add_header(c,
16091623
FLB_LOKI_CT, sizeof(FLB_LOKI_CT) - 1,
@@ -1812,6 +1826,12 @@ static struct flb_config_map config_map[] = {
18121826
"Set bearer token auth"
18131827
},
18141828

1829+
{
1830+
FLB_CONFIG_MAP_SLIST_1, "header", NULL,
1831+
FLB_CONFIG_MAP_MULT, FLB_TRUE, offsetof(struct flb_loki, headers),
1832+
"Add a HTTP header key/value pair. Multiple headers can be set"
1833+
},
1834+
18151835
{
18161836
FLB_CONFIG_MAP_STR, "compress", NULL,
18171837
0, FLB_FALSE, 0,

plugins/out_loki/loki.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ struct flb_loki {
9595

9696
/* Plugin instance */
9797
struct flb_output_instance *ins;
98+
99+
/* Arbitrary HTTP headers */
100+
struct mk_list *headers;
98101
};
99102

100103
#endif

0 commit comments

Comments
 (0)