diff --git a/plugins/out_loki/loki.c b/plugins/out_loki/loki.c index b10a4f1d306..19012da6da6 100644 --- a/plugins/out_loki/loki.c +++ b/plugins/out_loki/loki.c @@ -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); @@ -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, @@ -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, diff --git a/plugins/out_loki/loki.h b/plugins/out_loki/loki.h index 6d7e8c33741..5282ac31662 100644 --- a/plugins/out_loki/loki.h +++ b/plugins/out_loki/loki.h @@ -95,6 +95,9 @@ struct flb_loki { /* Plugin instance */ struct flb_output_instance *ins; + + /* Arbitrary HTTP headers */ + struct mk_list *headers; }; #endif