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_loki: add ability to add arbitrary http headers and adjust the URI path #7979

Merged
merged 1 commit into from
Nov 8, 2023
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
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
Loading