Skip to content

Commit

Permalink
out_prometheus_remote_write : Added headers
Browse files Browse the repository at this point in the history
Added optional headers to the prometheus remote write
plugin.

Signed-off-by: Leonardo Alminana <[email protected]>
  • Loading branch information
leonardo-albertovich authored and edsiper committed Jul 19, 2021
1 parent d3d78a0 commit 5ec75e3
Show file tree
Hide file tree
Showing 4 changed files with 281 additions and 260 deletions.
18 changes: 18 additions & 0 deletions plugins/out_prometheus_remote_write/remote_write.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ static int http_post(struct prometheus_remote_write_context *ctx,
struct flb_upstream *u;
struct flb_upstream_conn *u_conn;
struct flb_http_client *c;
struct mk_list *head;
struct flb_config_map_val *mv;
struct flb_slist_entry *key = NULL;
struct flb_slist_entry *val = NULL;

/* Get upstream context and connection */
u = ctx->u;
Expand Down Expand Up @@ -102,6 +106,15 @@ static int http_post(struct prometheus_remote_write_context *ctx,

flb_http_add_header(c, "User-Agent", 10, "Fluent-Bit", 10);

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));
}

ret = flb_http_do(c, &b_sent);
if (ret == 0) {
/*
Expand Down Expand Up @@ -261,6 +274,11 @@ static struct flb_config_map config_map[] = {
0, FLB_TRUE, offsetof(struct prometheus_remote_write_context, http_passwd),
"Set HTTP auth password"
},
{
FLB_CONFIG_MAP_SLIST_1, "header", NULL,
FLB_CONFIG_MAP_MULT, FLB_TRUE, offsetof(struct prometheus_remote_write_context, headers),
"Add a HTTP header key/value pair. Multiple headers can be set"
},
{
FLB_CONFIG_MAP_STR, "uri", NULL,
0, FLB_TRUE, offsetof(struct prometheus_remote_write_context, uri),
Expand Down
117 changes: 60 additions & 57 deletions plugins/out_prometheus_remote_write/remote_write.h
Original file line number Diff line number Diff line change
@@ -1,57 +1,60 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */

/* Fluent Bit
* ==========
* Copyright (C) 2019-2021 The Fluent Bit Authors
* Copyright (C) 2015-2018 Treasure Data Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef FLB_PROMETHEUS_REMOTE_WRITE_H
#define FLB_PROMETHEUS_REMOTE_WRITE_H

#include <fluent-bit/flb_output_plugin.h>

#define FLB_PROMETHEUS_REMOTE_WRITE_CONTENT_TYPE_HEADER_NAME "Content-Type"
#define FLB_PROMETHEUS_REMOTE_WRITE_MIME_PROTOBUF_LITERAL "application/x-protobuf"
#define FLB_PROMETHEUS_REMOTE_WRITE_VERSION_HEADER_NAME "X-Prometheus-Remote-Write-Version"
#define FLB_PROMETHEUS_REMOTE_WRITE_VERSION_LITERAL "0.1.0"

/* Plugin context */
struct prometheus_remote_write_context {
/* HTTP Auth */
char *http_user;
char *http_passwd;

/* Proxy */
const char *proxy;
char *proxy_host;
int proxy_port;

/* HTTP URI */
char *uri;
char *host;
int port;

/* Log the response paylod */
int log_response_payload;

/* Upstream connection to the backend server */
struct flb_upstream *u;

/* instance context */
struct flb_output_instance *ins;
};

#endif
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */

/* Fluent Bit
* ==========
* Copyright (C) 2019-2021 The Fluent Bit Authors
* Copyright (C) 2015-2018 Treasure Data Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef FLB_PROMETHEUS_REMOTE_WRITE_H
#define FLB_PROMETHEUS_REMOTE_WRITE_H

#include <fluent-bit/flb_output_plugin.h>

#define FLB_PROMETHEUS_REMOTE_WRITE_CONTENT_TYPE_HEADER_NAME "Content-Type"
#define FLB_PROMETHEUS_REMOTE_WRITE_MIME_PROTOBUF_LITERAL "application/x-protobuf"
#define FLB_PROMETHEUS_REMOTE_WRITE_VERSION_HEADER_NAME "X-Prometheus-Remote-Write-Version"
#define FLB_PROMETHEUS_REMOTE_WRITE_VERSION_LITERAL "0.1.0"

/* Plugin context */
struct prometheus_remote_write_context {
/* HTTP Auth */
char *http_user;
char *http_passwd;

/* Proxy */
const char *proxy;
char *proxy_host;
int proxy_port;

/* HTTP URI */
char *uri;
char *host;
int port;

/* Log the response paylod */
int log_response_payload;

/* Upstream connection to the backend server */
struct flb_upstream *u;

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

/* instance context */
struct flb_output_instance *ins;
};

#endif
Loading

0 comments on commit 5ec75e3

Please sign in to comment.