Skip to content

Commit

Permalink
out_loki: add ability to add arbitrary http headers and adjust the UR…
Browse files Browse the repository at this point in the history
…I 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 <[email protected]>
  • Loading branch information
alarobric authored Nov 8, 2023
1 parent cf4db83 commit db8487d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
20 changes: 20 additions & 0 deletions plugins/out_loki/loki.c
Original file line number Diff line number Diff line change
Expand Up @@ -1515,6 +1515,10 @@ static void cb_loki_flush(struct flb_event_chunk *event_chunk,
struct flb_connection *u_conn;
struct flb_http_client *c;
struct flb_loki_dynamic_tenant_id_entry *dynamic_tenant_id;
struct mk_list *head;
struct flb_config_map_val *mv;
struct flb_slist_entry *key = NULL;
struct flb_slist_entry *val = NULL;

dynamic_tenant_id = FLB_TLS_GET(thread_local_tenant_id);

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

/* Arbitrary additional headers */
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(c,
key->str, flb_sds_len(key->str),
val->str, flb_sds_len(val->str));
}

/* Add Content-Type header */
flb_http_add_header(c,
FLB_LOKI_CT, sizeof(FLB_LOKI_CT) - 1,
Expand Down Expand Up @@ -1812,6 +1826,12 @@ static struct flb_config_map config_map[] = {
"Set bearer token auth"
},

{
FLB_CONFIG_MAP_SLIST_1, "header", NULL,
FLB_CONFIG_MAP_MULT, FLB_TRUE, offsetof(struct flb_loki, headers),
"Add a HTTP header key/value pair. Multiple headers can be set"
},

{
FLB_CONFIG_MAP_STR, "compress", NULL,
0, FLB_FALSE, 0,
Expand Down
3 changes: 3 additions & 0 deletions plugins/out_loki/loki.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ struct flb_loki {

/* Plugin instance */
struct flb_output_instance *ins;

/* Arbitrary HTTP headers */
struct mk_list *headers;
};

#endif

0 comments on commit db8487d

Please sign in to comment.