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_prometheus_remote_write: added configurable compression method #7318

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
41 changes: 38 additions & 3 deletions plugins/out_prometheus_remote_write/remote_write.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,23 @@ static int http_post(struct prometheus_remote_write_context *ctx,
}

/* Map payload */
ret = flb_snappy_compress((void *) body, body_len,
(char **) &payload_buf,
&payload_size);

if (strcasecmp(ctx->compression, "snappy") == 0) {
ret = flb_snappy_compress((void *) body, body_len,
(char **) &payload_buf,
&payload_size);
}
else if (strcasecmp(ctx->compression, "gzip") == 0) {
ret = flb_gzip_compress((void *) body, body_len,
&payload_buf, &payload_size);
}
else {
payload_buf = body;
payload_size = body_len;

ret = 0;
}

if (ret != 0) {
flb_upstream_conn_release(u_conn);

Expand Down Expand Up @@ -105,6 +119,21 @@ static int http_post(struct prometheus_remote_write_context *ctx,
FLB_PROMETHEUS_REMOTE_WRITE_VERSION_LITERAL,
sizeof(FLB_PROMETHEUS_REMOTE_WRITE_VERSION_LITERAL) - 1);

if (strcasecmp(ctx->compression, "snappy") == 0) {
flb_http_add_header(c,
"Content-Encoding",
strlen("Content-Encoding"),
"snappy",
strlen("snappy"));
}
else if (strcasecmp(ctx->compression, "gzip") == 0) {
flb_http_add_header(c,
"Content-Encoding",
strlen("Content-Encoding"),
"gzip",
strlen("gzip"));
}

/* Basic Auth headers */
if (ctx->http_user && ctx->http_passwd) {
flb_http_basic_auth(c, ctx->http_user, ctx->http_passwd);
Expand Down Expand Up @@ -366,6 +395,12 @@ 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_STR, "compression", "snappy",
0, FLB_TRUE, offsetof(struct prometheus_remote_write_context, compression),
"Compress the payload with either snappy, gzip if set"
},

#ifdef FLB_HAVE_SIGNV4
#ifdef FLB_HAVE_AWS
{
Expand Down
2 changes: 2 additions & 0 deletions plugins/out_prometheus_remote_write/remote_write.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ struct prometheus_remote_write_context {
char *host;
int port;

const char *compression;

/* Log the response paylod */
int log_response_payload;

Expand Down