Skip to content

Commit 5686334

Browse files
author
leonardo-albertovich
authored
in_prometheus_scrape: added authorization support (#7785)
Signed-off-by: Leonardo Alminana <[email protected]>
1 parent f114e3a commit 5686334

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

plugins/in_prometheus_scrape/prom_scrape.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,13 @@ static int collect_metrics(struct prom_scrape *ctx)
100100

101101
flb_http_buffer_size(c, ctx->buffer_max_size);
102102

103+
/* Auth headers */
104+
if (ctx->http_user && ctx->http_passwd) { /* Basic */
105+
flb_http_basic_auth(c, ctx->http_user, ctx->http_passwd);
106+
} else if (ctx->bearer_token) { /* Bearer token */
107+
flb_http_bearer_auth(c, ctx->bearer_token);
108+
}
109+
103110
ret = flb_http_do(c, &b_sent);
104111
if (ret != 0) {
105112
flb_plg_error(ctx->ins, "http do error");
@@ -218,6 +225,24 @@ static struct flb_config_map config_map[] = {
218225
"Set the metrics URI endpoint, it must start with a forward slash."
219226
},
220227

228+
{
229+
FLB_CONFIG_MAP_STR, "http_user", NULL,
230+
0, FLB_TRUE, offsetof(struct prom_scrape, http_user),
231+
"Set HTTP auth user"
232+
},
233+
234+
{
235+
FLB_CONFIG_MAP_STR, "http_passwd", "",
236+
0, FLB_TRUE, offsetof(struct prom_scrape, http_passwd),
237+
"Set HTTP auth password"
238+
},
239+
240+
{
241+
FLB_CONFIG_MAP_STR, "bearer_token", NULL,
242+
0, FLB_TRUE, offsetof(struct prom_scrape, bearer_token),
243+
"Set bearer token auth"
244+
},
245+
221246
/* EOF */
222247
{0}
223248
};

plugins/in_prometheus_scrape/prom_scrape.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ struct prom_scrape
3333
struct flb_upstream *upstream;
3434
struct flb_input_instance *ins; /* input plugin instance */
3535
size_t buffer_max_size; /* Maximum buffer size */
36+
37+
/* HTTP Auth */
38+
flb_sds_t http_user;
39+
flb_sds_t http_passwd;
40+
41+
/* Bearer Token Auth */
42+
flb_sds_t bearer_token;
3643
};
3744

3845
#endif

0 commit comments

Comments
 (0)