Skip to content

Commit b8881fe

Browse files
out_kinesis_streams: add compression_level option
Allow tuning the record compression level (honored for zstd; other codecs keep their built-in default). The plugin previously compressed zstd at a hardcoded level 1 with no way to trade CPU for ratio, which matters for high-volume streams where per-record compression is the dominant cost lever. Defaults preserve existing behavior; setting compression_level without compression is a configuration error. Signed-off-by: Ivan Bushmarinov <ivan.bushmarinov@perplexity.ai>
1 parent 8b0ca6f commit b8881fe

3 files changed

Lines changed: 26 additions & 2 deletions

File tree

plugins/out_kinesis_streams/kinesis.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,17 @@ static int cb_kinesis_init(struct flb_output_instance *ins,
160160
ctx->compression = FLB_AWS_COMPRESS_NONE;
161161
}
162162

163+
ctx->compression_level = FLB_AWS_COMPRESS_LEVEL_DEFAULT;
164+
tmp = flb_output_get_property("compression_level", ins);
165+
if (tmp) {
166+
if (ctx->compression == FLB_AWS_COMPRESS_NONE) {
167+
flb_plg_error(ctx->ins,
168+
"compression_level requires compression to be set");
169+
goto error;
170+
}
171+
ctx->compression_level = atoi(tmp);
172+
}
173+
163174
tmp = flb_output_get_property("region", ins);
164175
if (tmp) {
165176
ctx->region = tmp;
@@ -544,6 +555,15 @@ static struct flb_config_map config_map[] = {
544555
"Defaults to no compression."
545556
},
546557

558+
{
559+
FLB_CONFIG_MAP_INT, "compression_level", "-1",
560+
0, FLB_FALSE, 0,
561+
"Compression level for the configured 'compression' type. Currently honored "
562+
"for 'zstd' only (valid levels follow the linked zstd library, typically "
563+
"-131072..22); other codecs use their built-in default and log a warning. "
564+
"Defaults to the codec's built-in default (zstd: 1)."
565+
},
566+
547567
/* EOF */
548568
{0}
549569
};

plugins/out_kinesis_streams/kinesis.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ struct flb_kinesis {
9999
int retry_requests;
100100
int simple_aggregation;
101101
int compression;
102+
/* FLB_AWS_COMPRESS_LEVEL_DEFAULT unless compression_level is set */
103+
int compression_level;
102104
char *sts_endpoint;
103105
int custom_endpoint;
104106
uint16_t port;

plugins/out_kinesis_streams/kinesis_api.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,8 @@ static int process_event(struct flb_kinesis *ctx, struct flush *buf,
390390
void *compressed_buf = NULL;
391391
size_t compressed_size = 0;
392392

393-
ret = flb_aws_compression_b64_truncate_compress(ctx->compression,
393+
ret = flb_aws_compression_b64_truncate_compress_level(ctx->compression,
394+
ctx->compression_level,
394395
MAX_B64_EVENT_SIZE,
395396
tmp_buf_ptr,
396397
written,
@@ -464,7 +465,8 @@ static int send_aggregated_record(struct flb_kinesis *ctx, struct flush *buf) {
464465
void *compressed_buf = NULL;
465466
size_t compressed_size = 0;
466467

467-
ret = flb_aws_compression_b64_truncate_compress(ctx->compression,
468+
ret = flb_aws_compression_b64_truncate_compress_level(ctx->compression,
469+
ctx->compression_level,
468470
MAX_B64_EVENT_SIZE,
469471
buf->agg_buf.agg_buf,
470472
agg_size,

0 commit comments

Comments
 (0)