2424#include <fluent-bit/flb_pack.h>
2525#include <fluent-bit/flb_config_map.h>
2626#include <fluent-bit/flb_gzip.h>
27+ #include <fluent-bit/flb_compression.h>
28+ #include <fluent-bit/flb_zstd.h>
2729#include <fluent-bit/flb_base64.h>
2830#include <fluent-bit/flb_sqldb.h>
2931#include <fluent-bit/flb_input_blob.h>
@@ -136,7 +138,7 @@ static int construct_request_buffer(struct flb_azure_blob *ctx, flb_sds_t new_da
136138 }
137139 body = buffered_data = tmp ;
138140 memcpy (body + buffer_size , new_data , flb_sds_len (new_data ));
139- if (ctx -> compress_gzip == FLB_FALSE ) {
141+ if (ctx -> compression == FLB_COMPRESSION_ALGORITHM_NONE ) {
140142 body [body_size ] = '\0' ;
141143 }
142144 }
@@ -149,6 +151,38 @@ static int construct_request_buffer(struct flb_azure_blob *ctx, flb_sds_t new_da
149151 return 0 ;
150152}
151153
154+ /*
155+ * Compress a payload using the configured algorithm. Returns 0 on success and
156+ * negative on failure so callers can gracefully fall back to sending the raw
157+ * payload.
158+ */
159+ static int azure_blob_compress_payload (int algorithm ,
160+ void * in_data , size_t in_len ,
161+ void * * out_data , size_t * out_len )
162+ {
163+ if (algorithm == FLB_COMPRESSION_ALGORITHM_GZIP ) {
164+ return flb_gzip_compress (in_data , in_len , out_data , out_len );
165+ }
166+ else if (algorithm == FLB_COMPRESSION_ALGORITHM_ZSTD ) {
167+ return flb_zstd_compress (in_data , in_len , out_data , out_len );
168+ }
169+
170+ return -1 ;
171+ }
172+
173+ /* Map a compression algorithm to its human-friendly label for logs. */
174+ static const char * azure_blob_compression_name (int algorithm )
175+ {
176+ if (algorithm == FLB_COMPRESSION_ALGORITHM_GZIP ) {
177+ return "gzip" ;
178+ }
179+ else if (algorithm == FLB_COMPRESSION_ALGORITHM_ZSTD ) {
180+ return "zstd" ;
181+ }
182+
183+ return "unknown" ;
184+ }
185+
152186void generate_random_string_blob (char * str , size_t length )
153187{
154188 const char charset [] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" ;
@@ -332,8 +366,12 @@ static int http_send_blob(struct flb_config *config, struct flb_azure_blob *ctx,
332366{
333367 int ret ;
334368 int compressed = FLB_FALSE ;
335- int content_encoding = FLB_FALSE ;
336- int content_type = FLB_FALSE ;
369+ int content_encoding = AZURE_BLOB_CE_NONE ;
370+ int content_type = AZURE_BLOB_CT_NONE ;
371+ int compression_algorithm = FLB_COMPRESSION_ALGORITHM_NONE ;
372+ int network_compression_algorithm = ctx -> compression ;
373+ int network_compression_applied = FLB_FALSE ;
374+ int blob_compression_applied = FLB_FALSE ;
337375 size_t b_sent ;
338376 void * payload_buf ;
339377 size_t payload_size ;
@@ -358,27 +396,62 @@ static int http_send_blob(struct flb_config *config, struct flb_azure_blob *ctx,
358396 payload_buf = data ;
359397 payload_size = bytes ;
360398
399+ /* Determine compression algorithm */
400+ if (network_compression_algorithm != FLB_COMPRESSION_ALGORITHM_NONE ) {
401+ compression_algorithm = network_compression_algorithm ;
402+ }
403+
404+ if (ctx -> compress_blob == FLB_TRUE ) {
405+ if (compression_algorithm == FLB_COMPRESSION_ALGORITHM_NONE ) {
406+ compression_algorithm = FLB_COMPRESSION_ALGORITHM_GZIP ;
407+ }
408+ }
409+
361410 /* Handle compression requests */
362- if (ctx -> compress_gzip == FLB_TRUE || ctx -> compress_blob == FLB_TRUE ) {
363- ret = flb_gzip_compress ((void * ) data , bytes , & payload_buf , & payload_size );
411+ if (compression_algorithm != FLB_COMPRESSION_ALGORITHM_NONE ) {
412+ ret = azure_blob_compress_payload (compression_algorithm ,
413+ (void * ) data , bytes ,
414+ & payload_buf , & payload_size );
364415 if (ret == 0 ) {
365416 compressed = FLB_TRUE ;
417+ if (network_compression_algorithm != FLB_COMPRESSION_ALGORITHM_NONE ) {
418+ network_compression_applied = FLB_TRUE ;
419+ }
420+ if (ctx -> compress_blob == FLB_TRUE ) {
421+ blob_compression_applied = FLB_TRUE ;
422+ }
366423 }
367424 else {
425+ const char * alg_name ;
426+
427+ alg_name = azure_blob_compression_name (compression_algorithm );
368428 flb_plg_warn (ctx -> ins ,
369- "cannot gzip payload, disabling compression" );
429+ "cannot %s payload, disabling compression" ,
430+ alg_name );
370431 payload_buf = data ;
371432 payload_size = bytes ;
433+ compression_algorithm = FLB_COMPRESSION_ALGORITHM_NONE ;
372434 }
373435 }
374436
375437 /* set http header flags */
376- if (ctx -> compress_blob == FLB_TRUE ) {
438+ if (blob_compression_applied == FLB_TRUE ) {
377439 content_encoding = AZURE_BLOB_CE_NONE ;
378- content_type = AZURE_BLOB_CT_GZIP ;
440+
441+ if (compression_algorithm == FLB_COMPRESSION_ALGORITHM_ZSTD ) {
442+ content_type = AZURE_BLOB_CT_ZSTD ;
443+ }
444+ else {
445+ content_type = AZURE_BLOB_CT_GZIP ;
446+ }
379447 }
380- else if (compressed == FLB_TRUE ) {
381- content_encoding = AZURE_BLOB_CE_GZIP ;
448+ else if (network_compression_applied == FLB_TRUE ) {
449+ if (network_compression_algorithm == FLB_COMPRESSION_ALGORITHM_GZIP ) {
450+ content_encoding = AZURE_BLOB_CE_GZIP ;
451+ }
452+ else if (network_compression_algorithm == FLB_COMPRESSION_ALGORITHM_ZSTD ) {
453+ content_encoding = AZURE_BLOB_CE_ZSTD ;
454+ }
382455 content_type = AZURE_BLOB_CT_JSON ;
383456 }
384457
@@ -1783,14 +1856,15 @@ static struct flb_config_map config_map[] = {
17831856 {
17841857 FLB_CONFIG_MAP_STR , "compress" , NULL ,
17851858 0 , FLB_FALSE , 0 ,
1786- "Set payload compression in network transfer. Option available is 'gzip'"
1859+ "Set payload compression in network transfer. Options: 'gzip', 'zstd '"
17871860 },
17881861
17891862 {
17901863 FLB_CONFIG_MAP_BOOL , "compress_blob" , "false" ,
17911864 0 , FLB_TRUE , offsetof(struct flb_azure_blob , compress_blob ),
1792- "Enable block blob GZIP compression in the final blob file. This option is "
1793- "not compatible with 'appendblob' block type"
1865+ "Enable block blob compression in the final blob file (defaults to gzip, "
1866+ "uses the 'compress' codec when set). This option is not compatible with "
1867+ "'appendblob' block type"
17941868 },
17951869
17961870 {
0 commit comments